mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
refactor: Mark CAddrMan::Select const
This commit is contained in:
parent
a3791da0e8
commit
fa02934c8c
2 changed files with 12 additions and 10 deletions
|
@ -410,7 +410,7 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
|
|||
}
|
||||
}
|
||||
|
||||
CAddrInfo CAddrMan::Select_(bool newOnly)
|
||||
CAddrInfo CAddrMan::Select_(bool newOnly) const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
|
@ -433,8 +433,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|||
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
||||
}
|
||||
int nId = vvTried[nKBucket][nKBucketPos];
|
||||
assert(mapInfo.count(nId) == 1);
|
||||
CAddrInfo& info = mapInfo[nId];
|
||||
const auto it_found{mapInfo.find(nId)};
|
||||
assert(it_found != mapInfo.end());
|
||||
const CAddrInfo& info{it_found->second};
|
||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
||||
return info;
|
||||
fChanceFactor *= 1.2;
|
||||
|
@ -450,8 +451,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|||
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
||||
}
|
||||
int nId = vvNew[nUBucket][nUBucketPos];
|
||||
assert(mapInfo.count(nId) == 1);
|
||||
CAddrInfo& info = mapInfo[nId];
|
||||
const auto it_found{mapInfo.find(nId)};
|
||||
assert(it_found != mapInfo.end());
|
||||
const CAddrInfo& info{it_found->second};
|
||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
||||
return info;
|
||||
fChanceFactor *= 1.2;
|
||||
|
|
|
@ -579,7 +579,7 @@ public:
|
|||
/**
|
||||
* Choose an address to connect to.
|
||||
*/
|
||||
CAddrInfo Select(bool newOnly = false)
|
||||
CAddrInfo Select(bool newOnly = false) const
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!cs)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
@ -631,7 +631,7 @@ protected:
|
|||
uint256 nKey;
|
||||
|
||||
//! Source of random numbers for randomization in inner loops
|
||||
FastRandomContext insecure_rand;
|
||||
mutable FastRandomContext insecure_rand;
|
||||
|
||||
private:
|
||||
//! A mutex to protect the inner data structures.
|
||||
|
@ -718,7 +718,7 @@ private:
|
|||
void Attempt_(const CService &addr, bool fCountFailure, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
//! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
|
||||
CAddrInfo Select_(bool newOnly) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
CAddrInfo Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
|
||||
void ResolveCollisions_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
@ -727,7 +727,7 @@ private:
|
|||
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
//! Consistency check
|
||||
void Check()
|
||||
void Check() const
|
||||
EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||
{
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
|
@ -741,7 +741,7 @@ private:
|
|||
|
||||
#ifdef DEBUG_ADDRMAN
|
||||
//! Perform consistency check. Returns an error code or zero.
|
||||
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
int Check_() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue