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

Method GetReceivedMessage

src/net.cpp:809–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807}
808
809CNetMessage V1Transport::GetReceivedMessage(NodeClock::time_point time, bool& reject_message)
810{
811 AssertLockNotHeld(m_recv_mutex);
812 // Initialize out parameter
813 reject_message = false;
814 // decompose a single CNetMessage from the TransportDeserializer
815 LOCK(m_recv_mutex);
816 CNetMessage msg(std::move(vRecv));
817
818 // store message type string, time, and sizes
819 msg.m_type = hdr.GetMessageType();
820 msg.m_time = time;
821 msg.m_message_size = hdr.nMessageSize;
822 msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
823
824 uint256 hash = GetMessageHash();
825
826 // We just received a message off the wire, harvest entropy from the time (and the message checksum)
827 RandAddEvent(ReadLE32(hash.begin()));
828
829 // Check checksum and header message type string
830 if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
831 LogDebug(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
832 SanitizeString(msg.m_type), msg.m_message_size,
833 HexStr(std::span{hash}.first(CMessageHeader::CHECKSUM_SIZE)),
834 HexStr(hdr.pchChecksum),
835 m_node_id);
836 reject_message = true;
837 } else if (!hdr.IsMessageTypeValid()) {
838 LogDebug(BCLog::NET, "Header error: Invalid message type (%s, %u bytes), peer=%d\n",
839 SanitizeString(hdr.GetMessageType()), msg.m_message_size, m_node_id);
840 reject_message = true;
841 }
842
843 // Always reset the network deserializer (prepare for the next message)
844 Reset();
845 return msg;
846}
847
848bool V1Transport::SetMessageToSend(CSerializedNetMsg& msg) noexcept
849{

Callers 5

ReceiveMsgBytesMethod · 0.80
InteractMethod · 0.80
SimulationTestFunction · 0.80
GetNetMsgMethod · 0.80

Calls 13

RandAddEventFunction · 0.85
ReadLE32Function · 0.85
SanitizeStringFunction · 0.85
UCharCastFunction · 0.85
ClearShrinkFunction · 0.85
IsMessageTypeValidMethod · 0.80
HexStrFunction · 0.50
GetMessageTypeMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
endMethod · 0.45

Tested by 3

InteractMethod · 0.64
SimulationTestFunction · 0.64
GetNetMsgMethod · 0.64