Commit bf23d9a6 authored by Matt Whitlock's avatar Matt Whitlock Committed by Andrius Štikonas
Browse files

dht/KBucket: don't accumulate duplicate replacement entries

KBucket::pingQuestionable(const KBucketEntry &) stashes its argument (the
prospective replacement KBucketEntry) in the KBucket::pending_entries
QList if the number of outstanding pings of questionable entries is 2 or
more. Unfortunately, the function was not checking for duplicate entries
in the pending_entries list, which was causing unbounded memory usage as
duplicate replacement entries would rapidly accumulate in the list.

This commit modifies the pingQuestionable function so that, before
inserting a replacement entry into the pending_entries list, it first
removes any matching entry from that list. Then, it *prepends* the new
entry to the list (rather than appending as it did before this commit)
since we want to consider the *freshest* replacements first when
endeavoring to replace bad entries. To bound memory usage, the list of
pending replacements is constrained to contain no more than K entries.
parent 9192610d
......@@ -163,7 +163,13 @@ void KBucket::onTimeout(RPCCall *c)
void KBucket::pingQuestionable(const KBucketEntry &replacement_entry)
{
if (pending_entries_busy_pinging.count() >= 2) {
pending_entries.append(replacement_entry); // lets not have to many pending_entries calls going on
// let's not have too many pending_entries calls going on
pending_entries.removeOne(replacement_entry); // drop any existing duplicate
while (pending_entries.count() >= (int)dht::K) { // limit number of pending entries
pending_entries.removeLast(); // drop stalest
}
// insert replacement entry at front to keep freshest first
pending_entries.prepend(replacement_entry);
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment