@@ -987,6 +987,9 @@ impl ConnectionCounters {
987987 fn check_max_established ( & self , endpoint : & ConnectedPoint )
988988 -> Result < ( ) , ConnectionLimit >
989989 {
990+ // Check total connection limit.
991+ Self :: check ( self . num_established ( ) , self . limits . max_established_total ) ?;
992+ // Check incoming/outgoing connection limits
990993 match endpoint {
991994 ConnectedPoint :: Dialer { .. } =>
992995 Self :: check ( self . established_outgoing , self . limits . max_established_outgoing ) ,
@@ -1031,6 +1034,7 @@ pub struct ConnectionLimits {
10311034 max_established_incoming : Option < u32 > ,
10321035 max_established_outgoing : Option < u32 > ,
10331036 max_established_per_peer : Option < u32 > ,
1037+ max_established_total : Option < u32 > ,
10341038}
10351039
10361040impl ConnectionLimits {
@@ -1058,6 +1062,17 @@ impl ConnectionLimits {
10581062 self
10591063 }
10601064
1065+ /// Configures the maximum number of concurrent established connections (both
1066+ /// inbound and outbound).
1067+ ///
1068+ /// Note: This should be used in conjunction with
1069+ /// [`ConnectionLimits::with_max_established_incoming`] to prevent possible
1070+ /// eclipse attacks (all connections being inbound).
1071+ pub fn with_max_established ( mut self , limit : Option < u32 > ) -> Self {
1072+ self . max_established_total = limit;
1073+ self
1074+ }
1075+
10611076 /// Configures the maximum number of concurrent established connections per peer,
10621077 /// regardless of direction (incoming or outgoing).
10631078 pub fn with_max_established_per_peer ( mut self , limit : Option < u32 > ) -> Self {
0 commit comments