Skip to content

Commit 754400e

Browse files
committed
net: set message deserialization version when it's time to deserialize
We'll soon no longer have access to vRecvMsg, and this is more intuitive anyway.
1 parent d2b8e0a commit 754400e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,6 +6108,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interru
61086108
// at this point, any failure means we can delete the current message
61096109
it++;
61106110

6111+
msg.SetVersion(pfrom->GetRecvVersion());
61116112
// Scan for message start
61126113
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) {
61136114
LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id);

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ bool CNode::ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete
709709
// get current incomplete message, or create a new one
710710
if (vRecvMsg.empty() ||
711711
vRecvMsg.back().complete())
712-
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, nRecvVersion));
712+
vRecvMsg.push_back(CNetMessage(Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION));
713713

714714
CNetMessage& msg = vRecvMsg.back();
715715

src/net.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class CNode
551551
std::list<CNetMessage> vRecvMsg;
552552
RecursiveMutex cs_vRecvMsg;
553553
uint64_t nRecvBytes;
554-
int nRecvVersion;
554+
std::atomic<int> nRecvVersion;
555555

556556
int64_t nLastSend;
557557
int64_t nLastRecv;
@@ -664,12 +664,13 @@ class CNode
664664
// requires LOCK(cs_vRecvMsg)
665665
bool ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete);
666666

667-
// requires LOCK(cs_vRecvMsg)
668667
void SetRecvVersion(int nVersionIn)
669668
{
670669
nRecvVersion = nVersionIn;
671-
for (CNetMessage& msg : vRecvMsg)
672-
msg.SetVersion(nVersionIn);
670+
}
671+
int GetRecvVersion()
672+
{
673+
return nRecvVersion;
673674
}
674675

675676
CNode* AddRef()

0 commit comments

Comments
 (0)