Do not query all DNS seed at once
Instead, when necessary, query 3. If that leads to a sufficient number of connects, stop. If not, query 3 more, and so on.
This commit is contained in:
parent
e5fdda68c6
commit
6170ec5d3a
1 changed files with 36 additions and 29 deletions
41
src/net.cpp
41
src/net.cpp
|
@ -49,6 +49,9 @@ static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"
|
||||||
// Dump addresses to peers.dat every 15 minutes (900s)
|
// Dump addresses to peers.dat every 15 minutes (900s)
|
||||||
static constexpr int DUMP_PEERS_INTERVAL = 15 * 60;
|
static constexpr int DUMP_PEERS_INTERVAL = 15 * 60;
|
||||||
|
|
||||||
|
/** Number of DNS seeds to query when the number of connections is low. */
|
||||||
|
static constexpr int DNSSEEDS_TO_QUERY_AT_ONCE = 3;
|
||||||
|
|
||||||
// We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
|
// We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
|
||||||
#define FEELER_SLEEP_WINDOW 1
|
#define FEELER_SLEEP_WINDOW 1
|
||||||
|
|
||||||
|
@ -1508,14 +1511,24 @@ void StopMapPort()
|
||||||
|
|
||||||
void CConnman::ThreadDNSAddressSeed()
|
void CConnman::ThreadDNSAddressSeed()
|
||||||
{
|
{
|
||||||
// goal: only query DNS seeds if address need is acute
|
FastRandomContext rng;
|
||||||
|
std::vector<std::string> seeds = Params().DNSSeeds();
|
||||||
|
Shuffle(seeds.begin(), seeds.end(), rng);
|
||||||
|
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
if (gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED)) {
|
||||||
|
// When -forcednsseed is provided, query all.
|
||||||
|
seeds_right_now = seeds.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const std::string& seed : seeds) {
|
||||||
|
// goal: only query DNS seed if address need is acute
|
||||||
// Avoiding DNS seeds when we don't need them improves user privacy by
|
// Avoiding DNS seeds when we don't need them improves user privacy by
|
||||||
// creating fewer identifying DNS requests, reduces trust by giving seeds
|
// creating fewer identifying DNS requests, reduces trust by giving seeds
|
||||||
// less influence on the network topology, and reduces traffic to the seeds.
|
// less influence on the network topology, and reduces traffic to the seeds.
|
||||||
if ((addrman.size() > 0) &&
|
if (addrman.size() > 0 && seeds_right_now == 0) {
|
||||||
(!gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) {
|
if (!interruptNet.sleep_for(std::chrono::seconds(11))) return;
|
||||||
if (!interruptNet.sleep_for(std::chrono::seconds(11)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
int nRelevant = 0;
|
int nRelevant = 0;
|
||||||
|
@ -1526,17 +1539,13 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
LogPrintf("P2P peers available. Skipped DNS seeding.\n");
|
LogPrintf("P2P peers available. Skipped DNS seeding.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
seeds_right_now += DNSSEEDS_TO_QUERY_AT_ONCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string> &vSeeds = Params().DNSSeeds();
|
|
||||||
int found = 0;
|
|
||||||
|
|
||||||
LogPrintf("Loading addresses from DNS seeds (could take a while)\n");
|
|
||||||
|
|
||||||
for (const std::string &seed : vSeeds) {
|
|
||||||
if (interruptNet) {
|
if (interruptNet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LogPrintf("Loading addresses from DNS seed %s\n", seed);
|
||||||
if (HaveNameProxy()) {
|
if (HaveNameProxy()) {
|
||||||
AddOneShot(seed);
|
AddOneShot(seed);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1549,13 +1558,11 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned int nMaxIPs = 256; // Limits number of IPs learned from a DNS seed
|
unsigned int nMaxIPs = 256; // Limits number of IPs learned from a DNS seed
|
||||||
if (LookupHost(host.c_str(), vIPs, nMaxIPs, true))
|
if (LookupHost(host.c_str(), vIPs, nMaxIPs, true)) {
|
||||||
{
|
for (const CNetAddr& ip : vIPs) {
|
||||||
for (const CNetAddr& ip : vIPs)
|
|
||||||
{
|
|
||||||
int nOneDay = 24*3600;
|
int nOneDay = 24*3600;
|
||||||
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
|
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 - rng.randrange(4*nOneDay); // use a random age between 3 and 7 days old
|
||||||
vAdd.push_back(addr);
|
vAdd.push_back(addr);
|
||||||
found++;
|
found++;
|
||||||
}
|
}
|
||||||
|
@ -1566,8 +1573,8 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
AddOneShot(seed);
|
AddOneShot(seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--seeds_right_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrintf("%d addresses found from DNS seeds\n", found);
|
LogPrintf("%d addresses found from DNS seeds\n", found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue