Browse Source

net: Add missing locks in net.{cpp,h}

* writing variable 'nTotalBytesRecv' requires holding mutex 'cs_totalBytesRecv' exclusively
* writing variables 'nTotalBytesSent'/'nMaxOutboundTotalBytesSentInCycle'/'nMaxOutboundCycleStartTime' require holding mutex 'cs_totalBytesSent' exclusively
* writing variable 'nMaxOutboundTimeframe'/'nMaxOutboundLimit' require holding mutex 'cs_totalBytesSent' exclusively
* writing variable 'vAddedNodes' requires holding mutex 'cs_vAddedNodes' exclusively
0.16
practicalswift 7 years ago
parent
commit
63f21d27ee
  1. 14
      src/net.cpp
  2. 12
      src/net.h

14
src/net.cpp

@ -2269,10 +2269,16 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions) @@ -2269,10 +2269,16 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
{
Init(connOptions);
nTotalBytesRecv = 0;
nTotalBytesSent = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundCycleStartTime = 0;
{
LOCK(cs_totalBytesRecv);
nTotalBytesRecv = 0;
}
{
LOCK(cs_totalBytesSent);
nTotalBytesSent = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundCycleStartTime = 0;
}
if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
if (clientInterface) {

12
src/net.h

@ -158,10 +158,16 @@ public: @@ -158,10 +158,16 @@ public:
m_msgproc = connOptions.m_msgproc;
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize;
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
{
LOCK(cs_totalBytesSent);
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
}
vWhitelistedRange = connOptions.vWhitelistedRange;
vAddedNodes = connOptions.m_added_nodes;
{
LOCK(cs_vAddedNodes);
vAddedNodes = connOptions.m_added_nodes;
}
}
CConnman(uint64_t seed0, uint64_t seed1);

Loading…
Cancel
Save