From 3695aa924b723f9e25ad66a1f427a15c7bff6ac4 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 24 Mar 2021 10:32:15 -0400 Subject: [PATCH] doesn't send peer test to a reserved address --- libi2pd/SSUSession.cpp | 22 +++++++++++++--------- libi2pd/Transports.cpp | 16 ++++++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libi2pd/SSUSession.cpp b/libi2pd/SSUSession.cpp index 66579a16..2e49e970 100644 --- a/libi2pd/SSUSession.cpp +++ b/libi2pd/SSUSession.cpp @@ -273,7 +273,7 @@ namespace transport s.Insert (payload, 8); // relayTag and signed on time m_RelayTag = bufbe32toh (payload); payload += 4; // relayTag - if (i2p::context.GetStatus () == eRouterStatusTesting) + if (ourIP.is_v4 () && i2p::context.GetStatus () == eRouterStatusTesting) { auto ts = i2p::util::GetSecondsSinceEpoch (); uint32_t signedOnTime = bufbe32toh(payload); @@ -358,7 +358,9 @@ namespace transport uint8_t * payload = buf + sizeof (SSUHeader); uint8_t flag = 0; // fill extended options, 3 bytes extended options don't change message size - if (i2p::context.GetStatus () == eRouterStatusOK) // we don't need relays + bool isV4 = m_RemoteEndpoint.address ().is_v4 (); + if ((isV4 && i2p::context.GetStatus () == eRouterStatusOK) || + (!isV4 && i2p::context.GetStatusV6 () == eRouterStatusOK)) // we don't need relays { // tell out peer to now assign relay tag flag = SSU_HEADER_EXTENDED_OPTIONS_INCLUDED; @@ -369,7 +371,6 @@ namespace transport } // fill payload memcpy (payload, m_DHKeysPair->GetPublicKey (), 256); // x - bool isV4 = m_RemoteEndpoint.address ().is_v4 (); if (isV4) { payload[256] = 4; @@ -657,13 +658,16 @@ namespace transport buf += ourSize; len -= ourSize; LogPrint (eLogInfo, "SSU: Our external address is ", ourIP.to_string (), ":", ourPort); i2p::context.UpdateAddress (ourIP); - if (ourPort != m_Server.GetPort ()) + if (ourIP.is_v4 ()) { - if (i2p::context.GetStatus () == eRouterStatusTesting) - i2p::context.SetError (eRouterErrorSymmetricNAT); - } - else if (i2p::context.GetStatus () == eRouterStatusError && i2p::context.GetError () == eRouterErrorSymmetricNAT) - i2p::context.SetStatus (eRouterStatusTesting); + if (ourPort != m_Server.GetPort ()) + { + if (i2p::context.GetStatus () == eRouterStatusTesting) + i2p::context.SetError (eRouterErrorSymmetricNAT); + } + else if (i2p::context.GetStatus () == eRouterStatusError && i2p::context.GetError () == eRouterErrorSymmetricNAT) + i2p::context.SetStatus (eRouterStatusTesting); + } uint32_t nonce = bufbe32toh (buf); buf += 4; // nonce auto it = m_RelayRequests.find (nonce); diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index 78b45e32..13c1d210 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -593,12 +593,16 @@ namespace transport auto router = i2p::data::netdb.GetRandomPeerTestRouter (true); // v4 if (router) { - if (!statusChanged) + auto addr = router->GetSSUAddress (true); // ipv4 + if (addr && !i2p::util::net::IsInReservedRange(addr->host)) { - statusChanged = true; - i2p::context.SetStatus (eRouterStatusTesting); // first time only - } - m_SSUServer->CreateSession (router, true, true); // peer test v4 + if (!statusChanged) + { + statusChanged = true; + i2p::context.SetStatus (eRouterStatusTesting); // first time only + } + m_SSUServer->CreateSession (router, addr, true); // peer test v4 + } } } if (!statusChanged) @@ -614,7 +618,7 @@ namespace transport if (router) { auto addr = router->GetSSUV6Address (); - if (addr) + if (addr && !i2p::util::net::IsInReservedRange(addr->host)) { if (!statusChanged) {