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

Method ProcessMessages

src/net_processing.cpp:5165–5245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5163}
5164
5165bool PeerManagerImpl::ProcessMessages(CNode& node, std::atomic<bool>& interruptMsgProc)
5166{
5167 AssertLockNotHeld(m_tx_download_mutex);
5168 AssertLockHeld(g_msgproc_mutex);
5169
5170 PeerRef maybe_peer{GetPeerRef(node.GetId())};
5171 if (maybe_peer == nullptr) return false;
5172 Peer& peer{*maybe_peer};
5173
5174 // For outbound connections, ensure that the initial VERSION message
5175 // has been sent first before processing any incoming messages
5176 if (!node.IsInboundConn() && !peer.m_outbound_version_message_sent) return false;
5177
5178 {
5179 LOCK(peer.m_getdata_requests_mutex);
5180 if (!peer.m_getdata_requests.empty()) {
5181 ProcessGetData(node, peer, interruptMsgProc);
5182 }
5183 }
5184
5185 const bool processed_orphan = ProcessOrphanTx(peer);
5186
5187 if (node.fDisconnect)
5188 return false;
5189
5190 if (processed_orphan) return true;
5191
5192 // this maintains the order of responses
5193 // and prevents m_getdata_requests to grow unbounded
5194 {
5195 LOCK(peer.m_getdata_requests_mutex);
5196 if (!peer.m_getdata_requests.empty()) return true;
5197 }
5198
5199 // Don't bother if send buffer is too full to respond anyway
5200 if (node.fPauseSend) return false;
5201
5202 auto poll_result{node.PollMessage()};
5203 if (!poll_result) {
5204 // No message to process
5205 return false;
5206 }
5207
5208 CNetMessage& msg{poll_result->first};
5209 bool fMoreWork = poll_result->second;
5210
5211 TRACEPOINT(net, inbound_message,
5212 node.GetId(),
5213 node.m_addr_name.c_str(),
5214 node.ConnectionTypeAsString().c_str(),
5215 msg.m_type.c_str(),
5216 msg.m_recv.size(),
5217 msg.m_recv.data()
5218 );
5219
5220 if (m_opts.capture_messages) {
5221 CaptureMessage(node.addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true);
5222 }

Callers 1

ThreadMessageHandlerMethod · 0.45

Calls 11

MakeUCharSpanFunction · 0.85
SanitizeStringFunction · 0.85
GetIdMethod · 0.80
IsInboundConnMethod · 0.80
PollMessageMethod · 0.80
HaveMoreWorkMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected