Merge 0f6d20e43f into merged_master (Bitcoin PR bitcoin/bitcoin#31163)

This commit is contained in:
ivanlele 2026-04-02 15:30:57 +00:00
commit 1feddba6f7
No known key found for this signature in database
11 changed files with 53 additions and 53 deletions

View file

@ -7,29 +7,29 @@
#include <common/system.h>
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* msg_type, unsigned int nMessageSizeIn)
: pchMessageStart{pchMessageStartIn}
{
// Copy the command name
// Copy the message type name
size_t i = 0;
for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];
assert(pszCommand[i] == 0); // Assert that the command name passed in is not longer than COMMAND_SIZE
for (; i < MESSAGE_TYPE_SIZE && msg_type[i] != 0; ++i) m_msg_type[i] = msg_type[i];
assert(msg_type[i] == 0); // Assert that the message type name passed in is not longer than MESSAGE_TYPE_SIZE
nMessageSize = nMessageSizeIn;
}
std::string CMessageHeader::GetCommand() const
std::string CMessageHeader::GetMessageType() const
{
return std::string(pchCommand, pchCommand + strnlen(pchCommand, COMMAND_SIZE));
return std::string(m_msg_type, m_msg_type + strnlen(m_msg_type, MESSAGE_TYPE_SIZE));
}
bool CMessageHeader::IsCommandValid() const
bool CMessageHeader::IsMessageTypeValid() const
{
// Check the command string for errors
for (const char* p1 = pchCommand; p1 < pchCommand + COMMAND_SIZE; ++p1) {
// Check the message type string for errors
for (const char* p1 = m_msg_type; p1 < m_msg_type + MESSAGE_TYPE_SIZE; ++p1) {
if (*p1 == 0) {
// Must be all zeros after the first zero
for (; p1 < pchCommand + COMMAND_SIZE; ++p1) {
for (; p1 < m_msg_type + MESSAGE_TYPE_SIZE; ++p1) {
if (*p1 != 0) {
return false;
}
@ -55,7 +55,7 @@ bool operator<(const CInv& a, const CInv& b)
return (a.type < b.type || (a.type == b.type && a.hash < b.hash));
}
std::string CInv::GetCommand() const
std::string CInv::GetMessageType() const
{
std::string cmd;
if (type & MSG_WITNESS_FLAG)
@ -70,14 +70,14 @@ std::string CInv::GetCommand() const
case MSG_FILTERED_BLOCK: return cmd.append(NetMsgType::MERKLEBLOCK);
case MSG_CMPCT_BLOCK: return cmd.append(NetMsgType::CMPCTBLOCK);
default:
throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
throw std::out_of_range(strprintf("CInv::GetMessageType(): type=%d unknown type", type));
}
}
std::string CInv::ToString() const
{
try {
return strprintf("%s %s", GetCommand(), hash.ToString());
return strprintf("%s %s", GetMessageType(), hash.ToString());
} catch(const std::out_of_range &) {
return strprintf("0x%08x %s", type, hash.ToString());
}