From b312cd770701aa806e9b264154646f481d212c1c Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 8 Oct 2018 15:34:39 +0200 Subject: [PATCH] Add missing locking annotations --- src/net.cpp | 15 +++------------ src/net.h | 38 +++++++++++++++++++------------------- src/netbase.cpp | 4 ++-- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index e065ac0f2838e..1e6375986626c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -82,8 +82,8 @@ bool fDiscover = true; bool fListen = true; bool fRelayTxes = true; CCriticalSection cs_mapLocalHost; -std::map mapLocalHost; -static bool vfLimited[NET_MAX] = {}; +std::map mapLocalHost GUARDED_BY(cs_mapLocalHost); +static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; std::string strSubVersion; limitedmap mapAlreadyAskedFor(MAX_INV_SZ); @@ -874,16 +874,7 @@ const uint256& CNetMessage::GetMessageHash() const return data_hash; } - - - - - - - - -// requires LOCK(cs_vSend) -size_t CConnman::SocketSendData(CNode *pnode) const +size_t CConnman::SocketSendData(CNode *pnode) const EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_vSend) { auto it = pnode->vSendMsg.begin(); size_t nSentSize = 0; diff --git a/src/net.h b/src/net.h index 32cc02f5a9c27..a059d32c89d6c 100644 --- a/src/net.h +++ b/src/net.h @@ -400,12 +400,12 @@ class CConnman std::vector vhListenSocket; std::atomic fNetworkActive; - banmap_t setBanned; + banmap_t setBanned GUARDED_BY(cs_setBanned); CCriticalSection cs_setBanned; - bool setBannedIsDirty; + bool setBannedIsDirty GUARDED_BY(cs_setBanned); bool fAddressesInitialized; CAddrMan addrman; - std::deque vOneShots; + std::deque vOneShots GUARDED_BY(cs_vOneShots); CCriticalSection cs_vOneShots; std::vector vAddedNodes GUARDED_BY(cs_vAddedNodes); CCriticalSection cs_vAddedNodes; @@ -540,7 +540,7 @@ struct LocalServiceInfo { }; extern CCriticalSection cs_mapLocalHost; -extern std::map mapLocalHost; +extern std::map mapLocalHost GUARDED_BY(cs_mapLocalHost); typedef std::map mapMsgCmdSize; //command, total bytes class CNodeStats @@ -630,23 +630,23 @@ class CNode public: // socket std::atomic nServices; - SOCKET hSocket; + SOCKET hSocket GUARDED_BY(cs_hSocket); size_t nSendSize; // total size of all vSendMsg entries size_t nSendOffset; // offset inside the first vSendMsg already sent - uint64_t nSendBytes; - std::deque> vSendMsg; + uint64_t nSendBytes GUARDED_BY(cs_vSend); + std::deque> vSendMsg GUARDED_BY(cs_vSend); CCriticalSection cs_vSend; CCriticalSection cs_hSocket; CCriticalSection cs_vRecv; CCriticalSection cs_vProcessMsg; - std::list vProcessMsg; + std::list vProcessMsg GUARDED_BY(cs_vProcessMsg); size_t nProcessQueueSize; CCriticalSection cs_sendProcessing; std::deque vRecvGetData; - uint64_t nRecvBytes; + uint64_t nRecvBytes GUARDED_BY(cs_vRecv); std::atomic nRecvVersion; std::atomic nLastSend; @@ -662,7 +662,7 @@ class CNode // to be printed out, displayed to humans in various forms and so on. So we sanitize it and // store the sanitized version in cleanSubVer. The original should be used when dealing with // the network or wire types and the cleaned string used when displayed or logged. - std::string strSubVer, cleanSubVer; + std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer); CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer bool fWhitelisted; // This peer can bypass DoS banning. bool fFeeler; // If true this node is being used as a short lived feeler. @@ -681,7 +681,7 @@ class CNode bool fSentAddr; CSemaphoreGrant grantOutbound; mutable CCriticalSection cs_filter; - std::unique_ptr pfilter; + std::unique_ptr pfilter PT_GUARDED_BY(cs_filter); std::atomic nRefCount; const uint64_t nKeyedNetGroup; @@ -690,7 +690,7 @@ class CNode protected: mapMsgCmdSize mapSendBytesPerMsgCmd; - mapMsgCmdSize mapRecvBytesPerMsgCmd; + mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); public: uint256 hashContinue; @@ -701,18 +701,18 @@ class CNode CRollingBloomFilter addrKnown; bool fGetAddr; std::set setKnown; - int64_t nNextAddrSend; - int64_t nNextLocalAddrSend; + int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing); + int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing); // inventory based relay - CRollingBloomFilter filterInventoryKnown; + CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory); // Set of transaction ids we still have to announce. // They are sorted by the mempool before relay, so the order is not important. std::set setInventoryTxToSend; // List of block ids we still have announce. // There is no final sorting before sending, as they are always sent immediately // and in the order requested. - std::vector vInventoryBlockToSend; + std::vector vInventoryBlockToSend GUARDED_BY(cs_inventory); CCriticalSection cs_inventory; std::set setAskFor; std::multimap mapAskFor; @@ -741,7 +741,7 @@ class CNode // Whether a ping is requested. std::atomic fPingQueued; // Minimum fee rate with which to filter inv's to this node - CAmount minFeeFilter; + CAmount minFeeFilter GUARDED_BY(cs_feeFilter); CCriticalSection cs_feeFilter; CAmount lastSentFeeFilter; int64_t nextSendTimeFeeFilter; @@ -761,10 +761,10 @@ class CNode std::list vRecvMsg; // Used only by SocketHandler thread mutable CCriticalSection cs_addrName; - std::string addrName; + std::string addrName GUARDED_BY(cs_addrName); // Our address, as reported by the peer - CService addrLocal; + CService addrLocal GUARDED_BY(cs_addrLocal); mutable CCriticalSection cs_addrLocal; public: diff --git a/src/netbase.cpp b/src/netbase.cpp index 6a750d5141060..1c043fc981aa6 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -26,9 +26,9 @@ #endif // Settings -static proxyType proxyInfo[NET_MAX]; -static proxyType nameProxy; static CCriticalSection cs_proxyInfos; +static proxyType proxyInfo[NET_MAX] GUARDED_BY(cs_proxyInfos); +static proxyType nameProxy GUARDED_BY(cs_proxyInfos); int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; bool fNameLookup = DEFAULT_NAME_LOOKUP;