@@ -552,77 +552,13 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
552
552
info.fInTried = true ;
553
553
}
554
554
555
- void AddrManImpl::Good_ (const CService& addr, bool test_before_evict, int64_t nTime)
556
- {
557
- AssertLockHeld (cs);
558
-
559
- int nId;
560
-
561
- nLastGood = nTime;
562
-
563
- AddrInfo* pinfo = Find (addr, &nId);
564
-
565
- // if not found, bail out
566
- if (!pinfo)
567
- return ;
568
-
569
- AddrInfo& info = *pinfo;
570
-
571
- // check whether we are talking about the exact same CService (including same port)
572
- if (!m_discriminate_ports && info != addr)
573
- return ;
574
-
575
- // update info
576
- info.nLastSuccess = nTime;
577
- info.nLastTry = nTime;
578
- info.nAttempts = 0 ;
579
- // nTime is not updated here, to avoid leaking information about
580
- // currently-connected peers.
581
-
582
- // if it is already in the tried set, don't do anything else
583
- if (info.fInTried )
584
- return ;
585
-
586
- // if it is not in new, something bad happened
587
- if (!Assume (info.nRefCount > 0 )) {
588
- return ;
589
- }
590
-
591
- // which tried bucket to move the entry to
592
- int tried_bucket = info.GetTriedBucket (nKey, m_asmap);
593
- int tried_bucket_pos = info.GetBucketPosition (nKey, false , tried_bucket);
594
-
595
- // Will moving this address into tried evict another entry?
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
- // Output the entry we'd be colliding with, for debugging purposes
601
- auto colliding_entry = mapInfo.find (vvTried[tried_bucket][tried_bucket_pos]);
602
- if (fLogIPs ) {
603
- LogPrint (BCLog::ADDRMAN, " Collision with %s while attempting to move %s to tried table. Collisions=%d\n " ,
604
- colliding_entry != mapInfo.end () ? colliding_entry->second .ToString () : " " ,
605
- addr.ToString (),
606
- m_tried_collisions.size ());
607
- }
608
- } else {
609
- // move nId to the tried tables
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
- }
616
- }
617
-
618
- bool AddrManImpl::Add_ (const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
555
+ bool AddrManImpl::AddSingle (const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
619
556
{
620
557
AssertLockHeld (cs);
621
558
622
559
if (!addr.IsRoutable ())
623
560
return false ;
624
561
625
- bool fNew = false ;
626
562
int nId;
627
563
AddrInfo* pinfo = Find (addr, &nId);
628
564
@@ -665,13 +601,12 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
665
601
pinfo = Create (addr, source, &nId);
666
602
pinfo->nTime = std::max ((int64_t )0 , (int64_t )pinfo->nTime - nTimePenalty);
667
603
nNew++;
668
- fNew = true ;
669
604
}
670
605
671
606
int nUBucket = pinfo->GetNewBucket (nKey, source, m_asmap);
672
607
int nUBucketPos = pinfo->GetBucketPosition (nKey, true , nUBucket);
608
+ bool fInsert = vvNew[nUBucket][nUBucketPos] == -1 ;
673
609
if (vvNew[nUBucket][nUBucketPos] != nId) {
674
- bool fInsert = vvNew[nUBucket][nUBucketPos] == -1 ;
675
610
if (!fInsert ) {
676
611
AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
677
612
if (infoExisting.IsTerrible () || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0 )) {
@@ -691,7 +626,82 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
691
626
}
692
627
}
693
628
}
694
- return fNew ;
629
+ return fInsert ;
630
+ }
631
+
632
+ void AddrManImpl::Good_ (const CService& addr, bool test_before_evict, int64_t nTime)
633
+ {
634
+ AssertLockHeld (cs);
635
+
636
+ int nId;
637
+
638
+ nLastGood = nTime;
639
+
640
+ AddrInfo* pinfo = Find (addr, &nId);
641
+
642
+ // if not found, bail out
643
+ if (!pinfo)
644
+ return ;
645
+
646
+ AddrInfo& info = *pinfo;
647
+
648
+ // check whether we are talking about the exact same CService (including same port)
649
+ if (!m_discriminate_ports && info != addr)
650
+ return ;
651
+
652
+ // update info
653
+ info.nLastSuccess = nTime;
654
+ info.nLastTry = nTime;
655
+ info.nAttempts = 0 ;
656
+ // nTime is not updated here, to avoid leaking information about
657
+ // currently-connected peers.
658
+
659
+ // if it is already in the tried set, don't do anything else
660
+ if (info.fInTried )
661
+ return ;
662
+
663
+ // if it is not in new, something bad happened
664
+ if (!Assume (info.nRefCount > 0 )) {
665
+ return ;
666
+ }
667
+
668
+ // which tried bucket to move the entry to
669
+ int tried_bucket = info.GetTriedBucket (nKey, m_asmap);
670
+ int tried_bucket_pos = info.GetBucketPosition (nKey, false , tried_bucket);
671
+
672
+ // Will moving this address into tried evict another entry?
673
+ if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1 )) {
674
+ if (m_tried_collisions.size () < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
675
+ m_tried_collisions.insert (nId);
676
+ }
677
+ // Output the entry we'd be colliding with, for debugging purposes
678
+ auto colliding_entry = mapInfo.find (vvTried[tried_bucket][tried_bucket_pos]);
679
+ if (fLogIPs ) {
680
+ LogPrint (BCLog::ADDRMAN, " Collision with %s while attempting to move %s to tried table. Collisions=%d\n " ,
681
+ colliding_entry != mapInfo.end () ? colliding_entry->second .ToString () : " " ,
682
+ addr.ToString (),
683
+ m_tried_collisions.size ());
684
+ }
685
+ } else {
686
+ // move nId to the tried tables
687
+ MakeTried (info, nId);
688
+ if (fLogIPs ) {
689
+ LogPrint (BCLog::ADDRMAN, " Moved %s mapped to AS%i to tried[%i][%i]\n " ,
690
+ addr.ToString (), addr.GetMappedAS (m_asmap), tried_bucket, tried_bucket_pos);
691
+ }
692
+ }
693
+ }
694
+
695
+ bool AddrManImpl::Add_ (const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
696
+ {
697
+ int added{0 };
698
+ for (std::vector<CAddress>::const_iterator it = vAddr.begin (); it != vAddr.end (); it++) {
699
+ added += AddSingle (*it, source, nTimePenalty) ? 1 : 0 ;
700
+ }
701
+ if (added > 0 ) {
702
+ LogPrint (BCLog::ADDRMAN, " Added %i addresses (of %i) from %s: %i tried, %i new\n " , added, vAddr.size (), source.ToString (), nTried, nNew);
703
+ }
704
+ return added > 0 ;
695
705
}
696
706
697
707
void AddrManImpl::Attempt_ (const CService& addr, bool fCountFailure , int64_t nTime)
@@ -1087,15 +1097,10 @@ size_t AddrManImpl::size() const
1087
1097
bool AddrManImpl::Add (const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
1088
1098
{
1089
1099
LOCK (cs);
1090
- int nAdd = 0 ;
1091
1100
Check ();
1092
- for (std::vector<CAddress>::const_iterator it = vAddr.begin (); it != vAddr.end (); it++)
1093
- nAdd += Add_ (*it, source, nTimePenalty) ? 1 : 0 ;
1101
+ auto ret = Add_ (vAddr, source, nTimePenalty);
1094
1102
Check ();
1095
- if (nAdd) {
1096
- LogPrint (BCLog::ADDRMAN, " Added %i addresses from %s: %i tried, %i new\n " , nAdd, source.ToString (), nTried, nNew);
1097
- }
1098
- return nAdd > 0 ;
1103
+ return ret;
1099
1104
}
1100
1105
1101
1106
void AddrManImpl::Good (const CService& addr, int64_t nTime)
0 commit comments