pull/2/merge
Gavin Andresen 13 years ago
commit e7e6ae2104

@ -2103,18 +2103,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CAddress addrFrom; CAddress addrFrom;
uint64 nNonce = 1; uint64 nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < 209)
{
// Since Februari 20, 2012, the protocol is initiated at version 209,
// and earlier versions are no longer supported
printf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion);
pfrom->fDisconnect = true;
return false;
}
if (pfrom->nVersion == 10300) if (pfrom->nVersion == 10300)
pfrom->nVersion = 300; pfrom->nVersion = 300;
if (pfrom->nVersion >= 106 && !vRecv.empty()) if (!vRecv.empty())
vRecv >> addrFrom >> nNonce; vRecv >> addrFrom >> nNonce;
if (pfrom->nVersion >= 106 && !vRecv.empty()) if (!vRecv.empty())
vRecv >> pfrom->strSubVer; vRecv >> pfrom->strSubVer;
if (pfrom->nVersion >= 209 && !vRecv.empty()) if (!vRecv.empty())
vRecv >> pfrom->nStartingHeight; vRecv >> pfrom->nStartingHeight;
if (pfrom->nVersion == 0)
return false;
// Disconnect if we connected to ourself // Disconnect if we connected to ourself
if (nNonce == nLocalHostNonce && nNonce > 1) if (nNonce == nLocalHostNonce && nNonce > 1)
{ {
@ -2132,11 +2138,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
AddTimeData(pfrom->addr, nTime); AddTimeData(pfrom->addr, nTime);
// Change version // Change version
if (pfrom->nVersion >= 209)
pfrom->PushMessage("verack"); pfrom->PushMessage("verack");
pfrom->vSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); pfrom->vSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
if (pfrom->nVersion < 209)
pfrom->vRecv.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
if (!pfrom->fInbound) if (!pfrom->fInbound)
{ {
@ -2200,8 +2203,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vRecv >> vAddr; vRecv >> vAddr;
// Don't want addr from older versions unless seeding // Don't want addr from older versions unless seeding
if (pfrom->nVersion < 209)
return true;
if (pfrom->nVersion < 31402 && mapAddresses.size() > 1000) if (pfrom->nVersion < 31402 && mapAddresses.size() > 1000)
return true; return true;
if (vAddr.size() > 1000) if (vAddr.size() > 1000)
@ -2663,8 +2664,6 @@ bool ProcessMessages(CNode* pfrom)
} }
// Checksum // Checksum
if (vRecv.GetVersion() >= 209)
{
uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize); uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize);
unsigned int nChecksum = 0; unsigned int nChecksum = 0;
memcpy(&nChecksum, &hash, sizeof(nChecksum)); memcpy(&nChecksum, &hash, sizeof(nChecksum));
@ -2674,7 +2673,6 @@ bool ProcessMessages(CNode* pfrom)
strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum); strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum);
continue; continue;
} }
}
// Copy message to its own buffer // Copy message to its own buffer
CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion); CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion);

@ -167,15 +167,9 @@ public:
nServices = 0; nServices = 0;
hSocket = hSocketIn; hSocket = hSocketIn;
vSend.SetType(SER_NETWORK); vSend.SetType(SER_NETWORK);
vSend.SetVersion(0);
vRecv.SetType(SER_NETWORK); vRecv.SetType(SER_NETWORK);
vRecv.SetVersion(0);
// Version 0.2 obsoletes 20 Feb 2012
if (GetTime() > 1329696000)
{
vSend.SetVersion(209); vSend.SetVersion(209);
vRecv.SetVersion(209); vRecv.SetVersion(209);
}
nLastSend = 0; nLastSend = 0;
nLastRecv = 0; nLastRecv = 0;
nLastSendEmpty = GetTime(); nLastSendEmpty = GetTime();
@ -334,14 +328,11 @@ public:
memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize));
// Set the checksum // Set the checksum
if (vSend.GetVersion() >= 209)
{
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end()); uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
unsigned int nChecksum = 0; unsigned int nChecksum = 0;
memcpy(&nChecksum, &hash, sizeof(nChecksum)); memcpy(&nChecksum, &hash, sizeof(nChecksum));
assert(nMessageStart - nHeaderStart >= offsetof(CMessageHeader, nChecksum) + sizeof(nChecksum)); assert(nMessageStart - nHeaderStart >= offsetof(CMessageHeader, nChecksum) + sizeof(nChecksum));
memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum)); memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum));
}
if (fDebug) { if (fDebug) {
printf("(%d bytes)\n", nSize); printf("(%d bytes)\n", nSize);

@ -45,7 +45,6 @@ class CMessageHeader
READWRITE(FLATDATA(pchMessageStart)); READWRITE(FLATDATA(pchMessageStart));
READWRITE(FLATDATA(pchCommand)); READWRITE(FLATDATA(pchCommand));
READWRITE(nMessageSize); READWRITE(nMessageSize);
if (nVersion >= 209)
READWRITE(nChecksum); READWRITE(nChecksum);
) )

Loading…
Cancel
Save