| 346 | } |
| 347 | |
| 348 | void ProcessPongMessage(CNode *pFrom, CDataStream &vRecv) { |
| 349 | int64_t pingUsecEnd = GetTimeMicros(); |
| 350 | uint64_t nonce = 0; |
| 351 | size_t nAvail = vRecv.in_avail(); |
| 352 | bool bPingFinished = false; |
| 353 | string sProblem; |
| 354 | |
| 355 | if (nAvail >= sizeof(nonce)) { |
| 356 | vRecv >> nonce; |
| 357 | |
| 358 | // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) |
| 359 | if (pFrom->nPingNonceSent != 0) { |
| 360 | if (nonce == pFrom->nPingNonceSent) { |
| 361 | // Matching pong received, this ping is no longer outstanding |
| 362 | bPingFinished = true; |
| 363 | int64_t pingUsecTime = pingUsecEnd - pFrom->nPingUsecStart; |
| 364 | if (pingUsecTime > 0) { |
| 365 | // Successful ping time measurement, replace previous |
| 366 | pFrom->nPingUsecTime = pingUsecTime; |
| 367 | } else { |
| 368 | // This should never happen |
| 369 | sProblem = "Timing mishap"; |
| 370 | } |
| 371 | } else { |
| 372 | // Nonce mismatches are normal when pings are overlapping |
| 373 | sProblem = "Nonce mismatch"; |
| 374 | if (nonce == 0) { |
| 375 | // This is most likely a bug in another implementation somewhere, cancel this ping |
| 376 | bPingFinished = true; |
| 377 | sProblem = "Nonce zero"; |
| 378 | } |
| 379 | } |
| 380 | } else { |
| 381 | sProblem = "Unsolicited pong without ping"; |
| 382 | } |
| 383 | } else { |
| 384 | // This is most likely a bug in another implementation somewhere, cancel this ping |
| 385 | bPingFinished = true; |
| 386 | sProblem = "Short payload"; |
| 387 | } |
| 388 | |
| 389 | if (!(sProblem.empty())) { |
| 390 | LogPrint(BCLog::NET, "pong %s %s: %s, %x expected, %x received, %u bytes\n", pFrom->addr.ToString(), |
| 391 | pFrom->cleanSubVer, sProblem, pFrom->nPingNonceSent, nonce, nAvail); |
| 392 | } |
| 393 | |
| 394 | if (bPingFinished) { |
| 395 | pFrom->nPingNonceSent = 0; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | bool ProcessAddrMessage(CNode *pFrom, CDataStream &vRecv) { |
| 400 | vector<CAddress> vAddr; |
no test coverage detected