diff --git a/Config.cpp b/Config.cpp index caec7e20..5e775e74 100644 --- a/Config.cpp +++ b/Config.cpp @@ -117,6 +117,7 @@ namespace config { ("datadir", value()->default_value(""), "Path to storage of i2pd data (RI, keys, peer profiles, ...)") ("host", value()->default_value("0.0.0.0"), "External IP") ("port", value()->default_value(0), "Port to listen for incoming connections (default: auto)") + ("ipv4", value()->zero_tokens()->default_value(true), "Enable communication through ipv4") ("ipv6", value()->zero_tokens()->default_value(false), "Enable communication through ipv6") ("daemon", value()->zero_tokens()->default_value(false), "Router will go to background after start") ("service", value()->zero_tokens()->default_value(false), "Router will use system folders like '/var/lib/i2pd'") diff --git a/Daemon.cpp b/Daemon.cpp index 7f96b470..bd89250e 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -104,9 +104,11 @@ namespace i2p i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host)); } - bool ipv6; i2p::config::GetOption("ipv6", ipv6); + bool ipv6; i2p::config::GetOption("ipv6", ipv6); + bool ipv4; i2p::config::GetOption("ipv4", ipv4); bool transit; i2p::config::GetOption("notransit", transit); - i2p::context.SetSupportsV6 (ipv6); + i2p::context.SetSupportsV6 (ipv6); + i2p::context.SetSupportsV4 (ipv4); i2p::context.SetAcceptsTunnels (!transit); bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill); diff --git a/RouterContext.cpp b/RouterContext.cpp index dc08ede3..2157a81e 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -257,7 +257,17 @@ namespace i2p else m_RouterInfo.DisableV6 (); UpdateRouterInfo (); - } + } + + void RouterContext::SetSupportsV4 (bool supportsV4) + { + if (supportsV4) + m_RouterInfo.EnableV4 (); + else + m_RouterInfo.DisableV4 (); + UpdateRouterInfo (); + } + void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host) { diff --git a/RouterContext.h b/RouterContext.h index bc1ee836..0679a038 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -64,7 +64,10 @@ namespace i2p bool AcceptsTunnels () const { return m_AcceptsTunnels; }; void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; }; bool SupportsV6 () const { return m_RouterInfo.IsV6 (); }; + bool SupportsV4 () const { return m_RouterInfo.IsV4 (); }; void SetSupportsV6 (bool supportsV6); + void SetSupportsV4 (bool supportsV4); + void UpdateNTCPV6Address (const boost::asio::ip::address& host); // called from NTCP session void UpdateStats (); diff --git a/RouterInfo.cpp b/RouterInfo.cpp index e9285d54..22c5f2f8 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -651,12 +651,24 @@ namespace data return m_SupportedTransports & (eNTCPV6 | eSSUV6); } + bool RouterInfo::IsV4 () const + { + return m_SupportedTransports & (eNTCPV4 | eSSUV4); + } + void RouterInfo::EnableV6 () { if (!IsV6 ()) m_SupportedTransports |= eNTCPV6 | eSSUV6; } - + + void RouterInfo::EnableV4 () + { + if (!IsV4 ()) + m_SupportedTransports |= eNTCPV4 | eSSUV4; + } + + void RouterInfo::DisableV6 () { if (IsV6 ()) @@ -686,7 +698,38 @@ namespace data } } } - + + void RouterInfo::DisableV4 () + { + if (IsV4 ()) + { + // NTCP + m_SupportedTransports &= ~eNTCPV4; + for (size_t i = 0; i < m_Addresses.size (); i++) + { + if (m_Addresses[i]->transportStyle == i2p::data::RouterInfo::eTransportNTCP && + m_Addresses[i]->host.is_v4 ()) + { + m_Addresses.erase (m_Addresses.begin () + i); + break; + } + } + + // SSU + m_SupportedTransports &= ~eSSUV4; + for (size_t i = 0; i < m_Addresses.size (); i++) + { + if (m_Addresses[i]->transportStyle == i2p::data::RouterInfo::eTransportSSU && + m_Addresses[i]->host.is_v4 ()) + { + m_Addresses.erase (m_Addresses.begin () + i); + break; + } + } + } + } + + bool RouterInfo::UsesIntroducer () const { return m_Caps & Caps::eUnreachable; // non-reachable diff --git a/RouterInfo.h b/RouterInfo.h index 69607d4b..5fa865b0 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -133,8 +133,11 @@ namespace data bool IsNTCP (bool v4only = true) const; bool IsSSU (bool v4only = true) const; bool IsV6 () const; + bool IsV4 () const; void EnableV6 (); void DisableV6 (); + void EnableV4 (); + void DisableV4 (); bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; }; bool UsesIntroducer () const; bool IsIntroducer () const { return m_Caps & eSSUIntroducer; };