18
18
#include < stdint.h>
19
19
#include < string>
20
20
21
- #define MESSAGE_START_SIZE 4
22
-
23
21
/* * Message header.
24
22
* (4) message start.
25
23
* (12) command.
29
27
class CMessageHeader
30
28
{
31
29
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
+ };
32
40
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
33
41
34
42
CMessageHeader (const MessageStartChars& pchMessageStartIn);
@@ -48,17 +56,6 @@ class CMessageHeader
48
56
READWRITE (FLATDATA (pchChecksum));
49
57
}
50
58
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
- };
62
59
char pchMessageStart[MESSAGE_START_SIZE];
63
60
char pchCommand[COMMAND_SIZE];
64
61
uint32_t nMessageSize;
@@ -315,20 +312,24 @@ class CAddress : public CService
315
312
unsigned int nTime;
316
313
};
317
314
318
- /* * getdata message types */
315
+ /* * getdata message type flags */
319
316
const uint32_t MSG_WITNESS_FLAG = 1 << 30 ;
320
317
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
+ */
321
323
enum GetDataMsg
322
324
{
323
325
UNDEFINED = 0 ,
324
- MSG_TX,
325
- MSG_BLOCK,
326
- MSG_TYPE_MAX = MSG_BLOCK,
326
+ MSG_TX = 1 ,
327
+ MSG_BLOCK = 2 ,
327
328
// 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
332
333
MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG,
333
334
};
334
335
0 commit comments