diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -403,12 +403,12 @@ 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; @@ -532,7 +532,8 @@ }; extern CCriticalSection cs_mapLocalHost; -extern std::map mapLocalHost; +extern std::map + mapLocalHost GUARDED_BY(cs_mapLocalHost); // Command, total bytes typedef std::map mapMsgCmdSize; @@ -632,25 +633,25 @@ public: // socket std::atomic nServices; - SOCKET hSocket; + SOCKET hSocket GUARDED_BY(cs_hSocket); // Total size of all vSendMsg entries. size_t nSendSize; // Offset inside the first vSendMsg already sent. size_t nSendOffset; - 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; @@ -667,7 +668,8 @@ // 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); // Used for both cleanSubVer and strSubVer. CCriticalSection cs_SubVer; // This peer can bypass DoS banning. @@ -693,7 +695,7 @@ bool fSentAddr; CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; - std::unique_ptr pfilter; + std::unique_ptr pfilter PT_GUARDED_BY(cs_filter); std::atomic nRefCount; const uint64_t nKeyedNetGroup; @@ -702,7 +704,7 @@ protected: mapMsgCmdSize mapSendBytesPerMsgCmd; - mapMsgCmdSize mapRecvBytesPerMsgCmd; + mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); public: uint256 hashContinue; @@ -713,18 +715,18 @@ 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; @@ -754,7 +756,7 @@ // Whether a ping is requested. std::atomic fPingQueued; // Minimum fee rate with which to filter inv's to this node - Amount minFeeFilter; + Amount minFeeFilter GUARDED_BY(cs_feeFilter); CCriticalSection cs_feeFilter; Amount lastSentFeeFilter; int64_t nextSendTimeFeeFilter; @@ -778,10 +780,10 @@ std::list vRecvMsg; 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/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -90,8 +90,8 @@ 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) = {}; limitedmap mapAlreadyAskedFor(MAX_INV_SZ); @@ -728,7 +728,10 @@ stats.nRecvBytes = nRecvBytes; } stats.fWhitelisted = fWhitelisted; - stats.minFeeFilter = minFeeFilter; + { + LOCK(cs_feeFilter); + stats.minFeeFilter = minFeeFilter; + } // It is common for nodes with good ping times to suddenly become lagged, // due to a new block arriving or other large transfer. Merely reporting @@ -905,9 +908,8 @@ return data_hash; } -// requires LOCK(cs_vSend) -size_t CConnman::SocketSendData(CNode *pnode) const { - AssertLockHeld(pnode->cs_vSend); +size_t CConnman::SocketSendData(CNode *pnode) const + EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_vSend) { size_t nSentSize = 0; size_t nMsgCount = 0; diff --git a/src/netbase.cpp b/src/netbase.cpp --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -25,9 +25,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;