mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
protocol.h: Move MESSAGE_START_SIZE into CMessageHeader
Also move the enum to the top, and remove a deceptive TODO comment.
This commit is contained in:
parent
f9bd92d235
commit
2c09a5209a
2 changed files with 13 additions and 16 deletions
|
@ -4358,11 +4358,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;
|
||||||
|
@ -6232,7 +6232,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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue