mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
scripted-diff: get rid of remaining "command" terminology in protocol.{h,cpp}
-BEGIN VERIFY SCRIPT- sed -i s/COMMAND_SIZE/MESSAGE_TYPE_SIZE/g $(git grep -l COMMAND_SIZE) sed -i s/pszCommand/msg_type/g $(git grep -l pszCommand) sed -i s/pchCommand/m_msg_type/g $(git grep -l pchCommand) sed -i s/GetCommand/GetMessageType/g ./src/net.cpp ./src/protocol.cpp ./src/protocol.h ./src/test/fuzz/protocol.cpp sed -i s/IsCommandValid/IsMessageTypeValid/g $(git grep -l IsCommandValid) sed -i "s/command/message type/g" ./src/protocol.h ./src/protocol.cpp -END VERIFY SCRIPT-
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user