From c8cdeead44cf6d3d4a4e6f70f02a675d0f3923d4 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 11 Sep 2014 09:32:34 -0400 Subject: [PATCH] override SSU port if specified --- Daemon.cpp | 10 ++++++---- RouterContext.cpp | 21 ++++++++++++--------- RouterContext.h | 4 ++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 51e8f938..6ccf7461 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -60,10 +60,12 @@ namespace i2p isDaemon = i2p::util::config::GetArg("-daemon", 0); isLogging = i2p::util::config::GetArg("-log", 1); - //TODO: This is an ugly workaround. fix it. - //TODO: Autodetect public IP. - i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"), - i2p::util::config::GetArg("-port", 17007)); + int port = i2p::util::config::GetArg("-port", 0); + if (port) + i2p::context.UpdatePort (port); + const char * host = i2p::util::config::GetCharArg("-host", ""); + if (host && host[0]) + i2p::context.UpdateAddress (host); if (i2p::util::config::GetArg("-unreachable", 0)) i2p::context.SetUnreachable (); diff --git a/RouterContext.cpp b/RouterContext.cpp index cdd6919f..9384a0bd 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -55,17 +55,20 @@ namespace i2p m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO)); m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch (); } - - void RouterContext::OverrideNTCPAddress (const char * host, int port) + + void RouterContext::UpdatePort (int port) { - m_RouterInfo.CreateBuffer (m_Keys); - auto address = const_cast(m_RouterInfo.GetNTCPAddress ()); - if (address) + bool updated = false; + for (auto& address : m_RouterInfo.GetAddresses ()) { - address->host = boost::asio::ip::address::from_string (host); - address->port = port; - } - UpdateRouterInfo (); + if (address.port != port) + { + address.port = port; + updated = true; + } + } + if (updated) + UpdateRouterInfo (); } void RouterContext::UpdateAddress (const char * host) diff --git a/RouterContext.h b/RouterContext.h index 99bb7153..2a97982c 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -26,8 +26,8 @@ namespace i2p const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; - void OverrideNTCPAddress (const char * host, int port); // temporary - void UpdateAddress (const char * host); // called from SSU + void UpdatePort (int port); // called from Daemon + void UpdateAddress (const char * 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; };