Skip to content

Commit

Permalink
init: add -cleanupaddrman
Browse files Browse the repository at this point in the history
This flag is used to control whether the user wants
to clean up addresses from addrman that do not
belong to the current supported network.
  • Loading branch information
brunoerg committed Jan 22, 2024
1 parent 24d5cc8 commit a814dc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-i2pacceptincoming", strprintf("Whether to accept inbound I2P connections (default: %i). Ignored if -i2psam is not set. Listening for inbound I2P connections is done through the SAM proxy, not by binding to a local address and port.", DEFAULT_I2P_ACCEPT_INCOMING), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-onlynet=<net>", "Make automatic outbound connections only to network <net> (" + Join(GetNetworkNames(), ", ") + "). Inbound and manual connections are not affected by this option. It can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-cleanupaddrman", strprintf("Clean up addresses from addrman that do not belong to the supported networks (default: %u)", DEFAULT_CLEANUP_ADDRMAN), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-v2transport", strprintf("Support v2 transport (default: %u)", DEFAULT_V2_TRANSPORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
Expand Down Expand Up @@ -1899,13 +1900,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

connOptions.m_i2p_accept_incoming = args.GetBoolArg("-i2pacceptincoming", DEFAULT_I2P_ACCEPT_INCOMING);

std::set<Network> networks;
for (size_t i = 0; i < NET_MAX; ++i) {
Network net = static_cast<Network>(i);
if (g_reachable_nets.Contains(net)) networks.insert(net);
if (args.GetBoolArg("-cleanupaddrman", DEFAULT_CLEANUP_ADDRMAN)) {
std::set<Network> networks;
for (size_t i = 0; i < NET_MAX; ++i) {
Network net = static_cast<Network>(i);
if (g_reachable_nets.Contains(net)) networks.insert(net);
}
AddrMan& node_addrman = *node.addrman;
node_addrman.DeleteAddresses(networks);
}
AddrMan& node_addrman = *node.addrman;
node_addrman.DeleteAddresses(networks);

if (!node.connman->Start(*node.scheduler, connOptions)) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;

static constexpr bool DEFAULT_V2_TRANSPORT{false};

static constexpr bool DEFAULT_CLEANUP_ADDRMAN{false};

typedef int64_t NodeId;

struct AddedNodeParams {
Expand Down

0 comments on commit a814dc3

Please sign in to comment.