@@ -41,7 +41,7 @@ static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
41
41
/* * The maximum time we'll spend trying to resolve a tried table collision, in seconds */
42
42
static constexpr int64_t ADDRMAN_TEST_WINDOW{40 *60 }; // 40 minutes
43
43
44
- int CAddrInfo ::GetTriedBucket (const uint256& nKey, const std::vector<bool > &asmap) const
44
+ int AddrInfo ::GetTriedBucket (const uint256& nKey, const std::vector<bool > &asmap) const
45
45
{
46
46
uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetKey ()).GetCheapHash ();
47
47
uint64_t hash2 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetGroup (asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash ();
@@ -51,7 +51,7 @@ int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asma
51
51
return tried_bucket;
52
52
}
53
53
54
- int CAddrInfo ::GetNewBucket (const uint256& nKey, const CNetAddr& src, const std::vector<bool > &asmap) const
54
+ int AddrInfo ::GetNewBucket (const uint256& nKey, const CNetAddr& src, const std::vector<bool > &asmap) const
55
55
{
56
56
std::vector<unsigned char > vchSourceGroupKey = src.GetGroup (asmap);
57
57
uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetGroup (asmap) << vchSourceGroupKey).GetCheapHash ();
@@ -62,13 +62,13 @@ int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std:
62
62
return new_bucket;
63
63
}
64
64
65
- int CAddrInfo ::GetBucketPosition (const uint256 &nKey, bool fNew , int nBucket) const
65
+ int AddrInfo ::GetBucketPosition (const uint256 &nKey, bool fNew , int nBucket) const
66
66
{
67
67
uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << (fNew ? uint8_t {' N' } : uint8_t {' K' }) << nBucket << GetKey ()).GetCheapHash ();
68
68
return hash1 % ADDRMAN_BUCKET_SIZE;
69
69
}
70
70
71
- bool CAddrInfo ::IsTerrible (int64_t nNow) const
71
+ bool AddrInfo ::IsTerrible (int64_t nNow) const
72
72
{
73
73
if (nLastTry && nLastTry >= nNow - 60 ) // never remove things tried in the last minute
74
74
return false ;
@@ -88,7 +88,7 @@ bool CAddrInfo::IsTerrible(int64_t nNow) const
88
88
return false ;
89
89
}
90
90
91
- double CAddrInfo ::GetChance (int64_t nNow) const
91
+ double AddrInfo ::GetChance (int64_t nNow) const
92
92
{
93
93
double fChance = 1.0 ;
94
94
int64_t nSinceLastTry = std::max<int64_t >(nNow - nLastTry, 0 );
@@ -190,7 +190,7 @@ void AddrManImpl::Serialize(Stream& s_) const
190
190
int nIds = 0 ;
191
191
for (const auto & entry : mapInfo) {
192
192
mapUnkIds[entry.first ] = nIds;
193
- const CAddrInfo &info = entry.second ;
193
+ const AddrInfo &info = entry.second ;
194
194
if (info.nRefCount ) {
195
195
assert (nIds != nNew); // this means nNew was wrong, oh ow
196
196
s << info;
@@ -199,7 +199,7 @@ void AddrManImpl::Serialize(Stream& s_) const
199
199
}
200
200
nIds = 0 ;
201
201
for (const auto & entry : mapInfo) {
202
- const CAddrInfo &info = entry.second ;
202
+ const AddrInfo &info = entry.second ;
203
203
if (info.fInTried ) {
204
204
assert (nIds != nTried); // this means nTried was wrong, oh ow
205
205
s << info;
@@ -283,7 +283,7 @@ void AddrManImpl::Unserialize(Stream& s_)
283
283
284
284
// Deserialize entries from the new table.
285
285
for (int n = 0 ; n < nNew; n++) {
286
- CAddrInfo &info = mapInfo[n];
286
+ AddrInfo &info = mapInfo[n];
287
287
s >> info;
288
288
mapAddr[info] = n;
289
289
info.nRandomPos = vRandom.size ();
@@ -294,7 +294,7 @@ void AddrManImpl::Unserialize(Stream& s_)
294
294
// Deserialize entries from the tried table.
295
295
int nLost = 0 ;
296
296
for (int n = 0 ; n < nTried; n++) {
297
- CAddrInfo info;
297
+ AddrInfo info;
298
298
s >> info;
299
299
int nKBucket = info.GetTriedBucket (nKey, m_asmap);
300
300
int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
@@ -351,7 +351,7 @@ void AddrManImpl::Unserialize(Stream& s_)
351
351
for (auto bucket_entry : bucket_entries) {
352
352
int bucket{bucket_entry.first };
353
353
const int entry_index{bucket_entry.second };
354
- CAddrInfo & info = mapInfo[entry_index];
354
+ AddrInfo & info = mapInfo[entry_index];
355
355
356
356
// Don't store the entry in the new bucket if it's not a valid address for our addrman
357
357
if (!info.IsValid ()) continue ;
@@ -401,7 +401,7 @@ void AddrManImpl::Unserialize(Stream& s_)
401
401
}
402
402
}
403
403
404
- CAddrInfo * AddrManImpl::Find (const CNetAddr& addr, int * pnId)
404
+ AddrInfo * AddrManImpl::Find (const CNetAddr& addr, int * pnId)
405
405
{
406
406
AssertLockHeld (cs);
407
407
@@ -416,12 +416,12 @@ CAddrInfo* AddrManImpl::Find(const CNetAddr& addr, int* pnId)
416
416
return nullptr ;
417
417
}
418
418
419
- CAddrInfo * AddrManImpl::Create (const CAddress& addr, const CNetAddr& addrSource, int * pnId)
419
+ AddrInfo * AddrManImpl::Create (const CAddress& addr, const CNetAddr& addrSource, int * pnId)
420
420
{
421
421
AssertLockHeld (cs);
422
422
423
423
int nId = nIdCount++;
424
- mapInfo[nId] = CAddrInfo (addr, addrSource);
424
+ mapInfo[nId] = AddrInfo (addr, addrSource);
425
425
mapAddr[addr] = nId;
426
426
mapInfo[nId].nRandomPos = vRandom.size ();
427
427
vRandom.push_back (nId);
@@ -459,7 +459,7 @@ void AddrManImpl::Delete(int nId)
459
459
AssertLockHeld (cs);
460
460
461
461
assert (mapInfo.count (nId) != 0 );
462
- CAddrInfo & info = mapInfo[nId];
462
+ AddrInfo & info = mapInfo[nId];
463
463
assert (!info.fInTried );
464
464
assert (info.nRefCount == 0 );
465
465
@@ -477,7 +477,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
477
477
// if there is an entry in the specified bucket, delete it.
478
478
if (vvNew[nUBucket][nUBucketPos] != -1 ) {
479
479
int nIdDelete = vvNew[nUBucket][nUBucketPos];
480
- CAddrInfo & infoDelete = mapInfo[nIdDelete];
480
+ AddrInfo & infoDelete = mapInfo[nIdDelete];
481
481
assert (infoDelete.nRefCount > 0 );
482
482
infoDelete.nRefCount --;
483
483
vvNew[nUBucket][nUBucketPos] = -1 ;
@@ -487,7 +487,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
487
487
}
488
488
}
489
489
490
- void AddrManImpl::MakeTried (CAddrInfo & info, int nId)
490
+ void AddrManImpl::MakeTried (AddrInfo & info, int nId)
491
491
{
492
492
AssertLockHeld (cs);
493
493
@@ -515,7 +515,7 @@ void AddrManImpl::MakeTried(CAddrInfo& info, int nId)
515
515
// find an item to evict
516
516
int nIdEvict = vvTried[nKBucket][nKBucketPos];
517
517
assert (mapInfo.count (nIdEvict) == 1 );
518
- CAddrInfo & infoOld = mapInfo[nIdEvict];
518
+ AddrInfo & infoOld = mapInfo[nIdEvict];
519
519
520
520
// Remove the to-be-evicted item from the tried set.
521
521
infoOld.fInTried = false ;
@@ -548,13 +548,13 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
548
548
549
549
nLastGood = nTime;
550
550
551
- CAddrInfo * pinfo = Find (addr, &nId);
551
+ AddrInfo * pinfo = Find (addr, &nId);
552
552
553
553
// if not found, bail out
554
554
if (!pinfo)
555
555
return ;
556
556
557
- CAddrInfo & info = *pinfo;
557
+ AddrInfo & info = *pinfo;
558
558
559
559
// check whether we are talking about the exact same CService (including same port)
560
560
if (info != addr)
@@ -605,7 +605,7 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
605
605
606
606
bool fNew = false ;
607
607
int nId;
608
- CAddrInfo * pinfo = Find (addr, &nId);
608
+ AddrInfo * pinfo = Find (addr, &nId);
609
609
610
610
// Do not set a penalty for a source's self-announcement
611
611
if (addr == source) {
@@ -652,7 +652,7 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
652
652
if (vvNew[nUBucket][nUBucketPos] != nId) {
653
653
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1 ;
654
654
if (!fInsert ) {
655
- CAddrInfo & infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
655
+ AddrInfo & infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
656
656
if (infoExisting.IsTerrible () || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0 )) {
657
657
// Overwrite the existing new table entry.
658
658
fInsert = true ;
@@ -675,13 +675,13 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, int64_t nTi
675
675
{
676
676
AssertLockHeld (cs);
677
677
678
- CAddrInfo * pinfo = Find (addr);
678
+ AddrInfo * pinfo = Find (addr);
679
679
680
680
// if not found, bail out
681
681
if (!pinfo)
682
682
return ;
683
683
684
- CAddrInfo & info = *pinfo;
684
+ AddrInfo & info = *pinfo;
685
685
686
686
// check whether we are talking about the exact same CService (including same port)
687
687
if (info != addr)
@@ -718,7 +718,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
718
718
int nId = vvTried[nKBucket][nKBucketPos];
719
719
const auto it_found{mapInfo.find (nId)};
720
720
assert (it_found != mapInfo.end ());
721
- const CAddrInfo & info{it_found->second };
721
+ const AddrInfo & info{it_found->second };
722
722
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
723
723
return {info, info.nLastTry };
724
724
}
@@ -737,7 +737,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
737
737
int nId = vvNew[nUBucket][nUBucketPos];
738
738
const auto it_found{mapInfo.find (nId)};
739
739
assert (it_found != mapInfo.end ());
740
- const CAddrInfo & info{it_found->second };
740
+ const AddrInfo & info{it_found->second };
741
741
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
742
742
return {info, info.nLastTry };
743
743
}
@@ -770,7 +770,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
770
770
const auto it{mapInfo.find (vRandom[n])};
771
771
assert (it != mapInfo.end ());
772
772
773
- const CAddrInfo & ai{it->second };
773
+ const AddrInfo & ai{it->second };
774
774
775
775
// Filter by network (optional)
776
776
if (network != std::nullopt && ai.GetNetClass () != network) continue ;
@@ -788,13 +788,13 @@ void AddrManImpl::Connected_(const CService& addr, int64_t nTime)
788
788
{
789
789
AssertLockHeld (cs);
790
790
791
- CAddrInfo * pinfo = Find (addr);
791
+ AddrInfo * pinfo = Find (addr);
792
792
793
793
// if not found, bail out
794
794
if (!pinfo)
795
795
return ;
796
796
797
- CAddrInfo & info = *pinfo;
797
+ AddrInfo & info = *pinfo;
798
798
799
799
// check whether we are talking about the exact same CService (including same port)
800
800
if (info != addr)
@@ -810,13 +810,13 @@ void AddrManImpl::SetServices_(const CService& addr, ServiceFlags nServices)
810
810
{
811
811
AssertLockHeld (cs);
812
812
813
- CAddrInfo * pinfo = Find (addr);
813
+ AddrInfo * pinfo = Find (addr);
814
814
815
815
// if not found, bail out
816
816
if (!pinfo)
817
817
return ;
818
818
819
- CAddrInfo & info = *pinfo;
819
+ AddrInfo & info = *pinfo;
820
820
821
821
// check whether we are talking about the exact same CService (including same port)
822
822
if (info != addr)
@@ -839,7 +839,7 @@ void AddrManImpl::ResolveCollisions_()
839
839
if (mapInfo.count (id_new) != 1 ) {
840
840
erase_collision = true ;
841
841
} else {
842
- CAddrInfo & info_new = mapInfo[id_new];
842
+ AddrInfo & info_new = mapInfo[id_new];
843
843
844
844
// Which tried bucket to move the entry to.
845
845
int tried_bucket = info_new.GetTriedBucket (nKey, m_asmap);
@@ -850,7 +850,7 @@ void AddrManImpl::ResolveCollisions_()
850
850
851
851
// Get the to-be-evicted address that is being tested
852
852
int id_old = vvTried[tried_bucket][tried_bucket_pos];
853
- CAddrInfo & info_old = mapInfo[id_old];
853
+ AddrInfo & info_old = mapInfo[id_old];
854
854
855
855
// Has successfully connected in last X hours
856
856
if (GetAdjustedTime () - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60 *60 )) {
@@ -905,13 +905,13 @@ std::pair<CAddress, int64_t> AddrManImpl::SelectTriedCollision_()
905
905
return {};
906
906
}
907
907
908
- const CAddrInfo & newInfo = mapInfo[id_new];
908
+ const AddrInfo & newInfo = mapInfo[id_new];
909
909
910
910
// which tried bucket to move the entry to
911
911
int tried_bucket = newInfo.GetTriedBucket (nKey, m_asmap);
912
912
int tried_bucket_pos = newInfo.GetBucketPosition (nKey, false , tried_bucket);
913
913
914
- const CAddrInfo & info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
914
+ const AddrInfo & info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
915
915
return {info_old, info_old.nLastTry };
916
916
}
917
917
@@ -944,7 +944,7 @@ int AddrManImpl::ForceCheckAddrman() const
944
944
945
945
for (const auto & entry : mapInfo) {
946
946
int n = entry.first ;
947
- const CAddrInfo & info = entry.second ;
947
+ const AddrInfo & info = entry.second ;
948
948
if (info.fInTried ) {
949
949
if (!info.nLastSuccess )
950
950
return -1 ;
0 commit comments