diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -55,13 +55,17 @@ /** * How long to delay before querying DNS seeds + * + * If we have more than THRESHOLD entries in addrman, then it's likely + * that we got those addresses from having previously connected to the P2P + * network, and that we'll be able to successfully reconnect to the P2P + * network via contacting one of them. So if that's the case, spend a + * little longer trying to connect to known peers before querying the + * DNS seeds. */ -// 11sec static constexpr std::chrono::seconds DNSSEEDS_DELAY_FEW_PEERS{11}; -// 5min -static constexpr std::chrono::seconds DNSSEEDS_DELAY_MANY_PEERS{300}; -// "many" vs "few" peers -- you should only get this many if you've been on the -// live network +static constexpr std::chrono::minutes DNSSEEDS_DELAY_MANY_PEERS{5}; +// "many" vs "few" peers static constexpr int DNSSEEDS_DELAY_PEER_THRESHOLD = 1000; // We add a random period time (0 to 1 seconds) to feeler connections to prevent @@ -1736,6 +1740,8 @@ seeds_right_now = seeds.size(); } else if (addrman.size() == 0) { // If we have no known peers, query all. + // This will occur on the first run, or if peers.dat has been + // deleted. seeds_right_now = seeds.size(); } @@ -1765,6 +1771,9 @@ seeds_wait_time.count()); std::chrono::seconds to_wait = seeds_wait_time; while (to_wait.count() > 0) { + // if sleeping for the MANY_PEERS interval, wake up + // early to see if we have enough peers and can stop + // this thread entirely freeing up its resources std::chrono::seconds w = std::min(DNSSEEDS_DELAY_FEW_PEERS, to_wait); if (!interruptNet.sleep_for(w)) { @@ -1802,7 +1811,7 @@ return; } - // hold off on querying seeds if p2p network deactivated + // hold off on querying seeds if P2P network deactivated if (!fNetworkActive) { LogPrintf("Waiting for network to be reactivated before querying " "DNS seeds.\n"); @@ -1954,6 +1963,9 @@ } // Add seed nodes if DNS seeds are all down (an infrastructure attack?). + // Note that we only do this if we started with an empty peers.dat, + // (in which case we will query DNS seeds immediately) *and* the DNS + // seeds have not returned any results. if (addrman.size() == 0 && (GetTime() - nStart > 60)) { static bool done = false; if (!done) {