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 ()