aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2023-02-18 17:38:58 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2023-03-05 17:34:15 -0800
commit9bf078f66c8f286e1ab5e34b8eeed7d80290a897 (patch)
treea334c3d8260d2b6b3a00b34360cdc432d80e6fea /src/addrman.cpp
parenta245429d680eb95cf4c0c78e58e63e3f0f5d979a (diff)
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>
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index f5ca9a5c34..ec5b0213b3 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -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) {