diff --git a/src/addrman.cpp b/src/addrman.cpp index ec5b0213b3..966cf6b043 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -792,6 +792,21 @@ std::pair AddrManImpl::Select_(bool newOnly) const } } +int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const +{ + AssertLockHeld(cs); + + assert(position < ADDRMAN_BUCKET_SIZE); + + if (use_tried) { + assert(bucket < ADDRMAN_TRIED_BUCKET_COUNT); + return vvTried[bucket][position]; + } else { + assert(bucket < ADDRMAN_NEW_BUCKET_COUNT); + return vvNew[bucket][position]; + } +} + std::vector AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional network) const { AssertLockHeld(cs); diff --git a/src/addrman_impl.h b/src/addrman_impl.h index 94fe81aca9..5410c3342c 100644 --- a/src/addrman_impl.h +++ b/src/addrman_impl.h @@ -253,6 +253,12 @@ private: std::pair Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs); + /** Helper to generalize looking up an addrman entry from either table. + * + * @return int The nid of the entry or -1 if the addrman position is empty. + * */ + int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs); + std::vector GetAddr_(size_t max_addresses, size_t max_pct, std::optional network) const EXCLUSIVE_LOCKS_REQUIRED(cs); void Connected_(const CService& addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);