From e0790700cddadbf27f1cbb1945d7c3b341ade00b Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 18 Jul 2018 14:19:12 -0400 Subject: [PATCH] don't connect to unpublished NTCP2 addresses --- libi2pd/NTCP2.cpp | 2 +- libi2pd/RouterInfo.cpp | 3 ++- libi2pd/RouterInfo.h | 2 ++ libi2pd/Transports.cpp | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 07ae9b99..85c7c7ac 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -590,7 +590,7 @@ namespace transport uint8_t * decrypted = new uint8_t[m_NextReceivedLen]; if (i2p::crypto::AEADChaCha20Poly1305 (m_NextReceivedBuffer, m_NextReceivedLen-16, nullptr, 0, m_ReceiveKey, nonce, decrypted, m_NextReceivedLen, false)) { - LogPrint (eLogInfo, "NTCP2: received message decrypted"); + LogPrint (eLogDebug, "NTCP2: received message decrypted"); ProcessNextFrame (decrypted, m_NextReceivedLen-16); ReceiveLength (); } diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index a0b818fb..535c7bd8 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -259,6 +259,7 @@ namespace data if (!address->ntcp2) address->ntcp2.reset (new NTCP2Ext ()); supportedTransports |= (address->host.is_v4 ()) ? eNTCP2V4 : eNTCP2V6; Base64ToByteStream (value, strlen (value), address->ntcp2->iv, 16); + address->ntcp2->isPublished = true; // presence if "i" means "published" } else if (key[0] == 'i') { @@ -292,7 +293,7 @@ namespace data if (!s) return; } if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented - if (supportedTransports && !isNtcp2) // we ignore NTCP2 addresses for now. TODO: + if (supportedTransports && (!isNtcp2 || address->IsPublishedNTCP2 ())) // we ignore unpublished NTCP2 only addresses { addresses->push_back(address); m_SupportedTransports |= supportedTransports; diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index a12b23e3..07cc3af4 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -94,6 +94,7 @@ namespace data { Tag<32> staticKey; Tag<16> iv; + bool isPublished = false; }; struct Address @@ -124,6 +125,7 @@ namespace data } bool IsNTCP2 () const { return (bool)ntcp2; }; + bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; }; }; typedef std::list > Addresses; diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index 32f1dc30..5f2747a6 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -405,7 +405,7 @@ namespace transport { peer.numAttempts++; auto address = peer.router->GetNTCPAddress (!context.SupportsV6 ()); - if (address && address->IsNTCP2 () && m_NTCP2Server) // NTCP2 have priority over NTCP if enabled + if (address && address->IsPublishedNTCP2 () && m_NTCP2Server) // NTCP2 have priority over NTCP if enabled { auto s = std::make_shared (*m_NTCP2Server, peer.router); m_NTCP2Server->Connect (address->host, address->port, s);