MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / SendMessages

Method SendMessages

src/net_processing.cpp:8613–9327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8611}
8612
8613bool PeerManagerImpl::SendMessages(const Config &config, CNode *pto) {
8614 AssertLockHeld(g_msgproc_mutex);
8615
8616 PeerRef peer = GetPeerRef(pto->GetId());
8617 if (!peer) {
8618 return false;
8619 }
8620 const Consensus::Params &consensusParams = m_chainparams.GetConsensus();
8621
8622 // We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
8623 // disconnect misbehaving peers even before the version handshake is
8624 // complete.
8625 if (MaybeDiscourageAndDisconnect(*pto, *peer)) {
8626 return true;
8627 }
8628
8629 // Don't send anything until the version handshake is complete
8630 if (!pto->fSuccessfullyConnected || pto->fDisconnect) {
8631 return true;
8632 }
8633
8634 const auto current_time{GetTime<std::chrono::microseconds>()};
8635
8636 if (pto->IsAddrFetchConn() &&
8637 current_time - pto->m_connected > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
8638 LogPrint(BCLog::NET,
8639 "addrfetch connection timeout; disconnecting peer=%d\n",
8640 pto->GetId());
8641 pto->fDisconnect = true;
8642 return true;
8643 }
8644
8645 MaybeSendPing(*pto, *peer, current_time);
8646
8647 // MaybeSendPing may have marked peer for disconnection
8648 if (pto->fDisconnect) {
8649 return true;
8650 }
8651
8652 bool sync_blocks_and_headers_from_peer = false;
8653
8654 MaybeSendAddr(*pto, *peer, current_time);
8655
8656 MaybeSendSendHeaders(*pto, *peer);
8657
8658 {
8659 LOCK(cs_main);
8660
8661 CNodeState &state = *State(pto->GetId());
8662
8663 // Start block sync
8664 if (m_chainman.m_best_header == nullptr) {
8665 m_chainman.m_best_header = m_chainman.ActiveChain().Tip();
8666 }
8667
8668 // Determine whether we might try initial headers sync or parallel
8669 // block download from this peer -- this mostly affects behavior while
8670 // in IBD (once out of IBD, we sync from all peers).

Callers 4

ThreadMessageHandlerMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
HandshakeMethod · 0.80

Calls 15

CanServeBlocksFunction · 0.85
GetAdjustedTimeFunction · 0.85
MakeFunction · 0.85
count_secondsFunction · 0.85
maxFunction · 0.85
IsLimitedPeerFunction · 0.85
LastCommonAncestorFunction · 0.85
IsAddrFetchConnMethod · 0.80
TipMethod · 0.80
LoadingBlocksMethod · 0.80
LookupBlockIndexMethod · 0.80
frontMethod · 0.80

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
HandshakeMethod · 0.64