diff --git a/src/main.cpp b/src/main.cpp index c92a38be9..f3b0e3c22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4371,11 +4371,11 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB unsigned int nSize = 0; try { // locate a header - unsigned char buf[MESSAGE_START_SIZE]; + unsigned char buf[CMessageHeader::MESSAGE_START_SIZE]; blkdat.FindByte(chainparams.MessageStart()[0]); nRewind = blkdat.GetPos()+1; blkdat >> FLATDATA(buf); - if (memcmp(buf, chainparams.MessageStart(), MESSAGE_START_SIZE)) + if (memcmp(buf, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) continue; // read size blkdat >> nSize; @@ -6266,7 +6266,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman) it++; // Scan for message start - if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), MESSAGE_START_SIZE) != 0) { + if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id); fOk = false; break; diff --git a/src/protocol.h b/src/protocol.h index 1bc1c25b3..d19e0d3a5 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -18,8 +18,6 @@ #include #include -#define MESSAGE_START_SIZE 4 - /** Message header. * (4) message start. * (12) command. @@ -29,6 +27,16 @@ class CMessageHeader { public: + enum { + MESSAGE_START_SIZE = 4, + COMMAND_SIZE = 12, + MESSAGE_SIZE_SIZE = 4, + CHECKSUM_SIZE = 4, + + MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, + CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE, + HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE + }; typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; CMessageHeader(const MessageStartChars& pchMessageStartIn); @@ -48,17 +56,6 @@ public: READWRITE(FLATDATA(pchChecksum)); } - // TODO: make private (improves encapsulation) -public: - enum { - COMMAND_SIZE = 12, - MESSAGE_SIZE_SIZE = 4, - CHECKSUM_SIZE = 4, - - MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, - CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE, - HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE - }; char pchMessageStart[MESSAGE_START_SIZE]; char pchCommand[COMMAND_SIZE]; uint32_t nMessageSize; @@ -315,20 +312,24 @@ public: unsigned int nTime; }; -/** getdata message types */ +/** getdata message type flags */ const uint32_t MSG_WITNESS_FLAG = 1 << 30; const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2; + +/** getdata / inv message types. + * These numbers are defined by the protocol. When adding a new value, be sure + * to mention it in the respective BIP. + */ enum GetDataMsg { UNDEFINED = 0, - MSG_TX, - MSG_BLOCK, - MSG_TYPE_MAX = MSG_BLOCK, + MSG_TX = 1, + MSG_BLOCK = 2, // The following can only occur in getdata. Invs always use TX or BLOCK. - MSG_FILTERED_BLOCK, - MSG_CMPCT_BLOCK, - MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, - MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, + MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37 + MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152 + MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144 + MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, //!< Defined in BIP144 MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG, }; diff --git a/src/version.h b/src/version.h index 68ccd6d37..87bd65506 100644 --- a/src/version.h +++ b/src/version.h @@ -39,7 +39,7 @@ static const int SENDHEADERS_VERSION = 70012; //! "feefilter" tells peers to filter invs to you by fee starts with this version static const int FEEFILTER_VERSION = 70013; -//! shord-id-based block download starts with this version +//! short-id-based block download starts with this version static const int SHORT_IDS_BLOCKS_VERSION = 70014; #endif // BITCOIN_VERSION_H