mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
[addrman] Clean up ctor
Use default initialization and initializer lists, and use range-based for loops for resetting the buckets.
This commit is contained in:
parent
7e6e65918f
commit
4d2fa97031
2 changed files with 12 additions and 21 deletions
|
@ -79,28 +79,19 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
||||||
|
|
||||||
CAddrMan::CAddrMan(bool deterministic, int32_t consistency_check_ratio)
|
CAddrMan::CAddrMan(bool deterministic, int32_t consistency_check_ratio)
|
||||||
: insecure_rand{deterministic}
|
: insecure_rand{deterministic}
|
||||||
|
, nKey{deterministic ? uint256{1} : insecure_rand.rand256()}
|
||||||
, m_consistency_check_ratio{consistency_check_ratio}
|
, m_consistency_check_ratio{consistency_check_ratio}
|
||||||
{
|
{
|
||||||
std::vector<int>().swap(vRandom);
|
for (auto& bucket : vvNew) {
|
||||||
nKey = insecure_rand.rand256();
|
for (auto& entry : bucket) {
|
||||||
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
|
entry = -1;
|
||||||
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 (auto& bucket : vvTried) {
|
||||||
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
|
for (auto& entry : bucket) {
|
||||||
vvTried[bucket][entry] = -1;
|
entry = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nIdCount = 0;
|
|
||||||
nTried = 0;
|
|
||||||
nNew = 0;
|
|
||||||
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
|
|
||||||
mapInfo.clear();
|
|
||||||
mapAddr.clear();
|
|
||||||
if (deterministic) nKey = uint256{1};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||||
|
|
|
@ -626,7 +626,7 @@ private:
|
||||||
static constexpr uint8_t INCOMPATIBILITY_BASE = 32;
|
static constexpr uint8_t INCOMPATIBILITY_BASE = 32;
|
||||||
|
|
||||||
//! last used nId
|
//! last used nId
|
||||||
int nIdCount GUARDED_BY(cs);
|
int nIdCount GUARDED_BY(cs){0};
|
||||||
|
|
||||||
//! table with information about all nIds
|
//! table with information about all nIds
|
||||||
std::unordered_map<int, CAddrInfo> mapInfo GUARDED_BY(cs);
|
std::unordered_map<int, CAddrInfo> mapInfo GUARDED_BY(cs);
|
||||||
|
@ -640,19 +640,19 @@ private:
|
||||||
mutable std::vector<int> vRandom GUARDED_BY(cs);
|
mutable std::vector<int> vRandom GUARDED_BY(cs);
|
||||||
|
|
||||||
// number of "tried" entries
|
// number of "tried" entries
|
||||||
int nTried GUARDED_BY(cs);
|
int nTried GUARDED_BY(cs){0};
|
||||||
|
|
||||||
//! list of "tried" buckets
|
//! list of "tried" buckets
|
||||||
int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
|
int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
|
||||||
|
|
||||||
//! number of (unique) "new" entries
|
//! number of (unique) "new" entries
|
||||||
int nNew GUARDED_BY(cs);
|
int nNew GUARDED_BY(cs){0};
|
||||||
|
|
||||||
//! list of "new" buckets
|
//! list of "new" buckets
|
||||||
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
|
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
|
||||||
|
|
||||||
//! last time Good was called (memory only)
|
//! last time Good was called (memory only). Initially set to 1 so that "never" is strictly worse.
|
||||||
int64_t nLastGood GUARDED_BY(cs);
|
int64_t nLastGood GUARDED_BY(cs){1};
|
||||||
|
|
||||||
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
|
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
|
||||||
std::set<int> m_tried_collisions;
|
std::set<int> m_tried_collisions;
|
||||||
|
|
Loading…
Add table
Reference in a new issue