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

Method Start

src/net.cpp:3534–3645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3532}
3533
3534bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
3535{
3536 AssertLockNotHeld(m_total_bytes_sent_mutex);
3537 Init(connOptions);
3538
3539 if (fListen && !InitBinds(connOptions)) {
3540 if (m_client_interface) {
3541 m_client_interface->ThreadSafeMessageBox(
3542 _("Failed to listen on any port. Use -listen=0 if you want this."),
3543 CClientUIInterface::MSG_ERROR);
3544 }
3545 return false;
3546 }
3547
3548 if (connOptions.m_i2p_accept_incoming) {
3549 if (const auto i2p_sam = GetProxy(NET_I2P)) {
3550 m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs.GetDataDirNet() / "i2p_private_key",
3551 *i2p_sam, m_interrupt_net);
3552 }
3553 }
3554
3555 // Randomize the order in which we may query seednode to potentially prevent connecting to the same one every restart (and signal that we have restarted)
3556 std::vector<std::string> seed_nodes = connOptions.vSeedNodes;
3557 if (!seed_nodes.empty()) {
3558 std::shuffle(seed_nodes.begin(), seed_nodes.end(), FastRandomContext{});
3559 }
3560
3561 if (m_use_addrman_outgoing) {
3562 // Load addresses from anchors.dat
3563 m_anchors = ReadAnchors(gArgs.GetDataDirNet() / ANCHORS_DATABASE_FILENAME);
3564 if (m_anchors.size() > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
3565 m_anchors.resize(MAX_BLOCK_RELAY_ONLY_ANCHORS);
3566 }
3567 LogInfo("%i block-relay-only anchors will be tried for connections.\n", m_anchors.size());
3568 }
3569
3570 if (m_client_interface) {
3571 m_client_interface->InitMessage(_("Starting network threads…"));
3572 }
3573
3574 fAddressesInitialized = true;
3575
3576 if (semOutbound == nullptr) {
3577 // initialize semaphore
3578 semOutbound = std::make_unique<std::counting_semaphore<>>(std::min(m_max_automatic_outbound, m_max_automatic_connections));
3579 }
3580 if (semAddnode == nullptr) {
3581 // initialize semaphore
3582 semAddnode = std::make_unique<std::counting_semaphore<>>(m_max_addnode);
3583 }
3584
3585 //
3586 // Start threads
3587 //
3588 assert(m_msgproc);
3589 m_interrupt_net->reset();
3590 flagInterruptMsgProc = false;
3591

Callers 2

StartHTTPServerFunction · 0.45
AppInitMainFunction · 0.45

Calls 14

_Function · 0.85
GetProxyFunction · 0.85
ReadAnchorsFunction · 0.85
GetDataDirNetMethod · 0.80
GetBoolArgMethod · 0.80
scheduleEveryMethod · 0.80
UsingASMapMethod · 0.80
InitClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected