@@ -55,7 +55,7 @@ class CAddrInfo : public CAddress
55
55
bool fInTried {false };
56
56
57
57
// ! position in vRandom
58
- int nRandomPos{-1 };
58
+ mutable int nRandomPos{-1 };
59
59
60
60
friend class CAddrMan ;
61
61
@@ -596,7 +596,7 @@ class CAddrMan
596
596
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
597
597
* @param[in] network Select only addresses of this network (nullopt = all).
598
598
*/
599
- std::vector<CAddress> GetAddr (size_t max_addresses, size_t max_pct, std::optional<Network> network)
599
+ std::vector<CAddress> GetAddr (size_t max_addresses, size_t max_pct, std::optional<Network> network) const
600
600
EXCLUSIVE_LOCKS_REQUIRED(!cs)
601
601
{
602
602
LOCK (cs);
@@ -669,7 +669,9 @@ class CAddrMan
669
669
std::unordered_map<CNetAddr, int , CNetAddrHash> mapAddr GUARDED_BY (cs);
670
670
671
671
// ! randomly-ordered vector of all nIds
672
- std::vector<int > vRandom GUARDED_BY (cs);
672
+ // ! This is mutable because it is unobservable outside the class, so any
673
+ // ! changes to it (even in const methods) are also unobservable.
674
+ mutable std::vector<int > vRandom GUARDED_BY (cs);
673
675
674
676
// number of "tried" entries
675
677
int nTried GUARDED_BY (cs);
@@ -697,7 +699,7 @@ class CAddrMan
697
699
CAddrInfo* Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs);
698
700
699
701
// ! Swap two elements in vRandom.
700
- void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) EXCLUSIVE_LOCKS_REQUIRED(cs);
702
+ void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs);
701
703
702
704
// ! Move an entry from the "new" table(s) to the "tried" table
703
705
void MakeTried (CAddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -752,7 +754,7 @@ class CAddrMan
752
754
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
753
755
* @param[in] network Select only addresses of this network (nullopt = all).
754
756
*/
755
- void GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) EXCLUSIVE_LOCKS_REQUIRED(cs);
757
+ void GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
756
758
757
759
/* * We have successfully connected to this peer. Calling this function
758
760
* updates the CAddress's nTime, which is used in our IsTerrible()
0 commit comments