Skip to content

Commit 444f599

Browse files
committed
Dont deserialize nVersion into CNode
1 parent f30f10e commit 444f599

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,7 +5289,8 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
52895289
CAddress addrFrom;
52905290
uint64_t nNonce = 1;
52915291
uint64_t nServiceInt;
5292-
vRecv >> pfrom->nVersion >> nServiceInt >> nTime >> addrMe;
5292+
int nVersion;
5293+
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
52935294
pfrom->nServices = ServiceFlags(nServiceInt);
52945295
if (!pfrom->fInbound) {
52955296
connman.SetServices(pfrom->addr, pfrom->nServices);
@@ -5302,11 +5303,11 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
53025303
return false;
53035304
}
53045305

5305-
if (pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand))
5306+
if (pfrom->DisconnectOldProtocol(nVersion, ActiveProtocol(), strCommand))
53065307
return false;
53075308

5308-
if (pfrom->nVersion == 10300)
5309-
pfrom->nVersion = 300;
5309+
if (nVersion == 10300)
5310+
nVersion = 300;
53105311
if (!vRecv.empty())
53115312
vRecv >> addrFrom >> nNonce;
53125313
if (!vRecv.empty()) {
@@ -5360,7 +5361,8 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
53605361
}
53615362
// Change version
53625363
connman.PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERACK));
5363-
int nSendVersion = std::min(pfrom->nVersion, PROTOCOL_VERSION);
5364+
int nSendVersion = std::min(nVersion, PROTOCOL_VERSION);
5365+
pfrom->nVersion = nVersion;
53645366
pfrom->SetSendVersion(nSendVersion);
53655367

53665368
if (!pfrom->fInbound) {
@@ -5854,7 +5856,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
58545856
}
58555857
}
58565858
//disconnect this node if its old protocol version
5857-
pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand);
5859+
pfrom->DisconnectOldProtocol(pfrom->nVersion, ActiveProtocol(), strCommand);
58585860
} else {
58595861
LogPrint(BCLog::NET, "%s : Already processed block %s, skipping ProcessNewBlock()\n", __func__, block.GetHash().GetHex());
58605862
}

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ void CNode::CloseSocketDisconnect()
466466
}
467467
}
468468

469-
bool CNode::DisconnectOldProtocol(int nVersionRequired, std::string strLastCommand)
469+
bool CNode::DisconnectOldProtocol(int nVersionIn, int nVersionRequired, std::string strLastCommand)
470470
{
471471
fDisconnect = false;
472-
if (nVersion < nVersionRequired) {
473-
LogPrintf("%s : peer=%d using obsolete version %i; disconnecting\n", __func__, id, nVersion);
472+
if (nVersionIn < nVersionRequired) {
473+
LogPrintf("%s : peer=%d using obsolete version %i; disconnecting\n", __func__, id, nVersionIn);
474474
g_connman->PushMessage(this, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strLastCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", ActiveProtocol())));
475475
fDisconnect = true;
476476
}

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ class CNode
813813
void Subscribe(unsigned int nChannel, unsigned int nHops = 0);
814814
void CancelSubscribe(unsigned int nChannel);
815815
void CloseSocketDisconnect();
816-
bool DisconnectOldProtocol(int nVersionRequired, std::string strLastCommand = "");
816+
bool DisconnectOldProtocol(int nVersionIn, int nVersionRequired, std::string strLastCommand = "");
817817

818818
void copyStats(CNodeStats& stats);
819819

0 commit comments

Comments
 (0)