pass our address as boost's address

This commit is contained in:
orignal 2014-10-29 13:49:21 -04:00
parent d513f20225
commit a3fd338fab
5 changed files with 14 additions and 15 deletions

View File

@ -67,7 +67,7 @@ namespace i2p
i2p::context.UpdatePort (port);
const char * host = i2p::util::config::GetCharArg("-host", "");
if (host && host[0])
i2p::context.UpdateAddress (host);
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
if (i2p::util::config::GetArg("-unreachable", 0))
i2p::context.SetUnreachable ();

View File

@ -623,7 +623,7 @@ namespace transport
{
LogPrint ("Connected");
if (GetSocket ().local_endpoint ().protocol () == boost::asio::ip::tcp::v6()) // ipv6
context.UpdateV6Address (GetSocket ().local_endpoint ().address ().to_string ());
context.UpdateNTCPV6Address (GetSocket ().local_endpoint ().address ());
ClientLogin ();
}
}

View File

@ -72,15 +72,14 @@ namespace i2p
UpdateRouterInfo ();
}
void RouterContext::UpdateAddress (const char * host)
void RouterContext::UpdateAddress (const boost::asio::ip::address& host)
{
bool updated = false;
auto newAddress = boost::asio::ip::address::from_string (host);
for (auto& address : m_RouterInfo.GetAddresses ())
{
if (address.host != newAddress && address.IsCompatible (newAddress))
if (address.host != host && address.IsCompatible (host))
{
address.host = newAddress;
address.host = host;
updated = true;
}
}
@ -139,19 +138,18 @@ namespace i2p
m_RouterInfo.DisableV6 ();
}
void RouterContext::UpdateV6Address (const std::string& host)
void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host)
{
bool updated = false, found = false;
int port = 0;
auto newAddress = boost::asio::ip::address::from_string (host);
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses)
{
if (addr.host.is_v6 ())
{
if (addr.host != newAddress)
if (addr.host != host)
{
addr.host = newAddress;
addr.host = host;
updated = true;
}
found = true;
@ -162,7 +160,7 @@ namespace i2p
if (!found)
{
// create new address
m_RouterInfo.AddNTCPAddress (host.c_str (), port);
m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port);
updated = true;
}
if (updated)

View File

@ -3,6 +3,7 @@
#include <inttypes.h>
#include <string>
#include <boost/asio.hpp>
#include <cryptopp/dsa.h>
#include <cryptopp/osrng.h>
#include "Identity.h"
@ -26,7 +27,7 @@ namespace i2p
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
void UpdatePort (int port); // called from Daemon
void UpdateAddress (const char * host); // called from SSU or Daemon
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; };
@ -35,7 +36,7 @@ namespace i2p
void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; };
bool SupportsV6 () const { return m_RouterInfo.IsV6 (); };
void SetSupportsV6 (bool supportsV6);
void UpdateV6Address (const std::string& host); // called from NTCP session
void UpdateNTCPV6Address (const boost::asio::ip::address& host); // called from NTCP session
// implements LocalDestination
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };

View File

@ -217,7 +217,7 @@ namespace transport
s.Insert (payload, 2); // our port
payload += 2; // port
LogPrint ("Our external address is ", ourIP.to_string (), ":", ourPort);
i2p::context.UpdateAddress (ourIP.to_string ().c_str ());
i2p::context.UpdateAddress (ourIP);
if (m_RemoteEndpoint.address ().is_v4 ())
s.Insert (m_RemoteEndpoint.address ().to_v4 ().to_bytes ().data (), 4); // remote IP v4
else
@ -575,7 +575,7 @@ namespace transport
uint16_t ourPort = be16toh (*(uint16_t *)(payload));
payload += 2; // our port
LogPrint ("Our external address is ", ourIP.to_string (), ":", ourPort);
i2p::context.UpdateAddress (ourIP.to_string ().c_str ());
i2p::context.UpdateAddress (ourIP);
}
void SSUSession::ProcessRelayIntro (uint8_t * buf, size_t len)