diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2022-07-22 14:51:44 -0400 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2022-09-06 15:16:35 -0400 |
commit | 385f5a4c3feb716fcf3f2b4823535df6da6bb67b (patch) | |
tree | aa4a7998d8c5784b0164c52d31ff6da762ac18a4 /src/init.cpp | |
parent | 91f0a7fbb79fe81a75370a4b60dcdd2e55edfa81 (diff) | |
download | bitcoin-385f5a4c3feb716fcf3f2b4823535df6da6bb67b.tar.xz |
p2p: Don't query DNS seeds when both IPv4 and IPv6 are unreachable
This happens, for example, if the user specified -onlynet=onion or
-onlynet=i2p. DNS seeds only resolve to IPv4 / IPv6 addresses,
making their answers useless to us, since we don't want to make
connections to these.
If, within the DNS seed thread, we'd instead do fallback AddrFetch
connections to one of the clearnet addresses the DNS seed resolves to,
we might get usable addresses from other networks
if lucky, but would be violating our -onlynet user preference
in doing so.
Therefore, in this case it is better to rely on fixed seeds for networks we
want to connect to.
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp index a94bbe6460..7bf60d3b76 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -719,6 +719,16 @@ void InitParameterInteraction(ArgsManager& args) if (args.SoftSetBoolArg("-whitelistrelay", true)) LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__); } + if (args.IsArgSet("-onlynet")) { + const auto onlynets = args.GetArgs("-onlynet"); + bool clearnet_reachable = std::any_of(onlynets.begin(), onlynets.end(), [](const auto& net) { + const auto n = ParseNetwork(net); + return n == NET_IPV4 || n == NET_IPV6; + }); + if (!clearnet_reachable && args.SoftSetBoolArg("-dnsseed", false)) { + LogPrintf("%s: parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0\n", __func__); + } + } } /** @@ -1322,6 +1332,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // 2.1. -onlynet is not given or // 2.2. -onlynet=cjdns is given + // Requesting DNS seeds entails connecting to IPv4/IPv6, which -onlynet options may prohibit: + // If -dnsseed=1 is explicitly specified, abort. If it's left unspecified by the user, we skip + // the DNS seeds by adjusting -dnsseed in InitParameterInteraction. + if (args.GetBoolArg("-dnsseed") == true && !IsReachable(NET_IPV4) && !IsReachable(NET_IPV6)) { + return InitError(strprintf(_("Incompatible options: -dnsseed=1 was explicitly specified, but -onlynet forbids connections to IPv4/IPv6"))); + }; + // Check for host lookup allowed before parsing any network related parameters fNameLookup = args.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); |