Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864430
D8673.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Subscribers
None
D8673.id.diff
View Options
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -553,6 +553,7 @@
consensus/activation.cpp
consensus/tx_verify.cpp
dbwrapper.cpp
+ dnsseeds.cpp
flatfile.cpp
httprpc.cpp
httpserver.cpp
diff --git a/src/chainparams.h b/src/chainparams.h
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -85,7 +85,6 @@
/** Return the BIP70 network string (main, test or regtest) */
std::string NetworkIDString() const { return strNetworkID; }
/** Return the list of hostnames to look up for DNS seeds */
- const std::vector<std::string> &DNSSeeds() const { return vSeeds; }
const std::vector<uint8_t> &Base58Prefix(Base58Type type) const {
return base58Prefixes[type];
}
@@ -116,6 +115,9 @@
bool m_is_mockable_chain;
CCheckpointData checkpointData;
ChainTxData chainTxData;
+
+ friend const std::vector<std::string>
+ GetRandomizedDNSSeeds(const CChainParams ¶ms);
};
/**
diff --git a/src/dnsseeds.h b/src/dnsseeds.h
new file mode 100644
--- /dev/null
+++ b/src/dnsseeds.h
@@ -0,0 +1,17 @@
+// Copyright (c) 2021 The Bitcoin developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_DNSSEEDS_H
+#define BITCOIN_DNSSEEDS_H
+
+#include <chainparams.h>
+
+#include <string>
+#include <vector>
+
+/** Return the list of hostnames to look up for DNS seeds */
+const std::vector<std::string>
+GetRandomizedDNSSeeds(const CChainParams ¶ms);
+
+#endif // BITCOIN_DNSSEEDS_H
diff --git a/src/dnsseeds.cpp b/src/dnsseeds.cpp
new file mode 100644
--- /dev/null
+++ b/src/dnsseeds.cpp
@@ -0,0 +1,22 @@
+// Copyright (c) 2021 The Bitcoin developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <dnsseeds.h>
+
+#include <random.h>
+#include <util/system.h>
+
+const std::vector<std::string>
+GetRandomizedDNSSeeds(const CChainParams ¶ms) {
+ FastRandomContext rng;
+ std::vector<std::string> seeds;
+ if (gArgs.IsArgSet("-overridednsseed")) {
+ seeds = {gArgs.GetArg("-overridednsseed", "")};
+ } else {
+ seeds = params.vSeeds;
+ }
+
+ Shuffle(seeds.begin(), seeds.end(), rng);
+ return seeds;
+}
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -665,6 +665,10 @@
"Always query for peer addresses via DNS lookup (default: %d)",
DEFAULT_FORCEDNSSEED),
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
+ argsman.AddArg("-overridednsseed",
+ "If set, only use the specified DNS seed when "
+ "querying for peer addresses via DNS lookup.",
+ ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg(
"-listen",
"Accept connections from outside (default: 1 if no -proxy or -connect)",
diff --git a/src/net.cpp b/src/net.cpp
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -14,6 +14,7 @@
#include <config.h>
#include <consensus/consensus.h>
#include <crypto/sha256.h>
+#include <dnsseeds.h>
#include <netbase.h>
#include <node/ui_interface.h>
#include <protocol.h>
@@ -1725,8 +1726,8 @@
void CConnman::ThreadDNSAddressSeed() {
FastRandomContext rng;
- std::vector<std::string> seeds = config->GetChainParams().DNSSeeds();
- Shuffle(seeds.begin(), seeds.end(), rng);
+ std::vector<std::string> seeds =
+ GetRandomizedDNSSeeds(config->GetChainParams());
// Number of seeds left before testing if we have enough connections
int seeds_right_now = 0;
int found = 0;
diff --git a/src/seeder/main.cpp b/src/seeder/main.cpp
--- a/src/seeder/main.cpp
+++ b/src/seeder/main.cpp
@@ -4,6 +4,7 @@
#include <chainparams.h>
#include <clientversion.h>
+#include <dnsseeds.h>
#include <fs.h>
#include <logging.h>
#include <protocol.h>
@@ -146,6 +147,10 @@
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-onion=<ip:port>", "Tor proxy IP/Port",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
+ argsman.AddArg("-overridednsseed",
+ "If set, only use the specified DNS seed when "
+ "querying for peer addresses via DNS lookup.",
+ ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-proxyipv4=<ip:port>", "IPV4 SOCKS5 proxy IP/Port",
ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
argsman.AddArg("-proxyipv6=<ip:port>", "IPV6 SOCKS5 proxy IP/Port",
@@ -458,7 +463,7 @@
extern "C" void *ThreadSeeder(void *) {
do {
- for (const std::string &seed : Params().DNSSeeds()) {
+ for (const std::string &seed : GetRandomizedDNSSeeds(Params())) {
std::vector<CNetAddr> ips;
LookupHost(seed.c_str(), ips, MAX_HOSTS_PER_SEED, true);
for (auto &ip : ips) {
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -196,6 +196,7 @@
script_standard_tests.cpp
script_tests.cpp
scriptnum_tests.cpp
+ dnsseeds_tests.cpp
serialize_tests.cpp
settings_tests.cpp
sigcache_tests.cpp
diff --git a/src/test/dnsseeds_tests.cpp b/src/test/dnsseeds_tests.cpp
new file mode 100644
--- /dev/null
+++ b/src/test/dnsseeds_tests.cpp
@@ -0,0 +1,24 @@
+// Copyright (c) 2020-2021 The Bitcoin developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <dnsseeds.h>
+
+#include <test/util/setup_common.h>
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_FIXTURE_TEST_SUITE(dnsseeds_tests, TestingSetup)
+
+BOOST_AUTO_TEST_CASE(override_dns_seed) {
+ // No override should always provide some DNS seeds
+ const auto params = CreateChainParams(CBaseChainParams::MAIN);
+ BOOST_CHECK(GetRandomizedDNSSeeds(*params).size() > 0);
+
+ // Overriding should only return that DNS seed
+ gArgs.ForceSetArg("-overridednsseed", "localhost");
+ BOOST_CHECK(GetRandomizedDNSSeeds(*params) ==
+ std::vector<std::string>{{"localhost"}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 19:37 (3 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5864033
Default Alt Text
D8673.id.diff (6 KB)
Attached To
D8673: Add -overridednsseed for testing DNS seed behavior
Event Timeline
Log In to Comment