| 2992 | } |
| 2993 | |
| 2994 | bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgProc) |
| 2995 | { |
| 2996 | const CChainParams& chainparams = Params(); |
| 2997 | // |
| 2998 | // Message format |
| 2999 | // (4) message start |
| 3000 | // (12) command |
| 3001 | // (4) size |
| 3002 | // (4) checksum |
| 3003 | // (x) data |
| 3004 | // |
| 3005 | bool fMoreWork = false; |
| 3006 | |
| 3007 | if (!pfrom->vRecvGetData.empty()) |
| 3008 | ProcessGetData(pfrom, chainparams, connman, interruptMsgProc); |
| 3009 | |
| 3010 | if (pfrom->fDisconnect) |
| 3011 | return false; |
| 3012 | |
| 3013 | // this maintains the order of responses |
| 3014 | if (!pfrom->vRecvGetData.empty()) return true; |
| 3015 | |
| 3016 | // Don't bother if send buffer is too full to respond anyway |
| 3017 | if (pfrom->fPauseSend) |
| 3018 | return false; |
| 3019 | |
| 3020 | std::list<CNetMessage> msgs; |
| 3021 | { |
| 3022 | LOCK(pfrom->cs_vProcessMsg); |
| 3023 | if (pfrom->vProcessMsg.empty()) |
| 3024 | return false; |
| 3025 | // Just take one message |
| 3026 | msgs.splice(msgs.begin(), pfrom->vProcessMsg, pfrom->vProcessMsg.begin()); |
| 3027 | pfrom->nProcessQueueSize -= msgs.front().vRecv.size() + CMessageHeader::HEADER_SIZE; |
| 3028 | pfrom->fPauseRecv = pfrom->nProcessQueueSize > connman->GetReceiveFloodSize(); |
| 3029 | fMoreWork = !pfrom->vProcessMsg.empty(); |
| 3030 | } |
| 3031 | CNetMessage& msg(msgs.front()); |
| 3032 | |
| 3033 | msg.SetVersion(pfrom->GetRecvVersion()); |
| 3034 | // Scan for message start |
| 3035 | if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { |
| 3036 | LogPrint(BCLog::NET, "PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->GetId()); |
| 3037 | pfrom->fDisconnect = true; |
| 3038 | return false; |
| 3039 | } |
| 3040 | |
| 3041 | // Read header |
| 3042 | CMessageHeader& hdr = msg.hdr; |
| 3043 | if (!hdr.IsValid(chainparams.MessageStart())) |
| 3044 | { |
| 3045 | LogPrint(BCLog::NET, "PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->GetId()); |
| 3046 | return fMoreWork; |
| 3047 | } |
| 3048 | std::string strCommand = hdr.GetCommand(); |
| 3049 | |
| 3050 | // Message size |
| 3051 | unsigned int nMessageSize = hdr.nMessageSize; |
no test coverage detected