Skip to content

Commit 7dc443a

Browse files
[addrman] Change addrman #define constants to be constexprs
Co-authored-by: John Newbery <[email protected]>
1 parent a65053f commit 7dc443a

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/addrman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ void CAddrMan::Unserialize(Stream& s_)
237237

238238
if (nNew > ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE || nNew < 0) {
239239
throw std::ios_base::failure(
240-
strprintf("Corrupt CAddrMan serialization: nNew=%d, should be in [0, %u]",
240+
strprintf("Corrupt CAddrMan serialization: nNew=%d, should be in [0, %d]",
241241
nNew,
242242
ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE));
243243
}
244244

245245
if (nTried > ADDRMAN_TRIED_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE || nTried < 0) {
246246
throw std::ios_base::failure(
247-
strprintf("Corrupt CAddrMan serialization: nTried=%d, should be in [0, %u]",
247+
strprintf("Corrupt CAddrMan serialization: nTried=%d, should be in [0, %d]",
248248
nTried,
249249
ADDRMAN_TRIED_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE));
250250
}

src/addrman.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,48 +132,48 @@ class CAddrInfo : public CAddress
132132
*/
133133

134134
//! total number of buckets for tried addresses
135-
#define ADDRMAN_TRIED_BUCKET_COUNT_LOG2 8
135+
static constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2{8};
136136

137137
//! total number of buckets for new addresses
138-
#define ADDRMAN_NEW_BUCKET_COUNT_LOG2 10
138+
static constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2{10};
139139

140140
//! maximum allowed number of entries in buckets for new and tried addresses
141-
#define ADDRMAN_BUCKET_SIZE_LOG2 6
141+
static constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2{6};
142142

143143
//! over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
144-
#define ADDRMAN_TRIED_BUCKETS_PER_GROUP 8
144+
static constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP{8};
145145

146146
//! over how many buckets entries with new addresses originating from a single group are spread
147-
#define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP 64
147+
static constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP{64};
148148

149149
//! in how many buckets for entries with new addresses a single address may occur
150-
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS 8
150+
static constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS{8};
151151

152152
//! how old addresses can maximally be
153-
#define ADDRMAN_HORIZON_DAYS 30
153+
static constexpr int64_t ADDRMAN_HORIZON_DAYS{30};
154154

155155
//! after how many failed attempts we give up on a new node
156-
#define ADDRMAN_RETRIES 3
156+
static constexpr int32_t ADDRMAN_RETRIES{3};
157157

158158
//! how many successive failures are allowed ...
159-
#define ADDRMAN_MAX_FAILURES 10
159+
static constexpr int32_t ADDRMAN_MAX_FAILURES{10};
160160

161161
//! ... in at least this many days
162-
#define ADDRMAN_MIN_FAIL_DAYS 7
162+
static constexpr int64_t ADDRMAN_MIN_FAIL_DAYS{7};
163163

164164
//! how recent a successful connection should be before we allow an address to be evicted from tried
165-
#define ADDRMAN_REPLACEMENT_HOURS 4
165+
static constexpr int64_t ADDRMAN_REPLACEMENT_HOURS{4};
166166

167167
//! Convenience
168-
#define ADDRMAN_TRIED_BUCKET_COUNT (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2)
169-
#define ADDRMAN_NEW_BUCKET_COUNT (1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2)
170-
#define ADDRMAN_BUCKET_SIZE (1 << ADDRMAN_BUCKET_SIZE_LOG2)
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};
170+
static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2};
171171

172172
//! the maximum number of tried addr collisions to store
173-
#define ADDRMAN_SET_TRIED_COLLISION_SIZE 10
173+
static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
174174

175175
//! the maximum time we'll spend trying to resolve a tried table collision, in seconds
176-
static const int64_t ADDRMAN_TEST_WINDOW = 40*60; // 40 minutes
176+
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
177177

178178
/**
179179
* Stochastical (IP) address manager

0 commit comments

Comments
 (0)