aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/addrman.cpp12
-rw-r--r--src/addrman.h10
2 files changed, 12 insertions, 10 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 8192b4eba6..6cbcbed839 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -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;
diff --git a/src/addrman.h b/src/addrman.h
index 1fc64ac07f..02b8c5d9a2 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -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
/**