From 513dc2fcc5935913ffe1c5607388c008c9c3b995 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 1 Mar 2015 07:55:03 -0500 Subject: [PATCH] don't use explicit unreachable parameter anymore --- Daemon.cpp | 3 --- README.md | 1 - RouterContext.cpp | 45 +++++++++++++++++++++++++++++++++++++++++---- RouterContext.h | 5 +++-- SSU.cpp | 3 ++- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index 1dbbc82f..42a78280 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -74,9 +74,6 @@ namespace i2p if (host && host[0]) i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host)); - if (i2p::util::config::GetArg("-unreachable", 0)) - i2p::context.SetUnreachable (); - i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0)); i2p::context.SetFloodfill (i2p::util::config::GetArg("-floodfill", 0)); diff --git a/README.md b/README.md index dbb9b5de..9afb84fc 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,6 @@ Cmdline options * --log= - Enable or disable logging to file. 1 for yes, 0 for no. * --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no. * --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd). -* --unreachable= - 1 if router is declared as unreachable and works through introducers. * --v6= - 1 if supports communication through ipv6, off by default * --floodfill= - 1 if router is floodfill, off by default * --httpproxyport= - The port to listen on (HTTP Proxy) diff --git a/RouterContext.cpp b/RouterContext.cpp index 3a894e6b..1a0121ed 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -13,8 +13,8 @@ namespace i2p RouterContext context; RouterContext::RouterContext (): - m_LastUpdateTime (0), m_IsUnreachable (false), m_AcceptsTunnels (true), - m_IsFloodfill (false), m_StartupTime (0), m_Status (eRouterStatusOK ) + m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false), + m_StartupTime (0), m_Status (eRouterStatusOK ) { } @@ -119,9 +119,13 @@ namespace i2p UpdateRouterInfo (); } + bool RouterContext::IsUnreachable () const + { + return m_RouterInfo.GetCaps () & i2p::data::RouterInfo::eUnreachable; + } + void RouterContext::SetUnreachable () { - m_IsUnreachable = true; // set caps m_RouterInfo.SetCaps (i2p::data::RouterInfo::eUnreachable | i2p::data::RouterInfo::eSSUTesting); // LU, B // remove NTCP address @@ -137,11 +141,41 @@ namespace i2p // delete previous introducers for (auto& addr : addresses) addr.introducers.clear (); - + // update UpdateRouterInfo (); } + void RouterContext::SetReachable () + { + // update caps + uint8_t caps = m_RouterInfo.GetCaps (); + caps &= ~i2p::data::RouterInfo::eUnreachable; + caps |= i2p::data::RouterInfo::eReachable; + caps |= i2p::data::RouterInfo::eSSUIntroducer; + if (m_IsFloodfill) + caps |= i2p::data::RouterInfo::eFloodfill; + m_RouterInfo.SetCaps (caps); + + // insert NTCP back + auto& addresses = m_RouterInfo.GetAddresses (); + for (size_t i = 0; i < addresses.size (); i++) + { + if (addresses[i].transportStyle == i2p::data::RouterInfo::eTransportSSU) + { + // insert NTCP address with host/port form SSU + m_RouterInfo.AddNTCPAddress (addresses[i].host.to_string ().c_str (), addresses[i].port); + break; + } + } + // delete previous introducers + for (auto& addr : addresses) + addr.introducers.clear (); + + // update + UpdateRouterInfo (); + } + void RouterContext::SetSupportsV6 (bool supportsV6) { if (supportsV6) @@ -200,6 +234,9 @@ namespace i2p m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); m_RouterInfo.SetProperty ("coreVersion", I2P_VERSION); m_RouterInfo.SetProperty ("router.version", I2P_VERSION); + + if (IsUnreachable ()) + SetReachable (); // we assume reachable until we discover firewall through peer tests return true; } diff --git a/RouterContext.h b/RouterContext.h index f1e8056c..24b761f9 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -47,8 +47,9 @@ namespace i2p 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 || m_Status == eRouterStatusFirewalled; }; + bool IsUnreachable () const; void SetUnreachable (); + void SetReachable (); bool IsFloodfill () const { return m_IsFloodfill; }; void SetFloodfill (bool floodfill); bool AcceptsTunnels () const { return m_AcceptsTunnels; }; @@ -81,7 +82,7 @@ namespace i2p i2p::data::PrivateKeys m_Keys; CryptoPP::AutoSeededRandomPool m_Rnd; uint64_t m_LastUpdateTime; - bool m_IsUnreachable, m_AcceptsTunnels, m_IsFloodfill; + bool m_AcceptsTunnels, m_IsFloodfill; uint64_t m_StartupTime; // in seconds since epoch RouterStatus m_Status; }; diff --git a/SSU.cpp b/SSU.cpp index 17c76068..dfea196b 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -427,7 +427,8 @@ namespace transport if (ecode != boost::asio::error::operation_aborted) { // timeout expired - if (!i2p::context.IsUnreachable ()) return; // we don't need introducers anymore + if (!i2p::context.GetStatus () != eRouterStatusFirewalled) return; // we don't need introducers anymore + if (!i2p::context.IsUnreachable ()) i2p::context.SetUnreachable (); std::list newList; size_t numIntroducers = 0; uint32_t ts = i2p::util::GetSecondsSinceEpoch ();