@@ -99,11 +99,11 @@ double AddrInfo::GetChance(int64_t nNow) const
99
99
return fChance ;
100
100
}
101
101
102
- AddrManImpl::AddrManImpl (std::vector< bool >&& asmap , bool deterministic, int32_t consistency_check_ratio)
102
+ AddrManImpl::AddrManImpl (const NetGroupManager& netgroupman , bool deterministic, int32_t consistency_check_ratio)
103
103
: insecure_rand{deterministic}
104
104
, nKey{deterministic ? uint256{1 } : insecure_rand.rand256 ()}
105
105
, m_consistency_check_ratio{consistency_check_ratio}
106
- , m_asmap{ std::move (asmap) }
106
+ , m_netgroupman{netgroupman }
107
107
{
108
108
for (auto & bucket : vvNew) {
109
109
for (auto & entry : bucket) {
@@ -219,8 +219,8 @@ void AddrManImpl::Serialize(Stream& s_) const
219
219
// Store asmap checksum after bucket entries so that it
220
220
// can be ignored by older clients for backward compatibility.
221
221
uint256 asmap_checksum;
222
- if (m_asmap .size () != 0 ) {
223
- asmap_checksum = SerializeHash (m_asmap );
222
+ if (m_netgroupman. GetAsmap () .size () != 0 ) {
223
+ asmap_checksum = SerializeHash (m_netgroupman. GetAsmap () );
224
224
}
225
225
s << asmap_checksum;
226
226
}
@@ -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_asmap );
301
+ int nKBucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
302
302
int nKBucketPos = info.GetBucketPosition (nKey, false , nKBucket);
303
303
if (info.IsValid ()
304
304
&& vvTried[nKBucket][nKBucketPos] == -1 ) {
@@ -336,8 +336,8 @@ void AddrManImpl::Unserialize(Stream& s_)
336
336
// to restore the entries to the buckets/positions they were in before
337
337
// serialization.
338
338
uint256 supplied_asmap_checksum;
339
- if (m_asmap .size () != 0 ) {
340
- supplied_asmap_checksum = SerializeHash (m_asmap );
339
+ if (m_netgroupman. GetAsmap () .size () != 0 ) {
340
+ supplied_asmap_checksum = SerializeHash (m_netgroupman. GetAsmap () );
341
341
}
342
342
uint256 serialized_asmap_checksum;
343
343
if (format >= Format::V2_ASMAP) {
@@ -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_asmap );
374
+ bucket = info.GetNewBucket (nKey, m_netgroupman. GetAsmap () );
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_asmap )};
498
+ const int start_bucket{info.GetNewBucket (nKey, m_netgroupman. GetAsmap () )};
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_asmap );
513
+ int nKBucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
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_asmap );
529
+ int nUBucket = infoOld.GetNewBucket (nKey, m_netgroupman. GetAsmap () );
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_asmap );
597
+ int nUBucket = pinfo->GetNewBucket (nKey, source, m_netgroupman. GetAsmap () );
598
598
int nUBucketPos = pinfo->GetBucketPosition (nKey, true , nUBucket);
599
599
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1 ;
600
600
if (vvNew[nUBucket][nUBucketPos] != nId) {
@@ -610,7 +610,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
610
610
pinfo->nRefCount ++;
611
611
vvNew[nUBucket][nUBucketPos] = nId;
612
612
LogPrint (BCLog::ADDRMAN, " Added %s mapped to AS%i to new[%i][%i]\n " ,
613
- addr.ToString (), addr.GetMappedAS (m_asmap ), nUBucket, nUBucketPos);
613
+ addr.ToString (), addr.GetMappedAS (m_netgroupman. GetAsmap () ), nUBucket, nUBucketPos);
614
614
} else {
615
615
if (pinfo->nRefCount == 0 ) {
616
616
Delete (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_asmap );
653
+ int tried_bucket = info.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
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?
@@ -669,7 +669,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
669
669
// move nId to the tried tables
670
670
MakeTried (info, nId);
671
671
LogPrint (BCLog::ADDRMAN, " Moved %s mapped to AS%i to tried[%i][%i]\n " ,
672
- addr.ToString (), addr.GetMappedAS (m_asmap ), tried_bucket, tried_bucket_pos);
672
+ addr.ToString (), addr.GetMappedAS (m_netgroupman. GetAsmap () ), tried_bucket, tried_bucket_pos);
673
673
return true ;
674
674
}
675
675
}
@@ -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_asmap );
866
+ int tried_bucket = info_new.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
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_asmap );
932
+ int tried_bucket = newInfo.GetTriedBucket (nKey, m_netgroupman. GetAsmap () );
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_asmap )};
948
+ int bucket{addr_info->GetTriedBucket (nKey, m_netgroupman. GetAsmap () )};
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_asmap )};
954
+ int bucket{addr_info->GetNewBucket (nKey, m_netgroupman. GetAsmap () )};
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_asmap ) != n) {
1029
+ if (it == mapInfo.end () || it->second .GetTriedBucket (nKey, m_netgroupman. GetAsmap () ) != n) {
1030
1030
return -17 ;
1031
1031
}
1032
1032
if (it->second .GetBucketPosition (nKey, false , n) != i) {
@@ -1154,13 +1154,8 @@ std::optional<AddressPosition> AddrManImpl::FindAddressEntry(const CAddress& add
1154
1154
return entry;
1155
1155
}
1156
1156
1157
- const std::vector<bool >& AddrManImpl::GetAsmap () const
1158
- {
1159
- return m_asmap;
1160
- }
1161
-
1162
- AddrMan::AddrMan (std::vector<bool > asmap, bool deterministic, int32_t consistency_check_ratio)
1163
- : m_impl(std::make_unique<AddrManImpl>(std::move(asmap), deterministic, consistency_check_ratio)) {}
1157
+ AddrMan::AddrMan (const NetGroupManager& netgroupman, bool deterministic, int32_t consistency_check_ratio)
1158
+ : m_impl(std::make_unique<AddrManImpl>(netgroupman, deterministic, consistency_check_ratio)) {}
1164
1159
1165
1160
AddrMan::~AddrMan () = default ;
1166
1161
@@ -1235,11 +1230,6 @@ void AddrMan::SetServices(const CService& addr, ServiceFlags nServices)
1235
1230
m_impl->SetServices (addr, nServices);
1236
1231
}
1237
1232
1238
- const std::vector<bool >& AddrMan::GetAsmap () const
1239
- {
1240
- return m_impl->GetAsmap ();
1241
- }
1242
-
1243
1233
std::optional<AddressPosition> AddrMan::FindAddressEntry (const CAddress& addr)
1244
1234
{
1245
1235
return m_impl->FindAddressEntry (addr);
0 commit comments