mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#25678: skip querying dns seeds if -onlynet disables IPv4 and IPv6
This commit is contained in:
parent
2d99be0aea
commit
1adb635ec6
18
src/init.cpp
18
src/init.cpp
@ -973,6 +973,17 @@ void InitParameterInteraction(ArgsManager& args)
|
||||
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__);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t nPruneArg = args.GetArg("-prune", 0);
|
||||
if (nPruneArg > 0) {
|
||||
if (args.SoftSetBoolArg("-disablegovernance", true)) {
|
||||
@ -1678,6 +1689,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", DEFAULT_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);
|
||||
|
||||
|
@ -2648,15 +2648,20 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, CDe
|
||||
LOCK2(m_addr_fetches_mutex, m_added_nodes_mutex);
|
||||
if (m_addr_fetches.empty() && m_added_nodes.empty()) {
|
||||
add_fixed_seeds_now = true;
|
||||
LogPrintf("Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted\n");
|
||||
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet), -addnode is not provided and all -seednode(s) attempted\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (add_fixed_seeds_now) {
|
||||
std::vector<CAddress> seed_addrs{ConvertSeeds(Params().FixedSeeds())};
|
||||
seed_addrs.erase(std::remove_if(seed_addrs.begin(), seed_addrs.end(),
|
||||
[](const CAddress& addr) { return !IsReachable(addr); }),
|
||||
seed_addrs.end());
|
||||
CNetAddr local;
|
||||
local.SetInternal("fixedseeds");
|
||||
addrman.Add(ConvertSeeds(Params().FixedSeeds()), local);
|
||||
addrman.Add(seed_addrs, local);
|
||||
add_fixed_seeds = false;
|
||||
LogPrintf("Added %d fixed seeds from reachable networks.\n", seed_addrs.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,11 +181,12 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=[
|
||||
"Loaded 0 addresses from peers.dat",
|
||||
"DNS seeding disabled",
|
||||
"Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted\n",
|
||||
"Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet), -addnode is not provided and all -seednode(s) attempted\n",
|
||||
]):
|
||||
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1'])
|
||||
assert time.time() - start < 60
|
||||
self.stop_node(0)
|
||||
self.nodes[0].assert_start_raises_init_error(['-dnsseed=1', '-onlynet=i2p', '-i2psam=127.0.0.1:7656'], "Error: Incompatible options: -dnsseed=1 was explicitly specified, but -onlynet forbids connections to IPv4/IPv6")
|
||||
|
||||
# No peers.dat exists and dns seeds are disabled.
|
||||
# We expect the node will not add fixed seeds when explicitly disabled.
|
||||
|
Loading…
Reference in New Issue
Block a user