MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ThreadOpenConnections

Method ThreadOpenConnections

src/net.cpp:2569–2951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2567}
2568
2569void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std::span<const std::string> seed_nodes)
2570{
2571 AssertLockNotHeld(m_nodes_mutex);
2572 AssertLockNotHeld(m_reconnections_mutex);
2573 AssertLockNotHeld(m_unused_i2p_sessions_mutex);
2574
2575 FastRandomContext rng;
2576 // Connect to specific addresses
2577 if (!connect.empty())
2578 {
2579 // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
2580 // peer doesn't support it or immediately disconnects us for another reason.
2581 const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
2582 for (int64_t nLoop = 0;; nLoop++)
2583 {
2584 for (const std::string& strAddr : connect)
2585 {
2586 OpenNetworkConnection(/*addrConnect=*/CAddress{CService{}, NODE_NONE},
2587 /*fCountFailure=*/false,
2588 /*grant_outbound=*/{},
2589 /*pszDest=*/strAddr.c_str(),
2590 /*conn_type=*/ConnectionType::MANUAL,
2591 /*use_v2transport=*/use_v2transport,
2592 /*proxy_override=*/std::nullopt);
2593 for (int i = 0; i < 10 && i < nLoop; i++)
2594 {
2595 if (!m_interrupt_net->sleep_for(500ms)) {
2596 return;
2597 }
2598 }
2599 }
2600 if (!m_interrupt_net->sleep_for(500ms)) {
2601 return;
2602 }
2603 PerformReconnections();
2604 }
2605 }
2606
2607 // Initiate network connections
2608 auto start = GetTime<std::chrono::microseconds>();
2609
2610 // Minimum time before next feeler connection (in microseconds).
2611 auto next_feeler = start + rng.rand_exp_duration(FEELER_INTERVAL);
2612 auto next_extra_block_relay = start + rng.rand_exp_duration(EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
2613 auto next_extra_network_peer{start + rng.rand_exp_duration(EXTRA_NETWORK_PEER_INTERVAL)};
2614 const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
2615 bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
2616 const bool use_seednodes{!gArgs.GetArgs("-seednode").empty()};
2617
2618 auto seed_node_timer = NodeClock::now();
2619 bool add_addr_fetch{addrman.get().Size() == 0 && !seed_nodes.empty()};
2620 constexpr std::chrono::seconds ADD_NEXT_SEEDNODE = 10s;
2621
2622 if (!add_fixed_seeds) {
2623 LogInfo("Fixed seeds are disabled\n");
2624 }
2625
2626 while (!m_interrupt_net->interrupted()) {

Callers

nothing calls this directly

Calls 15

ConvertSeedsFunction · 0.85
IsLocalFunction · 0.85
MayHaveUsefulAddressDBFunction · 0.85
IsBadPortFunction · 0.85
ConnectionTypeAsStringFunction · 0.85
GetNetworkNameFunction · 0.85
rand_exp_durationMethod · 0.80
GetBoolArgMethod · 0.80
GetArgsMethod · 0.80
countMethod · 0.80
GetNetworkMethod · 0.80
SetInternalMethod · 0.80

Tested by

no test coverage detected