mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
global peer tests
This commit is contained in:
parent
eee968ce56
commit
e250628174
3 changed files with 20 additions and 1 deletions
10
SSU.cpp
10
SSU.cpp
|
@ -462,6 +462,16 @@ namespace transport
|
||||||
ScheduleIntroducersUpdateTimer ();
|
ScheduleIntroducersUpdateTimer ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSUServer::NewPeerTest (uint32_t nonce)
|
||||||
|
{
|
||||||
|
m_PeerTests[nonce] = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSUServer::PeerTestComplete (uint32_t nonce)
|
||||||
|
{
|
||||||
|
m_PeerTests.erase (nonce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
SSU.h
4
SSU.h
|
@ -53,6 +53,9 @@ namespace transport
|
||||||
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
||||||
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
||||||
|
|
||||||
|
void NewPeerTest (uint32_t nonce);
|
||||||
|
void PeerTestComplete (uint32_t nonce);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Run ();
|
void Run ();
|
||||||
|
@ -84,6 +87,7 @@ namespace transport
|
||||||
std::mutex m_SessionsMutex;
|
std::mutex m_SessionsMutex;
|
||||||
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > m_Sessions;
|
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > m_Sessions;
|
||||||
std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer
|
std::map<uint32_t, boost::asio::ip::udp::endpoint> m_Relays; // we are introducer
|
||||||
|
std::map<uint32_t, uint64_t> m_PeerTests; // nonce -> creation time in milliseconds
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
|
|
|
@ -942,7 +942,10 @@ namespace transport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Alice");
|
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Alice");
|
||||||
|
m_Server.PeerTestComplete (nonce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -989,6 +992,7 @@ namespace transport
|
||||||
|
|
||||||
void SSUSession::SendPeerTest ()
|
void SSUSession::SendPeerTest ()
|
||||||
{
|
{
|
||||||
|
// we are Alice
|
||||||
LogPrint (eLogDebug, "SSU sending peer test");
|
LogPrint (eLogDebug, "SSU sending peer test");
|
||||||
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
|
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
|
||||||
if (!address)
|
if (!address)
|
||||||
|
@ -999,6 +1003,7 @@ namespace transport
|
||||||
uint32_t nonce = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
uint32_t nonce = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
if (!nonce) nonce = 1;
|
if (!nonce) nonce = 1;
|
||||||
m_PeerTestNonces.insert (nonce);
|
m_PeerTestNonces.insert (nonce);
|
||||||
|
m_Server.NewPeerTest (nonce);
|
||||||
SendPeerTest (nonce, 0, 0, address->key, false); // address and port always zero for Alice
|
SendPeerTest (nonce, 0, 0, address->key, false); // address and port always zero for Alice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue