X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fnet.cpp;h=f5ef026cdf82fa3274ef37672eb9b91c34351b62;hp=cd895678381d491c66a32e0577d9434132abc290;hb=22f4288ff023d68e40acc466875fad511dcdeae0;hpb=99486c73c0a40b9cee59f9525014dcf253089d44 diff --git a/src/net.cpp b/src/net.cpp index cd89567..f5ef026 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -12,6 +12,7 @@ #include "main.h" #include "miner.h" #include "ntp.h" +#include "random.h" #ifdef WIN32 #include @@ -79,6 +80,16 @@ CCriticalSection cs_vAddedNodes; static CSemaphore *semOutbound = NULL; +inline void RelayInventory(const CInv& inv) +{ + // Put on lists to offer to the other nodes + { + LOCK(cs_vNodes); + for (CNode* pnode : vNodes) + pnode->PushInventory(inv); + } +} + void AddOneShot(string strDest) { LOCK(cs_vOneShots); @@ -503,6 +514,39 @@ void CNode::Cleanup() { } +void CNode::EndMessage() +{ + if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) + { + printf("dropmessages DROPPING SEND MESSAGE\n"); + AbortMessage(); + return; + } + + if (nHeaderStart < 0) { + LEAVE_CRITICAL_SECTION(cs_vSend); + return; + } + + // Set the size + uint32_t nSize = (uint32_t) vSend.size() - nMessageStart; + memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize)); + + // Set the checksum + uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end()); + uint32_t nChecksum = 0; + memcpy(&nChecksum, &hash, sizeof(nChecksum)); + assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); + memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum)); + + if (fDebug) { + printf("(%d bytes)\n", nSize); + } + + nHeaderStart = -1; + nMessageStart = std::numeric_limits::max(); + LEAVE_CRITICAL_SECTION(cs_vSend); +} void CNode::PushVersion() {