MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetMessage

Method GetMessage

src/net.cpp:788–823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786}
787
788CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds time, bool& reject_message)
789{
790 // Initialize out parameter
791 reject_message = false;
792 // decompose a single CNetMessage from the TransportDeserializer
793 CNetMessage msg(std::move(vRecv));
794
795 // store command string, time, and sizes
796 msg.m_type = hdr.GetCommand();
797 msg.m_time = time;
798 msg.m_message_size = hdr.nMessageSize;
799 msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
800
801 uint256 hash = GetMessageHash();
802
803 // We just received a message off the wire, harvest entropy from the time (and the message checksum)
804 RandAddEvent(ReadLE32(hash.begin()));
805
806 // Check checksum and header command string
807 if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
808 LogPrint(BCLog::NET, "Header error: Wrong checksum (%s, %u bytes), expected %s was %s, peer=%d\n",
809 SanitizeString(msg.m_type), msg.m_message_size,
810 HexStr(Span{hash}.first(CMessageHeader::CHECKSUM_SIZE)),
811 HexStr(hdr.pchChecksum),
812 m_node_id);
813 reject_message = true;
814 } else if (!hdr.IsCommandValid()) {
815 LogPrint(BCLog::NET, "Header error: Invalid message type (%s, %u bytes), peer=%d\n",
816 SanitizeString(hdr.GetCommand()), msg.m_message_size, m_node_id);
817 reject_message = true;
818 }
819
820 // Always reset the network deserializer (prepare for the next message)
821 Reset();
822 return msg;
823}
824
825void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) {
826 // create dbl-sha256 checksum

Callers 2

ReceiveMsgBytesMethod · 0.80
FUZZ_TARGET_INITFunction · 0.80

Calls 7

RandAddEventFunction · 0.85
ReadLE32Function · 0.85
SanitizeStringFunction · 0.85
IsCommandValidMethod · 0.80
HexStrFunction · 0.50
GetCommandMethod · 0.45
beginMethod · 0.45

Tested by 1

FUZZ_TARGET_INITFunction · 0.64