Skip to content

Commit 6cdc488

Browse files
committed
net: switch to dummy internal ip for dns seed source
This addresss the TODO to avoid resolving twice.
1 parent 6d0bd5b commit 6cdc488

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

src/chainparams.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ class CMainParams : public CChainParams {
124124
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
125125

126126
// Note that of those with the service bits flag, most only support a subset of possible options
127-
vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be", true)); // Pieter Wuille, only supports x1, x5, x9, and xd
128-
vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me", true)); // Matt Corallo, only supports x9
129-
vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org")); // Luke Dashjr
130-
vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com", true)); // Christian Decker, supports x1 - xf
131-
vSeeds.push_back(CDNSSeedData("bitcoin.jonasschnelli.ch", "seed.bitcoin.jonasschnelli.ch", true)); // Jonas Schnelli, only supports x1, x5, x9, and xd
132-
vSeeds.push_back(CDNSSeedData("petertodd.org", "seed.btc.petertodd.org", true)); // Peter Todd, only supports x1, x5, x9, and xd
127+
vSeeds.emplace_back("seed.bitcoin.sipa.be", true); // Pieter Wuille, only supports x1, x5, x9, and xd
128+
vSeeds.emplace_back("dnsseed.bluematt.me", true); // Matt Corallo, only supports x9
129+
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
130+
vSeeds.emplace_back("seed.bitcoinstats.com", true); // Christian Decker, supports x1 - xf
131+
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch", true); // Jonas Schnelli, only supports x1, x5, x9, and xd
132+
vSeeds.emplace_back("seed.btc.petertodd.org", true); // Peter Todd, only supports x1, x5, x9, and xd
133133

134134
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
135135
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
@@ -225,10 +225,10 @@ class CTestNetParams : public CChainParams {
225225
vFixedSeeds.clear();
226226
vSeeds.clear();
227227
// nodes with support for servicebits filtering should be at the top
228-
vSeeds.push_back(CDNSSeedData("testnetbitcoin.jonasschnelli.ch", "testnet-seed.bitcoin.jonasschnelli.ch", true));
229-
vSeeds.push_back(CDNSSeedData("petertodd.org", "seed.tbtc.petertodd.org", true));
230-
vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me"));
231-
vSeeds.push_back(CDNSSeedData("bitcoin.schildbach.de", "testnet-seed.bitcoin.schildbach.de"));
228+
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch", true);
229+
vSeeds.emplace_back("seed.tbtc.petertodd.org", true);
230+
vSeeds.emplace_back("testnet-seed.bluematt.me");
231+
vSeeds.emplace_back("testnet-seed.bitcoin.schildbach.de");
232232

233233
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
234234
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);

src/chainparams.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include <vector>
1616

1717
struct CDNSSeedData {
18-
std::string name, host;
18+
std::string host;
1919
bool supportsServiceBitsFiltering;
20-
CDNSSeedData(const std::string &strName, const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
20+
CDNSSeedData(const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
2121
};
2222

2323
struct SeedSpec6 {

src/net.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,12 @@ void CConnman::ThreadDNSAddressSeed()
16041604
std::vector<CNetAddr> vIPs;
16051605
std::vector<CAddress> vAdd;
16061606
ServiceFlags requiredServiceBits = nRelevantServices;
1607-
if (LookupHost(GetDNSHost(seed, &requiredServiceBits).c_str(), vIPs, 0, true))
1607+
std::string host = GetDNSHost(seed, &requiredServiceBits);
1608+
CNetAddr resolveSource;
1609+
if (!resolveSource.SetInternal(host)) {
1610+
continue;
1611+
}
1612+
if (LookupHost(host.c_str(), vIPs, 0, true))
16081613
{
16091614
BOOST_FOREACH(const CNetAddr& ip, vIPs)
16101615
{
@@ -1614,18 +1619,7 @@ void CConnman::ThreadDNSAddressSeed()
16141619
vAdd.push_back(addr);
16151620
found++;
16161621
}
1617-
}
1618-
if (interruptNet) {
1619-
return;
1620-
}
1621-
// TODO: The seed name resolve may fail, yielding an IP of [::], which results in
1622-
// addrman assigning the same source to results from different seeds.
1623-
// This should switch to a hard-coded stable dummy IP for each seed name, so that the
1624-
// resolve is not required at all.
1625-
if (!vIPs.empty()) {
1626-
CService seedSource;
1627-
Lookup(seed.name.c_str(), seedSource, 0, true);
1628-
addrman.Add(vAdd, seedSource);
1622+
addrman.Add(vAdd, resolveSource);
16291623
}
16301624
}
16311625
}

0 commit comments

Comments
 (0)