From fc50b24809fc8f6f3c3ba1e766882c7b0042103e Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 8 Sep 2014 16:43:20 -0400 Subject: [PATCH] unreachable mode --- Daemon.cpp | 3 +++ README.md | 3 ++- RouterContext.cpp | 23 +++++++++++++++++++++-- RouterContext.h | 5 ++++- SSU.cpp | 2 ++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Daemon.cpp b/Daemon.cpp index dcd34990..51e8f938 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -65,6 +65,9 @@ namespace i2p i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"), i2p::util::config::GetArg("-port", 17007)); + if (i2p::util::config::GetArg("-unreachable", 0)) + i2p::context.SetUnreachable (); + LogPrint("CMD parameters:"); for (int i = 0; i < argc; ++i) LogPrint(i, " ", argv[i]); diff --git a/README.md b/README.md index be42a06d..d4af6a6c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ Options * --port= - The port to listen on * --httpport= - The http port to listen on * --log= - Enable or disable logging to file. 1 for yes, 0 for no. -* --daemon= - Eanble or disable daemon mode. 1 for yes, 0 for no. +* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no. +* --unreachable= - 1 if router is declared as unreachable and works through introducers. * --httpproxyport= - The port to listen on (HTTP Proxy) * --socksproxyport= - The port to listen on (SOCKS Proxy) * --ircport= - The local port of IRC tunnel to listen on. 6668 by default diff --git a/RouterContext.cpp b/RouterContext.cpp index a4f99ba7..8bf8cde5 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -12,7 +12,7 @@ namespace i2p RouterContext context; RouterContext::RouterContext (): - m_LastUpdateTime (0) + m_LastUpdateTime (0), m_IsUnreachable (false) { } @@ -100,7 +100,26 @@ namespace i2p if (m_RouterInfo.RemoveIntroducer (e)) UpdateRouterInfo (); } - + + void RouterContext::SetUnreachable () + { + m_IsUnreachable = true; + // set caps + m_RouterInfo.SetCaps (i2p::data::RouterInfo::eUnreachable | i2p::data::RouterInfo::eSSUTesting); // LU, B + // remove NTCP address + auto& addresses = m_RouterInfo.GetAddresses (); + for (size_t i = 0; i < addresses.size (); i++) + { + if (addresses[i].transportStyle == i2p::data::RouterInfo::eTransportNTCP) + { + addresses.erase (addresses.begin () + i); + break; + } + } + // update + UpdateRouterInfo (); + } + bool RouterContext::Load () { std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in); diff --git a/RouterContext.h b/RouterContext.h index 27c289d8..d8a387f8 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -30,7 +30,9 @@ namespace i2p void UpdateAddress (const char * host); // called from SSU void AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag); void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); - + bool IsUnreachable () const { return m_IsUnreachable; }; + void SetUnreachable (); + // implements LocalDestination const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); }; @@ -51,6 +53,7 @@ namespace i2p i2p::data::PrivateKeys m_Keys; CryptoPP::AutoSeededRandomPool m_Rnd; uint64_t m_LastUpdateTime; + bool m_IsUnreachable; }; extern RouterContext context; diff --git a/SSU.cpp b/SSU.cpp index a30b116e..8f9c1c50 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -905,6 +905,8 @@ namespace ssu m_IsRunning = true; m_Thread = new std::thread (std::bind (&SSUServer::Run, this)); m_Service.post (boost::bind (&SSUServer::Receive, this)); + if (i2p::context.IsUnreachable ()) + ScheduleIntroducersUpdateTimer (); } void SSUServer::Stop ()