mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
refactor: Mark CAddrMan::Select const
This commit is contained in:
@@ -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);
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
@@ -433,8 +433,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|||||||
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
||||||
}
|
}
|
||||||
int nId = vvTried[nKBucket][nKBucketPos];
|
int nId = vvTried[nKBucket][nKBucketPos];
|
||||||
assert(mapInfo.count(nId) == 1);
|
const auto it_found{mapInfo.find(nId)};
|
||||||
CAddrInfo& info = mapInfo[nId];
|
assert(it_found != mapInfo.end());
|
||||||
|
const CAddrInfo& info{it_found->second};
|
||||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
||||||
return info;
|
return info;
|
||||||
fChanceFactor *= 1.2;
|
fChanceFactor *= 1.2;
|
||||||
@@ -450,8 +451,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|||||||
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
||||||
}
|
}
|
||||||
int nId = vvNew[nUBucket][nUBucketPos];
|
int nId = vvNew[nUBucket][nUBucketPos];
|
||||||
assert(mapInfo.count(nId) == 1);
|
const auto it_found{mapInfo.find(nId)};
|
||||||
CAddrInfo& info = mapInfo[nId];
|
assert(it_found != mapInfo.end());
|
||||||
|
const CAddrInfo& info{it_found->second};
|
||||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
||||||
return info;
|
return info;
|
||||||
fChanceFactor *= 1.2;
|
fChanceFactor *= 1.2;
|
||||||
|
|||||||
@@ -579,7 +579,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Choose an address to connect to.
|
* Choose an address to connect to.
|
||||||
*/
|
*/
|
||||||
CAddrInfo Select(bool newOnly = false)
|
CAddrInfo Select(bool newOnly = false) const
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!cs)
|
EXCLUSIVE_LOCKS_REQUIRED(!cs)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
@@ -631,7 +631,7 @@ protected:
|
|||||||
uint256 nKey;
|
uint256 nKey;
|
||||||
|
|
||||||
//! Source of random numbers for randomization in inner loops
|
//! Source of random numbers for randomization in inner loops
|
||||||
FastRandomContext insecure_rand;
|
mutable FastRandomContext insecure_rand;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! A mutex to protect the inner data structures.
|
//! 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);
|
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.
|
//! 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.
|
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
|
||||||
void ResolveCollisions_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
void ResolveCollisions_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
@@ -727,7 +727,7 @@ private:
|
|||||||
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
//! Consistency check
|
//! Consistency check
|
||||||
void Check()
|
void Check() const
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(cs)
|
EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_ADDRMAN
|
#ifdef DEBUG_ADDRMAN
|
||||||
@@ -741,7 +741,7 @@ private:
|
|||||||
|
|
||||||
#ifdef DEBUG_ADDRMAN
|
#ifdef DEBUG_ADDRMAN
|
||||||
//! Perform consistency check. Returns an error code or zero.
|
//! Perform consistency check. Returns an error code or zero.
|
||||||
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
int Check_() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user