Skip to content

Commit

Permalink
Use new network message (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Fieroni <[email protected]>

Co-authored-by: Ahmed Hilali <[email protected]>
  • Loading branch information
bvbfan and monstrobishi authored Mar 11, 2021
1 parent 52e0ee1 commit 9bd1cc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,21 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
// get current incomplete message, or create a new one
if (vRecvMsg.empty() ||
vRecvMsg.back().complete())
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION));
vRecvMsg.push_back(CNetMessage(Params().MessageStartPostAMK(), SER_NETWORK, INIT_PROTO_VERSION));

CNetMessage& msg = vRecvMsg.back();

// absorb network data
int handled;
if (!msg.in_data)
if (!msg.in_data) {
handled = msg.readHeader(pch, nBytes);
else
// NOTE: for compatibility with current working nodes, remove after Dakota
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE) == 0) {
memcpy(msg.hdr.pchMessageStart, Params().MessageStartPostAMK(), CMessageHeader::MESSAGE_START_SIZE);
}
} else {
handled = msg.readData(pch, nBytes);
}

if (handled < 0)
return false;
Expand Down Expand Up @@ -2668,7 +2673,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
std::vector<unsigned char> serializedHeader;
serializedHeader.reserve(CMessageHeader::HEADER_SIZE);
uint256 hash = Hash(msg.data.data(), msg.data.data() + nMessageSize);
CMessageHeader hdr(Params().MessageStart(), msg.command.c_str(), nMessageSize);
CMessageHeader hdr(Params().MessageStartPostAMK(), msg.command.c_str(), nMessageSize);
memcpy(hdr.pchChecksum, hash.begin(), CMessageHeader::CHECKSUM_SIZE);

CVectorWriter{SER_NETWORK, INIT_PROTO_VERSION, serializedHeader, 0, hdr};
Expand Down
6 changes: 2 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3512,17 +3512,15 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter

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

// Read header
CMessageHeader& hdr = msg.hdr;
if (!hdr.IsValid(chainparams.MessageStart()) && !hdr.IsValid(chainparams.MessageStartPostAMK()))
{
if (!hdr.IsValid(chainparams.MessageStartPostAMK())) {
LogPrint(BCLog::NET, "PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->GetId());
return fMoreWork;
}
Expand Down

0 comments on commit 9bd1cc5

Please sign in to comment.