From 9e5935aea5c979a3a41a1c200811687b48356f68 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 30 Jan 2021 18:32:17 -0500 Subject: [PATCH] NTCP2Mesh added --- libi2pd/NTCP2.cpp | 2 +- libi2pd/RouterInfo.cpp | 23 +++++++++++++++++------ libi2pd/RouterInfo.h | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index d72aa014..1c2a71cf 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -655,7 +655,7 @@ namespace transport SendTerminationAndTerminate (eNTCP2Message3Error); return; } - auto addr = ri.GetNTCP2Address (false, false); // any NTCP2 address including v6 + auto addr = ri.GetNTCP2Address (false); // any NTCP2 address if (!addr) { LogPrint (eLogError, "NTCP2: No NTCP2 address found in SessionConfirmed"); diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index a1c8821f..34d377cb 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -16,6 +16,7 @@ #include #endif #include "version.h" +#include "util.h" #include "Crypto.h" #include "Base.h" #include "Timestamp.h" @@ -298,8 +299,18 @@ namespace data } if (address->transportStyle == eTransportNTCP) { - if (isStaticKey && isHost) - supportedTransports |= address->host.is_v4 () ? eNTCP2V4 : eNTCP2V6; + if (isStaticKey) + { + if (isHost) + { + if (address->host.is_v6 ()) + supportedTransports |= i2p::util::net::IsYggdrasilAddress (address->host) ? eNTCP2V6Mesh : eNTCP2V6; + else + supportedTransports |= eNTCP2V4; + } + else if (!address->ntcp2->isPublished) + supportedTransports |= eNTCP2V4; // most likely, since we don't have host + } } else if (address->transportStyle == eTransportSSU) { @@ -920,12 +931,12 @@ namespace data return nullptr; } - std::shared_ptr RouterInfo::GetNTCP2Address (bool publishedOnly, bool v4only) const + std::shared_ptr RouterInfo::GetNTCP2Address (bool publishedOnly) const { return GetAddress ( - [publishedOnly, v4only](std::shared_ptr address)->bool - { - return address->IsNTCP2 () && (!publishedOnly || address->IsPublishedNTCP2 ()) && (!v4only || address->host.is_v4 ()); + [publishedOnly](std::shared_ptr address)->bool + { + return address->IsNTCP2 () && (!publishedOnly || address->IsPublishedNTCP2 ()); }); } diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index a5303e84..50ed3576 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -57,7 +57,8 @@ namespace data eNTCP2V4 = 0x01, eNTCP2V6 = 0x02, eSSUV4 = 0x04, - eSSUV6 = 0x08 + eSSUV6 = 0x08, + eNTCP2V6Mesh = 0x10 }; enum Caps @@ -149,7 +150,7 @@ namespace data uint64_t GetTimestamp () const { return m_Timestamp; }; int GetVersion () const { return m_Version; }; Addresses& GetAddresses () { return *m_Addresses; }; // should be called for local RI only, otherwise must return shared_ptr - std::shared_ptr GetNTCP2Address (bool publishedOnly, bool v4only = true) const; + std::shared_ptr GetNTCP2Address (bool publishedOnly) const; std::shared_ptr GetPublishedNTCP2V4Address () const; std::shared_ptr GetPublishedNTCP2V6Address () const; std::shared_ptr GetSSUAddress (bool v4only = true) const;