addrman: Introduce helper to generalize looking up an addrman entry

Unused until later commit.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
Amiti Uttarwar 2023-02-18 17:46:13 -07:00
parent 9bf078f66c
commit 052fbcd5a7
2 changed files with 21 additions and 0 deletions

View File

@ -792,6 +792,21 @@ std::pair<CAddress, NodeSeconds> 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<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
{
AssertLockHeld(cs);

View File

@ -253,6 +253,12 @@ private:
std::pair<CAddress, NodeSeconds> 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<CAddress> GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
void Connected_(const CService& addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);