@@ -45,21 +45,15 @@ int AddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool>& asmap
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 ();
48
- int tried_bucket = hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
49
- uint32_t mapped_as = GetMappedAS (asmap);
50
- LogPrint (BCLog::NET, " IP %s mapped to AS%i belongs to tried bucket %i\n " , ToStringIP (), mapped_as, tried_bucket);
51
- return tried_bucket;
48
+ return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
52
49
}
53
50
54
51
int AddrInfo::GetNewBucket (const uint256& nKey, const CNetAddr& src, const std::vector<bool >& asmap) const
55
52
{
56
53
std::vector<unsigned char > vchSourceGroupKey = src.GetGroup (asmap);
57
54
uint64_t hash1 = (CHashWriter (SER_GETHASH, 0 ) << nKey << GetGroup (asmap) << vchSourceGroupKey).GetCheapHash ();
58
55
uint64_t hash2 = (CHashWriter (SER_GETHASH, 0 ) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetCheapHash ();
59
- int new_bucket = hash2 % ADDRMAN_NEW_BUCKET_COUNT;
60
- uint32_t mapped_as = GetMappedAS (asmap);
61
- LogPrint (BCLog::NET, " IP %s mapped to AS%i belongs to new bucket %i\n " , ToStringIP (), mapped_as, new_bucket);
62
- return new_bucket;
56
+ return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
63
57
}
64
58
65
59
int AddrInfo::GetBucketPosition (const uint256& nKey, bool fNew , int nBucket) const
@@ -481,6 +475,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
481
475
assert (infoDelete.nRefCount > 0 );
482
476
infoDelete.nRefCount --;
483
477
vvNew[nUBucket][nUBucketPos] = -1 ;
478
+ LogPrint (BCLog::ADDRMAN, " Removed %s from new[%i][%i]\n " , infoDelete.ToString (), nUBucket, nUBucketPos);
484
479
if (infoDelete.nRefCount == 0 ) {
485
480
Delete (nIdDelete);
486
481
}
@@ -532,6 +527,8 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
532
527
infoOld.nRefCount = 1 ;
533
528
vvNew[nUBucket][nUBucketPos] = nIdEvict;
534
529
nNew++;
530
+ LogPrint (BCLog::ADDRMAN, " Moved %s from tried[%i][%i] to new[%i][%i] to make space\n " ,
531
+ infoOld.ToString (), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
535
532
}
536
533
assert (vvTried[nKBucket][nKBucketPos] == -1 );
537
534
@@ -582,17 +579,20 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
582
579
583
580
// Will moving this address into tried evict another entry?
584
581
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1 )) {
585
- // Output the entry we'd be colliding with, for debugging purposes
586
- auto colliding_entry = mapInfo.find (vvTried[tried_bucket][tried_bucket_pos]);
587
- LogPrint (BCLog::ADDRMAN, " Collision inserting element into tried table (%s), moving %s to m_tried_collisions=%d\n " , colliding_entry != mapInfo.end () ? colliding_entry->second .ToString () : " " , addr.ToString (), m_tried_collisions.size ());
588
582
if (m_tried_collisions.size () < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
589
583
m_tried_collisions.insert (nId);
590
584
}
585
+ // Output the entry we'd be colliding with, for debugging purposes
586
+ auto colliding_entry = mapInfo.find (vvTried[tried_bucket][tried_bucket_pos]);
587
+ LogPrint (BCLog::ADDRMAN, " Collision with %s while attempting to move %s to tried table. Collisions=%d\n " ,
588
+ colliding_entry != mapInfo.end () ? colliding_entry->second .ToString () : " " ,
589
+ addr.ToString (),
590
+ m_tried_collisions.size ());
591
591
} else {
592
- LogPrint (BCLog::ADDRMAN, " Moving %s to tried\n " , addr.ToString ());
593
-
594
592
// move nId to the tried tables
595
593
MakeTried (info, nId);
594
+ LogPrint (BCLog::ADDRMAN, " Moved %s mapped to AS%i to tried[%i][%i]\n " ,
595
+ addr.ToString (), addr.GetMappedAS (m_asmap), tried_bucket, tried_bucket_pos);
596
596
}
597
597
}
598
598
@@ -662,6 +662,8 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
662
662
ClearNew (nUBucket, nUBucketPos);
663
663
pinfo->nRefCount ++;
664
664
vvNew[nUBucket][nUBucketPos] = nId;
665
+ LogPrint (BCLog::ADDRMAN, " Added %s mapped to AS%i to new[%i][%i]\n " ,
666
+ addr.ToString (), addr.GetMappedAS (m_asmap), nUBucket, nUBucketPos);
665
667
} else {
666
668
if (pinfo->nRefCount == 0 ) {
667
669
Delete (nId);
@@ -720,6 +722,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
720
722
assert (it_found != mapInfo.end ());
721
723
const AddrInfo& info{it_found->second };
722
724
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
725
+ LogPrint (BCLog::ADDRMAN, " Selected %s from tried\n " , info.ToString ());
723
726
return {info, info.nLastTry };
724
727
}
725
728
fChanceFactor *= 1.2 ;
@@ -739,6 +742,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
739
742
assert (it_found != mapInfo.end ());
740
743
const AddrInfo& info{it_found->second };
741
744
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
745
+ LogPrint (BCLog::ADDRMAN, " Selected %s from new\n " , info.ToString ());
742
746
return {info, info.nLastTry };
743
747
}
744
748
fChanceFactor *= 1.2 ;
@@ -780,7 +784,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
780
784
781
785
addresses.push_back (ai);
782
786
}
783
-
787
+ LogPrint (BCLog::ADDRMAN, " GetAddr returned %d random addresses \n " , addresses. size ());
784
788
return addresses;
785
789
}
786
790
0 commit comments