mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
try to find existing SSU session to introducer first
This commit is contained in:
parent
6ce3e41a70
commit
a7406e03ab
38
SSU.cpp
38
SSU.cpp
@ -77,7 +77,7 @@ namespace ssu
|
||||
if (m_State == eSessionStateIntroduced)
|
||||
{
|
||||
// HolePunch received
|
||||
LogPrint ("SSU HolePuch of ", len, " bytes received");
|
||||
LogPrint ("SSU HolePunch of ", len, " bytes received");
|
||||
m_State = eSessionStateUnknown;
|
||||
Connect ();
|
||||
}
|
||||
@ -151,6 +151,7 @@ namespace ssu
|
||||
}
|
||||
case PAYLOAD_TYPE_RELAY_RESPONSE:
|
||||
ProcessRelayResponse (buf, len);
|
||||
if (m_State != eSessionStateEstablished)
|
||||
m_Server.DeleteSession (this);
|
||||
break;
|
||||
case PAYLOAD_TYPE_RELAY_REQUEST:
|
||||
@ -985,30 +986,41 @@ namespace ssu
|
||||
else
|
||||
{
|
||||
// connect through introducer
|
||||
session->WaitForIntroduction ();
|
||||
if (address->introducers.size () > 0)
|
||||
int numIntroducers = address->introducers.size ();
|
||||
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;
|
||||
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 ())
|
||||
{
|
||||
LogPrint ("Session to introducer already exists");
|
||||
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);
|
||||
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
|
||||
LogPrint ("Router is unreachable, but not introducers presentd. Ignored");
|
||||
LogPrint ("Router is unreachable, but no introducers presented. Ignored");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user