Skip to content

Commit ffd4859

Browse files
theuniFuzzbawls
authored andcommitted
net: handle message accounting in ReceiveMsgBytes
This allows locking to be pushed down to only where it's needed Also reuse the current time rather than checking multiple times.
1 parent 8cee696 commit ffd4859

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/net.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ void CNode::copyStats(CNodeStats& stats)
708708
bool CNode::ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete)
709709
{
710710
complete = false;
711+
int64_t nTimeMicros = GetTimeMicros();
712+
nLastRecv = nTimeMicros / 1000000;
713+
nRecvBytes += nBytes;
711714
while (nBytes > 0) {
712715
// get current incomplete message, or create a new one
713716
if (vRecvMsg.empty() ||
@@ -744,7 +747,7 @@ bool CNode::ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete
744747
assert(i != mapRecvBytesPerMsgCmd.end());
745748
i->second += msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE;
746749

747-
msg.nTime = GetTimeMicros();
750+
msg.nTime = nTimeMicros;
748751
complete = true;
749752
}
750753
}
@@ -1242,8 +1245,6 @@ void CConnman::ThreadSocketHandler()
12421245
pnode->CloseSocketDisconnect();
12431246
if(notify)
12441247
condMsgProc.notify_one();
1245-
pnode->nLastRecv = GetTime();
1246-
pnode->nRecvBytes += nBytes;
12471248
RecordBytesRecv(nBytes);
12481249
} else if (nBytes == 0) {
12491250
// socket closed gracefully

0 commit comments

Comments
 (0)