From 54ec71d30d35e8edce5883e472db2a68b3de4c9b Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 29 Oct 2014 21:16:27 -0400 Subject: [PATCH] select proper SSU address for incoming sessions --- RouterInfo.cpp | 9 +++++++-- RouterInfo.h | 3 ++- SSU.cpp | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 684e3cb8..a782c219 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -625,13 +625,18 @@ namespace data return GetAddress (eTransportSSU, v4only); } - const RouterInfo::Address * RouterInfo::GetAddress (TransportStyle s, bool v4only) const + const RouterInfo::Address * RouterInfo::GetSSUV6Address () const + { + return GetAddress (eTransportSSU, false, true); + } + + const RouterInfo::Address * RouterInfo::GetAddress (TransportStyle s, bool v4only, bool v6only) const { for (auto& address : m_Addresses) { if (address.transportStyle == s) { - if (!v4only || address.host.is_v4 ()) + if ((!v4only || address.host.is_v4 ()) && (!v6only || address.host.is_v6 ())) return &address; } } diff --git a/RouterInfo.h b/RouterInfo.h index 0ea62342..75cdd51b 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -98,6 +98,7 @@ namespace data std::vector
& GetAddresses () { return m_Addresses; }; const Address * GetNTCPAddress (bool v4only = true) const; const Address * GetSSUAddress (bool v4only = true) const; + const Address * GetSSUV6Address () const; void AddNTCPAddress (const char * host, int port); void AddSSUAddress (const char * host, int port, const uint8_t * key); @@ -152,7 +153,7 @@ namespace data size_t ReadString (char * str, std::istream& s); void WriteString (const std::string& str, std::ostream& s); void ExtractCaps (const char * value); - const Address * GetAddress (TransportStyle s, bool v4only) const; + const Address * GetAddress (TransportStyle s, bool v4only, bool v6only = false) const; void UpdateCapsProperty (); private: diff --git a/SSU.cpp b/SSU.cpp index fef956d9..4ee9e892 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -327,7 +327,8 @@ namespace transport void SSUSession::SendSessionCreated (const uint8_t * x) { auto introKey = GetIntroKey (); - auto address = i2p::context.GetRouterInfo ().GetSSUAddress (); + auto address = IsV6 () ? i2p::context.GetRouterInfo ().GetSSUV6Address () : + i2p::context.GetRouterInfo ().GetSSUAddress (true); //v4 only if (!introKey || !address) { LogPrint (eLogError, "SSU is not supported");