Skip to content

Commit

Permalink
Factor out RecordRecvBytesPerMsgCmd()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Mar 11, 2019
1 parent 2047793 commit 48d789f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/net.cpp
Expand Up @@ -552,6 +552,17 @@ void CNode::copyStats(CNodeStats &stats)
}
#undef X

void CNode::RecordRecvBytesPerMsgCmd(const std::string& cmd, uint32_t bytes)
{
//store received bytes per message command
//to prevent a memory DOS, only allow valid commands
mapMsgCmdSize::iterator i = mapRecvBytesPerMsgCmd.find(cmd);
if (i == mapRecvBytesPerMsgCmd.end())
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
assert(i != mapRecvBytesPerMsgCmd.end());
i->second += bytes;
}

bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete)
{
complete = false;
Expand Down Expand Up @@ -583,14 +594,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
nBytes -= handled;

if (msg->Complete()) {
//store received bytes per message command
//to prevent a memory DOS, only allow valid commands
mapMsgCmdSize::iterator i = mapRecvBytesPerMsgCmd.find(msg->GetCommandName());
if (i == mapRecvBytesPerMsgCmd.end())
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
assert(i != mapRecvBytesPerMsgCmd.end());
i->second += msg->GetMessageSizeWithHeader();

RecordRecvBytesPerMsgCmd(msg->GetCommandName(), msg->GetMessageSizeWithHeader());
msg->nTime = nTimeMicros;
complete = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Expand Up @@ -711,6 +711,8 @@ class CNode
// Our address, as reported by the peer
CService addrLocal GUARDED_BY(cs_addrLocal);
mutable CCriticalSection cs_addrLocal;

void RecordRecvBytesPerMsgCmd(const std::string& cmd, uint32_t bytes);
public:

NodeId GetId() const {
Expand Down

0 comments on commit 48d789f

Please sign in to comment.