|
|
@ -274,12 +274,17 @@ namespace transport |
|
|
|
|
|
|
|
|
|
|
|
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest) |
|
|
|
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::shared_ptr<SSUSession> session; |
|
|
|
|
|
|
|
if (router) |
|
|
|
if (router) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (router->UsesIntroducer ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CreateSessionThroughIntroducer (router, peerTest); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
auto address = router->GetSSUAddress (!context.SupportsV6 ()); |
|
|
|
auto address = router->GetSSUAddress (!context.SupportsV6 ()); |
|
|
|
if (address) |
|
|
|
if (address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
std::shared_ptr<SSUSession> session; |
|
|
|
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port); |
|
|
|
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port); |
|
|
|
auto it = m_Sessions.find (remoteEndpoint); |
|
|
|
auto it = m_Sessions.find (remoteEndpoint); |
|
|
|
if (it != m_Sessions.end ()) |
|
|
|
if (it != m_Sessions.end ()) |
|
|
@ -296,16 +301,35 @@ namespace transport |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
m_Sessions[remoteEndpoint] = session; |
|
|
|
m_Sessions[remoteEndpoint] = session; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!router->UsesIntroducer ()) |
|
|
|
// connect
|
|
|
|
{ |
|
|
|
|
|
|
|
// connect directly
|
|
|
|
|
|
|
|
LogPrint ("Creating new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), "] ", |
|
|
|
LogPrint ("Creating new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), "] ", |
|
|
|
remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port ()); |
|
|
|
remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port ()); |
|
|
|
session->Connect (); |
|
|
|
session->Connect (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SSUServer::CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (router && router->UsesIntroducer ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto address = router->GetSSUAddress (!context.SupportsV6 ()); |
|
|
|
|
|
|
|
if (address) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port); |
|
|
|
|
|
|
|
auto it = m_Sessions.find (remoteEndpoint); |
|
|
|
|
|
|
|
// check if session if presented alredy
|
|
|
|
|
|
|
|
if (it != m_Sessions.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// connect through introducer
|
|
|
|
auto session = it->second; |
|
|
|
|
|
|
|
if (peerTest && session->GetState () == eSessionStateEstablished) |
|
|
|
|
|
|
|
session->SendPeerTest (); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// create new session
|
|
|
|
int numIntroducers = address->introducers.size (); |
|
|
|
int numIntroducers = address->introducers.size (); |
|
|
|
if (numIntroducers > 0) |
|
|
|
if (numIntroducers > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -334,6 +358,12 @@ namespace transport |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
m_Sessions[introducerEndpoint] = introducerSession; |
|
|
|
m_Sessions[introducerEndpoint] = introducerSession; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// create session
|
|
|
|
|
|
|
|
auto session = std::make_shared<SSUSession> (*this, remoteEndpoint, router, peerTest); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
|
|
|
|
m_Sessions[remoteEndpoint] = session; |
|
|
|
|
|
|
|
} |
|
|
|
// introduce
|
|
|
|
// introduce
|
|
|
|
LogPrint ("Introduce new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), |
|
|
|
LogPrint ("Introduce new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), |
|
|
|
"] through introducer ", introducer->iHost, ":", introducer->iPort); |
|
|
|
"] through introducer ", introducer->iHost, ":", introducer->iPort); |
|
|
@ -346,13 +376,7 @@ namespace transport |
|
|
|
introducerSession->Introduce (*introducer); |
|
|
|
introducerSession->Introduce (*introducer); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented"); |
|
|
|
LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented"); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
|
|
|
|
m_Sessions.erase (remoteEndpoint); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address"); |
|
|
|
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address"); |
|
|
|