From d1341aa961720bdadca28da36f86e21679958421 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 15 Oct 2026 21:36:07 -0400 Subject: [PATCH] delete expired node from full bucket before find_node --- libi2pd_client/TorrentsDHT.cpp | 15 +++++++++++++-- libi2pd_client/TorrentsDHT.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libi2pd_client/TorrentsDHT.cpp b/libi2pd_client/TorrentsDHT.cpp index 9fc58410..370d7d15 100644 --- a/libi2pd_client/TorrentsDHT.cpp +++ b/libi2pd_client/TorrentsDHT.cpp @@ -250,12 +250,22 @@ namespace torrents bucket->nodes.erase (id); } - std::list > RoutingTable::GetExploratoryTargets (std::mt19937& rng) const + std::list > RoutingTable::GetExploratoryTargets (std::mt19937& rng, uint64_t ts) { std::list > ret; auto bucket = m_Buckets; while (bucket) { + if (bucket->IsFull ()) + { + // delete one node about to expire + for (auto it = bucket->nodes.begin (); it != bucket->nodes.end (); it++) + if (ts > it->second->lastUpdateTime + DHT_NODE_SEND_PING_TIME) + { + bucket->nodes.erase (it); + break; + } + } if (!bucket->IsFull () || bucket->IsInBucket (m_OurNode)) ret.emplace_back (std::make_pair (bucket->GetRandomID (rng), bucket)); bucket = bucket->next; @@ -1017,7 +1027,8 @@ namespace torrents { if (m_RoutingTable && m_Tunnel.GetLocalDestination ()) { - auto targets = m_RoutingTable->GetExploratoryTargets (m_Tunnel.GetLocalDestination ()->GetRng ()); + auto targets = m_RoutingTable->GetExploratoryTargets (m_Tunnel.GetLocalDestination ()->GetRng (), + i2p::util::GetMonotonicSeconds ()); for (auto [target, bucket]: targets) { auto request = std::make_shared(nullptr, DHT_MAX_NUM_FIND_NODE_ATTEMPTS); diff --git a/libi2pd_client/TorrentsDHT.h b/libi2pd_client/TorrentsDHT.h index 8537856a..3530488b 100644 --- a/libi2pd_client/TorrentsDHT.h +++ b/libi2pd_client/TorrentsDHT.h @@ -137,7 +137,7 @@ namespace torrents std::shared_ptr AddNode (std::shared_ptr node); void RemoveNode (const NodeID& id); - std::list > GetExploratoryTargets (std::mt19937& rng) const; // (target, node to send find_node to) + std::list > GetExploratoryTargets (std::mt19937& rng, uint64_t ts); // (target, node to send find_node to) size_t DeleteExpiredNodes (uint64_t ts); std::list > GetNodesToPing (uint64_t ts);