From 052fbcd5a791855406141e85d32e42e297220fe9 Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Sat, 18 Feb 2023 17:46:13 -0700 Subject: [PATCH] addrman: Introduce helper to generalize looking up an addrman entry Unused until later commit. Co-authored-by: Martin Zumsande --- src/addrman.cpp | 15 +++++++++++++++ src/addrman_impl.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/addrman.cpp b/src/addrman.cpp index ec5b0213b3c..966cf6b0432 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 94fe81aca9b..5410c3342c5 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);