@@ -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
@@ -544,12 +544,12 @@ class CAddrMan
544
544
}
545
545
546
546
// ! Mark an entry as accessible.
547
- void Good (const CService &addr, bool test_before_evict = true , int64_t nTime = GetAdjustedTime())
547
+ void Good (const CService &addr, int64_t nTime = GetAdjustedTime())
548
548
EXCLUSIVE_LOCKS_REQUIRED(!cs)
549
549
{
550
550
LOCK (cs);
551
551
Check ();
552
- Good_ (addr, test_before_evict, nTime);
552
+ Good_ (addr, /* test_before_evict */ true , nTime);
553
553
Check ();
554
554
}
555
555
@@ -587,7 +587,7 @@ class CAddrMan
587
587
/* *
588
588
* Choose an address to connect to.
589
589
*/
590
- CAddrInfo Select (bool newOnly = false )
590
+ CAddrInfo Select (bool newOnly = false ) const
591
591
EXCLUSIVE_LOCKS_REQUIRED(!cs)
592
592
{
593
593
LOCK (cs);
@@ -604,7 +604,7 @@ class CAddrMan
604
604
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
605
605
* @param[in] network Select only addresses of this network (nullopt = all).
606
606
*/
607
- std::vector<CAddress> GetAddr (size_t max_addresses, size_t max_pct, std::optional<Network> network)
607
+ std::vector<CAddress> GetAddr (size_t max_addresses, size_t max_pct, std::optional<Network> network) const
608
608
EXCLUSIVE_LOCKS_REQUIRED(!cs)
609
609
{
610
610
LOCK (cs);
@@ -650,12 +650,12 @@ class CAddrMan
650
650
uint256 nKey;
651
651
652
652
// ! Source of random numbers for randomization in inner loops
653
- FastRandomContext insecure_rand;
653
+ mutable FastRandomContext insecure_rand GUARDED_BY (cs) ;
654
654
655
- private:
656
655
// ! A mutex to protect the inner data structures.
657
656
mutable Mutex cs;
658
657
658
+ private:
659
659
// ! Serialization versions.
660
660
enum Format : uint8_t {
661
661
V0_HISTORICAL = 0 , // !< historic format, before commit e6b343d88
@@ -688,7 +688,9 @@ class CAddrMan
688
688
std::map<CService, int > mapAddr GUARDED_BY (cs);
689
689
690
690
// ! randomly-ordered vector of all nIds
691
- std::vector<int > vRandom GUARDED_BY (cs);
691
+ // ! This is mutable because it is unobservable outside the class, so any
692
+ // ! changes to it (even in const methods) are also unobservable.
693
+ mutable std::vector<int > vRandom GUARDED_BY (cs);
692
694
693
695
// number of "tried" entries
694
696
int nTried GUARDED_BY (cs);
@@ -718,7 +720,7 @@ class CAddrMan
718
720
CAddrInfo* Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs);
719
721
720
722
// ! Swap two elements in vRandom.
721
- void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) EXCLUSIVE_LOCKS_REQUIRED(cs);
723
+ void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs);
722
724
723
725
// ! Move an entry from the "new" table(s) to the "tried" table
724
726
void MakeTried (CAddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -739,7 +741,7 @@ class CAddrMan
739
741
void Attempt_ (const CService &addr, bool fCountFailure , int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);
740
742
741
743
// ! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
742
- CAddrInfo Select_ (bool newOnly) EXCLUSIVE_LOCKS_REQUIRED(cs);
744
+ CAddrInfo Select_ (bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
743
745
744
746
// ! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
745
747
void ResolveCollisions_ () EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -748,7 +750,7 @@ class CAddrMan
748
750
CAddrInfo SelectTriedCollision_ () EXCLUSIVE_LOCKS_REQUIRED(cs);
749
751
750
752
// ! Consistency check
751
- void Check ()
753
+ void Check () const
752
754
EXCLUSIVE_LOCKS_REQUIRED(cs)
753
755
{
754
756
#ifdef DEBUG_ADDRMAN
@@ -762,7 +764,7 @@ class CAddrMan
762
764
763
765
#ifdef DEBUG_ADDRMAN
764
766
// ! Perform consistency check. Returns an error code or zero.
765
- int Check_ () EXCLUSIVE_LOCKS_REQUIRED(cs);
767
+ int Check_ () const EXCLUSIVE_LOCKS_REQUIRED(cs);
766
768
#endif
767
769
768
770
/* *
@@ -773,7 +775,7 @@ class CAddrMan
773
775
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
774
776
* @param[in] network Select only addresses of this network (nullopt = all).
775
777
*/
776
- void GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) EXCLUSIVE_LOCKS_REQUIRED(cs);
778
+ void GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
777
779
778
780
/* * We have successfully connected to this peer. Calling this function
779
781
* updates the CAddress's nTime, which is used in our IsTerrible()
0 commit comments