requires LOCK(cs_vRecvMsg)
| 7237 | |
| 7238 | // requires LOCK(cs_vRecvMsg) |
| 7239 | bool ProcessMessages(CNode* pfrom) |
| 7240 | { |
| 7241 | const CChainParams& chainparams = Params(); |
| 7242 | //if (fDebug) |
| 7243 | // LogPrintf("ProcessMessages(%u messages)\n", pfrom->vRecvMsg.size()); |
| 7244 | |
| 7245 | // |
| 7246 | // Message format |
| 7247 | // (4) message start |
| 7248 | // (12) command |
| 7249 | // (4) size |
| 7250 | // (4) checksum |
| 7251 | // (x) data |
| 7252 | // |
| 7253 | bool fOk = true; |
| 7254 | |
| 7255 | if (!pfrom->vRecvGetData.empty()) |
| 7256 | ProcessGetData(pfrom, chainparams.GetConsensus()); |
| 7257 | |
| 7258 | // this maintains the order of responses |
| 7259 | if (!pfrom->vRecvGetData.empty()) return fOk; |
| 7260 | |
| 7261 | std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin(); |
| 7262 | while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { |
| 7263 | // Don't bother if send buffer is too full to respond anyway |
| 7264 | if (pfrom->nSendSize >= SendBufferSize()) |
| 7265 | break; |
| 7266 | |
| 7267 | // get next message |
| 7268 | CNetMessage& msg = *it; |
| 7269 | |
| 7270 | //if (fDebug) |
| 7271 | // LogPrintf("ProcessMessages(message %u msgsz, %u bytes, complete:%s)\n", |
| 7272 | // msg.hdr.nMessageSize, msg.vRecv.size(), |
| 7273 | // msg.complete() ? "Y" : "N"); |
| 7274 | |
| 7275 | // end, if an incomplete message is found |
| 7276 | if (!msg.complete()) |
| 7277 | break; |
| 7278 | |
| 7279 | // at this point, any failure means we can delete the current message |
| 7280 | it++; |
| 7281 | |
| 7282 | // Scan for message start |
| 7283 | if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), MESSAGE_START_SIZE) != 0) { |
| 7284 | LogPrint("net", "%s: INVALID MESSAGESTART %s peer=%d\n", __func__, SanitizeString(msg.hdr.GetCommand()), pfrom->id); |
| 7285 | fOk = false; |
| 7286 | break; |
| 7287 | } |
| 7288 | |
| 7289 | // Read header |
| 7290 | CMessageHeader& hdr = msg.hdr; |
| 7291 | if (!hdr.IsValid()) { |
| 7292 | LogPrint("net", "%s: ERRORS IN HEADER %s peer=%d\n", __func__, SanitizeString(hdr.GetCommand()), pfrom->id); |
| 7293 | continue; |
| 7294 | } |
| 7295 | string strCommand = hdr.GetCommand(); |
| 7296 |
nothing calls this directly
no test coverage detected