@@ -761,7 +761,10 @@ class CConnman
761
761
bool m_i2p_accept_incoming;
762
762
};
763
763
764
- void Init (const Options& connOptions) {
764
+ void Init (const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
765
+ {
766
+ AssertLockNotHeld (m_total_bytes_sent_mutex);
767
+
765
768
nLocalServices = connOptions.nLocalServices ;
766
769
nMaxConnections = connOptions.nMaxConnections ;
767
770
m_max_outbound_full_relay = std::min (connOptions.m_max_outbound_full_relay , connOptions.nMaxConnections );
@@ -777,7 +780,7 @@ class CConnman
777
780
nReceiveFloodSize = connOptions.nReceiveFloodSize ;
778
781
m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout };
779
782
{
780
- LOCK (cs_totalBytesSent );
783
+ LOCK (m_total_bytes_sent_mutex );
781
784
nMaxOutboundLimit = connOptions.nMaxOutboundLimit ;
782
785
}
783
786
vWhitelistedRange = connOptions.vWhitelistedRange ;
@@ -792,7 +795,7 @@ class CConnman
792
795
bool network_active = true );
793
796
794
797
~CConnman ();
795
- bool Start (CScheduler& scheduler, const Options& options);
798
+ bool Start (CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
796
799
797
800
void StopThreads ();
798
801
void StopNodes ();
@@ -811,7 +814,7 @@ class CConnman
811
814
812
815
bool ForNode (NodeId id, std::function<bool (CNode* pnode)> func);
813
816
814
- void PushMessage (CNode* pnode, CSerializedNetMsg&& msg);
817
+ void PushMessage (CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
815
818
816
819
using NodeFn = std::function<void (CNode*)>;
817
820
void ForEachNode (const NodeFn& func)
@@ -902,24 +905,22 @@ class CConnman
902
905
// ! that peer during `net_processing.cpp:PushNodeVersion()`.
903
906
ServiceFlags GetLocalServices () const ;
904
907
905
- uint64_t GetMaxOutboundTarget () const ;
908
+ uint64_t GetMaxOutboundTarget () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
906
909
std::chrono::seconds GetMaxOutboundTimeframe () const ;
907
910
908
911
// ! check if the outbound target is reached
909
912
// ! if param historicalBlockServingLimit is set true, the function will
910
913
// ! response true if the limit for serving historical blocks has been reached
911
- bool OutboundTargetReached (bool historicalBlockServingLimit) const ;
914
+ bool OutboundTargetReached (bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
912
915
913
916
// ! response the bytes left in the current max outbound cycle
914
917
// ! in case of no limit, it will always response 0
915
- uint64_t GetOutboundTargetBytesLeft () const ;
918
+ uint64_t GetOutboundTargetBytesLeft () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
916
919
917
- // ! returns the time left in the current max outbound cycle
918
- // ! in case of no limit, it will always return 0
919
- std::chrono::seconds GetMaxOutboundTimeLeftInCycle () const ;
920
+ std::chrono::seconds GetMaxOutboundTimeLeftInCycle () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
920
921
921
922
uint64_t GetTotalBytesRecv () const ;
922
- uint64_t GetTotalBytesSent () const ;
923
+ uint64_t GetTotalBytesSent () const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
923
924
924
925
/* * Get a unique deterministic randomizer. */
925
926
CSipHasher GetDeterministicRandomizer (uint64_t id) const ;
@@ -945,6 +946,10 @@ class CConnman
945
946
NetPermissionFlags m_permissions;
946
947
};
947
948
949
+ // ! returns the time left in the current max outbound cycle
950
+ // ! in case of no limit, it will always return 0
951
+ std::chrono::seconds GetMaxOutboundTimeLeftInCycle_ () const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
952
+
948
953
bool BindListenPort (const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
949
954
bool Bind (const CService& addr, unsigned int flags, NetPermissionFlags permissions);
950
955
bool InitBinds (const Options& options);
@@ -1004,7 +1009,7 @@ class CConnman
1004
1009
/* *
1005
1010
* Check connected and listening sockets for IO readiness and process them accordingly.
1006
1011
*/
1007
- void SocketHandler ();
1012
+ void SocketHandler () EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1008
1013
1009
1014
/* *
1010
1015
* Do the read/write for connected sockets that are ready for IO.
@@ -1017,15 +1022,16 @@ class CConnman
1017
1022
void SocketHandlerConnected (const std::vector<CNode*>& nodes,
1018
1023
const std::set<SOCKET>& recv_set,
1019
1024
const std::set<SOCKET>& send_set,
1020
- const std::set<SOCKET>& error_set);
1025
+ const std::set<SOCKET>& error_set)
1026
+ EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1021
1027
1022
1028
/* *
1023
1029
* Accept incoming connections, one from each read-ready listening socket.
1024
1030
* @param[in] recv_set Sockets that are ready for read.
1025
1031
*/
1026
1032
void SocketHandlerListening (const std::set<SOCKET>& recv_set);
1027
1033
1028
- void ThreadSocketHandler ();
1034
+ void ThreadSocketHandler () EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1029
1035
void ThreadDNSAddressSeed ();
1030
1036
1031
1037
uint64_t CalculateKeyedNetGroup (const CAddress& ad) const ;
@@ -1054,7 +1060,7 @@ class CConnman
1054
1060
1055
1061
// Network stats
1056
1062
void RecordBytesRecv (uint64_t bytes);
1057
- void RecordBytesSent (uint64_t bytes);
1063
+ void RecordBytesSent (uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex) ;
1058
1064
1059
1065
/* *
1060
1066
* Return vector of current BLOCK_RELAY peers.
@@ -1065,14 +1071,14 @@ class CConnman
1065
1071
static bool NodeFullyConnected (const CNode* pnode);
1066
1072
1067
1073
// Network usage totals
1068
- mutable RecursiveMutex cs_totalBytesSent ;
1074
+ mutable Mutex m_total_bytes_sent_mutex ;
1069
1075
std::atomic<uint64_t > nTotalBytesRecv{0 };
1070
- uint64_t nTotalBytesSent GUARDED_BY (cs_totalBytesSent ) {0 };
1076
+ uint64_t nTotalBytesSent GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1071
1077
1072
1078
// outbound limit & stats
1073
- uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY (cs_totalBytesSent ) {0 };
1074
- std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY (cs_totalBytesSent ) {0 };
1075
- uint64_t nMaxOutboundLimit GUARDED_BY (cs_totalBytesSent );
1079
+ uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1080
+ std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY (m_total_bytes_sent_mutex ) {0 };
1081
+ uint64_t nMaxOutboundLimit GUARDED_BY (m_total_bytes_sent_mutex );
1076
1082
1077
1083
// P2P timeout in seconds
1078
1084
std::chrono::seconds m_peer_connect_timeout;
0 commit comments