diff --git a/src/main.cpp b/src/main.cpp index 35d73595ab..e64b3cfb4e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -6596,7 +6596,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(50); - printf("\r\n **Hacker tried to send inventory > MAX_INV_SZ **\r\n"); return error("message inv size() = %" PRIszu "", vInv.size()); } @@ -6608,6 +6607,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, break; } } + + LOCK(cs_main); CTxDB txdb("r"); for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { @@ -6655,6 +6656,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (fDebug10) printf("received getdata (%" PRIszu " invsz)\n", vInv.size()); } + LOCK(cs_main); for (auto const& inv : vInv) { if (fShutdown) @@ -6723,6 +6725,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, uint256 hashStop; vRecv >> locator >> hashStop; + LOCK(cs_main); + // Find the last block the caller has in the main chain CBlockIndex* pindex = locator.GetBlockIndex(); @@ -6760,6 +6764,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, uint256 hashStop; vRecv >> locator >> hashStop; + LOCK(cs_main); + CBlockIndex* pindex = NULL; if (locator.IsNull()) { @@ -6798,6 +6804,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CInv inv(MSG_TX, tx.GetHash()); pfrom->AddInventoryKnown(inv); + LOCK(cs_main); + bool fMissingInputs = false; if (AcceptToMemoryPool(mempool, tx, &fMissingInputs)) { @@ -6876,6 +6884,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CInv inv(MSG_BLOCK, hashBlock); pfrom->AddInventoryKnown(inv); + LOCK(cs_main); + if (ProcessBlock(pfrom, &block, false)) { mapAlreadyAskedFor.erase(inv); @@ -6904,6 +6914,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (strCommand == "mempool") { + LOCK(cs_main); + std::vector vtxid; mempool.queryHashes(vtxid); vector vInv; @@ -7196,13 +7208,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // requires LOCK(cs_vRecvMsg) bool ProcessMessages(CNode* pfrom) -{ - LOCK(cs_main); - - TRY_LOCK(pfrom->cs_vRecvMsg, lockRecv); - if (!lockRecv) - return true; - +{ // // Message format // (4) message start @@ -7270,7 +7276,7 @@ bool ProcessMessages(CNode* pfrom) bool fRet = false; try { - fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime); + fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime); if (fShutdown) break; } @@ -7955,10 +7961,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if(!lockMain) return true; - TRY_LOCK(pto->cs_vSend, lockSend); - if (!lockSend) - return true; - // Don't send anything until we get their version message if (pto->nVersion == 0) return true; diff --git a/src/net.cpp b/src/net.cpp index 6c0a7e8334..fe65502903 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1984,14 +1984,23 @@ void ThreadMessageHandler2(void* parg) //11-25-2015 // Receive messages - if (!ProcessMessages(pnode)) - pnode->CloseSocketDisconnect(); + { + TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); + if (lockRecv) + if (!ProcessMessages(pnode)) + pnode->CloseSocketDisconnect(); + } if (fShutdown) return; // Send messages - SendMessages(pnode, pnode == pnodeTrickle); + { + TRY_LOCK(pnode->cs_vSend, lockSend); + if (lockSend) + SendMessages(pnode, pnode == pnodeTrickle); + } + if (fShutdown) return; }