From a3fd338fabddb976fa6d40ed01084f8f0be58565 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 29 Oct 2014 13:49:21 -0400 Subject: [PATCH] pass our address as boost's address --- Daemon.cpp | 2 +- NTCPSession.cpp | 2 +- RouterContext.cpp | 16 +++++++--------- RouterContext.h | 5 +++-- SSU.cpp | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 3836bd96..b8943db1 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -67,7 +67,7 @@ namespace i2p i2p::context.UpdatePort (port); const char * host = i2p::util::config::GetCharArg("-host", ""); if (host && host[0]) - i2p::context.UpdateAddress (host); + i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host)); if (i2p::util::config::GetArg("-unreachable", 0)) i2p::context.SetUnreachable (); diff --git a/NTCPSession.cpp b/NTCPSession.cpp index b9b1a163..4afe4942 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -623,7 +623,7 @@ namespace transport { LogPrint ("Connected"); if (GetSocket ().local_endpoint ().protocol () == boost::asio::ip::tcp::v6()) // ipv6 - context.UpdateV6Address (GetSocket ().local_endpoint ().address ().to_string ()); + context.UpdateNTCPV6Address (GetSocket ().local_endpoint ().address ()); ClientLogin (); } } diff --git a/RouterContext.cpp b/RouterContext.cpp index 65905196..8701d46c 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -72,15 +72,14 @@ namespace i2p UpdateRouterInfo (); } - void RouterContext::UpdateAddress (const char * host) + void RouterContext::UpdateAddress (const boost::asio::ip::address& host) { bool updated = false; - auto newAddress = boost::asio::ip::address::from_string (host); for (auto& address : m_RouterInfo.GetAddresses ()) { - if (address.host != newAddress && address.IsCompatible (newAddress)) + if (address.host != host && address.IsCompatible (host)) { - address.host = newAddress; + address.host = host; updated = true; } } @@ -139,19 +138,18 @@ namespace i2p m_RouterInfo.DisableV6 (); } - void RouterContext::UpdateV6Address (const std::string& host) + void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host) { bool updated = false, found = false; int port = 0; - auto newAddress = boost::asio::ip::address::from_string (host); auto& addresses = m_RouterInfo.GetAddresses (); for (auto& addr : addresses) { if (addr.host.is_v6 ()) { - if (addr.host != newAddress) + if (addr.host != host) { - addr.host = newAddress; + addr.host = host; updated = true; } found = true; @@ -162,7 +160,7 @@ namespace i2p if (!found) { // create new address - m_RouterInfo.AddNTCPAddress (host.c_str (), port); + m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port); updated = true; } if (updated) diff --git a/RouterContext.h b/RouterContext.h index e2e5b24e..aef7d6ac 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "Identity.h" @@ -26,7 +27,7 @@ namespace i2p CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; void UpdatePort (int port); // called from Daemon - void UpdateAddress (const char * host); // called from SSU or Daemon + void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon bool AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag); void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); bool IsUnreachable () const { return m_IsUnreachable; }; @@ -35,7 +36,7 @@ namespace i2p void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; }; bool SupportsV6 () const { return m_RouterInfo.IsV6 (); }; void SetSupportsV6 (bool supportsV6); - void UpdateV6Address (const std::string& host); // called from NTCP session + void UpdateNTCPV6Address (const boost::asio::ip::address& host); // called from NTCP session // implements LocalDestination const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; diff --git a/SSU.cpp b/SSU.cpp index e3106de0..72f7ba1b 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -217,7 +217,7 @@ namespace transport s.Insert (payload, 2); // our port payload += 2; // port LogPrint ("Our external address is ", ourIP.to_string (), ":", ourPort); - i2p::context.UpdateAddress (ourIP.to_string ().c_str ()); + i2p::context.UpdateAddress (ourIP); if (m_RemoteEndpoint.address ().is_v4 ()) s.Insert (m_RemoteEndpoint.address ().to_v4 ().to_bytes ().data (), 4); // remote IP v4 else @@ -575,7 +575,7 @@ namespace transport uint16_t ourPort = be16toh (*(uint16_t *)(payload)); payload += 2; // our port LogPrint ("Our external address is ", ourIP.to_string (), ":", ourPort); - i2p::context.UpdateAddress (ourIP.to_string ().c_str ()); + i2p::context.UpdateAddress (ourIP); } void SSUSession::ProcessRelayIntro (uint8_t * buf, size_t len)