try to find existing SSU session to introducer first

pull/81/head
orignal 10 years ago
parent 6ce3e41a70
commit a7406e03ab

@ -77,7 +77,7 @@ namespace ssu
if (m_State == eSessionStateIntroduced) if (m_State == eSessionStateIntroduced)
{ {
// HolePunch received // HolePunch received
LogPrint ("SSU HolePuch of ", len, " bytes received"); LogPrint ("SSU HolePunch of ", len, " bytes received");
m_State = eSessionStateUnknown; m_State = eSessionStateUnknown;
Connect (); Connect ();
} }
@ -151,6 +151,7 @@ namespace ssu
} }
case PAYLOAD_TYPE_RELAY_RESPONSE: case PAYLOAD_TYPE_RELAY_RESPONSE:
ProcessRelayResponse (buf, len); ProcessRelayResponse (buf, len);
if (m_State != eSessionStateEstablished)
m_Server.DeleteSession (this); m_Server.DeleteSession (this);
break; break;
case PAYLOAD_TYPE_RELAY_REQUEST: case PAYLOAD_TYPE_RELAY_REQUEST:
@ -985,30 +986,41 @@ namespace ssu
else else
{ {
// connect through introducer // connect through introducer
session->WaitForIntroduction (); int numIntroducers = address->introducers.size ();
if (address->introducers.size () > 0) if (numIntroducers > 0)
{ {
auto& introducer = address->introducers[0]; // TODO:
boost::asio::ip::udp::endpoint introducerEndpoint (introducer.iHost, introducer.iPort);
LogPrint ("Creating new SSU session to [", router->GetIdentHashAbbreviation (),
"] through introducer ", introducerEndpoint.address ().to_string (), ":", introducerEndpoint.port ());
it = m_Sessions.find (introducerEndpoint);
SSUSession * introducerSession = nullptr; SSUSession * introducerSession = nullptr;
const i2p::data::RouterInfo::Introducer * introducer = nullptr;
// we might have a session to introducer already
for (int i = 0; i < numIntroducers; i++)
{
introducer = &(address->introducers[i]);
it = m_Sessions.find (boost::asio::ip::udp::endpoint (introducer->iHost, introducer->iPort));
if (it != m_Sessions.end ()) if (it != m_Sessions.end ())
{ {
LogPrint ("Session to introducer already exists");
introducerSession = it->second; introducerSession = it->second;
break;
} }
else }
if (introducerSession) // session found
LogPrint ("Session to introducer already exists");
else // create new
{ {
LogPrint ("New session to introducer created"); LogPrint ("Creating new session to introducer");
introducer = &(address->introducers[0]); // TODO:
boost::asio::ip::udp::endpoint introducerEndpoint (introducer->iHost, introducer->iPort);
introducerSession = new SSUSession (*this, introducerEndpoint, router); introducerSession = new SSUSession (*this, introducerEndpoint, router);
m_Sessions[introducerEndpoint] = introducerSession; m_Sessions[introducerEndpoint] = introducerSession;
} }
introducerSession->Introduce (introducer.iTag, introducer.iKey); // introduce
LogPrint ("Introduce new SSU session to [", router->GetIdentHashAbbreviation (),
"] through introducer ", introducer->iHost, ":", introducer->iPort);
session->WaitForIntroduction ();
introducerSession->Introduce (introducer->iTag, introducer->iKey);
} }
else else
LogPrint ("Router is unreachable, but not introducers presentd. Ignored"); LogPrint ("Router is unreachable, but no introducers presented. Ignored");
} }
} }
} }

Loading…
Cancel
Save