| 519 | #undef X |
| 520 | #define X(name) stats.name = name |
| 521 | void CNode::copyStats(CNodeStats &stats) |
| 522 | { |
| 523 | stats.nodeid = this->GetId(); |
| 524 | X(nServices); |
| 525 | X(nLastSend); |
| 526 | X(nLastRecv); |
| 527 | X(nTimeConnected); |
| 528 | X(nTimeOffset); |
| 529 | X(addrName); |
| 530 | X(nVersion); |
| 531 | X(cleanSubVer); |
| 532 | X(fInbound); |
| 533 | X(nStartingHeight); |
| 534 | X(nSendBytes); |
| 535 | X(nRecvBytes); |
| 536 | X(fWhitelisted); |
| 537 | |
| 538 | // It is common for nodes with good ping times to suddenly become lagged, |
| 539 | // due to a new block arriving or other large transfer. |
| 540 | // Merely reporting pingtime might fool the caller into thinking the node was still responsive, |
| 541 | // since pingtime does not update until the ping is complete, which might take a while. |
| 542 | // So, if a ping is taking an unusually long time in flight, |
| 543 | // the caller can immediately detect that this is happening. |
| 544 | int64_t nPingUsecWait = 0; |
| 545 | if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) { |
| 546 | nPingUsecWait = GetTimeMicros() - nPingUsecStart; |
| 547 | } |
| 548 | |
| 549 | // Raw ping time is in microseconds, but show it to user as whole seconds (Bitcoin users should be well used to small numbers with many decimal places by now :) |
| 550 | stats.dPingTime = (((double)nPingUsecTime) / 1e6); |
| 551 | stats.dPingWait = (((double)nPingUsecWait) / 1e6); |
| 552 | |
| 553 | // Leave string empty if addrLocal invalid (not filled in yet) |
| 554 | stats.addrLocal = addrLocal.IsValid() ? addrLocal.ToString() : ""; |
| 555 | } |
| 556 | #undef X |
| 557 | |
| 558 | // requires LOCK(cs_vRecvMsg) |
no test coverage detected