Skip to content

Commit fa02934

Browse files
author
MarcoFalke
committed
refactor: Mark CAddrMan::Select const
1 parent a3791da commit fa02934

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/addrman.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
410410
}
411411
}
412412

413-
CAddrInfo CAddrMan::Select_(bool newOnly)
413+
CAddrInfo CAddrMan::Select_(bool newOnly) const
414414
{
415415
AssertLockHeld(cs);
416416

@@ -433,8 +433,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
433433
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
434434
}
435435
int nId = vvTried[nKBucket][nKBucketPos];
436-
assert(mapInfo.count(nId) == 1);
437-
CAddrInfo& info = mapInfo[nId];
436+
const auto it_found{mapInfo.find(nId)};
437+
assert(it_found != mapInfo.end());
438+
const CAddrInfo& info{it_found->second};
438439
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
439440
return info;
440441
fChanceFactor *= 1.2;
@@ -450,8 +451,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
450451
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
451452
}
452453
int nId = vvNew[nUBucket][nUBucketPos];
453-
assert(mapInfo.count(nId) == 1);
454-
CAddrInfo& info = mapInfo[nId];
454+
const auto it_found{mapInfo.find(nId)};
455+
assert(it_found != mapInfo.end());
456+
const CAddrInfo& info{it_found->second};
455457
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
456458
return info;
457459
fChanceFactor *= 1.2;

src/addrman.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class CAddrMan
579579
/**
580580
* Choose an address to connect to.
581581
*/
582-
CAddrInfo Select(bool newOnly = false)
582+
CAddrInfo Select(bool newOnly = false) const
583583
EXCLUSIVE_LOCKS_REQUIRED(!cs)
584584
{
585585
LOCK(cs);
@@ -631,7 +631,7 @@ class CAddrMan
631631
uint256 nKey;
632632

633633
//! Source of random numbers for randomization in inner loops
634-
FastRandomContext insecure_rand;
634+
mutable FastRandomContext insecure_rand;
635635

636636
private:
637637
//! A mutex to protect the inner data structures.
@@ -718,7 +718,7 @@ class CAddrMan
718718
void Attempt_(const CService &addr, bool fCountFailure, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);
719719

720720
//! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
721-
CAddrInfo Select_(bool newOnly) EXCLUSIVE_LOCKS_REQUIRED(cs);
721+
CAddrInfo Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
722722

723723
//! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
724724
void ResolveCollisions_() EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -727,7 +727,7 @@ class CAddrMan
727727
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
728728

729729
//! Consistency check
730-
void Check()
730+
void Check() const
731731
EXCLUSIVE_LOCKS_REQUIRED(cs)
732732
{
733733
#ifdef DEBUG_ADDRMAN
@@ -741,7 +741,7 @@ class CAddrMan
741741

742742
#ifdef DEBUG_ADDRMAN
743743
//! Perform consistency check. Returns an error code or zero.
744-
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs);
744+
int Check_() const EXCLUSIVE_LOCKS_REQUIRED(cs);
745745
#endif
746746

747747
/**

0 commit comments

Comments
 (0)