This PR introduces AddrMan::AddrPolicy, a predicate that allows callers to
exclude addresses during selection. The policy returns true to skip a given
entry and is evaluated while holding AddrMan::cs.
The mechanism is used in CConnman::GetAddressesUnsafe() to filter out
banned and discouraged peers during address selection instead of removing
them afterward. This prevents P2P responses (GETADDR) and RPCs (getnodeaddresses) from
returning fewer results than requested when large portions of the address space are filtered.
Additional improvements:
- Logs the number of filtered entries for diagnostics
- Avoids redundant filtering passes in higher-level callers
- Keeps locking behavior unchanged (the policy runs under
AddrMan::cs)
Testing
- Repro: ban or discourage a large set of addresses, then call
getnodeaddresses 1, previously underfilled. - After this change, the RPC returns up to the requested count as expected.
No behavior change for unaffected callers.