Skip to content

Commit a9d21f6

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 ac90b05 commit a9d21f6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
550550
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);
551551
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);
552552
argsman.AddArg("-v2transport", strprintf("Support v2 transport (default: %u)", DEFAULT_V2_TRANSPORT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
553+
argsman.AddArg("-v2onlyclearnet", strprintf("Disallow v1 connections on IPV4/IPV6 (default: %u). Enabling this is not recommended unless absolutely necessary, as it may risk network partitions if all users enable it.", false), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
553554
argsman.AddArg("-peerbloomfilters", strprintf("Support filtering of blocks and transaction with bloom filters (default: %u)", DEFAULT_PEERBLOOMFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
554555
argsman.AddArg("-peerblockfilters", strprintf("Serve compact block filters to peers per BIP 157 (default: %u)", DEFAULT_PEERBLOCKFILTERS), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
555556
argsman.AddArg("-txreconciliation", strprintf("Enable transaction reconciliations per BIP 330 (default: %d)", DEFAULT_TXRECONCILIATION_ENABLE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);
@@ -843,6 +844,7 @@ int available_fds;
843844
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
844845
int64_t peer_connect_timeout;
845846
std::set<BlockFilterType> g_enabled_filter_types;
847+
bool disable_v1conn_clearnet = false;
846848

847849
} // namespace
848850

@@ -956,6 +958,11 @@ bool AppInitParameterInteraction(const ArgsManager& args)
956958
// Signal NODE_P2P_V2 if BIP324 v2 transport is enabled.
957959
if (args.GetBoolArg("-v2transport", DEFAULT_V2_TRANSPORT)) {
958960
nLocalServices = ServiceFlags(nLocalServices | NODE_P2P_V2);
961+
if (args.GetBoolArg("-v2onlyclearnet", false)) {
962+
disable_v1conn_clearnet = true;
963+
}
964+
} else if (args.GetBoolArg("-v2onlyclearnet", false)) {
965+
return InitError(_("Cannot set -v2onlyclearnet to true when v2transport is disabled."));
959966
}
960967

961968
// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
@@ -1874,6 +1881,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18741881
connOptions.m_peer_connect_timeout = peer_connect_timeout;
18751882
connOptions.whitelist_forcerelay = args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY);
18761883
connOptions.whitelist_relay = args.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY);
1884+
connOptions.disable_v1conn_clearnet = disable_v1conn_clearnet;
18771885

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

0 commit comments

Comments
 (0)