Skip to content

Commit 49c5910

Browse files
committed
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)
2 parents 088d1f4 + 1df3111 commit 49c5910

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,11 +4371,11 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
43714371
unsigned int nSize = 0;
43724372
try {
43734373
// locate a header
4374-
unsigned char buf[MESSAGE_START_SIZE];
4374+
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
43754375
blkdat.FindByte(chainparams.MessageStart()[0]);
43764376
nRewind = blkdat.GetPos()+1;
43774377
blkdat >> FLATDATA(buf);
4378-
if (memcmp(buf, chainparams.MessageStart(), MESSAGE_START_SIZE))
4378+
if (memcmp(buf, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE))
43794379
continue;
43804380
// read size
43814381
blkdat >> nSize;
@@ -6266,7 +6266,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman)
62666266
it++;
62676267

62686268
// Scan for message start
6269-
if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), MESSAGE_START_SIZE) != 0) {
6269+
if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
62706270
LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id);
62716271
fOk = false;
62726272
break;

src/protocol.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <stdint.h>
1919
#include <string>
2020

21-
#define MESSAGE_START_SIZE 4
22-
2321
/** Message header.
2422
* (4) message start.
2523
* (12) command.
@@ -29,6 +27,16 @@
2927
class CMessageHeader
3028
{
3129
public:
30+
enum {
31+
MESSAGE_START_SIZE = 4,
32+
COMMAND_SIZE = 12,
33+
MESSAGE_SIZE_SIZE = 4,
34+
CHECKSUM_SIZE = 4,
35+
36+
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE,
37+
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE,
38+
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE
39+
};
3240
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
3341

3442
CMessageHeader(const MessageStartChars& pchMessageStartIn);
@@ -48,17 +56,6 @@ class CMessageHeader
4856
READWRITE(FLATDATA(pchChecksum));
4957
}
5058

51-
// TODO: make private (improves encapsulation)
52-
public:
53-
enum {
54-
COMMAND_SIZE = 12,
55-
MESSAGE_SIZE_SIZE = 4,
56-
CHECKSUM_SIZE = 4,
57-
58-
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE,
59-
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE,
60-
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE
61-
};
6259
char pchMessageStart[MESSAGE_START_SIZE];
6360
char pchCommand[COMMAND_SIZE];
6461
uint32_t nMessageSize;
@@ -315,20 +312,24 @@ class CAddress : public CService
315312
unsigned int nTime;
316313
};
317314

318-
/** getdata message types */
315+
/** getdata message type flags */
319316
const uint32_t MSG_WITNESS_FLAG = 1 << 30;
320317
const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2;
318+
319+
/** getdata / inv message types.
320+
* These numbers are defined by the protocol. When adding a new value, be sure
321+
* to mention it in the respective BIP.
322+
*/
321323
enum GetDataMsg
322324
{
323325
UNDEFINED = 0,
324-
MSG_TX,
325-
MSG_BLOCK,
326-
MSG_TYPE_MAX = MSG_BLOCK,
326+
MSG_TX = 1,
327+
MSG_BLOCK = 2,
327328
// The following can only occur in getdata. Invs always use TX or BLOCK.
328-
MSG_FILTERED_BLOCK,
329-
MSG_CMPCT_BLOCK,
330-
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG,
331-
MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG,
329+
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
330+
MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
331+
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144
332+
MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, //!< Defined in BIP144
332333
MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG,
333334
};
334335

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static const int SENDHEADERS_VERSION = 70012;
3939
//! "feefilter" tells peers to filter invs to you by fee starts with this version
4040
static const int FEEFILTER_VERSION = 70013;
4141

42-
//! shord-id-based block download starts with this version
42+
//! short-id-based block download starts with this version
4343
static const int SHORT_IDS_BLOCKS_VERSION = 70014;
4444

4545
#endif // BITCOIN_VERSION_H

0 commit comments

Comments
 (0)