Browse Source

Merge #8880: protocol.h: Move MESSAGE_START_SIZE into CMessageHeader

1df3111 protocol.h: Make enums in GetDataMsg concrete values (Wladimir J. van der Laan)
2c09a52 protocol.h: Move MESSAGE_START_SIZE into CMessageHeader (Wladimir J. van der Laan)
f9bd92d version.h: s/shord/short/ in comment (Wladimir J. van der Laan)
0.14
Wladimir J. van der Laan 8 years ago
parent
commit
49c5910372
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 6
      src/main.cpp
  2. 43
      src/protocol.h
  3. 2
      src/version.h

6
src/main.cpp

@ -4371,11 +4371,11 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
unsigned int nSize = 0; unsigned int nSize = 0;
try { try {
// locate a header // locate a header
unsigned char buf[MESSAGE_START_SIZE]; unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
blkdat.FindByte(chainparams.MessageStart()[0]); blkdat.FindByte(chainparams.MessageStart()[0]);
nRewind = blkdat.GetPos()+1; nRewind = blkdat.GetPos()+1;
blkdat >> FLATDATA(buf); blkdat >> FLATDATA(buf);
if (memcmp(buf, chainparams.MessageStart(), MESSAGE_START_SIZE)) if (memcmp(buf, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE))
continue; continue;
// read size // read size
blkdat >> nSize; blkdat >> nSize;
@ -6266,7 +6266,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman)
it++; it++;
// Scan for message start // 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); LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id);
fOk = false; fOk = false;
break; break;

43
src/protocol.h

@ -18,8 +18,6 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#define MESSAGE_START_SIZE 4
/** Message header. /** Message header.
* (4) message start. * (4) message start.
* (12) command. * (12) command.
@ -29,6 +27,16 @@
class CMessageHeader class CMessageHeader
{ {
public: 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]; typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
CMessageHeader(const MessageStartChars& pchMessageStartIn); CMessageHeader(const MessageStartChars& pchMessageStartIn);
@ -48,17 +56,6 @@ public:
READWRITE(FLATDATA(pchChecksum)); 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 pchMessageStart[MESSAGE_START_SIZE];
char pchCommand[COMMAND_SIZE]; char pchCommand[COMMAND_SIZE];
uint32_t nMessageSize; uint32_t nMessageSize;
@ -315,20 +312,24 @@ public:
unsigned int nTime; unsigned int nTime;
}; };
/** getdata message types */ /** getdata message type flags */
const uint32_t MSG_WITNESS_FLAG = 1 << 30; const uint32_t MSG_WITNESS_FLAG = 1 << 30;
const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2; 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 enum GetDataMsg
{ {
UNDEFINED = 0, UNDEFINED = 0,
MSG_TX, MSG_TX = 1,
MSG_BLOCK, MSG_BLOCK = 2,
MSG_TYPE_MAX = MSG_BLOCK,
// The following can only occur in getdata. Invs always use TX or BLOCK. // The following can only occur in getdata. Invs always use TX or BLOCK.
MSG_FILTERED_BLOCK, MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
MSG_CMPCT_BLOCK, MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144
MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, //!< Defined in BIP144
MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG, MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG,
}; };

2
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 //! "feefilter" tells peers to filter invs to you by fee starts with this version
static const int FEEFILTER_VERSION = 70013; 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; static const int SHORT_IDS_BLOCKS_VERSION = 70014;
#endif // BITCOIN_VERSION_H #endif // BITCOIN_VERSION_H

Loading…
Cancel
Save