From ace80c29e7caf25ea50534370962443faada5991 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 1 Feb 2021 18:00:03 -0500 Subject: [PATCH] meshnets.yggaddress added --- daemon/Daemon.cpp | 21 +++++++++++++++++---- libi2pd/Config.cpp | 1 + libi2pd/RouterInfo.cpp | 3 ++- libi2pd/util.cpp | 4 ++-- libi2pd/util.h | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/daemon/Daemon.cpp b/daemon/Daemon.cpp index c53a5d47..70c4affc 100644 --- a/daemon/Daemon.cpp +++ b/daemon/Daemon.cpp @@ -148,11 +148,24 @@ namespace i2p boost::asio::ip::address_v6 yggaddr; if (ygg) { - yggaddr = i2p::util::net::GetYggdrasilAddress (); - if (yggaddr.is_unspecified ()) + std::string yggaddress; i2p::config::GetOption ("meshnets.yggaddress", yggaddress); + if (!yggaddress.empty ()) { - LogPrint(eLogWarning, "Daemon: Yggdrasil is not running. Disabled"); - ygg = false; + yggaddr = boost::asio::ip::address_v6::from_string (yggaddress); + if (yggaddr.is_unspecified () || i2p::util::net::GetMTU (yggaddr) != 0xFFFF) // ygg's MTU is always 65535 + { + LogPrint(eLogWarning, "Daemon: Can't find Yggdrasil address ", yggaddress); + ygg = false; + } + } + else + { + yggaddr = i2p::util::net::GetYggdrasilAddress (); + if (yggaddr.is_unspecified ()) + { + LogPrint(eLogWarning, "Daemon: Yggdrasil is not running. Disabled"); + ygg = false; + } } } diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index eb7a230e..9da0bbe0 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -279,6 +279,7 @@ namespace config { options_description meshnets("Meshnet transports options"); meshnets.add_options() ("meshnets.yggdrasil", bool_switch()->default_value(false), "Support transports through the Yggdrasil (deafult: false)") + ("meshnets.yggaddress", value()->default_value(""), "Yggdrasil address to publish") ; m_OptionsDesc diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 3f710aec..13988f5f 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -980,7 +980,8 @@ namespace data return GetAddress ( [](std::shared_ptr address)->bool { - return address->IsPublishedNTCP2 () && address->host.is_v6 (); + return address->IsPublishedNTCP2 () && address->host.is_v6 () && + !i2p::util::net::IsYggdrasilAddress (address->host); }); } diff --git a/libi2pd/util.cpp b/libi2pd/util.cpp index b70aed8d..f9beacf0 100644 --- a/libi2pd/util.cpp +++ b/libi2pd/util.cpp @@ -461,7 +461,7 @@ namespace net #endif } - bool IsInReservedRange (const boost::asio::ip::address& host, bool checkYggdrasil) + bool IsInReservedRange (const boost::asio::ip::address& host) { // https://en.wikipedia.org/wiki/Reserved_IP_addresses if(host.is_v4()) @@ -502,7 +502,7 @@ namespace net if (ipv6_address >= it.first && ipv6_address <= it.second) return true; } - if (checkYggdrasil && IsYggdrasilAddress (ipv6_address.data ())) // yggdrasil? + if (IsYggdrasilAddress (ipv6_address.data ())) // yggdrasil? return true; } return false; diff --git a/libi2pd/util.h b/libi2pd/util.h index bd02c648..d4b9da51 100644 --- a/libi2pd/util.h +++ b/libi2pd/util.h @@ -189,7 +189,7 @@ namespace util int GetMTU (const boost::asio::ip::address& localAddress); const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false); boost::asio::ip::address_v6 GetYggdrasilAddress (); - bool IsInReservedRange (const boost::asio::ip::address& host, bool checkYggdrasil = true); + bool IsInReservedRange (const boost::asio::ip::address& host); bool IsYggdrasilAddress (const boost::asio::ip::address& addr); } }