Merge bitcoin/bitcoin#28016: p2p: gives seednode priority over dnsseed if both are provided
82f41d76f1Added seednode prioritization message to help output (tdb3)3120a4678aGives seednode priority over dnsseed if both are provided (Sergi Delgado Segura) Pull request description: This is a follow-up of #27577 If both `seednode` and `dnsseed` are provided, the node will start a race between them in order to fetch data to feed the `addrman`. This PR gives priority to `seednode` over `dnsseed` so if some nodes are provided as seeds, they can be tried before defaulting to the `dnsseeds` ACKs for top commit: davidgumberg: untested reACK https://github.com/bitcoin/bitcoin/commit/82f41d76f1c6ad38290917dad5499ffbe6b3974d itornaza: tested re-ACK82f41d76f1achow101: ACK82f41d76f1cbergqvist: ACK82f41d76f1Tree-SHA512: 4e39e10a7449af6cd9b8f9f6878f846b94bca11baf89ff2d4fbcd4f28293978a6ed71a3a86cea36d49eca891314c834e32af93f37a09c2cc698a878f84d31c62
This commit is contained in:
3 files changed
+49
-10
No files matched your search
+1
-1
@@ -544,7 +544,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
|||||||
argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
|
argsman.AddArg("-proxy=<ip:port>", "Connect through SOCKS5 proxy, set -noproxy to disable (default: disabled)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_ELISION, OptionsCategory::CONNECTION);
|
||||||
#endif
|
#endif
|
||||||
argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-proxyrandomize", strprintf("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)", DEFAULT_PROXYRANDOMIZE), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
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);
|
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);
|
||||||
argsman.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
argsman.AddArg("-networkactive", "Enable all P2P network activity (default: 1). Can be changed by the setnetworkactive RPC command", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
|
|||||||
+46
-9
@@ -2183,11 +2183,36 @@ void CConnman::WakeMessageHandler()
|
|||||||
|
|
||||||
void CConnman::ThreadDNSAddressSeed()
|
void CConnman::ThreadDNSAddressSeed()
|
||||||
{
|
{
|
||||||
|
constexpr int TARGET_OUTBOUND_CONNECTIONS = 2;
|
||||||
|
int outbound_connection_count = 0;
|
||||||
|
|
||||||
|
if (gArgs.IsArgSet("-seednode")) {
|
||||||
|
auto start = NodeClock::now();
|
||||||
|
constexpr std::chrono::seconds SEEDNODE_TIMEOUT = 30s;
|
||||||
|
LogPrintf("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count());
|
||||||
|
while (!interruptNet) {
|
||||||
|
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Abort if we have spent enough time without reaching our target.
|
||||||
|
// Giving seed nodes 30 seconds so this does not become a race against fixedseeds (which triggers after 1 min)
|
||||||
|
if (NodeClock::now() > start + SEEDNODE_TIMEOUT) {
|
||||||
|
LogPrintf("Couldn't connect to enough peers via seed nodes. Handing fetch logic to the DNS seeds.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
outbound_connection_count = GetFullOutboundConnCount();
|
||||||
|
if (outbound_connection_count >= TARGET_OUTBOUND_CONNECTIONS) {
|
||||||
|
LogPrintf("P2P peers available. Finished fetching data from seed nodes.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FastRandomContext rng;
|
FastRandomContext rng;
|
||||||
std::vector<std::string> seeds = m_params.DNSSeeds();
|
std::vector<std::string> seeds = m_params.DNSSeeds();
|
||||||
Shuffle(seeds.begin(), seeds.end(), rng);
|
Shuffle(seeds.begin(), seeds.end(), rng);
|
||||||
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
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)) {
|
if (gArgs.GetBoolArg("-forcednsseed", DEFAULT_FORCEDNSSEED)) {
|
||||||
// When -forcednsseed is provided, query all.
|
// When -forcednsseed is provided, query all.
|
||||||
@@ -2199,6 +2224,8 @@ void CConnman::ThreadDNSAddressSeed()
|
|||||||
seeds_right_now = seeds.size();
|
seeds_right_now = seeds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Proceed with dnsseeds if seednodes hasn't reached the target or if forcednsseed is set
|
||||||
|
if (outbound_connection_count < TARGET_OUTBOUND_CONNECTIONS || seeds_right_now) {
|
||||||
// goal: only query DNS seed if address need is acute
|
// goal: only query DNS seed if address need is acute
|
||||||
// * If we have a reasonable number of peers in addrman, spend
|
// * If we have a reasonable number of peers in addrman, spend
|
||||||
// some time trying them first. This improves user privacy by
|
// some time trying them first. This improves user privacy by
|
||||||
@@ -2211,6 +2238,7 @@ void CConnman::ThreadDNSAddressSeed()
|
|||||||
// * If we continue having problems, eventually query all the
|
// * If we continue having problems, eventually query all the
|
||||||
// DNS seeds, and if that fails too, also try the fixed seeds.
|
// DNS seeds, and if that fails too, also try the fixed seeds.
|
||||||
// (done in ThreadOpenConnections)
|
// (done in ThreadOpenConnections)
|
||||||
|
int found = 0;
|
||||||
const std::chrono::seconds seeds_wait_time = (addrman.Size() >= DNSSEEDS_DELAY_PEER_THRESHOLD ? DNSSEEDS_DELAY_MANY_PEERS : DNSSEEDS_DELAY_FEW_PEERS);
|
const std::chrono::seconds seeds_wait_time = (addrman.Size() >= DNSSEEDS_DELAY_PEER_THRESHOLD ? DNSSEEDS_DELAY_MANY_PEERS : DNSSEEDS_DELAY_FEW_PEERS);
|
||||||
|
|
||||||
for (const std::string& seed : seeds) {
|
for (const std::string& seed : seeds) {
|
||||||
@@ -2228,14 +2256,7 @@ void CConnman::ThreadDNSAddressSeed()
|
|||||||
if (!interruptNet.sleep_for(w)) return;
|
if (!interruptNet.sleep_for(w)) return;
|
||||||
to_wait -= w;
|
to_wait -= w;
|
||||||
|
|
||||||
int nRelevant = 0;
|
if (GetFullOutboundConnCount() >= TARGET_OUTBOUND_CONNECTIONS) {
|
||||||
{
|
|
||||||
LOCK(m_nodes_mutex);
|
|
||||||
for (const CNode* pnode : m_nodes) {
|
|
||||||
if (pnode->fSuccessfullyConnected && pnode->IsFullOutboundConn()) ++nRelevant;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nRelevant >= 2) {
|
|
||||||
if (found > 0) {
|
if (found > 0) {
|
||||||
LogPrintf("%d addresses found from DNS seeds\n", found);
|
LogPrintf("%d addresses found from DNS seeds\n", found);
|
||||||
LogPrintf("P2P peers available. Finished DNS seeding.\n");
|
LogPrintf("P2P peers available. Finished DNS seeding.\n");
|
||||||
@@ -2295,6 +2316,9 @@ void CConnman::ThreadDNSAddressSeed()
|
|||||||
--seeds_right_now;
|
--seeds_right_now;
|
||||||
}
|
}
|
||||||
LogPrintf("%d addresses found from DNS seeds\n", found);
|
LogPrintf("%d addresses found from DNS seeds\n", found);
|
||||||
|
} else {
|
||||||
|
LogPrintf("Skipping DNS seeds. Enough peers have been found\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnman::DumpAddresses()
|
void CConnman::DumpAddresses()
|
||||||
@@ -2345,6 +2369,19 @@ void CConnman::StartExtraBlockRelayPeers()
|
|||||||
m_start_extra_block_relay_peers = true;
|
m_start_extra_block_relay_peers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the number of outbound connections that are full relay (not blocks only)
|
||||||
|
int CConnman::GetFullOutboundConnCount() const
|
||||||
|
{
|
||||||
|
int nRelevant = 0;
|
||||||
|
{
|
||||||
|
LOCK(m_nodes_mutex);
|
||||||
|
for (const CNode* pnode : m_nodes) {
|
||||||
|
if (pnode->fSuccessfullyConnected && pnode->IsFullOutboundConn()) ++nRelevant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nRelevant;
|
||||||
|
}
|
||||||
|
|
||||||
// Return the number of peers we have over our outbound connection limit
|
// Return the number of peers we have over our outbound connection limit
|
||||||
// Exclude peers that are marked for disconnect, or are going to be
|
// Exclude peers that are marked for disconnect, or are going to be
|
||||||
// disconnected soon (eg ADDR_FETCH and FEELER)
|
// disconnected soon (eg ADDR_FETCH and FEELER)
|
||||||
|
|||||||
@@ -1173,6 +1173,8 @@ public:
|
|||||||
|
|
||||||
void StartExtraBlockRelayPeers();
|
void StartExtraBlockRelayPeers();
|
||||||
|
|
||||||
|
// Count the number of full-relay peer we have.
|
||||||
|
int GetFullOutboundConnCount() const;
|
||||||
// Return the number of outbound peers we have in excess of our target (eg,
|
// Return the number of outbound peers we have in excess of our target (eg,
|
||||||
// if we previously called SetTryNewOutboundPeer(true), and have since set
|
// if we previously called SetTryNewOutboundPeer(true), and have since set
|
||||||
// to false, we may have extra peers that we wish to disconnect). This may
|
// to false, we may have extra peers that we wish to disconnect). This may
|
||||||
|
|||||||
Reference in new issue
Block a user