From 6176bccc7e650d411f235975e6db0e9b29afd347 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 12 Oct 2026 16:48:53 -0400 Subject: [PATCH] don't send datagrams to self --- libi2pd_client/TorrentsDHT.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/libi2pd_client/TorrentsDHT.cpp b/libi2pd_client/TorrentsDHT.cpp index 94bc4212..654a9eb2 100644 --- a/libi2pd_client/TorrentsDHT.cpp +++ b/libi2pd_client/TorrentsDHT.cpp @@ -816,7 +816,7 @@ namespace torrents { memcpy (nodeInfo.data (), nodes.data (), nodeInfo.size ()); auto node = std::make_shared(nodeInfo); - if (info && node->VerifyID () && info->AddNode (node)) + if (info && node->id != m_NodeID && node->VerifyID () && info->AddNode (node)) { if (m_HeardFrom.contains (node->id)) UpdateNode (node); @@ -855,7 +855,7 @@ namespace torrents { memcpy (nodeInfo.data (), nodes.data (), nodeInfo.size ()); auto node = std::make_shared(nodeInfo); - if (info && node->VerifyID () && info->AddNode (node)) + if (info && node->id != m_NodeID && node->VerifyID () && info->AddNode (node)) { if (m_HeardFrom.contains (node->id)) UpdateNode (node); @@ -881,9 +881,14 @@ namespace torrents auto dest = m_Tunnel.GetLocalDestination (); if (dest) { - auto dgramDest = dest->GetDatagramDestination (); - if (dgramDest) - dgramDest->SendDatagramTo ((const uint8_t *)msg.data (), msg.size (), toIdent, m_Port, toPort); + if (toIdent != dest->GetIdentHash ()) + { + auto dgramDest = dest->GetDatagramDestination (); + if (dgramDest) + dgramDest->SendDatagramTo ((const uint8_t *)msg.data (), msg.size (), toIdent, m_Port, toPort); + } + else + LogPrint (eLogWarning, "TorrentsDHT: Can't send datagram to self"); } } @@ -892,9 +897,14 @@ namespace torrents auto dest = m_Tunnel.GetLocalDestination (); if (dest) { - auto dgramDest = dest->GetDatagramDestination (); - if (dgramDest) - dgramDest->SendRawDatagramTo ((const uint8_t *)msg.data (), msg.size (), toIdent, m_Port, toPort); + if (toIdent != dest->GetIdentHash ()) + { + auto dgramDest = dest->GetDatagramDestination (); + if (dgramDest) + dgramDest->SendRawDatagramTo ((const uint8_t *)msg.data (), msg.size (), toIdent, m_Port, toPort); + } + else + LogPrint (eLogWarning, "TorrentsDHT: Can't send raw datagram to self"); } }