Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | static const std::string allNetMessageTypes[] = { | ||||
NetMsgType::FILTERCLEAR, NetMsgType::REJECT, NetMsgType::SENDHEADERS, | NetMsgType::FILTERCLEAR, NetMsgType::REJECT, NetMsgType::SENDHEADERS, | ||||
NetMsgType::FEEFILTER, NetMsgType::SENDCMPCT, NetMsgType::CMPCTBLOCK, | NetMsgType::FEEFILTER, NetMsgType::SENDCMPCT, NetMsgType::CMPCTBLOCK, | ||||
NetMsgType::GETBLOCKTXN, NetMsgType::BLOCKTXN, | NetMsgType::GETBLOCKTXN, NetMsgType::BLOCKTXN, | ||||
}; | }; | ||||
static const std::vector<std::string> | static const std::vector<std::string> | ||||
allNetMessageTypesVec(allNetMessageTypes, | allNetMessageTypesVec(allNetMessageTypes, | ||||
allNetMessageTypes + ARRAYLEN(allNetMessageTypes)); | allNetMessageTypes + ARRAYLEN(allNetMessageTypes)); | ||||
CMessageHeader::CMessageHeader(const MessageStartChars &pchMessageStartIn) { | CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn) { | ||||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); | memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); | ||||
memset(pchCommand, 0, sizeof(pchCommand)); | memset(pchCommand, 0, sizeof(pchCommand)); | ||||
nMessageSize = -1; | nMessageSize = -1; | ||||
memset(pchChecksum, 0, CHECKSUM_SIZE); | memset(pchChecksum, 0, CHECKSUM_SIZE); | ||||
} | } | ||||
CMessageHeader::CMessageHeader(const MessageStartChars &pchMessageStartIn, | CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn, | ||||
const char *pszCommand, | const char *pszCommand, | ||||
unsigned int nMessageSizeIn) { | unsigned int nMessageSizeIn) { | ||||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); | memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); | ||||
memset(pchCommand, 0, sizeof(pchCommand)); | memset(pchCommand, 0, sizeof(pchCommand)); | ||||
strncpy(pchCommand, pszCommand, COMMAND_SIZE); | strncpy(pchCommand, pszCommand, COMMAND_SIZE); | ||||
nMessageSize = nMessageSizeIn; | nMessageSize = nMessageSizeIn; | ||||
memset(pchChecksum, 0, CHECKSUM_SIZE); | memset(pchChecksum, 0, CHECKSUM_SIZE); | ||||
} | } | ||||
std::string CMessageHeader::GetCommand() const { | std::string CMessageHeader::GetCommand() const { | ||||
return std::string(pchCommand, | return std::string(pchCommand, | ||||
pchCommand + strnlen(pchCommand, COMMAND_SIZE)); | pchCommand + strnlen(pchCommand, COMMAND_SIZE)); | ||||
} | } | ||||
bool CMessageHeader::IsValid(const MessageStartChars &pchMessageStartIn) const { | bool CMessageHeader::IsValid(const MessageMagic &pchMessageStartIn) const { | ||||
// Check start string | // Check start string | ||||
if (memcmp(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE) != 0) | if (memcmp(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE) != 0) | ||||
return false; | return false; | ||||
// Check the command string for errors | // Check the command string for errors | ||||
for (const char *p1 = pchCommand; p1 < pchCommand + COMMAND_SIZE; p1++) { | for (const char *p1 = pchCommand; p1 < pchCommand + COMMAND_SIZE; p1++) { | ||||
if (*p1 == 0) { | if (*p1 == 0) { | ||||
// Must be all zeros after the first zero | // Must be all zeros after the first zero | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |