override SSU port if specified

This commit is contained in:
orignal 2014-09-11 09:32:34 -04:00
parent 888a19fdba
commit c8cdeead44
3 changed files with 20 additions and 15 deletions

View File

@ -60,10 +60,12 @@ namespace i2p
isDaemon = i2p::util::config::GetArg("-daemon", 0); isDaemon = i2p::util::config::GetArg("-daemon", 0);
isLogging = i2p::util::config::GetArg("-log", 1); isLogging = i2p::util::config::GetArg("-log", 1);
//TODO: This is an ugly workaround. fix it. int port = i2p::util::config::GetArg("-port", 0);
//TODO: Autodetect public IP. if (port)
i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"), i2p::context.UpdatePort (port);
i2p::util::config::GetArg("-port", 17007)); const char * host = i2p::util::config::GetCharArg("-host", "");
if (host && host[0])
i2p::context.UpdateAddress (host);
if (i2p::util::config::GetArg("-unreachable", 0)) if (i2p::util::config::GetArg("-unreachable", 0))
i2p::context.SetUnreachable (); i2p::context.SetUnreachable ();

View File

@ -56,15 +56,18 @@ namespace i2p
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch (); m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
} }
void RouterContext::OverrideNTCPAddress (const char * host, int port) void RouterContext::UpdatePort (int port)
{ {
m_RouterInfo.CreateBuffer (m_Keys); bool updated = false;
auto address = const_cast<i2p::data::RouterInfo::Address *>(m_RouterInfo.GetNTCPAddress ()); for (auto& address : m_RouterInfo.GetAddresses ())
if (address)
{ {
address->host = boost::asio::ip::address::from_string (host); if (address.port != port)
address->port = port; {
address.port = port;
updated = true;
} }
}
if (updated)
UpdateRouterInfo (); UpdateRouterInfo ();
} }

View File

@ -26,8 +26,8 @@ namespace i2p
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); }; const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
void OverrideNTCPAddress (const char * host, int port); // temporary void UpdatePort (int port); // called from Daemon
void UpdateAddress (const char * host); // called from SSU void UpdateAddress (const char * host); // called from SSU or Daemon
bool AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag); bool AddIntroducer (const i2p::data::RouterInfo& routerInfo, uint32_t tag);
void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
bool IsUnreachable () const { return m_IsUnreachable; }; bool IsUnreachable () const { return m_IsUnreachable; };