refactor: update Select_ function

Extract the logic that decides whether the new or the tried table is going to
be searched to the beginning of the function.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
Amiti Uttarwar 2023-02-18 17:38:58 -07:00
parent a245429d68
commit 9bf078f66c

View File

@ -719,12 +719,21 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
AssertLockHeld(cs);
if (vRandom.empty()) return {};
if (newOnly && nNew == 0) return {};
// Decide if we are going to search the new or tried table
bool search_tried;
// Use a 50% chance for choosing between tried and new table entries.
if (!newOnly &&
(nTried > 0 && (nNew == 0 || insecure_rand.randbool() == 0))) {
(nTried > 0 &&
(nNew == 0 || insecure_rand.randbool() == 0))) {
search_tried = true;
} else {
search_tried = false;
}
if (search_tried) {
// use a tried node
double fChanceFactor = 1.0;
while (1) {