mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +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:
parent
005ae79cf3
commit
0f021e55f6
@ -2323,7 +2323,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interru
|
||||
|
||||
msg.SetVersion(pfrom->GetRecvVersion());
|
||||
// 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);
|
||||
pfrom->fDisconnect = true;
|
||||
return false;
|
||||
|
@ -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;
|
||||
@ -319,30 +316,34 @@ public:
|
||||
unsigned int nTime;
|
||||
};
|
||||
|
||||
/** 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_TX = 1,
|
||||
MSG_BLOCK = 2,
|
||||
// The following can only occur in getdata. Invs always use TX or BLOCK.
|
||||
MSG_FILTERED_BLOCK,
|
||||
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
|
||||
// Dash message types
|
||||
// NOTE: declare non-implmented here, we must keep this enum consistent and backwards compatible
|
||||
MSG_TXLOCK_REQUEST,
|
||||
MSG_TXLOCK_VOTE,
|
||||
MSG_SPORK,
|
||||
MSG_MASTERNODE_PAYMENT_VOTE,
|
||||
MSG_MASTERNODE_PAYMENT_BLOCK, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
|
||||
MSG_BUDGET_VOTE, // depreciated since 12.1
|
||||
MSG_BUDGET_PROPOSAL, // depreciated since 12.1
|
||||
MSG_BUDGET_FINALIZED, // depreciated since 12.1
|
||||
MSG_BUDGET_FINALIZED_VOTE, // depreciated since 12.1
|
||||
MSG_MASTERNODE_QUORUM, // not implemented
|
||||
MSG_MASTERNODE_ANNOUNCE,
|
||||
MSG_MASTERNODE_PING,
|
||||
MSG_DSTX,
|
||||
MSG_GOVERNANCE_OBJECT,
|
||||
MSG_GOVERNANCE_OBJECT_VOTE,
|
||||
MSG_MASTERNODE_VERIFY,
|
||||
MSG_TXLOCK_REQUEST = 4,
|
||||
MSG_TXLOCK_VOTE = 5,
|
||||
MSG_SPORK = 6,
|
||||
MSG_MASTERNODE_PAYMENT_VOTE = 7,
|
||||
MSG_MASTERNODE_PAYMENT_BLOCK = 8, // reusing, was MSG_MASTERNODE_SCANNING_ERROR previousely, was NOT used in 12.0
|
||||
MSG_BUDGET_VOTE = 9, // depreciated since 12.1
|
||||
MSG_BUDGET_PROPOSAL = 10, // depreciated since 12.1
|
||||
MSG_BUDGET_FINALIZED = 11, // depreciated since 12.1
|
||||
MSG_BUDGET_FINALIZED_VOTE = 12, // depreciated since 12.1
|
||||
MSG_MASTERNODE_QUORUM = 13, // not implemented
|
||||
MSG_MASTERNODE_ANNOUNCE = 14,
|
||||
MSG_MASTERNODE_PING = 15,
|
||||
MSG_DSTX = 16,
|
||||
MSG_GOVERNANCE_OBJECT = 17,
|
||||
MSG_GOVERNANCE_OBJECT_VOTE = 18,
|
||||
MSG_MASTERNODE_VERIFY = 19,
|
||||
};
|
||||
|
||||
/** inv message data */
|
||||
|
@ -4102,11 +4102,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;
|
||||
|
Loading…
Reference in New Issue
Block a user