aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-08-05 14:10:02 +0100
committerJohn Newbery <john@johnnewbery.com>2021-08-19 11:29:54 +0100
commit7e6e65918f75211b517fc887f5d90df8edd52ced (patch)
treea58e8031205061393d89bba7130cf9723f0fc87d /src/addrman.h
parent406be5ff9699874dc1d38d11f036e33cbdb820c9 (diff)
downloadbitcoin-7e6e65918f75211b517fc887f5d90df8edd52ced.tar.xz
[addrman] inline Clear() into CAddrMan ctor
Clear() is now only called from the ctor, so just inline the code into that function. The LOCK(cs) can be removed, since there can be no data races in the ctor. Also move the function definition out of the header and into the cpp file.
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h44
1 files changed, 5 insertions, 39 deletions
diff --git a/src/addrman.h b/src/addrman.h
index c2df87e986..3d49c2583f 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -471,40 +471,7 @@ public:
Check();
}
-private:
- void Clear()
- EXCLUSIVE_LOCKS_REQUIRED(!cs)
- {
- LOCK(cs);
- std::vector<int>().swap(vRandom);
- nKey = insecure_rand.rand256();
- for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
- for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
- vvNew[bucket][entry] = -1;
- }
- }
- for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; bucket++) {
- for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
- vvTried[bucket][entry] = -1;
- }
- }
-
- nIdCount = 0;
- nTried = 0;
- nNew = 0;
- nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
- mapInfo.clear();
- mapAddr.clear();
- }
-
-public:
- explicit CAddrMan(bool deterministic, int32_t consistency_check_ratio)
- : insecure_rand{deterministic},
- m_consistency_check_ratio{consistency_check_ratio}
- {
- Clear();
- if (deterministic) nKey = uint256{1};
- }
+ explicit CAddrMan(bool deterministic, int32_t consistency_check_ratio);
~CAddrMan()
{
@@ -626,17 +593,16 @@ public:
Check();
}
-protected:
- //! secret key to randomize bucket select with
- uint256 nKey;
-
+private:
//! A mutex to protect the inner data structures.
mutable Mutex cs;
-private:
//! Source of random numbers for randomization in inner loops
mutable FastRandomContext insecure_rand GUARDED_BY(cs);
+ //! secret key to randomize bucket select with
+ uint256 nKey;
+
//! Serialization versions.
enum Format : uint8_t {
V0_HISTORICAL = 0, //!< historic format, before commit e6b343d88