requires LOCK(cs_vRecvMsg)
| 5834 | |
| 5835 | // requires LOCK(cs_vRecvMsg) |
| 5836 | bool ProcessMessages(CNode* pfrom) |
| 5837 | { |
| 5838 | //if (fDebug) |
| 5839 | // LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size()); |
| 5840 | |
| 5841 | // |
| 5842 | // Message format |
| 5843 | // (4) message start |
| 5844 | // (12) command |
| 5845 | // (4) size |
| 5846 | // (4) checksum |
| 5847 | // (x) data |
| 5848 | // |
| 5849 | bool fOk = true; |
| 5850 | |
| 5851 | if (!pfrom->vRecvGetData.empty()) |
| 5852 | ProcessGetData(pfrom); |
| 5853 | |
| 5854 | // this maintains the order of responses |
| 5855 | if (!pfrom->vRecvGetData.empty()) return fOk; |
| 5856 | |
| 5857 | std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin(); |
| 5858 | while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { |
| 5859 | // Don't bother if send buffer is too full to respond anyway |
| 5860 | if (pfrom->nSendSize >= SendBufferSize()) |
| 5861 | break; |
| 5862 | |
| 5863 | // get next message |
| 5864 | CNetMessage& msg = *it; |
| 5865 | |
| 5866 | //if (fDebug) |
| 5867 | // LogPrintf("%s(message %u msgsz, %u bytes, complete:%s)\n", __func__, |
| 5868 | // msg.hdr.nMessageSize, msg.vRecv.size(), |
| 5869 | // msg.complete() ? "Y" : "N"); |
| 5870 | |
| 5871 | // end, if an incomplete message is found |
| 5872 | if (!msg.complete()) |
| 5873 | break; |
| 5874 | |
| 5875 | // at this point, any failure means we can delete the current message |
| 5876 | it++; |
| 5877 | |
| 5878 | // Scan for message start |
| 5879 | if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) { |
| 5880 | LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id); |
| 5881 | fOk = false; |
| 5882 | break; |
| 5883 | } |
| 5884 | |
| 5885 | // Read header |
| 5886 | CMessageHeader& hdr = msg.hdr; |
| 5887 | if (!hdr.IsValid(Params().MessageStart())) |
| 5888 | { |
| 5889 | LogPrintf("PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->id); |
| 5890 | continue; |
| 5891 | } |
| 5892 | string strCommand = hdr.GetCommand(); |
| 5893 |
nothing calls this directly
no test coverage detected