Skip to content

Commit 9a364e1

Browse files
jonasschnelliFuzzbawls
authored andcommitted
Add support for dnsseeds with option to filter by servicebits
1 parent 521d13b commit 9a364e1

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/chainparams.cpp

Lines changed: 13 additions & 4 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;
@@ -222,8 +230,8 @@ class CMainParams : public CChainParams
222230
nDefaultPort = 51472;
223231

224232
// Note that of those with the service bits flag, most only support a subset of possible options
225-
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx.seed.fuzzbawls.pw")); // Primary DNS Seeder from Fuzzbawls
226-
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx.seed2.fuzzbawls.pw")); // Secondary DNS Seeder from Fuzzbawls
233+
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx.seed.fuzzbawls.pw", true)); // Primary DNS Seeder from Fuzzbawls
234+
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx.seed2.fuzzbawls.pw", true)); // Secondary DNS Seeder from Fuzzbawls
227235
vSeeds.push_back(CDNSSeedData("warrows.dev", "dnsseed.pivx.warrows.dev")); // Primery DNS Seeder from warrows
228236

229237
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 30);
@@ -339,8 +347,9 @@ class CTestNetParams : public CMainParams
339347

340348
vFixedSeeds.clear();
341349
vSeeds.clear();
342-
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx-testnet.seed.fuzzbawls.pw"));
343-
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx-testnet.seed2.fuzzbawls.pw"));
350+
// nodes with support for servicebits filtering should be at the top
351+
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx-testnet.seed.fuzzbawls.pw", true));
352+
vSeeds.push_back(CDNSSeedData("fuzzbawls.pw", "pivx-testnet.seed2.fuzzbawls.pw", true));
344353
vSeeds.push_back(CDNSSeedData("warrows.dev", "testnet.dnsseed.pivx.warrows.dev"));
345354

346355
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 139); // Testnet pivx addresses start with 'x' or 'y'

src/chainparams.h

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

2020
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
2121

22-
struct CDNSSeedData {
22+
class CDNSSeedData {
23+
public:
2324
std::string name, host;
24-
CDNSSeedData(const std::string& strName, const std::string& strHost) : name(strName), host(strHost) {}
25+
bool supportsServiceBitsFiltering;
26+
std::string getHost(uint64_t requiredServiceBits) const;
27+
CDNSSeedData(const std::string& strName, const std::string& strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
2528
};
2629

2730
struct SeedSpec6 {

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,11 @@ void ThreadDNSAddressSeed()
12831283
} else {
12841284
std::vector<CNetAddr> vIPs;
12851285
std::vector<CAddress> vAdd;
1286-
if (LookupHost(seed.host.c_str(), vIPs, 0, true)) {
1286+
uint64_t requiredServiceBits = NODE_NETWORK;
1287+
if (LookupHost(seed.getHost(requiredServiceBits).c_str(), vIPs, 0, true)) {
12871288
for (CNetAddr& ip : vIPs) {
12881289
int nOneDay = 24 * 3600;
1289-
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()));
1290+
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
12901291
addr.nTime = GetTime() - 3 * nOneDay - GetRand(4 * nOneDay); // use a random age between 3 and 7 days old
12911292
vAdd.push_back(addr);
12921293
found++;

0 commit comments

Comments
 (0)