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

Method SendMessages

src/net_processing.cpp:5816–6324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5814}
5815
5816bool PeerManagerImpl::SendMessages(CNode& node)
5817{
5818 AssertLockNotHeld(m_tx_download_mutex);
5819 AssertLockHeld(g_msgproc_mutex);
5820
5821 PeerRef maybe_peer{GetPeerRef(node.GetId())};
5822 if (!maybe_peer) return false;
5823 Peer& peer{*maybe_peer};
5824 const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
5825
5826 // We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
5827 // disconnect misbehaving peers even before the version handshake is complete.
5828 if (MaybeDiscourageAndDisconnect(node, peer)) return true;
5829
5830 // Initiate version handshake for outbound connections
5831 if (!node.IsInboundConn() && !peer.m_outbound_version_message_sent) {
5832 PushNodeVersion(node, peer);
5833 peer.m_outbound_version_message_sent = true;
5834 }
5835
5836 // Don't send anything until the version handshake is complete
5837 if (!node.fSuccessfullyConnected || node.fDisconnect)
5838 return true;
5839
5840 const auto now{NodeClock::now()};
5841 const auto current_time{GetTime<std::chrono::microseconds>()};
5842
5843 // The logic below does not apply to private broadcast peers, so skip it.
5844 // Also in CConnman::PushMessage() we make sure that unwanted messages are
5845 // not sent. This here is just an optimization.
5846 if (node.IsPrivateBroadcastConn()) {
5847 if (node.m_connected + PRIVATE_BROADCAST_MAX_CONNECTION_LIFETIME < now) {
5848 LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: did not complete the transaction send within %d seconds, %s",
5849 count_seconds(PRIVATE_BROADCAST_MAX_CONNECTION_LIFETIME), node.LogPeer());
5850 node.fDisconnect = true;
5851 }
5852 return true;
5853 }
5854
5855 if (node.IsAddrFetchConn() && now - node.m_connected > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
5856 LogDebug(BCLog::NET, "addrfetch connection timeout, %s", node.DisconnectMsg());
5857 node.fDisconnect = true;
5858 return true;
5859 }
5860
5861 MaybeSendPing(node, peer, now);
5862
5863 // MaybeSendPing may have marked peer for disconnection
5864 if (node.fDisconnect) return true;
5865
5866 MaybeSendAddr(node, peer, current_time);
5867
5868 MaybeSendSendHeaders(node, peer);
5869
5870 {
5871 LOCK(cs_main);
5872
5873 CNodeState &state = *State(node.GetId());

Callers 1

ThreadMessageHandlerMethod · 0.45

Calls 15

count_secondsFunction · 0.85
CanServeBlocksFunction · 0.85
IsLimitedPeerFunction · 0.85
LastCommonAncestorFunction · 0.85
GetIdMethod · 0.80
IsInboundConnMethod · 0.80
LogPeerMethod · 0.80
IsAddrFetchConnMethod · 0.80
DisconnectMsgMethod · 0.80
LoadingBlocksMethod · 0.80
LookupBlockIndexMethod · 0.80

Tested by

no test coverage detected