Skip to content

Commit

Permalink
override SSU port if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 11, 2014
1 parent 888a19f commit c8cdeea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
21 changes: 12 additions & 9 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<i2p::data::RouterInfo::Address *>(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)
Expand Down
4 changes: 2 additions & 2 deletions RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down

0 comments on commit c8cdeea

Please sign in to comment.