mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
try to find existing SSU session to introducer first
This commit is contained in:
parent
6ce3e41a70
commit
a7406e03ab
52
SSU.cpp
52
SSU.cpp
@ -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,7 +151,8 @@ namespace ssu
|
|||||||
}
|
}
|
||||||
case PAYLOAD_TYPE_RELAY_RESPONSE:
|
case PAYLOAD_TYPE_RELAY_RESPONSE:
|
||||||
ProcessRelayResponse (buf, len);
|
ProcessRelayResponse (buf, len);
|
||||||
m_Server.DeleteSession (this);
|
if (m_State != eSessionStateEstablished)
|
||||||
|
m_Server.DeleteSession (this);
|
||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_RELAY_REQUEST:
|
case PAYLOAD_TYPE_RELAY_REQUEST:
|
||||||
LogPrint ("SSU relay request received");
|
LogPrint ("SSU relay request received");
|
||||||
@ -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;
|
||||||
if (it != m_Sessions.end ())
|
const i2p::data::RouterInfo::Introducer * introducer = nullptr;
|
||||||
|
// we might have a session to introducer already
|
||||||
|
for (int i = 0; i < numIntroducers; i++)
|
||||||
{
|
{
|
||||||
LogPrint ("Session to introducer already exists");
|
introducer = &(address->introducers[i]);
|
||||||
introducerSession = it->second;
|
it = m_Sessions.find (boost::asio::ip::udp::endpoint (introducer->iHost, introducer->iPort));
|
||||||
}
|
if (it != m_Sessions.end ())
|
||||||
else
|
{
|
||||||
{
|
introducerSession = it->second;
|
||||||
LogPrint ("New session to introducer created");
|
break;
|
||||||
introducerSession = new SSUSession (*this, introducerEndpoint, router);
|
}
|
||||||
m_Sessions[introducerEndpoint] = introducerSession;
|
|
||||||
}
|
}
|
||||||
introducerSession->Introduce (introducer.iTag, introducer.iKey);
|
|
||||||
|
if (introducerSession) // session found
|
||||||
|
LogPrint ("Session to introducer already exists");
|
||||||
|
else // create new
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// 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…
x
Reference in New Issue
Block a user