@@ -79,6 +79,8 @@ double CAddrInfo::GetChance(int64_t nNow) const
79
79
80
80
CAddrInfo* CAddrMan::Find (const CNetAddr& addr, int * pnId)
81
81
{
82
+ AssertLockHeld (cs);
83
+
82
84
const auto it = mapAddr.find (addr);
83
85
if (it == mapAddr.end ())
84
86
return nullptr ;
@@ -92,6 +94,8 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
92
94
93
95
CAddrInfo* CAddrMan::Create (const CAddress& addr, const CNetAddr& addrSource, int * pnId)
94
96
{
97
+ AssertLockHeld (cs);
98
+
95
99
int nId = nIdCount++;
96
100
mapInfo[nId] = CAddrInfo (addr, addrSource);
97
101
mapAddr[addr] = nId;
@@ -104,6 +108,8 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
104
108
105
109
void CAddrMan::SwapRandom (unsigned int nRndPos1, unsigned int nRndPos2)
106
110
{
111
+ AssertLockHeld (cs);
112
+
107
113
if (nRndPos1 == nRndPos2)
108
114
return ;
109
115
@@ -124,6 +130,8 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
124
130
125
131
void CAddrMan::Delete (int nId)
126
132
{
133
+ AssertLockHeld (cs);
134
+
127
135
assert (mapInfo.count (nId) != 0 );
128
136
CAddrInfo& info = mapInfo[nId];
129
137
assert (!info.fInTried );
@@ -138,6 +146,8 @@ void CAddrMan::Delete(int nId)
138
146
139
147
void CAddrMan::ClearNew (int nUBucket, int nUBucketPos)
140
148
{
149
+ AssertLockHeld (cs);
150
+
141
151
// if there is an entry in the specified bucket, delete it.
142
152
if (vvNew[nUBucket][nUBucketPos] != -1 ) {
143
153
int nIdDelete = vvNew[nUBucket][nUBucketPos];
@@ -153,6 +163,8 @@ void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
153
163
154
164
void CAddrMan::MakeTried (CAddrInfo& info, int nId)
155
165
{
166
+ AssertLockHeld (cs);
167
+
156
168
// remove the entry from all new buckets
157
169
for (int bucket = 0 ; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
158
170
int pos = info.GetBucketPosition (nKey, true , bucket);
@@ -201,6 +213,8 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
201
213
202
214
void CAddrMan::Good_ (const CService& addr, bool test_before_evict, int64_t nTime)
203
215
{
216
+ AssertLockHeld (cs);
217
+
204
218
int nId;
205
219
206
220
nLastGood = nTime;
@@ -267,6 +281,8 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
267
281
268
282
bool CAddrMan::Add_ (const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
269
283
{
284
+ AssertLockHeld (cs);
285
+
270
286
if (!addr.IsRoutable ())
271
287
return false ;
272
288
@@ -340,6 +356,8 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
340
356
341
357
void CAddrMan::Attempt_ (const CService& addr, bool fCountFailure , int64_t nTime)
342
358
{
359
+ AssertLockHeld (cs);
360
+
343
361
CAddrInfo* pinfo = Find (addr);
344
362
345
363
// if not found, bail out
@@ -362,6 +380,8 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
362
380
363
381
CAddrInfo CAddrMan::Select_ (bool newOnly)
364
382
{
383
+ AssertLockHeld (cs);
384
+
365
385
if (vRandom.empty ())
366
386
return CAddrInfo ();
367
387
@@ -410,6 +430,8 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
410
430
#ifdef DEBUG_ADDRMAN
411
431
int CAddrMan::Check_ ()
412
432
{
433
+ AssertLockHeld (cs);
434
+
413
435
std::unordered_set<int > setTried;
414
436
std::unordered_map<int , int > mapNew;
415
437
@@ -487,6 +509,8 @@ int CAddrMan::Check_()
487
509
488
510
void CAddrMan::GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
489
511
{
512
+ AssertLockHeld (cs);
513
+
490
514
size_t nNodes = vRandom.size ();
491
515
if (max_pct != 0 ) {
492
516
nNodes = max_pct * nNodes / 100 ;
@@ -519,6 +543,8 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
519
543
520
544
void CAddrMan::Connected_ (const CService& addr, int64_t nTime)
521
545
{
546
+ AssertLockHeld (cs);
547
+
522
548
CAddrInfo* pinfo = Find (addr);
523
549
524
550
// if not found, bail out
@@ -539,6 +565,8 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
539
565
540
566
void CAddrMan::SetServices_ (const CService& addr, ServiceFlags nServices)
541
567
{
568
+ AssertLockHeld (cs);
569
+
542
570
CAddrInfo* pinfo = Find (addr);
543
571
544
572
// if not found, bail out
@@ -557,6 +585,8 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
557
585
558
586
void CAddrMan::ResolveCollisions_ ()
559
587
{
588
+ AssertLockHeld (cs);
589
+
560
590
for (std::set<int >::iterator it = m_tried_collisions.begin (); it != m_tried_collisions.end ();) {
561
591
int id_new = *it;
562
592
@@ -616,6 +646,8 @@ void CAddrMan::ResolveCollisions_()
616
646
617
647
CAddrInfo CAddrMan::SelectTriedCollision_ ()
618
648
{
649
+ AssertLockHeld (cs);
650
+
619
651
if (m_tried_collisions.size () == 0 ) return CAddrInfo ();
620
652
621
653
std::set<int >::iterator it = m_tried_collisions.begin ();
0 commit comments