This PR adds a new flag -cleanupaddrman
. When initializing a node with this flag, it will delete addresses from addrman (both new and tried tables) that do not belong to the supported networks (e.g. -onlynet
). Deleting addresses that do not belong to the supported networks can avoid a lot of unnecessary addrman Select
calls (especially when turning from clearnet + Tor/I2P/CJDNS to Tor/I2P/CJDNS).
- This flag is not enabled by default, if user intends to go back to the previous network, just do not set it.
- Addresses from non-supported networks will naturely be replaced in addrman since we only store addresses from networks we support (cleaning up them on init is a way to avoid spending resources on it).
- Avoiding these addresses in addrman can avoid exceeding the maximum number of tries in
ThreadOpenConnections
.
0// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
1// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
2// already-connected network ranges, ...) before trying new addrman addresses.
3nTries++;
4if (nTries > 100)
5 break;
- Specially turning from clearnet + Tor/I2P/CJDNS to Tor/I2P/CJDNS, this feature it will ensure we will relay more addresses from these networks to other peers.