Browse Source

support ipv6 for outgoing NTCP connections

pull/106/head
orignal 10 years ago
parent
commit
7fb7341502
  1. 2
      Daemon.cpp
  2. 10
      RouterContext.cpp
  3. 2
      RouterContext.h
  4. 32
      RouterInfo.cpp
  5. 9
      RouterInfo.h
  6. 2
      Transports.cpp

2
Daemon.cpp

@ -72,6 +72,8 @@ namespace i2p
if (i2p::util::config::GetArg("-unreachable", 0)) if (i2p::util::config::GetArg("-unreachable", 0))
i2p::context.SetUnreachable (); i2p::context.SetUnreachable ();
i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0));
LogPrint("CMD parameters:"); LogPrint("CMD parameters:");
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
LogPrint(i, " ", argv[i]); LogPrint(i, " ", argv[i]);

10
RouterContext.cpp

@ -78,7 +78,7 @@ namespace i2p
auto newAddress = boost::asio::ip::address::from_string (host); auto newAddress = boost::asio::ip::address::from_string (host);
for (auto& address : m_RouterInfo.GetAddresses ()) for (auto& address : m_RouterInfo.GetAddresses ())
{ {
if (address.host != newAddress) if (address.host != newAddress && address.IsCompatible (newAddress))
{ {
address.host = newAddress; address.host = newAddress;
updated = true; updated = true;
@ -131,6 +131,14 @@ namespace i2p
UpdateRouterInfo (); UpdateRouterInfo ();
} }
void RouterContext::SetSupportsV6 (bool supportsV6)
{
if (supportsV6)
m_RouterInfo.EnableV6 ();
else
m_RouterInfo.DisableV6 ();
}
bool RouterContext::Load () bool RouterContext::Load ()
{ {
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in); std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);

2
RouterContext.h

@ -32,6 +32,8 @@ namespace i2p
void SetUnreachable (); void SetUnreachable ();
bool AcceptsTunnels () const { return m_AcceptsTunnels; }; bool AcceptsTunnels () const { return m_AcceptsTunnels; };
void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; }; void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; };
bool SupportsV6 () const { return m_RouterInfo.IsV6 (); };
void SetSupportsV6 (bool supportsV6);
// implements LocalDestination // implements LocalDestination
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };

32
RouterInfo.cpp

@ -458,7 +458,7 @@ namespace data
addr.cost = 2; addr.cost = 2;
addr.date = 0; addr.date = 0;
m_Addresses.push_back(addr); m_Addresses.push_back(addr);
m_SupportedTransports |= eNTCPV4; m_SupportedTransports |= addr.host.is_v6 () ? eNTCPV6 : eNTCPV4;
} }
void RouterInfo::AddSSUAddress (const char * host, int port, const uint8_t * key) void RouterInfo::AddSSUAddress (const char * host, int port, const uint8_t * key)
@ -471,7 +471,7 @@ namespace data
addr.date = 0; addr.date = 0;
memcpy (addr.key, key, 32); memcpy (addr.key, key, 32);
m_Addresses.push_back(addr); m_Addresses.push_back(addr);
m_SupportedTransports |= eSSUV4; m_SupportedTransports |= addr.host.is_v6 () ? eNTCPV6 : eSSUV4;
m_Caps |= eSSUTesting; m_Caps |= eSSUTesting;
m_Caps |= eSSUIntroducer; m_Caps |= eSSUIntroducer;
} }
@ -560,6 +560,34 @@ namespace data
return m_SupportedTransports & (eSSUV4 | eSSUV6); return m_SupportedTransports & (eSSUV4 | eSSUV6);
} }
bool RouterInfo::IsV6 () const
{
return m_SupportedTransports & (eNTCPV6 | eSSUV6);
}
void RouterInfo::EnableV6 ()
{
if (!IsV6 ())
m_SupportedTransports |= eNTCPV6;
}
void RouterInfo::DisableV6 ()
{
if (IsV6 ())
{
m_SupportedTransports &= ~eNTCPV6;
for (size_t i = 0; i < m_Addresses.size (); i++)
{
if (m_Addresses[i].transportStyle == i2p::data::RouterInfo::eTransportNTCP &&
m_Addresses[i].host.is_v6 ())
{
m_Addresses.erase (m_Addresses.begin () + i);
break;
}
}
}
}
bool RouterInfo::UsesIntroducer () const bool RouterInfo::UsesIntroducer () const
{ {
return m_Caps & Caps::eUnreachable; // non-reachable return m_Caps & Caps::eUnreachable; // non-reachable

9
RouterInfo.h

@ -75,6 +75,12 @@ namespace data
// SSU only // SSU only
Tag<32> key; // intro key for SSU Tag<32> key; // intro key for SSU
std::vector<Introducer> introducers; std::vector<Introducer> introducers;
bool IsCompatible (const boost::asio::ip::address& other) const
{
return (host.is_v4 () && other.is_v4 ()) ||
(host.is_v6 () && other.is_v6 ());
}
}; };
RouterInfo (const std::string& fullPath); RouterInfo (const std::string& fullPath);
@ -102,6 +108,9 @@ namespace data
bool IsFloodfill () const; bool IsFloodfill () const;
bool IsNTCP (bool v4only = true) const; bool IsNTCP (bool v4only = true) const;
bool IsSSU (bool v4only = true) const; bool IsSSU (bool v4only = true) const;
bool IsV6 () const;
void EnableV6 ();
void DisableV6 ();
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; }; bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
bool UsesIntroducer () const; bool UsesIntroducer () const;
bool IsIntroducer () const { return m_Caps & eSSUIntroducer; }; bool IsIntroducer () const { return m_Caps & eSSUIntroducer; };

2
Transports.cpp

@ -253,7 +253,7 @@ namespace transport
{ {
// existing session not found. create new // existing session not found. create new
// try NTCP first if message size < 16K // try NTCP first if message size < 16K
auto address = r->GetNTCPAddress (); auto address = r->GetNTCPAddress (!context.SupportsV6 ());
if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < NTCP_MAX_MESSAGE_SIZE) if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < NTCP_MAX_MESSAGE_SIZE)
{ {
auto s = new NTCPClient (m_Service, address->host, address->port, *r); auto s = new NTCPClient (m_Service, address->host, address->port, *r);

Loading…
Cancel
Save