@@ -723,33 +723,39 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
723
723
724
724
// Decide if we are going to search the new or tried table
725
725
bool search_tried;
726
+ int bucket_count;
726
727
727
728
// Use a 50% chance for choosing between tried and new table entries.
728
729
if (!newOnly &&
729
730
(nTried > 0 &&
730
731
(nNew == 0 || insecure_rand.randbool () == 0 ))) {
731
732
search_tried = true ;
733
+ bucket_count = ADDRMAN_TRIED_BUCKET_COUNT;
732
734
} else {
733
735
search_tried = false ;
736
+ bucket_count = ADDRMAN_NEW_BUCKET_COUNT;
734
737
}
735
738
736
739
if (search_tried) {
737
740
// use a tried node
738
741
double fChanceFactor = 1.0 ;
739
742
while (1 ) {
740
743
// Pick a tried bucket, and an initial position in that bucket.
741
- int nKBucket = insecure_rand.randrange (ADDRMAN_TRIED_BUCKET_COUNT );
744
+ int nKBucket = insecure_rand.randrange (bucket_count );
742
745
int nKBucketPos = insecure_rand.randrange (ADDRMAN_BUCKET_SIZE);
743
746
// Iterate over the positions of that bucket, starting at the initial one,
744
747
// and looping around.
745
748
int i;
746
749
for (i = 0 ; i < ADDRMAN_BUCKET_SIZE; ++i) {
747
- if (vvTried[nKBucket][(nKBucketPos + i) % ADDRMAN_BUCKET_SIZE] != -1 ) break ;
750
+ int position = (nKBucketPos + i) % ADDRMAN_BUCKET_SIZE;
751
+ int node_id = GetEntry (search_tried, nKBucket, position);
752
+ if (node_id != -1 ) break ;
748
753
}
749
754
// If the bucket is entirely empty, start over with a (likely) different one.
750
755
if (i == ADDRMAN_BUCKET_SIZE) continue ;
751
756
// Find the entry to return.
752
- int nId = vvTried[nKBucket][(nKBucketPos + i) % ADDRMAN_BUCKET_SIZE];
757
+ int position = (nKBucketPos + i) % ADDRMAN_BUCKET_SIZE;
758
+ int nId = GetEntry (search_tried, nKBucket, position);
753
759
const auto it_found{mapInfo.find (nId)};
754
760
assert (it_found != mapInfo.end ());
755
761
const AddrInfo& info{it_found->second };
@@ -766,18 +772,21 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
766
772
double fChanceFactor = 1.0 ;
767
773
while (1 ) {
768
774
// Pick a new bucket, and an initial position in that bucket.
769
- int nUBucket = insecure_rand.randrange (ADDRMAN_NEW_BUCKET_COUNT );
775
+ int nUBucket = insecure_rand.randrange (bucket_count );
770
776
int nUBucketPos = insecure_rand.randrange (ADDRMAN_BUCKET_SIZE);
771
777
// Iterate over the positions of that bucket, starting at the initial one,
772
778
// and looping around.
773
779
int i;
774
780
for (i = 0 ; i < ADDRMAN_BUCKET_SIZE; ++i) {
775
- if (vvNew[nUBucket][(nUBucketPos + i) % ADDRMAN_BUCKET_SIZE] != -1 ) break ;
781
+ int position = (nUBucketPos + i) % ADDRMAN_BUCKET_SIZE;
782
+ int node_id = GetEntry (search_tried, nUBucket, position);
783
+ if (node_id != -1 ) break ;
776
784
}
777
785
// If the bucket is entirely empty, start over with a (likely) different one.
778
786
if (i == ADDRMAN_BUCKET_SIZE) continue ;
779
787
// Find the entry to return.
780
- int nId = vvNew[nUBucket][(nUBucketPos + i) % ADDRMAN_BUCKET_SIZE];
788
+ int position = (nUBucketPos + i) % ADDRMAN_BUCKET_SIZE;
789
+ int nId = GetEntry (search_tried, nUBucket, position);
781
790
const auto it_found{mapInfo.find (nId)};
782
791
assert (it_found != mapInfo.end ());
783
792
const AddrInfo& info{it_found->second };
0 commit comments