Skip to content

Commit 052fbcd

Browse files
addrman: Introduce helper to generalize looking up an addrman entry
Unused until later commit. Co-authored-by: Martin Zumsande <[email protected]>
1 parent 9bf078f commit 052fbcd

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/addrman.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,21 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
792792
}
793793
}
794794

795+
int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const
796+
{
797+
AssertLockHeld(cs);
798+
799+
assert(position < ADDRMAN_BUCKET_SIZE);
800+
801+
if (use_tried) {
802+
assert(bucket < ADDRMAN_TRIED_BUCKET_COUNT);
803+
return vvTried[bucket][position];
804+
} else {
805+
assert(bucket < ADDRMAN_NEW_BUCKET_COUNT);
806+
return vvNew[bucket][position];
807+
}
808+
}
809+
795810
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
796811
{
797812
AssertLockHeld(cs);

src/addrman_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ class AddrManImpl
253253

254254
std::pair<CAddress, NodeSeconds> Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
255255

256+
/** Helper to generalize looking up an addrman entry from either table.
257+
*
258+
* @return int The nid of the entry or -1 if the addrman position is empty.
259+
* */
260+
int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs);
261+
256262
std::vector<CAddress> GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
257263

258264
void Connected_(const CService& addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);

0 commit comments

Comments
 (0)