Merge #8083: Add support for dnsseeds with option to filter by servicebits

2d83013d Add support for dnsseeds with option to filter by servicebits (Jonas Schnelli)
This commit is contained in:
Pieter Wuille 2016-06-08 17:33:21 +02:00 committed by Alexander Block
parent 361d26037b
commit b3e26cc757
3 changed files with 17 additions and 4 deletions

View File

@ -19,6 +19,14 @@
#include "chainparamsseeds.h" #include "chainparamsseeds.h"
std::string CDNSSeedData::getHost(uint64_t requiredServiceBits) const {
//use default host for non-filter-capable seeds or if we use the default service bits (NODE_NETWORK)
if (!supportsServiceBitsFiltering || requiredServiceBits == NODE_NETWORK)
return host;
return strprintf("x%x.%s", requiredServiceBits, host);
}
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{ {
CMutableTransaction txNew; CMutableTransaction txNew;
@ -328,6 +336,7 @@ public:
vFixedSeeds.clear(); vFixedSeeds.clear();
vSeeds.clear(); vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.push_back(CDNSSeedData("dashdot.io", "testnet-seed.dashdot.io")); vSeeds.push_back(CDNSSeedData("dashdot.io", "testnet-seed.dashdot.io"));
vSeeds.push_back(CDNSSeedData("masternode.io", "test.dnsseed.masternode.io")); vSeeds.push_back(CDNSSeedData("masternode.io", "test.dnsseed.masternode.io"));

View File

@ -13,9 +13,12 @@
#include <vector> #include <vector>
struct CDNSSeedData { class CDNSSeedData {
public:
std::string name, host; std::string name, host;
CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {} bool supportsServiceBitsFiltering;
std::string getHost(uint64_t requiredServiceBits) const;
CDNSSeedData(const std::string &strName, const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
}; };
struct SeedSpec6 { struct SeedSpec6 {

View File

@ -1528,12 +1528,13 @@ void CConnman::ThreadDNSAddressSeed()
} else { } else {
std::vector<CNetAddr> vIPs; std::vector<CNetAddr> vIPs;
std::vector<CAddress> vAdd; std::vector<CAddress> vAdd;
if (LookupHost(seed.host.c_str(), vIPs, 0, true)) ServiceFlags requiredServiceBits = NODE_NETWORK;
if (LookupHost(seed.getHost(requiredServiceBits).c_str(), vIPs, 0, true))
{ {
BOOST_FOREACH(const CNetAddr& ip, vIPs) BOOST_FOREACH(const CNetAddr& ip, vIPs)
{ {
int nOneDay = 24*3600; int nOneDay = 24*3600;
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), NODE_NETWORK); CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old
vAdd.push_back(addr); vAdd.push_back(addr);
found++; found++;