X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=c41f43ad3b963d6f422ff109cfb62737bbabdf55;hp=1668679134e0f6fbdcefb0e19111dc345150cbf8;hb=8e064484abe4d65e15e3ec1bcdbb2b91f97dd726;hpb=866895525a0bf940795f827629727d2b2320260b diff --git a/src/main.cpp b/src/main.cpp index 1668679..c41f43a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,6 @@ int64_t nMinimumInputValue = MIN_TXOUT_AMOUNT; // Ping and address broadcast intervals int64_t nPingInterval = 30 * 60; -int64_t nBroadcastInterval = nOneDay; extern enum Checkpoints::CPMode CheckpointsMode; @@ -2508,7 +2507,7 @@ bool static ReserealizeBlockSignature(CBlock* pblock) return true; } - return CKey::ReserealizeSignature(pblock->vchBlockSig); + return CPubKey::ReserealizeSignature(pblock->vchBlockSig); } bool static IsCanonicalBlockSignature(CBlock* pblock) @@ -2667,8 +2666,8 @@ bool CBlock::CheckBlockSignature() const if (whichType == TX_PUBKEY) { valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!key.SetPubKey(vchPubKey)) + CPubKey key(vchPubKey); + if (!key.IsValid()) return false; return key.Verify(GetHash(), vchBlockSig); } @@ -2723,7 +2722,7 @@ static unsigned int nCurrentBlockFile = 1; FILE* AppendBlockFile(unsigned int& nFileRet) { nFileRet = 0; - while (true) + for ( ; ; ) { FILE* file = OpenBlockFile(nCurrentBlockFile, 0, "ab"); if (!file) @@ -2974,7 +2973,7 @@ bool LoadExternalBlockFile(FILE* fileIn) unsigned char pchData[65536]; do { fseek(blkdat, nPos, SEEK_SET); - int nRead = fread(pchData, 1, sizeof(pchData), blkdat); + size_t nRead = fread(pchData, 1, sizeof(pchData), blkdat); if (nRead <= 8) { nPos = std::numeric_limits::max(); @@ -3037,7 +3036,7 @@ string GetWarnings(string strFor) strRPC = "test"; // Misc warnings like out of disk space and clock is wrong - if (strMiscWarning != "") + if (!strMiscWarning.empty()) { nPriority = 1000; strStatusBar = strMiscWarning; @@ -3362,15 +3361,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } // find last block in inv vector - unsigned int nLastBlock = std::numeric_limits::max(); - for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { + size_t nLastBlock = std::numeric_limits::max(); + for (size_t nInv = 0; nInv < vInv.size(); nInv++) { if (vInv[vInv.size() - 1 - nInv].type == MSG_BLOCK) { nLastBlock = vInv.size() - 1 - nInv; break; } } CTxDB txdb("r"); - for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) + for (size_t nInv = 0; nInv < vInv.size(); nInv++) { const CInv &inv = vInv[nInv]; @@ -3808,7 +3807,7 @@ bool ProcessMessages(CNode* pfrom) // (x) data // - while (true) + for ( ; ; ) { // Don't bother if send buffer is too full to respond anyway if (pfrom->vSend.size() >= SendBufferSize()) @@ -3917,6 +3916,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle) { TRY_LOCK(cs_main, lockMain); if (lockMain) { + // Current time in microseconds + int64_t nNow = GetTimeMicros(); + // Don't send anything until we get their version message if (pto->nVersion == 0) return true; @@ -3938,39 +3940,20 @@ bool SendMessages(CNode* pto, bool fSendTrickle) ResendWalletTransactions(); // Address refresh broadcast - static int64_t nLastRebroadcast; - if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > nBroadcastInterval)) - { - { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - // Periodically clear setAddrKnown to allow refresh broadcasts - if (nLastRebroadcast) - pnode->setAddrKnown.clear(); - - // Rebroadcast our address - if (!fNoListen) - { - CAddress addr = GetLocalAddress(&pnode->addr); - if (addr.IsRoutable()) - pnode->PushAddress(addr); - } - } - } - nLastRebroadcast = GetTime(); + if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) { + AdvertiseLocal(pto); + pto->nNextLocalAddrSend = PoissonNextSend(nNow, nOneDay); } // // Message: addr // - if (fSendTrickle) - { + if (pto->nNextAddrSend < nNow) { + pto->nNextAddrSend = PoissonNextSend(nNow, 30); vector vAddr; vAddr.reserve(pto->vAddrToSend.size()); BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) { - // returns true if wasn't already contained in the set if (pto->setAddrKnown.insert(addr).second) { vAddr.push_back(addr); @@ -3987,13 +3970,17 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->PushMessage("addr", vAddr); } - // // Message: inventory // vector vInv; vector vInvWait; { + bool fSendTrickle = false; + if (pto->nNextInvSend < nNow) { + fSendTrickle = true; + pto->nNextInvSend = PoissonNextSend(nNow, 5); + } LOCK(pto->cs_inventory); vInv.reserve(pto->vInventoryToSend.size()); vInvWait.reserve(pto->vInventoryToSend.size()); @@ -4013,15 +4000,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle) hashRand = Hash(BEGIN(hashRand), END(hashRand)); bool fTrickleWait = ((hashRand & 3) != 0); - // always trickle our own transactions - if (!fTrickleWait) - { - CWalletTx wtx; - if (GetTransaction(inv.hash, wtx)) - if (wtx.fFromMe) - fTrickleWait = true; - } - if (fTrickleWait) { vInvWait.push_back(inv); @@ -4050,7 +4028,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Message: getdata // vector vGetData; - int64_t nNow = GetTime() * 1000000; CTxDB txdb("r"); while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) {