@@ -187,36 +187,37 @@ class CAddrInfo : public CAddress
187
187
*/
188
188
class CAddrMan
189
189
{
190
- private :
190
+ protected :
191
191
// ! critical section to protect the inner data structures
192
192
mutable CCriticalSection cs;
193
193
194
+ private:
194
195
// ! last used nId
195
- int nIdCount;
196
+ int nIdCount GUARDED_BY (cs) ;
196
197
197
198
// ! table with information about all nIds
198
- std::map<int , CAddrInfo> mapInfo;
199
+ std::map<int , CAddrInfo> mapInfo GUARDED_BY (cs) ;
199
200
200
201
// ! find an nId based on its network address
201
- std::map<CNetAddr, int > mapAddr;
202
+ std::map<CNetAddr, int > mapAddr GUARDED_BY (cs) ;
202
203
203
204
// ! randomly-ordered vector of all nIds
204
- std::vector<int > vRandom;
205
+ std::vector<int > vRandom GUARDED_BY (cs) ;
205
206
206
207
// number of "tried" entries
207
- int nTried;
208
+ int nTried GUARDED_BY (cs) ;
208
209
209
210
// ! list of "tried" buckets
210
- int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
211
+ int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs) ;
211
212
212
213
// ! number of (unique) "new" entries
213
- int nNew;
214
+ int nNew GUARDED_BY (cs) ;
214
215
215
216
// ! list of "new" buckets
216
- int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
217
+ int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs) ;
217
218
218
219
// ! last time Good was called (memory only)
219
- int64_t nLastGood;
220
+ int64_t nLastGood GUARDED_BY (cs) ;
220
221
221
222
// ! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
222
223
std::set<int > m_tried_collisions;
@@ -229,58 +230,58 @@ class CAddrMan
229
230
FastRandomContext insecure_rand;
230
231
231
232
// ! Find an entry.
232
- CAddrInfo* Find (const CNetAddr& addr, int *pnId = nullptr );
233
+ CAddrInfo* Find (const CNetAddr& addr, int *pnId = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
233
234
234
235
// ! find an entry, creating it if necessary.
235
236
// ! nTime and nServices of the found node are updated, if necessary.
236
- CAddrInfo* Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr );
237
+ CAddrInfo* Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
237
238
238
239
// ! Swap two elements in vRandom.
239
- void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2);
240
+ void SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
240
241
241
242
// ! Move an entry from the "new" table(s) to the "tried" table
242
- void MakeTried (CAddrInfo& info, int nId);
243
+ void MakeTried (CAddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
243
244
244
245
// ! Delete an entry. It must not be in tried, and have refcount 0.
245
- void Delete (int nId);
246
+ void Delete (int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
246
247
247
248
// ! Clear a position in a "new" table. This is the only place where entries are actually deleted.
248
- void ClearNew (int nUBucket, int nUBucketPos);
249
+ void ClearNew (int nUBucket, int nUBucketPos) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
249
250
250
251
// ! Mark an entry "good", possibly moving it from "new" to "tried".
251
- void Good_ (const CService &addr, bool test_before_evict, int64_t time);
252
+ void Good_ (const CService &addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
252
253
253
254
// ! Add an entry to the "new" table.
254
- bool Add_ (const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty);
255
+ bool Add_ (const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
255
256
256
257
// ! Mark an entry as attempted to connect.
257
- void Attempt_ (const CService &addr, bool fCountFailure , int64_t nTime);
258
+ void Attempt_ (const CService &addr, bool fCountFailure , int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
258
259
259
260
// ! Select an address to connect to, if newOnly is set to true, only the new table is selected from.
260
- CAddrInfo Select_ (bool newOnly);
261
+ CAddrInfo Select_ (bool newOnly) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
261
262
262
263
// ! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
263
- void ResolveCollisions_ ();
264
+ void ResolveCollisions_ () EXCLUSIVE_LOCKS_REQUIRED(cs) ;
264
265
265
266
// ! Return a random to-be-evicted tried table address.
266
- CAddrInfo SelectTriedCollision_ ();
267
+ CAddrInfo SelectTriedCollision_ () EXCLUSIVE_LOCKS_REQUIRED(cs) ;
267
268
268
269
// ! Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
269
270
virtual int RandomInt (int nMax);
270
271
271
272
#ifdef DEBUG_ADDRMAN
272
273
// ! Perform consistency check. Returns an error code or zero.
273
- int Check_ ();
274
+ int Check_ () EXCLUSIVE_LOCKS_REQUIRED(cs) ;
274
275
#endif
275
276
276
277
// ! Select several addresses at once.
277
- void GetAddr_ (std::vector<CAddress> &vAddr);
278
+ void GetAddr_ (std::vector<CAddress> &vAddr) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
278
279
279
280
// ! Mark an entry as currently-connected-to.
280
- void Connected_ (const CService &addr, int64_t nTime);
281
+ void Connected_ (const CService &addr, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
281
282
282
283
// ! Update an entry's service bits.
283
- void SetServices_ (const CService &addr, ServiceFlags nServices);
284
+ void SetServices_ (const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs) ;
284
285
285
286
public:
286
287
/* *
0 commit comments