Skip to content

Commit 61ec053

Browse files
committed
[MOVEONLY] reorder functions in addrman_impl.h and addrman.cpp
Keep the internal {Function}_() functions grouped together. Review with `git diff --color-moved=dimmed-zebra`
1 parent 2095df7 commit 61ec053

File tree

2 files changed

+57
-57
lines changed

2 files changed

+57
-57
lines changed

src/addrman.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -537,61 +537,6 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
537537
info.fInTried = true;
538538
}
539539

540-
void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
541-
{
542-
AssertLockHeld(cs);
543-
544-
int nId;
545-
546-
nLastGood = nTime;
547-
548-
AddrInfo* pinfo = Find(addr, &nId);
549-
550-
// if not found, bail out
551-
if (!pinfo)
552-
return;
553-
554-
AddrInfo& info = *pinfo;
555-
556-
// update info
557-
info.nLastSuccess = nTime;
558-
info.nLastTry = nTime;
559-
info.nAttempts = 0;
560-
// nTime is not updated here, to avoid leaking information about
561-
// currently-connected peers.
562-
563-
// if it is already in the tried set, don't do anything else
564-
if (info.fInTried)
565-
return;
566-
567-
// if it is not in new, something bad happened
568-
if (!Assume(info.nRefCount > 0)) {
569-
return;
570-
}
571-
572-
// which tried bucket to move the entry to
573-
int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
574-
int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket);
575-
576-
// Will moving this address into tried evict another entry?
577-
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) {
578-
if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
579-
m_tried_collisions.insert(nId);
580-
}
581-
// Output the entry we'd be colliding with, for debugging purposes
582-
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
583-
LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
584-
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
585-
addr.ToString(),
586-
m_tried_collisions.size());
587-
} else {
588-
// move nId to the tried tables
589-
MakeTried(info, nId);
590-
LogPrint(BCLog::ADDRMAN, "Moved %s mapped to AS%i to tried[%i][%i]\n",
591-
addr.ToString(), addr.GetMappedAS(m_asmap), tried_bucket, tried_bucket_pos);
592-
}
593-
}
594-
595540
bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
596541
{
597542
AssertLockHeld(cs);
@@ -667,6 +612,61 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
667612
return fInsert;
668613
}
669614

615+
void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
616+
{
617+
AssertLockHeld(cs);
618+
619+
int nId;
620+
621+
nLastGood = nTime;
622+
623+
AddrInfo* pinfo = Find(addr, &nId);
624+
625+
// if not found, bail out
626+
if (!pinfo)
627+
return;
628+
629+
AddrInfo& info = *pinfo;
630+
631+
// update info
632+
info.nLastSuccess = nTime;
633+
info.nLastTry = nTime;
634+
info.nAttempts = 0;
635+
// nTime is not updated here, to avoid leaking information about
636+
// currently-connected peers.
637+
638+
// if it is already in the tried set, don't do anything else
639+
if (info.fInTried)
640+
return;
641+
642+
// if it is not in new, something bad happened
643+
if (!Assume(info.nRefCount > 0)) {
644+
return;
645+
}
646+
647+
// which tried bucket to move the entry to
648+
int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
649+
int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket);
650+
651+
// Will moving this address into tried evict another entry?
652+
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) {
653+
if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) {
654+
m_tried_collisions.insert(nId);
655+
}
656+
// Output the entry we'd be colliding with, for debugging purposes
657+
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
658+
LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
659+
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
660+
addr.ToString(),
661+
m_tried_collisions.size());
662+
} else {
663+
// move nId to the tried tables
664+
MakeTried(info, nId);
665+
LogPrint(BCLog::ADDRMAN, "Moved %s mapped to AS%i to tried[%i][%i]\n",
666+
addr.ToString(), addr.GetMappedAS(m_asmap), tried_bucket, tried_bucket_pos);
667+
}
668+
}
669+
670670
bool AddrManImpl::Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
671671
{
672672
int added{0};

src/addrman_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ class AddrManImpl
242242
//! Move an entry from the "new" table(s) to the "tried" table
243243
void MakeTried(AddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
244244

245-
void Good_(const CService& addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
246-
247245
/** Attempt to add a single address to addrman's new table.
248246
* @see AddrMan::Add() for parameters. */
249247
bool AddSingle(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
250248

249+
void Good_(const CService& addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
250+
251251
bool Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
252252

253253
void Attempt_(const CService& addr, bool fCountFailure, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);

0 commit comments

Comments
 (0)