mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge pull request #5151
eec3713
make CMessageHeader a dumb storage class (Cory Fields)
This commit is contained in:
commit
2f10aa0fa1
@ -14,8 +14,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
|
||||
|
||||
struct CDNSSeedData {
|
||||
std::string name, host;
|
||||
CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
|
||||
@ -42,7 +40,7 @@ public:
|
||||
};
|
||||
|
||||
const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
|
||||
const MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
|
||||
int GetDefaultPort() const { return nDefaultPort; }
|
||||
const arith_uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
|
||||
@ -83,7 +81,7 @@ protected:
|
||||
CChainParams() {}
|
||||
|
||||
uint256 hashGenesisBlock;
|
||||
MessageStartChars pchMessageStart;
|
||||
CMessageHeader::MessageStartChars pchMessageStart;
|
||||
//! Raw pub key bytes for the broadcast alert signing key.
|
||||
std::vector<unsigned char> vAlertPubKey;
|
||||
int nDefaultPort;
|
||||
|
@ -4305,7 +4305,7 @@ bool ProcessMessages(CNode* pfrom)
|
||||
|
||||
// Read header
|
||||
CMessageHeader& hdr = msg.hdr;
|
||||
if (!hdr.IsValid())
|
||||
if (!hdr.IsValid(Params().MessageStart()))
|
||||
{
|
||||
LogPrintf("PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->id);
|
||||
continue;
|
||||
|
@ -510,7 +510,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
|
||||
// get current incomplete message, or create a new one
|
||||
if (vRecvMsg.empty() ||
|
||||
vRecvMsg.back().complete())
|
||||
vRecvMsg.push_back(CNetMessage(SER_NETWORK, nRecvVersion));
|
||||
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, nRecvVersion));
|
||||
|
||||
CNetMessage& msg = vRecvMsg.back();
|
||||
|
||||
@ -1976,7 +1976,7 @@ void CNode::BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSen
|
||||
{
|
||||
ENTER_CRITICAL_SECTION(cs_vSend);
|
||||
assert(ssSend.size() == 0);
|
||||
ssSend << CMessageHeader(pszCommand, 0);
|
||||
ssSend << CMessageHeader(Params().MessageStart(), pszCommand, 0);
|
||||
LogPrint("net", "sending: %s ", SanitizeString(pszCommand));
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ public:
|
||||
|
||||
int64_t nTime; // time (in microseconds) of message receipt.
|
||||
|
||||
CNetMessage(int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) {
|
||||
CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
|
||||
hdrbuf.resize(24);
|
||||
in_data = false;
|
||||
nHdrPos = 0;
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "protocol.h"
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
@ -21,17 +20,17 @@ static const char* ppszTypeName[] =
|
||||
"filtered block"
|
||||
};
|
||||
|
||||
CMessageHeader::CMessageHeader()
|
||||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn)
|
||||
{
|
||||
memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE);
|
||||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
|
||||
memset(pchCommand, 0, sizeof(pchCommand));
|
||||
nMessageSize = -1;
|
||||
nChecksum = 0;
|
||||
}
|
||||
|
||||
CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)
|
||||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
||||
{
|
||||
memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE);
|
||||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
|
||||
memset(pchCommand, 0, sizeof(pchCommand));
|
||||
strncpy(pchCommand, pszCommand, COMMAND_SIZE);
|
||||
nMessageSize = nMessageSizeIn;
|
||||
@ -43,10 +42,10 @@ std::string CMessageHeader::GetCommand() const
|
||||
return std::string(pchCommand, pchCommand + strnlen(pchCommand, COMMAND_SIZE));
|
||||
}
|
||||
|
||||
bool CMessageHeader::IsValid() const
|
||||
bool CMessageHeader::IsValid(const MessageStartChars& pchMessageStartIn) const
|
||||
{
|
||||
// Check start string
|
||||
if (memcmp(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0)
|
||||
if (memcmp(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE) != 0)
|
||||
return false;
|
||||
|
||||
// Check the command string for errors
|
||||
|
@ -29,11 +29,13 @@
|
||||
class CMessageHeader
|
||||
{
|
||||
public:
|
||||
CMessageHeader();
|
||||
CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
|
||||
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
|
||||
|
||||
CMessageHeader(const MessageStartChars& pchMessageStartIn);
|
||||
CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
|
||||
|
||||
std::string GetCommand() const;
|
||||
bool IsValid() const;
|
||||
bool IsValid(const MessageStartChars& messageStart) const;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user