@@ -43,17 +43,17 @@ static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
43
43
/* * The maximum time we'll spend trying to resolve a tried table collision, in seconds */
44
44
static constexpr int64_t ADDRMAN_TEST_WINDOW{40 *60 }; // 40 minutes
45
45
46
- int AddrInfo::GetTriedBucket (const uint256& nKey, const std::vector< bool >& asmap ) const
46
+ int AddrInfo::GetTriedBucket (const uint256& nKey, const NetGroupManager& netgroupman ) const
47
47
{
48
48
uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetKey ()).GetCheapHash ();
49
- uint64_t hash2 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetGroup (asmap ) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash ();
49
+ uint64_t hash2 = (CHashWriter (SER_GETHASH, 0 ) << nKey << netgroupman. GetGroup (* this ) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash ();
50
50
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
51
51
}
52
52
53
- int AddrInfo::GetNewBucket (const uint256& nKey, const CNetAddr& src, const std::vector< bool >& asmap ) const
53
+ int AddrInfo::GetNewBucket (const uint256& nKey, const CNetAddr& src, const NetGroupManager& netgroupman ) const
54
54
{
55
- std::vector<unsigned char > vchSourceGroupKey = src .GetGroup (asmap );
56
- uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetGroup (asmap ) << vchSourceGroupKey).GetCheapHash ();
55
+ std::vector<unsigned char > vchSourceGroupKey = netgroupman .GetGroup (src );
56
+ uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << netgroupman. GetGroup (* this ) << vchSourceGroupKey).GetCheapHash ();
57
57
uint64_t hash2 = (CHashWriter (SER_GETHASH, 0 ) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetCheapHash ();
58
58
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
59
59
}
@@ -298,7 +298,7 @@ void AddrManImpl::Unserialize(Stream& s_)
298
298
for (int n = 0 ; n < nTried; n++) {
299
299
AddrInfo info;
300
300
s >> info;
301
- int nKBucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
301
+ int nKBucket = info.GetTriedBucket (nKey, m_netgroupman);
302
302
int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
303
303
if (info.IsValid ()
304
304
&& vvTried[nKBucket][nKBucketPos] == -1 ) {
@@ -371,7 +371,7 @@ void AddrManImpl::Unserialize(Stream& s_)
371
371
} else {
372
372
// In case the new table data cannot be used (bucket count wrong or new asmap),
373
373
// try to give them a reference based on their primary source address.
374
- bucket = info.GetNewBucket (nKey, m_netgroupman. GetAsmap () );
374
+ bucket = info.GetNewBucket (nKey, m_netgroupman);
375
375
bucket_position = info.GetBucketPosition (nKey, true , bucket);
376
376
if (vvNew[bucket][bucket_position] == -1 ) {
377
377
vvNew[bucket][bucket_position] = entry_index;
@@ -495,7 +495,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
495
495
AssertLockHeld (cs);
496
496
497
497
// remove the entry from all new buckets
498
- const int start_bucket{info.GetNewBucket (nKey, m_netgroupman. GetAsmap () )};
498
+ const int start_bucket{info.GetNewBucket (nKey, m_netgroupman)};
499
499
for (int n = 0 ; n < ADDRMAN_NEW_BUCKET_COUNT; ++n) {
500
500
const int bucket{(start_bucket + n) % ADDRMAN_NEW_BUCKET_COUNT};
501
501
const int pos{info.GetBucketPosition (nKey, true , bucket)};
@@ -510,7 +510,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
510
510
assert (info.nRefCount == 0 );
511
511
512
512
// which tried bucket to move the entry to
513
- int nKBucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
513
+ int nKBucket = info.GetTriedBucket (nKey, m_netgroupman);
514
514
int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
515
515
516
516
// first make space to add it (the existing tried entry there is moved to new, deleting whatever is there).
@@ -526,7 +526,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
526
526
nTried--;
527
527
528
528
// find which new bucket it belongs to
529
- int nUBucket = infoOld.GetNewBucket (nKey, m_netgroupman. GetAsmap () );
529
+ int nUBucket = infoOld.GetNewBucket (nKey, m_netgroupman);
530
530
int nUBucketPos = infoOld.GetBucketPosition (nKey, true , nUBucket);
531
531
ClearNew (nUBucket, nUBucketPos);
532
532
assert (vvNew[nUBucket][nUBucketPos] == -1 );
@@ -594,7 +594,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
594
594
nNew++;
595
595
}
596
596
597
- int nUBucket = pinfo->GetNewBucket (nKey, source, m_netgroupman. GetAsmap () );
597
+ int nUBucket = pinfo->GetNewBucket (nKey, source, m_netgroupman);
598
598
int nUBucketPos = pinfo->GetBucketPosition (nKey, true , nUBucket);
599
599
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1 ;
600
600
if (vvNew[nUBucket][nUBucketPos] != nId) {
@@ -650,7 +650,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
650
650
651
651
652
652
// which tried bucket to move the entry to
653
- int tried_bucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
653
+ int tried_bucket = info.GetTriedBucket (nKey, m_netgroupman);
654
654
int tried_bucket_pos = info.GetBucketPosition (nKey, false , tried_bucket);
655
655
656
656
// Will moving this address into tried evict another entry?
@@ -863,7 +863,7 @@ void AddrManImpl::ResolveCollisions_()
863
863
AddrInfo& info_new = mapInfo[id_new];
864
864
865
865
// Which tried bucket to move the entry to.
866
- int tried_bucket = info_new.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
866
+ int tried_bucket = info_new.GetTriedBucket (nKey, m_netgroupman);
867
867
int tried_bucket_pos = info_new.GetBucketPosition (nKey, false , tried_bucket);
868
868
if (!info_new.IsValid ()) { // id_new may no longer map to a valid address
869
869
erase_collision = true ;
@@ -929,7 +929,7 @@ std::pair<CAddress, int64_t> AddrManImpl::SelectTriedCollision_()
929
929
const AddrInfo& newInfo = mapInfo[id_new];
930
930
931
931
// which tried bucket to move the entry to
932
- int tried_bucket = newInfo.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
932
+ int tried_bucket = newInfo.GetTriedBucket (nKey, m_netgroupman);
933
933
int tried_bucket_pos = newInfo.GetBucketPosition (nKey, false , tried_bucket);
934
934
935
935
const AddrInfo& info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
@@ -945,13 +945,13 @@ std::optional<AddressPosition> AddrManImpl::FindAddressEntry_(const CAddress& ad
945
945
if (!addr_info) return std::nullopt;
946
946
947
947
if (addr_info->fInTried ) {
948
- int bucket{addr_info->GetTriedBucket (nKey, m_netgroupman. GetAsmap () )};
948
+ int bucket{addr_info->GetTriedBucket (nKey, m_netgroupman)};
949
949
return AddressPosition (/* tried_in=*/ true ,
950
950
/* multiplicity_in=*/ 1 ,
951
951
/* bucket_in=*/ bucket,
952
952
/* position_in=*/ addr_info->GetBucketPosition (nKey, false , bucket));
953
953
} else {
954
- int bucket{addr_info->GetNewBucket (nKey, m_netgroupman. GetAsmap () )};
954
+ int bucket{addr_info->GetNewBucket (nKey, m_netgroupman)};
955
955
return AddressPosition (/* tried_in=*/ false ,
956
956
/* multiplicity_in=*/ addr_info->nRefCount ,
957
957
/* bucket_in=*/ bucket,
@@ -1026,7 +1026,7 @@ int AddrManImpl::CheckAddrman() const
1026
1026
if (!setTried.count (vvTried[n][i]))
1027
1027
return -11 ;
1028
1028
const auto it{mapInfo.find (vvTried[n][i])};
1029
- if (it == mapInfo.end () || it->second .GetTriedBucket (nKey, m_netgroupman. GetAsmap () ) != n) {
1029
+ if (it == mapInfo.end () || it->second .GetTriedBucket (nKey, m_netgroupman) != n) {
1030
1030
return -17 ;
1031
1031
}
1032
1032
if (it->second .GetBucketPosition (nKey, false , n) != i) {
0 commit comments