Skip to content

Commit 82f41d7

Browse files
tdb3sr-gi
authored andcommitted
Added seednode prioritization message to help output
1 parent 3120a46 commit 82f41d7

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void SetupServerArgs(ArgsManager& argsman)
546546
argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
547547
#endif
548548
argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
549-
argsman.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
549+
argsman.AddArg("-seednode=<ip>", "Connect to a node to retrieve peer addresses, and disconnect. This option can be specified multiple times to connect to multiple nodes. During startup, seednodes will be tried before dnsseeds.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
550550
argsman.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
551551
argsman.AddArg("-timeout=<n>", strprintf("Specify socket connection timeout in milliseconds. If an initial attempt to connect is unsuccessful after this amount of time, drop it (minimum: 1, default: %d)", DEFAULT_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
552552
argsman.AddArg("-peertimeout=<n>", strprintf("Specify a p2p connection timeout delay in seconds. After connecting to a peer, wait this amount of time before considering disconnection based on inactivity (minimum: 1, default: %d)", DEFAULT_PEER_CONNECT_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CONNECTION);

src/net.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,35 +2168,37 @@ void CConnman::WakeMessageHandler()
21682168

21692169
void CConnman::ThreadDNSAddressSeed()
21702170
{
2171-
FastRandomContext rng;
2172-
std::vector<std::string> seeds = m_params.DNSSeeds();
2173-
Shuffle(seeds.begin(), seeds.end(), rng);
2174-
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
2175-
int target_outbound_connections = 2;
2171+
constexpr int TARGET_OUTBOUND_CONNECTIONS = 2;
21762172
int outbound_connection_count = 0;
21772173

2178-
auto start = NodeClock::now();
21792174
if (gArgs.IsArgSet("-seednode")) {
2180-
LogPrintf("-seednode enabled. Trying the provided seeds before defaulting to the dnsseeds.\n");
2175+
auto start = NodeClock::now();
2176+
constexpr std::chrono::seconds SEEDNODE_TIMEOUT = 30s;
2177+
LogPrintf("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count());
21812178
while (!interruptNet) {
21822179
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
21832180
return;
21842181

21852182
// Abort if we have spent enough time without reaching our target.
21862183
// Giving seed nodes 30 seconds so this does not become a race against fixedseeds (which triggers after 1 min)
2187-
if (NodeClock::now() > start + 30s) {
2184+
if (NodeClock::now() > start + SEEDNODE_TIMEOUT) {
21882185
LogPrintf("Couldn't connect to enough peers via seed nodes. Handing fetch logic to the DNS seeds.\n");
21892186
break;
21902187
}
21912188

21922189
outbound_connection_count = GetFullOutboundConnCount();
2193-
if (outbound_connection_count >= target_outbound_connections) {
2194-
LogPrintf("P2P peers available. Finished fetching data from seed nodes.\n");
2190+
if (outbound_connection_count >= TARGET_OUTBOUND_CONNECTIONS) {
2191+
LogPrintf("P2P peers available. Finished fetching data from seed nodes.\n");
21952192
break;
21962193
}
21972194
}
21982195
}
21992196

2197+
FastRandomContext rng;
2198+
std::vector<std::string> seeds = m_params.DNSSeeds();
2199+
Shuffle(seeds.begin(), seeds.end(), rng);
2200+
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
2201+
22002202
if (gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED)) {
22012203
// When -forcednsseed is provided, query all.
22022204
seeds_right_now = seeds.size();
@@ -2208,7 +2210,7 @@ void CConnman::ThreadDNSAddressSeed()
22082210
}
22092211

22102212
// Proceed with dnsseeds if seednodes hasn't reached the target or if forcednsseed is set
2211-
if (outbound_connection_count < target_outbound_connections || seeds_right_now) {
2213+
if (outbound_connection_count < TARGET_OUTBOUND_CONNECTIONS || seeds_right_now) {
22122214
// goal: only query DNS seed if address need is acute
22132215
// * If we have a reasonable number of peers in addrman, spend
22142216
// some time trying them first. This improves user privacy by
@@ -2239,7 +2241,7 @@ void CConnman::ThreadDNSAddressSeed()
22392241
if (!interruptNet.sleep_for(w)) return;
22402242
to_wait -= w;
22412243

2242-
if (GetFullOutboundConnCount() >= target_outbound_connections) {
2244+
if (GetFullOutboundConnCount() >= TARGET_OUTBOUND_CONNECTIONS) {
22432245
if (found > 0) {
22442246
LogPrintf("%d addresses found from DNS seeds\n", found);
22452247
LogPrintf("P2P peers available. Finished DNS seeding.\n");

0 commit comments

Comments
 (0)