From 9583477288072e203541b747fcffe8d50cfefb8d Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Mon, 17 Oct 2016 23:08:52 +0000 Subject: [PATCH 1/2] Be more aggressive in connecting to peers with relevant services. Only allow skipping relevant services until there are four outbound connections up. This avoids quickly filling up with peers lacking the relevant services when addrman has few or none of them. --- src/net.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 5f9942c9d..de8f8184a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1675,8 +1675,8 @@ void CConnman::ThreadOpenConnections() if (nANow - addr.nLastTry < 600 && nTries < 30) continue; - // only consider nodes missing relevant services after 40 failed attempts - if ((addr.nServices & nRelevantServices) != nRelevantServices && nTries < 40) + // only consider nodes missing relevant services after 40 failed attempts and only if less than half the outbound are up. + if ((addr.nServices & nRelevantServices) != nRelevantServices && (nTries < 40 || nOutbound >= (nMaxOutbound >> 1))) continue; // do not allow non-default ports, unless after 50 invalid addresses selected already From 46304791353d2bb61004a035869612620c30b4eb Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Mon, 17 Oct 2016 23:11:35 +0000 Subject: [PATCH 2/2] Make dnsseed's definition of acute need include relevant services. We normally prefer to connect to peers offering the relevant services. If we're not connected to enough peers with relevant services, we probably don't know about them and could use dnsseed's help. --- src/net.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index de8f8184a..99f5604ff 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1462,12 +1462,19 @@ static std::string GetDNSHost(const CDNSSeedData& data, ServiceFlags* requiredSe void CConnman::ThreadDNSAddressSeed() { // goal: only query DNS seeds if address need is acute + // Avoiding DNS seeds when we don't need them improves user privacy by + // creating fewer identifying DNS requests, reduces trust by giving seeds + // less influence on the network topology, and reduces traffic to the seeds. if ((addrman.size() > 0) && (!GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED))) { MilliSleep(11 * 1000); LOCK(cs_vNodes); - if (vNodes.size() >= 2) { + int nRelevant = 0; + for (auto pnode : vNodes) { + nRelevant += pnode->fSuccessfullyConnected && ((pnode->nServices & nRelevantServices) == nRelevantServices); + } + if (nRelevant >= 2) { LogPrintf("P2P peers available. Skipped DNS seeding.\n"); return; }