Skip to content

Commit

Permalink
net: Add missing locks in net.{cpp,h}
Browse files Browse the repository at this point in the history
* writing variable 'nTotalBytesRecv' requires holding mutex 'cs_totalBytesRecv' exclusively
* writing variables 'nTotalBytesSent' require holding mutex 'cs_totalBytesSent' exclusively
* writing variable 'vAddedNodes' requires holding mutex 'cs_vAddedNodes' exclusively

Backports btc@63f21d27ee463dafc32982d1ac50a1032449dd36 without the nMaxOut* variable changes that we don't have.
  • Loading branch information
furszy committed Nov 26, 2021
1 parent 8c02b59 commit 5716940
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,8 +1966,14 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
{
Init(connOptions);

nTotalBytesRecv = 0;
nTotalBytesSent = 0;
{
LOCK(cs_totalBytesRecv);
nTotalBytesRecv = 0;
}
{
LOCK(cs_totalBytesSent);
nTotalBytesSent = 0;
}

if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
if (clientInterface) {
Expand Down
5 changes: 4 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ class CConnman
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize;
vWhitelistedRange = connOptions.vWhitelistedRange;
vAddedNodes = connOptions.m_added_nodes;
{
LOCK(cs_vAddedNodes);
vAddedNodes = connOptions.m_added_nodes;
}
}

CConnman(uint64_t seed0, uint64_t seed1);
Expand Down

0 comments on commit 5716940

Please sign in to comment.