@@ -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
@@ -496,6 +490,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
496
490
assert (infoDelete.nRefCount > 0 );
497
491
infoDelete.nRefCount --;
498
492
vvNew[nUBucket][nUBucketPos] = -1 ;
493
+ LogPrint (BCLog::ADDRMAN, " Removed %s from new[%i][%i]\n " , infoDelete.ToString (), nUBucket, nUBucketPos);
499
494
if (infoDelete.nRefCount == 0 ) {
500
495
Delete (nIdDelete);
501
496
}
@@ -547,6 +542,8 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
547
542
infoOld.nRefCount = 1 ;
548
543
vvNew[nUBucket][nUBucketPos] = nIdEvict;
549
544
nNew++;
545
+ LogPrint (BCLog::ADDRMAN, " Moved %s from tried[%i][%i] to new[%i][%i] to make space\n " ,
546
+ infoOld.ToString (), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
550
547
}
551
548
assert (vvTried[nKBucket][nKBucketPos] == -1 );
552
549
@@ -597,21 +594,24 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
597
594
598
595
// Will moving this address into tried evict another entry?
599
596
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1 )) {
597
+ if (m_tried_collisions.size () < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
598
+ m_tried_collisions.insert (nId);
599
+ }
600
600
// Output the entry we'd be colliding with, for debugging purposes
601
601
auto colliding_entry = mapInfo.find (vvTried[tried_bucket][tried_bucket_pos]);
602
602
if (fLogIPs ) {
603
- LogPrint (BCLog::ADDRMAN, " Collision inserting element into tried table (%s), moving %s to m_tried_collisions =%d\n " ,
603
+ LogPrint (BCLog::ADDRMAN, " Collision with %s while attempting to move %s to tried table. Collisions =%d\n " ,
604
604
colliding_entry != mapInfo.end () ? colliding_entry->second .ToString () : " " ,
605
- addr.ToString (), m_tried_collisions.size ());
606
- }
607
- if (m_tried_collisions.size () < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
608
- m_tried_collisions.insert (nId);
605
+ addr.ToString (),
606
+ m_tried_collisions.size ());
609
607
}
610
608
} else {
611
- if (fLogIPs ) LogPrint (BCLog::ADDRMAN, " Moving %s to tried\n " , addr.ToString ());
612
-
613
609
// move nId to the tried tables
614
610
MakeTried (info, nId);
611
+ if (fLogIPs ) {
612
+ LogPrint (BCLog::ADDRMAN, " Moved %s mapped to AS%i to tried[%i][%i]\n " ,
613
+ addr.ToString (), addr.GetMappedAS (m_asmap), tried_bucket, tried_bucket_pos);
614
+ }
615
615
}
616
616
}
617
617
@@ -683,6 +683,8 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
683
683
ClearNew (nUBucket, nUBucketPos);
684
684
pinfo->nRefCount ++;
685
685
vvNew[nUBucket][nUBucketPos] = nId;
686
+ LogPrint (BCLog::ADDRMAN, " Added %s mapped to AS%i to new[%i][%i]\n " ,
687
+ addr.ToString (), addr.GetMappedAS (m_asmap), nUBucket, nUBucketPos);
686
688
} else {
687
689
if (pinfo->nRefCount == 0 ) {
688
690
Delete (nId);
@@ -741,6 +743,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
741
743
assert (it_found != mapInfo.end ());
742
744
const AddrInfo& info{it_found->second };
743
745
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
746
+ LogPrint (BCLog::ADDRMAN, " Selected %s from tried\n " , info.ToString ());
744
747
return {info, info.nLastTry };
745
748
}
746
749
fChanceFactor *= 1.2 ;
@@ -760,6 +763,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
760
763
assert (it_found != mapInfo.end ());
761
764
const AddrInfo& info{it_found->second };
762
765
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 )) {
766
+ LogPrint (BCLog::ADDRMAN, " Selected %s from new\n " , info.ToString ());
763
767
return {info, info.nLastTry };
764
768
}
765
769
fChanceFactor *= 1.2 ;
@@ -801,7 +805,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
801
805
802
806
addresses.push_back (ai);
803
807
}
804
-
808
+ LogPrint (BCLog::ADDRMAN, " GetAddr returned %d random addresses \n " , addresses. size ());
805
809
return addresses;
806
810
}
807
811
0 commit comments