@@ -53,10 +53,17 @@ static constexpr std::chrono::minutes DUMP_PEERS_INTERVAL{15};
53
53
static constexpr int DNSSEEDS_TO_QUERY_AT_ONCE = 3 ;
54
54
55
55
/* * How long to delay before querying DNS seeds
56
+ *
57
+ * If we have more than THRESHOLD entries in addrman, then it's likely
58
+ * that we got those addresses from having previously connected to the P2P
59
+ * network, and that we'll be able to successfully reconnect to the P2P
60
+ * network via contacting one of them. So if that's the case, spend a
61
+ * little longer trying to connect to known peers before querying the
62
+ * DNS seeds.
56
63
*/
57
- static constexpr std::chrono::seconds DNSSEEDS_DELAY_FEW_PEERS{11 }; // 11sec
58
- static constexpr std::chrono::seconds DNSSEEDS_DELAY_MANY_PEERS{300 }; // 5min
59
- static constexpr int DNSSEEDS_DELAY_PEER_THRESHOLD = 1000 ; // "many" vs "few" peers -- you should only get this many if you've been on the live network
64
+ static constexpr std::chrono::seconds DNSSEEDS_DELAY_FEW_PEERS{11 };
65
+ static constexpr std::chrono::minutes DNSSEEDS_DELAY_MANY_PEERS{5 };
66
+ static constexpr int DNSSEEDS_DELAY_PEER_THRESHOLD = 1000 ; // "many" vs "few" peers
60
67
61
68
// We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization.
62
69
#define FEELER_SLEEP_WINDOW 1
@@ -1595,6 +1602,8 @@ void CConnman::ThreadDNSAddressSeed()
1595
1602
seeds_right_now = seeds.size ();
1596
1603
} else if (addrman.size () == 0 ) {
1597
1604
// If we have no known peers, query all.
1605
+ // This will occur on the first run, or if peers.dat has been
1606
+ // deleted.
1598
1607
seeds_right_now = seeds.size ();
1599
1608
}
1600
1609
@@ -1620,6 +1629,9 @@ void CConnman::ThreadDNSAddressSeed()
1620
1629
LogPrintf (" Waiting %d seconds before querying DNS seeds.\n " , seeds_wait_time.count ());
1621
1630
std::chrono::seconds to_wait = seeds_wait_time;
1622
1631
while (to_wait.count () > 0 ) {
1632
+ // if sleeping for the MANY_PEERS interval, wake up
1633
+ // early to see if we have enough peers and can stop
1634
+ // this thread entirely freeing up its resources
1623
1635
std::chrono::seconds w = std::min (DNSSEEDS_DELAY_FEW_PEERS, to_wait);
1624
1636
if (!interruptNet.sleep_for (w)) return ;
1625
1637
to_wait -= w;
@@ -1646,7 +1658,7 @@ void CConnman::ThreadDNSAddressSeed()
1646
1658
1647
1659
if (interruptNet) return ;
1648
1660
1649
- // hold off on querying seeds if p2p network deactivated
1661
+ // hold off on querying seeds if P2P network deactivated
1650
1662
if (!fNetworkActive ) {
1651
1663
LogPrintf (" Waiting for network to be reactivated before querying DNS seeds.\n " );
1652
1664
do {
@@ -1797,6 +1809,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1797
1809
return ;
1798
1810
1799
1811
// Add seed nodes if DNS seeds are all down (an infrastructure attack?).
1812
+ // Note that we only do this if we started with an empty peers.dat,
1813
+ // (in which case we will query DNS seeds immediately) *and* the DNS
1814
+ // seeds have not returned any results.
1800
1815
if (addrman.size () == 0 && (GetTime () - nStart > 60 )) {
1801
1816
static bool done = false ;
1802
1817
if (!done) {
0 commit comments