@@ -252,6 +252,12 @@ pub struct Builder {
252
252
253
253
/// Maximum amount of bytes to "buffer" for writing per stream.
254
254
max_send_buffer_size : usize ,
255
+
256
+ /// Maximum number of locally reset streams due to protocol error across
257
+ /// the lifetime of the connection.
258
+ ///
259
+ /// When this gets exceeded, we issue GOAWAYs.
260
+ local_max_error_reset_streams : Option < usize > ,
255
261
}
256
262
257
263
/// Send a response back to the client
@@ -650,6 +656,8 @@ impl Builder {
650
656
settings : Settings :: default ( ) ,
651
657
initial_target_connection_window_size : None ,
652
658
max_send_buffer_size : proto:: DEFAULT_MAX_SEND_BUFFER_SIZE ,
659
+
660
+ local_max_error_reset_streams : Some ( proto:: DEFAULT_LOCAL_RESET_COUNT_MAX ) ,
653
661
}
654
662
}
655
663
@@ -887,6 +895,24 @@ impl Builder {
887
895
self
888
896
}
889
897
898
+ /// Sets the maximum number of local resets due to protocol errors made by the remote end.
899
+ ///
900
+ /// Invalid frames and many other protocol errors will lead to resets being generated for those streams.
901
+ /// Too many of these often indicate a malicious client, and there are attacks which can abuse this to DOS servers.
902
+ /// This limit protects against these DOS attacks by limiting the amount of resets we can be forced to generate.
903
+ ///
904
+ /// When the number of local resets exceeds this threshold, the server will issue GOAWAYs with an error code of
905
+ /// `ENHANCE_YOUR_CALM` to the client.
906
+ ///
907
+ /// If you really want to disable this, supply [`Option::None`] here.
908
+ /// Disabling this is not recommended and may expose you to DOS attacks.
909
+ ///
910
+ /// The default value is currently 1024, but could change.
911
+ pub fn max_local_error_reset_streams ( & mut self , max : Option < usize > ) -> & mut Self {
912
+ self . local_max_error_reset_streams = max;
913
+ self
914
+ }
915
+
890
916
/// Sets the maximum number of pending-accept remotely-reset streams.
891
917
///
892
918
/// Streams that have been received by the peer, but not accepted by the
@@ -1361,6 +1387,9 @@ where
1361
1387
reset_stream_duration : self . builder . reset_stream_duration ,
1362
1388
reset_stream_max : self . builder . reset_stream_max ,
1363
1389
remote_reset_stream_max : self . builder . pending_accept_reset_stream_max ,
1390
+ local_error_reset_streams_max : self
1391
+ . builder
1392
+ . local_max_error_reset_streams ,
1364
1393
settings : self . builder . settings . clone ( ) ,
1365
1394
} ,
1366
1395
) ;
0 commit comments