Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to new network message #244

Merged
merged 6 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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