Browse Source

try SSU if NTCP address is not presented

pull/307/head
orignal 9 years ago
parent
commit
0ef42870e5
  1. 22
      SSU.cpp
  2. 2
      SSU.h
  3. 17
      Transports.cpp

22
SSU.cpp

@ -272,23 +272,27 @@ 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)
{
auto address = router->GetSSUAddress (!context.SupportsV6 ());
if (address)
CreateSession (router, address->host, address->port, peerTest);
else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
}
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
const boost::asio::ip::address& addr, int port, bool peerTest)
{ {
if (router) if (router)
{ {
if (router->UsesIntroducer ()) if (router->UsesIntroducer ())
{
m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, peerTest)); // always V4 thread m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, peerTest)); // always V4 thread
return; else
}
auto address = router->GetSSUAddress (!context.SupportsV6 ());
if (address)
{ {
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port); boost::asio::ip::udp::endpoint remoteEndpoint (addr, port);
auto& s = remoteEndpoint.address ().is_v6 () ? m_ServiceV6 : m_Service; auto& s = addr.is_v6 () ? m_ServiceV6 : m_Service;
s.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest)); s.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest));
} }
else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
} }
} }

2
SSU.h

@ -41,6 +41,8 @@ namespace transport
void Start (); void Start ();
void Stop (); void Stop ();
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false); void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
const boost::asio::ip::address& addr, int port, bool peerTest = false);
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const; std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const; std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded); std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded);

17
Transports.cpp

@ -284,15 +284,24 @@ namespace transport
} }
} }
} }
else
LogPrint (eLogInfo, "NTCP address is not presented. Trying SSU");
} }
else if (peer.numAttempts == 1)// SSU if (peer.numAttempts == 1)// SSU
{ {
peer.numAttempts++; peer.numAttempts++;
if (m_SSUServer) if (m_SSUServer && peer.router->IsSSU (!context.SupportsV6 ()))
{ {
if (peer.router->IsSSU (!context.SupportsV6 ())) auto address = peer.router->GetSSUAddress (!context.SupportsV6 ());
#if BOOST_VERSION >= 104900
if (!address->host.is_unspecified ()) // we have address now
#else
boost::system::error_code ecode;
address->host.to_string (ecode);
if (!ecode)
#endif
{ {
m_SSUServer->CreateSession (peer.router); m_SSUServer->CreateSession (peer.router, address->host, address->port);
return true; return true;
} }
} }

Loading…
Cancel
Save