From 03a5059617ea623e4b98fa085410e68f719e3266 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Apr 2014 19:28:06 -0400 Subject: [PATCH] peer test --- SSU.cpp | 25 +++++++++++++++---------- SSU.h | 5 +++-- Transports.cpp | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index 5ae377e2..36817a65 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -16,8 +16,9 @@ namespace ssu { SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, - const i2p::data::RouterInfo * router): m_Server (server), m_RemoteEndpoint (remoteEndpoint), - m_RemoteRouter (router), m_Timer (m_Server.GetService ()), m_State (eSessionStateUnknown) + const i2p::data::RouterInfo * router, bool peerTest ): + m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_RemoteRouter (router), + m_Timer (m_Server.GetService ()), m_PeerTest (peerTest), m_State (eSessionStateUnknown) { m_DHKeysPair = i2p::transports.GetNextDHKeysPair (); } @@ -170,7 +171,8 @@ namespace ssu break; } case PAYLOAD_TYPE_PEER_TEST: - // TODO + LogPrint ("SSU peer test received"); + // TODO: break; default: ; } @@ -541,7 +543,9 @@ namespace ssu for (auto it :m_DelayedMessages) Send (it); m_DelayedMessages.clear (); - } + } + if (m_PeerTest) + SendPeerTest (); } void SSUSession::Failed () @@ -730,6 +734,7 @@ namespace ssu void SSUSession::SendPeerTest () { + LogPrint ("SSU sending peer test"); auto address = i2p::context.GetRouterInfo ().GetSSUAddress (); if (!address) { @@ -937,7 +942,7 @@ namespace ssu return nullptr; } - SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router) + SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router, bool peerTest) { SSUSession * session = nullptr; if (router) @@ -955,10 +960,10 @@ namespace ssu if (!router->UsesIntroducer ()) { // connect directly - session = new SSUSession (*this, remoteEndpoint, router); + session = new SSUSession (*this, remoteEndpoint, router, peerTest); m_Sessions[remoteEndpoint] = session; - LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (), "] ", - remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port (), " created"); + LogPrint ("Creating new SSU session to [", router->GetIdentHashAbbreviation (), "] ", + remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port ()); session->Connect (); } else @@ -970,7 +975,7 @@ namespace ssu boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort); session = new SSUSession (*this, introducerEndpoint, router); m_Sessions[introducerEndpoint] = session; - LogPrint ("New SSU session to [", router->GetIdentHashAbbreviation (), + LogPrint ("Creating new SSU session to [", router->GetIdentHashAbbreviation (), "] through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ()); session->ConnectThroughIntroducer (introducer); } @@ -1013,7 +1018,7 @@ namespace ssu auto session = it->second; m_Sessions.erase (it); m_Sessions[newEndpoint] = session; - LogPrint ("SSU session ressigned from ", oldEndpoint.address ().to_string (), ":", oldEndpoint.port (), + LogPrint ("SSU session reassigned from ", oldEndpoint.address ().to_string (), ":", oldEndpoint.port (), " to ", newEndpoint.address ().to_string (), ":", newEndpoint.port ()); } } diff --git a/SSU.h b/SSU.h index b299d852..88e3dd45 100644 --- a/SSU.h +++ b/SSU.h @@ -72,7 +72,7 @@ namespace ssu public: SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, - const i2p::data::RouterInfo * router = nullptr); + const i2p::data::RouterInfo * router = nullptr, bool peerTest = false); void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); ~SSUSession (); @@ -122,6 +122,7 @@ namespace ssu const i2p::data::RouterInfo * m_RemoteRouter; boost::asio::deadline_timer m_Timer; i2p::data::DHKeysPair * m_DHKeysPair; // X - for client and Y - for server + bool m_PeerTest; SessionState m_State; CryptoPP::CBC_Mode::Encryption m_Encryption; CryptoPP::CBC_Mode::Decryption m_Decryption; @@ -138,7 +139,7 @@ namespace ssu ~SSUServer (); void Start (); void Stop (); - SSUSession * GetSession (const i2p::data::RouterInfo * router); + SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false); SSUSession * FindSession (const i2p::data::RouterInfo * router); void DeleteSession (SSUSession * session); void DeleteAllSessions (); diff --git a/Transports.cpp b/Transports.cpp index 9d86d605..a0c968d6 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -270,7 +270,7 @@ namespace i2p { auto router = i2p::data::netdb.GetRandomRouter (); if (router && router->IsSSU () && m_SSUServer) - m_SSUServer->GetSession (router); + m_SSUServer->GetSession (router, true); // peer test } if (m_Timer) {