Skip to content

Commit 800ed43

Browse files
committed
Move MESSAGE_START_SIZE into CMessageHeader
Also move the enum to the top, and remove a deceptive TODO comment. Adaptation of btc@2c09a5209ab00573a2422e1e65c437a6e2f59624
1 parent 3296b9e commit 800ed43

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
19791979

19801980
msg.SetVersion(pfrom->GetRecvVersion());
19811981
// Scan for message start
1982-
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) {
1982+
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
19831983
LogPrint(BCLog::NET, "PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->GetId());
19841984
pfrom->fDisconnect = true;
19851985
return false;

src/protocol.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <stdint.h>
2222
#include <string>
2323

24-
#define MESSAGE_START_SIZE 4
25-
2624
/** Message header.
2725
* (4) message start.
2826
* (12) command.
@@ -32,6 +30,7 @@
3230
class CMessageHeader
3331
{
3432
public:
33+
static constexpr size_t MESSAGE_START_SIZE = 4;
3534
static constexpr size_t COMMAND_SIZE = 12;
3635
static constexpr size_t MESSAGE_SIZE_SIZE = 4;
3736
static constexpr size_t CHECKSUM_SIZE = 4;
@@ -52,8 +51,6 @@ class CMessageHeader
5251

5352
SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
5453

55-
// TODO: make private (improves encapsulation)
56-
public:
5754
char pchMessageStart[MESSAGE_START_SIZE];
5855
char pchCommand[COMMAND_SIZE];
5956
uint32_t nMessageSize;

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,11 +3918,11 @@ bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
39183918
unsigned int nSize = 0;
39193919
try {
39203920
// locate a header
3921-
unsigned char buf[MESSAGE_START_SIZE];
3921+
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
39223922
blkdat.FindByte(Params().MessageStart()[0]);
39233923
nRewind = blkdat.GetPos()+1;
39243924
blkdat >> buf;
3925-
if (memcmp(buf, Params().MessageStart(), MESSAGE_START_SIZE))
3925+
if (memcmp(buf, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE))
39263926
continue;
39273927
// read size
39283928
blkdat >> nSize;

0 commit comments

Comments
 (0)