@@ -857,7 +857,10 @@ friend class CNode;
857
857
bool m_i2p_accept_incoming;
858
858
};
859
859
860
- void Init (const Options& connOptions) {
860
+ void Init (const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
861
+ {
862
+ AssertLockNotHeld (m_total_bytes_sent_mutex);
863
+
861
864
nLocalServices = connOptions.nLocalServices ;
862
865
nMaxConnections = connOptions.nMaxConnections ;
863
866
m_max_outbound_full_relay = std::min (connOptions.m_max_outbound_full_relay , connOptions.nMaxConnections );
@@ -873,7 +876,7 @@ friend class CNode;
873
876
nReceiveFloodSize = connOptions.nReceiveFloodSize ;
874
877
m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout };
875
878
{
876
- LOCK (cs_totalBytesSent );
879
+ LOCK (m_total_bytes_sent_mutex );
877
880
nMaxOutboundLimit = connOptions.nMaxOutboundLimit ;
878
881
}
879
882
vWhitelistedRange = connOptions.vWhitelistedRange ;
@@ -888,7 +891,7 @@ friend class CNode;
888
891
CConnman (uint64_t seed0, uint64_t seed1, CAddrMan& addrman, bool network_active = true );
889
892
~CConnman ();
890
893
bool Start (CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman, CMasternodeSync& mn_sync,
891
- CScheduler& scheduler, const Options& options);
894
+ CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
892
895
893
896
void StopThreads ();
894
897
void StopNodes ();
@@ -956,7 +959,7 @@ friend class CNode;
956
959
957
960
bool IsMasternodeOrDisconnectRequested (const CService& addr);
958
961
959
- void PushMessage (CNode* pnode, CSerializedNetMsg&& msg);
962
+ void PushMessage (CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
960
963
961
964
template <typename Condition, typename Callable>
962
965
bool ForEachNodeContinueIf (const Condition& cond, Callable&& func)
@@ -1141,24 +1144,22 @@ friend class CNode;
1141
1144
// ! that peer during `net_processing.cpp:PushNodeVersion()`.
1142
1145
ServiceFlags GetLocalServices () const ;
1143
1146
1144
- uint64_t GetMaxOutboundTarget () const ;
1147
+ uint64_t GetMaxOutboundTarget () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1145
1148
std::chrono::seconds GetMaxOutboundTimeframe () const ;
1146
1149
1147
1150
// ! check if the outbound target is reached
1148
1151
// ! if param historicalBlockServingLimit is set true, the function will
1149
1152
// ! response true if the limit for serving historical blocks has been reached
1150
- bool OutboundTargetReached (bool historicalBlockServingLimit) const ;
1153
+ bool OutboundTargetReached (bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1151
1154
1152
1155
// ! response the bytes left in the current max outbound cycle
1153
1156
// ! in case of no limit, it will always response 0
1154
- uint64_t GetOutboundTargetBytesLeft () const ;
1157
+ uint64_t GetOutboundTargetBytesLeft () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1155
1158
1156
- // ! returns the time left in the current max outbound cycle
1157
- // ! in case of no limit, it will always return 0
1158
- std::chrono::seconds GetMaxOutboundTimeLeftInCycle () const ;
1159
+ std::chrono::seconds GetMaxOutboundTimeLeftInCycle () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1159
1160
1160
1161
uint64_t GetTotalBytesRecv () const ;
1161
- uint64_t GetTotalBytesSent () const ;
1162
+ uint64_t GetTotalBytesSent () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1162
1163
1163
1164
/* * Get a unique deterministic randomizer. */
1164
1165
CSipHasher GetDeterministicRandomizer (uint64_t id) const ;
@@ -1209,6 +1210,10 @@ friend class CNode;
1209
1210
NetPermissionFlags m_permissions;
1210
1211
};
1211
1212
1213
+ // ! returns the time left in the current max outbound cycle
1214
+ // ! in case of no limit, it will always return 0
1215
+ std::chrono::seconds GetMaxOutboundTimeLeftInCycle_ () const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
1216
+
1212
1217
bool BindListenPort (const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
1213
1218
bool Bind (const CService& addr, unsigned int flags, NetPermissionFlags permissions);
1214
1219
bool InitBinds (
@@ -1300,7 +1305,7 @@ friend class CNode;
1300
1305
/* *
1301
1306
* Check connected and listening sockets for IO readiness and process them accordingly.
1302
1307
*/
1303
- void SocketHandler (CMasternodeSync& mn_sync);
1308
+ void SocketHandler (CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1304
1309
1305
1310
/* *
1306
1311
* Do the read/write for connected sockets that are ready for IO.
@@ -1310,15 +1315,16 @@ friend class CNode;
1310
1315
*/
1311
1316
void SocketHandlerConnected (const std::set<SOCKET>& recv_set,
1312
1317
const std::set<SOCKET>& send_set,
1313
- const std::set<SOCKET>& error_set);
1318
+ const std::set<SOCKET>& error_set)
1319
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1314
1320
1315
1321
/* *
1316
1322
* Accept incoming connections, one from each read-ready listening socket.
1317
1323
* @param[in] recv_set Sockets that are ready for read.
1318
1324
*/
1319
1325
void SocketHandlerListening (const std::set<SOCKET>& recv_set, CMasternodeSync& mn_sync);
1320
1326
1321
- void ThreadSocketHandler (CMasternodeSync& mn_sync);
1327
+ void ThreadSocketHandler (CMasternodeSync& mn_sync) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1322
1328
void ThreadDNSAddressSeed ();
1323
1329
void ThreadOpenMasternodeConnections (CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
1324
1330
CMasternodeSync& mn_sync);
@@ -1350,7 +1356,7 @@ friend class CNode;
1350
1356
1351
1357
// Network stats
1352
1358
void RecordBytesRecv (uint64_t bytes);
1353
- void RecordBytesSent (uint64_t bytes);
1359
+ void RecordBytesSent (uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1354
1360
1355
1361
/* *
1356
1362
* Return vector of current BLOCK_RELAY peers.
@@ -1364,14 +1370,14 @@ friend class CNode;
1364
1370
void UnregisterEvents (CNode* pnode);
1365
1371
1366
1372
// Network usage totals
1367
- mutable RecursiveMutex cs_totalBytesSent ;
1373
+ mutable Mutex m_total_bytes_sent_mutex ;
1368
1374
std::atomic<uint64_t > nTotalBytesRecv{0 };
1369
- uint64_t nTotalBytesSent GUARDED_BY (cs_totalBytesSent ) {0 };
1375
+ uint64_t nTotalBytesSent GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1370
1376
1371
1377
// outbound limit & stats
1372
- uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY (cs_totalBytesSent ) {0 };
1373
- std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY (cs_totalBytesSent ) {0 };
1374
- uint64_t nMaxOutboundLimit GUARDED_BY (cs_totalBytesSent );
1378
+ uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1379
+ std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1380
+ uint64_t nMaxOutboundLimit GUARDED_BY (m_total_bytes_sent_mutex );
1375
1381
1376
1382
// P2P timeout in seconds
1377
1383
std::chrono::seconds m_peer_connect_timeout;
0 commit comments