mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-09 08:21:59 +02:00
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:
@@ -719,12 +719,21 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
|
|||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (vRandom.empty()) return {};
|
if (vRandom.empty()) return {};
|
||||||
|
|
||||||
if (newOnly && nNew == 0) 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.
|
// Use a 50% chance for choosing between tried and new table entries.
|
||||||
if (!newOnly &&
|
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
|
// use a tried node
|
||||||
double fChanceFactor = 1.0;
|
double fChanceFactor = 1.0;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
Reference in New Issue
Block a user