mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-10-23 19:22:48 +00:00
delete expired node from full bucket before find_node
This commit is contained in:
1 parent
3988b898c4
commit
d1341aa961
2 files changed
+14
-3
No files matched your search
@@ -250,12 +250,22 @@ namespace torrents
|
||||
bucket->nodes.erase (id);
|
||||
}
|
||||
|
||||
std::list<std::pair<NodeID, Bucket * > > RoutingTable::GetExploratoryTargets (std::mt19937& rng) const
|
||||
std::list<std::pair<NodeID, Bucket * > > RoutingTable::GetExploratoryTargets (std::mt19937& rng, uint64_t ts)
|
||||
{
|
||||
std::list<std::pair<NodeID, Bucket * > > 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<RequestInfo>(nullptr, DHT_MAX_NUM_FIND_NODE_ATTEMPTS);
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace torrents
|
||||
|
||||
std::shared_ptr<Node> AddNode (std::shared_ptr<Node> node);
|
||||
void RemoveNode (const NodeID& id);
|
||||
std::list<std::pair<NodeID, Bucket * > > GetExploratoryTargets (std::mt19937& rng) const; // (target, node to send find_node to)
|
||||
std::list<std::pair<NodeID, Bucket * > > GetExploratoryTargets (std::mt19937& rng, uint64_t ts); // (target, node to send find_node to)
|
||||
size_t DeleteExpiredNodes (uint64_t ts);
|
||||
std::list<std::shared_ptr<Node> > GetNodesToPing (uint64_t ts);
|
||||
|
||||
|
||||
Reference in new issue
Block a user