From 0ef42870e56808d225b0673f19f4a17570901385 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 2 Dec 2015 12:48:10 -0500 Subject: [PATCH] try SSU if NTCP address is not presented --- SSU.cpp | 24 ++++++++++++++---------- SSU.h | 2 ++ Transports.cpp | 19 ++++++++++++++----- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/SSU.cpp b/SSU.cpp index 7e51538f..6fe03dd2 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -270,25 +270,29 @@ namespace transport else return nullptr; } - + void SSUServer::CreateSession (std::shared_ptr 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 router, + const boost::asio::ip::address& addr, int port, bool peerTest) { if (router) { if (router->UsesIntroducer ()) - { m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, peerTest)); // always V4 thread - return; - } - auto address = router->GetSSUAddress (!context.SupportsV6 ()); - if (address) + else { - boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port); - auto& s = remoteEndpoint.address ().is_v6 () ? m_ServiceV6 : m_Service; + boost::asio::ip::udp::endpoint remoteEndpoint (addr, port); + auto& s = addr.is_v6 () ? m_ServiceV6 : m_Service; s.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest)); } - else - LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address"); } } diff --git a/SSU.h b/SSU.h index 8f9bec77..efe6203d 100644 --- a/SSU.h +++ b/SSU.h @@ -41,6 +41,8 @@ namespace transport void Start (); void Stop (); void CreateSession (std::shared_ptr router, bool peerTest = false); + void CreateSession (std::shared_ptr router, + const boost::asio::ip::address& addr, int port, bool peerTest = false); std::shared_ptr FindSession (std::shared_ptr router) const; std::shared_ptr FindSession (const boost::asio::ip::udp::endpoint& e) const; std::shared_ptr GetRandomEstablishedV4Session (std::shared_ptr excluded); diff --git a/Transports.cpp b/Transports.cpp index 1b74093c..702be15d 100644 --- a/Transports.cpp +++ b/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++; - if (m_SSUServer) - { - if (peer.router->IsSSU (!context.SupportsV6 ())) + if (m_SSUServer && 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; } }