addrman: add functionality to select by network

Add an optional parameter to the addrman Select function that allows callers to
specify which network the returned address should be on. Ensure that the proper
table is selected with different cases of whether the new or tried table has
network addresses that match.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
Amiti Uttarwar
2023-02-18 18:29:45 -07:00
parent 26c3bf11e2
commit 6b229284fd
3 changed files with 46 additions and 23 deletions

View File

@@ -146,11 +146,12 @@ public:
/**
* Choose an address to connect to.
*
* @param[in] new_only Whether to only select addresses from the new table.
* @param[in] new_only Whether to only select addresses from the new table.
* @param[in] network Select only addresses of this network (nullopt = all)
* @return CAddress The record for the selected peer.
* seconds The last time we attempted to connect to that peer.
*/
std::pair<CAddress, NodeSeconds> Select(bool new_only = false) const;
std::pair<CAddress, NodeSeconds> Select(bool new_only = false, std::optional<Network> network = std::nullopt) const;
/**
* Return all or many randomly selected addresses, optionally by network.