Skip to content

Commit b3e26cc

Browse files
sipacodablock
authored andcommitted
Merge bitcoin#8083: Add support for dnsseeds with option to filter by servicebits
2d83013 Add support for dnsseeds with option to filter by servicebits (Jonas Schnelli)
1 parent 361d260 commit b3e26cc

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/chainparams.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
#include "chainparamsseeds.h"
2121

22+
std::string CDNSSeedData::getHost(uint64_t requiredServiceBits) const {
23+
//use default host for non-filter-capable seeds or if we use the default service bits (NODE_NETWORK)
24+
if (!supportsServiceBitsFiltering || requiredServiceBits == NODE_NETWORK)
25+
return host;
26+
27+
return strprintf("x%x.%s", requiredServiceBits, host);
28+
}
29+
2230
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
2331
{
2432
CMutableTransaction txNew;
@@ -328,6 +336,7 @@ class CTestNetParams : public CChainParams {
328336

329337
vFixedSeeds.clear();
330338
vSeeds.clear();
339+
// nodes with support for servicebits filtering should be at the top
331340
vSeeds.push_back(CDNSSeedData("dashdot.io", "testnet-seed.dashdot.io"));
332341
vSeeds.push_back(CDNSSeedData("masternode.io", "test.dnsseed.masternode.io"));
333342

src/chainparams.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
#include <vector>
1515

16-
struct CDNSSeedData {
16+
class CDNSSeedData {
17+
public:
1718
std::string name, host;
18-
CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
19+
bool supportsServiceBitsFiltering;
20+
std::string getHost(uint64_t requiredServiceBits) const;
21+
CDNSSeedData(const std::string &strName, const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
1922
};
2023

2124
struct SeedSpec6 {

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,12 +1528,13 @@ void CConnman::ThreadDNSAddressSeed()
15281528
} else {
15291529
std::vector<CNetAddr> vIPs;
15301530
std::vector<CAddress> vAdd;
1531-
if (LookupHost(seed.host.c_str(), vIPs, 0, true))
1531+
ServiceFlags requiredServiceBits = NODE_NETWORK;
1532+
if (LookupHost(seed.getHost(requiredServiceBits).c_str(), vIPs, 0, true))
15321533
{
15331534
BOOST_FOREACH(const CNetAddr& ip, vIPs)
15341535
{
15351536
int nOneDay = 24*3600;
1536-
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), NODE_NETWORK);
1537+
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
15371538
addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old
15381539
vAdd.push_back(addr);
15391540
found++;

0 commit comments

Comments
 (0)