aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2024-03-11 10:17:20 -0400
committerPieter Wuille <pieter@wuille.net>2024-07-01 12:39:57 -0400
commit4eaa239dc3e189369d59144b524cb2808cbef8c3 (patch)
tree6c2471ad2111e89d097f4c132795c09151c2d9ab /src/net.cpp
parent82de1b80d95fc9447e64c098dcadb6b8a2f1f2ee (diff)
downloadbitcoin-4eaa239dc3e189369d59144b524cb2808cbef8c3.tar.xz
random: convert GetRand{Micros,Millis} into randrange
There are only a few call sites of these throughout the codebase, so move the functionality into FastRandomContext, and rewrite all call sites. This requires the callers to explicit construct FastRandomContext objects, which do add to the verbosity, but also make potentially apparent locations where the code can be improved by reusing a FastRandomContext object (see further commit).
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index ac66540022..9e969718b7 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -3475,7 +3475,8 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
// nodes to be "terrible" (see IsTerrible()) if the timestamps are older than 30 days,
// max. 24 hours of "penalty" due to cache shouldn't make any meaningful difference
// in terms of the freshness of the response.
- cache_entry.m_cache_entry_expiration = current_time + std::chrono::hours(21) + GetRandMicros(std::chrono::hours(6));
+ cache_entry.m_cache_entry_expiration = current_time +
+ 21h + FastRandomContext().randrange<std::chrono::microseconds>(6h);
}
return cache_entry.m_addrs_response_cache;
}