Skip to content

Commit 2f8eb3c

Browse files
committed
init: add -v2onlyclearnet config option
if this option is set by the user, v1 connections on unencrypted networks like IPV4/IPV6 will be disallowed. Only users with real need are recommended to turn this on because it could risk network partitioning in the unlikely scenario that everyone turns it on.
1 parent eb2fba9 commit 2f8eb3c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/init.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
545545
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);
546546
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);
547547
argsman.AddArg("-v2transport", strprintf("Support v2 transport (default: %u)", DEFAULT_V2_TRANSPORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
548+
argsman.AddArg("-v2onlyclearnet", strprintf("Disallow outbound v1 connections on IPV4/IPV6 (default: %u). Enable this option only if you really need it. Use -listen=0 to disable inbound connections since they can be unencrypted.", false), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
548549
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
549550
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
550551
argsman.AddArg("-txreconciliation", strprintf("Enable transaction reconciliations per BIP 330 (default: %d)", DEFAULT_TXRECONCILIATION_ENABLE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
@@ -817,6 +818,7 @@ int available_fds;
817818
ServiceFlags g_local_services = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
818819
int64_t peer_connect_timeout;
819820
std::set<BlockFilterType> g_enabled_filter_types;
821+
bool disable_v1conn_clearnet = false;
820822

821823
} // namespace
822824

@@ -930,6 +932,11 @@ bool AppInitParameterInteraction(const ArgsManager& args)
930932
// Signal NODE_P2P_V2 if BIP324 v2 transport is enabled.
931933
if (args.GetBoolArg("-v2transport", DEFAULT_V2_TRANSPORT)) {
932934
g_local_services = ServiceFlags(g_local_services | NODE_P2P_V2);
935+
if (args.GetBoolArg("-v2onlyclearnet", false)) {
936+
disable_v1conn_clearnet = true;
937+
}
938+
} else if (args.GetBoolArg("-v2onlyclearnet", false)) {
939+
return InitError(_("Cannot set -v2onlyclearnet to true when v2transport is disabled."));
933940
}
934941

935942
// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
@@ -1843,6 +1850,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18431850
connOptions.m_peer_connect_timeout = peer_connect_timeout;
18441851
connOptions.whitelist_forcerelay = args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY);
18451852
connOptions.whitelist_relay = args.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY);
1853+
connOptions.disable_v1conn_clearnet = disable_v1conn_clearnet;
18461854

18471855
// Port to bind to if `-bind=addr` is provided without a `:port` suffix.
18481856
const uint16_t default_bind_port =

0 commit comments

Comments
 (0)