Commit bf23d9a6 authored by Committed by Andrius ŠtikonasBrowse 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.