[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.
This commit is contained in:
1 parent
406be5ff96
commit
7e6e65918f
3 files changed
+32
-40
No files matched your search
@@ -77,6 +77,32 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
|||||||
return fChance;
|
return fChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAddrMan::CAddrMan(bool deterministic, int32_t consistency_check_ratio)
|
||||||
|
: insecure_rand{deterministic}
|
||||||
|
, m_consistency_check_ratio{consistency_check_ratio}
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
if (deterministic) nKey = uint256{1};
|
||||||
|
}
|
||||||
|
|
||||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
|
|||||||
+5
-39
@@ -471,40 +471,7 @@ public:
|
|||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
explicit CAddrMan(bool deterministic, int32_t consistency_check_ratio);
|
||||||
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};
|
|
||||||
}
|
|
||||||
|
|
||||||
~CAddrMan()
|
~CAddrMan()
|
||||||
{
|
{
|
||||||
@@ -626,17 +593,16 @@ public:
|
|||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
//! secret key to randomize bucket select with
|
|
||||||
uint256 nKey;
|
|
||||||
|
|
||||||
//! A mutex to protect the inner data structures.
|
//! A mutex to protect the inner data structures.
|
||||||
mutable Mutex cs;
|
mutable Mutex cs;
|
||||||
|
|
||||||
private:
|
|
||||||
//! Source of random numbers for randomization in inner loops
|
//! Source of random numbers for randomization in inner loops
|
||||||
mutable FastRandomContext insecure_rand GUARDED_BY(cs);
|
mutable FastRandomContext insecure_rand GUARDED_BY(cs);
|
||||||
|
|
||||||
|
//! secret key to randomize bucket select with
|
||||||
|
uint256 nKey;
|
||||||
|
|
||||||
//! Serialization versions.
|
//! Serialization versions.
|
||||||
enum Format : uint8_t {
|
enum Format : uint8_t {
|
||||||
V0_HISTORICAL = 0, //!< historic format, before commit e6b343d88
|
V0_HISTORICAL = 0, //!< historic format, before commit e6b343d88
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
unsigned char nVersion = 1;
|
unsigned char nVersion = 1;
|
||||||
s << nVersion;
|
s << nVersion;
|
||||||
s << ((unsigned char)32);
|
s << ((unsigned char)32);
|
||||||
s << nKey;
|
s << uint256::ONE;
|
||||||
s << 10; // nNew
|
s << 10; // nNew
|
||||||
s << 10; // nTried
|
s << 10; // nTried
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user