diff --git a/src/init.cpp b/src/init.cpp index c034826d6..cd44128ea 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,6 +1134,22 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__); } + if(mapMultiArgs["-disableipv6"].size() > 1) { + return InitError("-disableipv6 can only be used once"); + } + + if(mapMultiArgs["-disableipv4"].size() > 1) { + return InitError("-disableipv4 can only be used once"); + } + + if (GetBoolArg("-disableipv6", DEFAULT_DISABLE_IPV6)) { + SetReachable(NET_IPV6, false); + } + + if (GetBoolArg("-disableipv4", DEFAULT_DISABLE_IPV4)) { + SetReachable(NET_IPV4, false); + } + // Read asmap file by default for HUSH3 and all Hush Arrakis Chains if (GetArg("-asmap",1)) { fs::path asmap_path = fs::path(GetArg("-asmap", "")); @@ -1647,8 +1663,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::set nets; BOOST_FOREACH(const std::string& snet, mapMultiArgs["-onlynet"]) { enum Network net = ParseNetwork(snet); - if (net == NET_UNROUTABLE) + if (net == NET_UNROUTABLE) { return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet)); + } 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", DEFAULT_DISABLE_IPV4)) { + return InitError(strprintf(_("-onlynet=ipv6 is incompatible with -disableipv6 !"))); + } nets.insert(net); } for (int n = 0; n < NET_MAX; n++) { 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)*/