Skip to content

Commit af9638a

Browse files
[move-only] Extract constants from addrman .h to .cpp
Reviewer hint: use `git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space` Co-authored-by: John Newbery <[email protected]>
1 parent 7dc443a commit af9638a

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

src/addrman.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@
1515
#include <unordered_map>
1616
#include <unordered_set>
1717

18+
//! over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
19+
static constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP{8};
20+
21+
//! over how many buckets entries with new addresses originating from a single group are spread
22+
static constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP{64};
23+
24+
//! in how many buckets for entries with new addresses a single address may occur
25+
static constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS{8};
26+
27+
//! how old addresses can maximally be
28+
static constexpr int64_t ADDRMAN_HORIZON_DAYS{30};
29+
30+
//! after how many failed attempts we give up on a new node
31+
static constexpr int32_t ADDRMAN_RETRIES{3};
32+
33+
//! how many successive failures are allowed ...
34+
static constexpr int32_t ADDRMAN_MAX_FAILURES{10};
35+
36+
//! ... in at least this many days
37+
static constexpr int64_t ADDRMAN_MIN_FAIL_DAYS{7};
38+
39+
//! how recent a successful connection should be before we allow an address to be evicted from tried
40+
static constexpr int64_t ADDRMAN_REPLACEMENT_HOURS{4};
41+
42+
//! the maximum number of tried addr collisions to store
43+
static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
44+
45+
//! the maximum time we'll spend trying to resolve a tried table collision, in seconds
46+
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
47+
48+
1849
int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
1950
{
2051
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetCheapHash();

src/addrman.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -133,48 +133,16 @@ class CAddrInfo : public CAddress
133133

134134
//! total number of buckets for tried addresses
135135
static constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2{8};
136+
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT{1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2};
136137

137138
//! total number of buckets for new addresses
138139
static constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2{10};
140+
static constexpr int ADDRMAN_NEW_BUCKET_COUNT{1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2};
139141

140142
//! maximum allowed number of entries in buckets for new and tried addresses
141143
static constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2{6};
142-
143-
//! over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
144-
static constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP{8};
145-
146-
//! over how many buckets entries with new addresses originating from a single group are spread
147-
static constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP{64};
148-
149-
//! in how many buckets for entries with new addresses a single address may occur
150-
static constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS{8};
151-
152-
//! how old addresses can maximally be
153-
static constexpr int64_t ADDRMAN_HORIZON_DAYS{30};
154-
155-
//! after how many failed attempts we give up on a new node
156-
static constexpr int32_t ADDRMAN_RETRIES{3};
157-
158-
//! how many successive failures are allowed ...
159-
static constexpr int32_t ADDRMAN_MAX_FAILURES{10};
160-
161-
//! ... in at least this many days
162-
static constexpr int64_t ADDRMAN_MIN_FAIL_DAYS{7};
163-
164-
//! how recent a successful connection should be before we allow an address to be evicted from tried
165-
static constexpr int64_t ADDRMAN_REPLACEMENT_HOURS{4};
166-
167-
//! Convenience
168-
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT{1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2};
169-
static constexpr int ADDRMAN_NEW_BUCKET_COUNT{1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2};
170144
static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2};
171145

172-
//! the maximum number of tried addr collisions to store
173-
static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
174-
175-
//! the maximum time we'll spend trying to resolve a tried table collision, in seconds
176-
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
177-
178146
/**
179147
* Stochastical (IP) address manager
180148
*/

0 commit comments

Comments
 (0)