From 53cf574c03f58f9dafb641991ade996edc88b0fe Mon Sep 17 00:00:00 2001 From: Duke Date: Wed, 12 Feb 2025 17:23:48 -0500 Subject: [PATCH] Use constants for the defaults of disableipv4/disableipv6 so the code and docs cannot be out of sync --- src/init.cpp | 14 ++++++-------- src/net.h | 6 ++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 48ec9d0ee..82ebefa20 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -429,8 +429,8 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-i2psam=", strprintf(_("I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)"))); strUsage += HelpMessageOpt("-i2pacceptincoming", strprintf(_("If set and -i2psam is also set then incoming I2P connections are accepted via the SAM proxy. If this is not set but -i2psam is set then only outgoing connections will be made to the I2P network. Ignored if -i2psam is not set. Listening for incoming I2P connections is done through the SAM proxy, not by binding to a local address and port (default: 1)"))); strUsage += HelpMessageOpt("-onlynet=", _("Only connect to nodes in network (ipv4, ipv6, onion or i2p)")); - strUsage += HelpMessageOpt("-disableipv4", _("Disable Ipv4 network connections") + " " + _("(default: 0)")); - strUsage += HelpMessageOpt("-disableipv6", _("Disable Ipv6 network connections") + " " + _("(default: 0)")); + strUsage += HelpMessageOpt("-disableipv4", _("Disable Ipv4 network connections") + " " + strprintf(_("(default: %u)"), DEFAULT_DISABLE_IPV4)); + strUsage += HelpMessageOpt("-disableipv6", _("Disable Ipv6 network connections") + " " + strprintf(_("(default: %u)"), DEFAULT_DISABLE_IPV6)); strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1)); strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with Bloom filters (default: %u)"), 1)); @@ -1134,13 +1134,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__); } - //TODO: define a constant for the default of each of these that the CLI - //help also uses - if (GetBoolArg("-disableipv6", false)) { + if (GetBoolArg("-disableipv6", DEFAULT_DISABLE_IPV6)) { SetReachable(NET_IPV6, false); } - if (GetBoolArg("-disableipv4", false)) { + if (GetBoolArg("-disableipv4", DEFAULT_DISABLE_IPV4)) { SetReachable(NET_IPV4, false); } @@ -1659,9 +1657,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) enum Network net = ParseNetwork(snet); if (net == NET_UNROUTABLE) { return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet)); - } else if (net == NET_IPV4 && GetBoolArg("-disableipv4", false)) { + } else if (net == NET_IPV4 && GetBoolArg("-disableipv4", DEFAULT_DISABLE_IPV4)) { return InitError(strprintf(_("-onlynet=ipv4 is incompatible with -disableipv4 !"))); - } else if (net == NET_IPV6 && GetBoolArg("-disableipv6", false)) { + } else if (net == NET_IPV6 && GetBoolArg("-disableipv6", DEFAULT_DISABLE_IPV4)) { return InitError(strprintf(_("-onlynet=ipv6 is incompatible with -disableipv6 !"))); } nets.insert(net); diff --git a/src/net.h b/src/net.h index f7df49aa7..8684b3419 100644 --- a/src/net.h +++ b/src/net.h @@ -85,6 +85,12 @@ static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = (_MAX_BLOCK_SIZE + 24); static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ static const bool DEFAULT_LISTEN = true; + +/** -disableipv4 default */ +static const bool DEFAULT_DISABLE_IPV4 = false; +/** -disableipv6 default */ +static const bool DEFAULT_DISABLE_IPV6 = false; + /** The maximum number of entries in mapAskFor */ static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ; /** The maximum number of entries in setAskFor (larger due to getdata latency)*/