Skip to content

Commit 9f4da19

Browse files
committed
Use pong receive time rather than processing time
1 parent dd49e92 commit 9f4da19

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ void static ProcessGetData(CNode* pfrom)
35443544
}
35453545
}
35463546

3547-
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
3547+
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived)
35483548
{
35493549
RandAddSeedPerfmon();
35503550
LogPrint("net", "received: %s (%u bytes)\n", strCommand, vRecv.size());
@@ -4054,7 +4054,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
40544054

40554055
else if (strCommand == "pong")
40564056
{
4057-
int64_t pingUsecEnd = GetTimeMicros();
4057+
int64_t pingUsecEnd = nTimeReceived;
40584058
uint64_t nonce = 0;
40594059
size_t nAvail = vRecv.in_avail();
40604060
bool bPingFinished = false;
@@ -4305,7 +4305,7 @@ bool ProcessMessages(CNode* pfrom)
43054305
bool fRet = false;
43064306
try
43074307
{
4308-
fRet = ProcessMessage(pfrom, strCommand, vRecv);
4308+
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime);
43094309
boost::this_thread::interruption_point();
43104310
}
43114311
catch (std::ios_base::failure& e)

src/net.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
653653

654654
pch += handled;
655655
nBytes -= handled;
656+
657+
if (msg.complete())
658+
msg.nTime = GetTimeMicros();
656659
}
657660

658661
return true;

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,14 @@ class CNetMessage {
173173
CDataStream vRecv; // received message data
174174
unsigned int nDataPos;
175175

176+
int64_t nTime; // time (in microseconds) of message receipt.
177+
176178
CNetMessage(int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) {
177179
hdrbuf.resize(24);
178180
in_data = false;
179181
nHdrPos = 0;
180182
nDataPos = 0;
183+
nTime = 0;
181184
}
182185

183186
bool complete() const

0 commit comments

Comments
 (0)