diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -319,7 +319,7 @@ /** * Transport protocol agnostic message container. * Ideally it should only contain receive time, payload, - * command and size. + * type and size. */ class CNetMessage { public: @@ -334,7 +334,7 @@ uint32_t m_message_size{0}; //! used wire size of the message (including header/checksum) uint32_t m_raw_message_size{0}; - std::string m_command; + std::string m_type; CNetMessage(CDataStream &&recv_in) : m_recv(std::move(recv_in)) {} diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -684,8 +684,7 @@ // Store received bytes per message command to prevent a memory DOS, // only allow valid commands. - mapMsgCmdSize::iterator i = - mapRecvBytesPerMsgCmd.find(msg.m_command); + mapMsgCmdSize::iterator i = mapRecvBytesPerMsgCmd.find(msg.m_type); if (i == mapRecvBytesPerMsgCmd.end()) { i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER); } @@ -778,7 +777,7 @@ uint256 hash = GetMessageHash(); // store command string, payload size - msg.m_command = hdr.GetCommand(); + msg.m_type = hdr.GetCommand(); msg.m_message_size = hdr.nMessageSize; msg.m_raw_message_size = hdr.nMessageSize + CMessageHeader::HEADER_SIZE; @@ -792,7 +791,7 @@ if (!msg.m_valid_checksum) { LogPrint(BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s\n", - SanitizeString(msg.m_command), msg.m_message_size, + SanitizeString(msg.m_type), msg.m_message_size, HexStr(Span{hash}.first(CMessageHeader::CHECKSUM_SIZE)), HexStr(hdr.pchChecksum)); } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -6216,11 +6216,11 @@ CNetMessage &msg(msgs.front()); TRACE6(net, inbound_message, pfrom->GetId(), pfrom->m_addr_name.c_str(), - pfrom->ConnectionTypeAsString().c_str(), msg.m_command.c_str(), + pfrom->ConnectionTypeAsString().c_str(), msg.m_type.c_str(), msg.m_recv.size(), msg.m_recv.data()); if (gArgs.GetBoolArg("-capturemessages", false)) { - CaptureMessage(pfrom->addr, msg.m_command, MakeUCharSpan(msg.m_recv), + CaptureMessage(pfrom->addr, msg.m_type, MakeUCharSpan(msg.m_recv), /*is_incoming=*/true); } @@ -6230,7 +6230,7 @@ if (!msg.m_valid_netmagic) { LogPrint(BCLog::NET, "PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", - SanitizeString(msg.m_command), pfrom->GetId()); + SanitizeString(msg.m_type), pfrom->GetId()); // Make sure we discourage where that come from for some time. if (m_banman) { @@ -6245,19 +6245,15 @@ // Check header if (!msg.m_valid_header) { LogPrint(BCLog::NET, "PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", - SanitizeString(msg.m_command), pfrom->GetId()); + SanitizeString(msg.m_type), pfrom->GetId()); return fMoreWork; } - const std::string &msg_type = msg.m_command; - - // Message size - unsigned int nMessageSize = msg.m_message_size; // Checksum CDataStream &vRecv = msg.m_recv; if (!msg.m_valid_checksum) { LogPrint(BCLog::NET, "%s(%s, %u bytes): CHECKSUM ERROR peer=%d\n", - __func__, SanitizeString(msg_type), nMessageSize, + __func__, SanitizeString(msg.m_type), msg.m_message_size, pfrom->GetId()); if (m_banman) { m_banman->Discourage(pfrom->addr); @@ -6267,7 +6263,7 @@ } try { - ProcessMessage(config, *pfrom, msg_type, vRecv, msg.m_time, + ProcessMessage(config, *pfrom, msg.m_type, vRecv, msg.m_time, interruptMsgProc); if (interruptMsgProc) { return false; @@ -6281,11 +6277,11 @@ } } catch (const std::exception &e) { LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", - __func__, SanitizeString(msg_type), nMessageSize, e.what(), - typeid(e).name()); + __func__, SanitizeString(msg.m_type), msg.m_message_size, + e.what(), typeid(e).name()); } catch (...) { LogPrint(BCLog::NET, "%s(%s, %u bytes): Unknown exception caught\n", - __func__, SanitizeString(msg_type), nMessageSize); + __func__, SanitizeString(msg.m_type), msg.m_message_size); } return fMoreWork; diff --git a/src/test/fuzz/p2p_transport_deserializer.cpp b/src/test/fuzz/p2p_transport_deserializer.cpp --- a/src/test/fuzz/p2p_transport_deserializer.cpp +++ b/src/test/fuzz/p2p_transport_deserializer.cpp @@ -32,7 +32,7 @@ const std::chrono::microseconds m_time{ std::numeric_limits::max()}; const CNetMessage msg = deserializer.GetMessage(config, m_time); - assert(msg.m_command.size() <= CMessageHeader::COMMAND_SIZE); + assert(msg.m_type.size() <= CMessageHeader::COMMAND_SIZE); assert(msg.m_raw_message_size <= buffer.size()); assert(msg.m_raw_message_size == CMessageHeader::HEADER_SIZE + msg.m_message_size);