mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
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)
This commit is contained in:
commit
49c5910372
@ -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;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user