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

bfb0c0a Add Clang thread safety analysis annotations (practicalswift)
63f21d2 net: Add missing locks in net.{cpp,h} (practicalswift)

Pull request description:

  Add missing locks in `net.{cpp,h}`:
  * writing variable `nTotalBytesRecv` requires holding mutex `cs_totalBytesRecv` exclusively
  * writing variables `nTotalBytesSent`, `nMaxOutboundTotalBytesSentInCycle` and `nMaxOutboundCycleStartTime` require holding mutex `cs_totalBytesSent` exclusively
  * writing variables `nMaxOutboundTimeframe` and `nMaxOutboundLimit` require holding mutex `cs_totalBytesSent` exclusively
  * writing variable `vAddedNodes` requires holding mutex `cs_vAddedNodes` exclusively

Tree-SHA512: 54a5b4bc6dc6f404dacf403af2ddd7b2214cc0a17d1d32a282def1c6b536105dada56bfabbc8606f56755f2d24874abba09913b51c8d13b0f2b000149551f0b0
This commit is contained in:
Wladimir J. van der Laan 2017-11-30 11:32:51 +01:00
commit 3ff6ff5ec5
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D
2 changed files with 26 additions and 14 deletions

View file

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

View file

@ -158,11 +158,17 @@ public:
m_msgproc = connOptions.m_msgproc; m_msgproc = connOptions.m_msgproc;
nSendBufferMaxSize = connOptions.nSendBufferMaxSize; nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize; nReceiveFloodSize = connOptions.nReceiveFloodSize;
{
LOCK(cs_totalBytesSent);
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe; nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
nMaxOutboundLimit = connOptions.nMaxOutboundLimit; nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
}
vWhitelistedRange = connOptions.vWhitelistedRange; vWhitelistedRange = connOptions.vWhitelistedRange;
{
LOCK(cs_vAddedNodes);
vAddedNodes = connOptions.m_added_nodes; vAddedNodes = connOptions.m_added_nodes;
} }
}
CConnman(uint64_t seed0, uint64_t seed1); CConnman(uint64_t seed0, uint64_t seed1);
~CConnman(); ~CConnman();
@ -364,14 +370,14 @@ private:
// Network usage totals // Network usage totals
CCriticalSection cs_totalBytesRecv; CCriticalSection cs_totalBytesRecv;
CCriticalSection cs_totalBytesSent; CCriticalSection cs_totalBytesSent;
uint64_t nTotalBytesRecv; uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv);
uint64_t nTotalBytesSent; uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent);
// outbound limit & stats // outbound limit & stats
uint64_t nMaxOutboundTotalBytesSentInCycle; uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
uint64_t nMaxOutboundCycleStartTime; uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
uint64_t nMaxOutboundLimit; uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
uint64_t nMaxOutboundTimeframe; uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
// Whitelisted ranges. Any node connecting from these is automatically // Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds). // whitelisted (as well as those connecting to whitelisted binds).
@ -389,7 +395,7 @@ private:
CAddrMan addrman; CAddrMan addrman;
std::deque<std::string> vOneShots; std::deque<std::string> vOneShots;
CCriticalSection cs_vOneShots; CCriticalSection cs_vOneShots;
std::vector<std::string> vAddedNodes; std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
CCriticalSection cs_vAddedNodes; CCriticalSection cs_vAddedNodes;
std::vector<CNode*> vNodes; std::vector<CNode*> vNodes;
std::list<CNode*> vNodesDisconnected; std::list<CNode*> vNodesDisconnected;