aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-05-13 13:43:36 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-07-21 16:01:14 +0200
commitfae0c79351ce34186249d44af0c5c9c7521f4b6c (patch)
tree07be60559c4d33a3d7e430552ea0888052b761b6 /src/addrman.h
parentfa02934c8c9d290ea4d12683e8680c70967a4d3a (diff)
downloadbitcoin-fae0c79351ce34186249d44af0c5c9c7521f4b6c.tar.xz
refactor: Mark CAddrMan::GetAddr const
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 02b8c5d9a2..d4f67c2f5b 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -55,7 +55,7 @@ private:
bool fInTried{false};
//! position in vRandom
- int nRandomPos{-1};
+ mutable int nRandomPos{-1};
friend class CAddrMan;
@@ -596,7 +596,7 @@ public:
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
* @param[in] network Select only addresses of this network (nullopt = all).
*/
- std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network)
+ std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
EXCLUSIVE_LOCKS_REQUIRED(!cs)
{
LOCK(cs);
@@ -669,7 +669,9 @@ private:
std::unordered_map<CNetAddr, int, CNetAddrHash> mapAddr GUARDED_BY(cs);
//! randomly-ordered vector of all nIds
- std::vector<int> vRandom GUARDED_BY(cs);
+ //! This is mutable because it is unobservable outside the class, so any
+ //! changes to it (even in const methods) are also unobservable.
+ mutable std::vector<int> vRandom GUARDED_BY(cs);
// number of "tried" entries
int nTried GUARDED_BY(cs);
@@ -697,7 +699,7 @@ private:
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
//! Swap two elements in vRandom.
- void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs);
//! Move an entry from the "new" table(s) to the "tried" table
void MakeTried(CAddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -752,7 +754,7 @@ private:
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
* @param[in] network Select only addresses of this network (nullopt = all).
*/
- void GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
/** We have successfully connected to this peer. Calling this function
* updates the CAddress's nTime, which is used in our IsTerrible()