From 7a47324c7846ab0e500b974cd1f40e4030a7c0d2 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Wed, 26 May 2010 00:05:26 +0000 Subject: better prevention of inventory relaying during initial download, message checksum between nodes with 0.2.9 or higher, optimization level up from -O0 to -O2, rpc functions: setlabel, getlabel, getaddressesbylabel, getreceivedbyaddress, getreceivedbylabel, listreceivedbyaddress, listreceivedbylabel -- version 0.2.9 --- net.h | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'net.h') diff --git a/net.h b/net.h index 1593a975a3..46344ed928 100644 --- a/net.h +++ b/net.h @@ -8,6 +8,7 @@ class CInv; class CRequestTracker; class CNode; class CBlockIndex; +extern int nBestHeight; @@ -59,7 +60,7 @@ public: char pchMessageStart[sizeof(::pchMessageStart)]; char pchCommand[COMMAND_SIZE]; unsigned int nMessageSize; - //unsigned int nChecksum; + unsigned int nChecksum; CMessageHeader() { @@ -67,7 +68,7 @@ public: memset(pchCommand, 0, sizeof(pchCommand)); pchCommand[1] = 1; nMessageSize = -1; - //nChecksum = 0; + nChecksum = 0; } CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) @@ -75,6 +76,7 @@ public: memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)); strncpy(pchCommand, pszCommand, COMMAND_SIZE); nMessageSize = nMessageSizeIn; + nChecksum = 0; } IMPLEMENT_SERIALIZE @@ -82,8 +84,8 @@ public: READWRITE(FLATDATA(pchMessageStart)); READWRITE(FLATDATA(pchCommand)); READWRITE(nMessageSize); - //if (nVersion >= 209 && GetCommand() != "version") - // READWRITE(nChecksum); + if (nVersion >= 209) + READWRITE(nChecksum); ) string GetCommand() @@ -475,6 +477,7 @@ extern CAddress addrProxy; + class CNode { public: @@ -507,6 +510,7 @@ public: uint256 hashContinue; CBlockIndex* pindexLastGetBlocksBegin; uint256 hashLastGetBlocksEnd; + int nStartingHeight; // flood vector vAddrToSend; @@ -529,7 +533,9 @@ public: nServices = 0; hSocket = hSocketIn; vSend.SetType(SER_NETWORK); + vSend.SetVersion(0); vRecv.SetType(SER_NETWORK); + vRecv.SetVersion(0); nLastSend = 0; nLastRecv = 0; nLastSendEmpty = GetTime(); @@ -548,6 +554,7 @@ public: hashContinue = 0; pindexLastGetBlocksBegin = 0; hashLastGetBlocksEnd = 0; + nStartingHeight = -1; fGetAddr = false; nNextSendTxInv = 0; vfSubscribe.assign(256, false); @@ -558,7 +565,8 @@ public: CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr); CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); - PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, string(pszSubVer)); + PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe, + nLocalHostNonce, string(pszSubVer), nBestHeight); } ~CNode() @@ -680,10 +688,20 @@ public: if (nHeaderStart == -1) return; - // Patch in the size + // Set the size unsigned int nSize = vSend.size() - nMessageStart; memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); + // Set the checksum + if (vSend.GetVersion() >= 209) + { + uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end()); + unsigned int nChecksum = 0; + memcpy(&nChecksum, &hash, sizeof(nChecksum)); + assert(nMessageStart - nHeaderStart >= offsetof(CMessageHeader, nChecksum) + sizeof(nChecksum)); + memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum)); + } + printf("(%d bytes) ", nSize); printf("\n"); -- cgit v1.2.3