Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub struct Builder {
max_send_buffer_size: usize,

/// Maximum number of locally reset streams to keep at a time.
reset_stream_max: usize,
reset_stream_max: Option<usize>,

/// Maximum number of remotely reset streams to allow in the pending
/// accept queue.
Expand Down Expand Up @@ -661,7 +661,7 @@ impl Builder {
Builder {
max_send_buffer_size: proto::DEFAULT_MAX_SEND_BUFFER_SIZE,
reset_stream_duration: Duration::from_secs(proto::DEFAULT_RESET_STREAM_SECS),
reset_stream_max: proto::DEFAULT_RESET_STREAM_MAX,
reset_stream_max: None,
pending_accept_reset_stream_max: proto::DEFAULT_REMOTE_RESET_STREAM_MAX,
initial_target_connection_window_size: None,
initial_max_send_streams: usize::MAX,
Expand Down Expand Up @@ -930,7 +930,11 @@ impl Builder {
/// received for that stream will result in a connection level protocol
/// error, forcing the connection to terminate.
///
/// The default value is currently 50.
/// If unset, this limit currently defaults to a value based on the
/// configured [maximum concurrent streams], or a larger fixed value
/// if that setting is also unset.
///
/// [maximum concurrent streams]: Self::max_concurrent_streams
///
/// # Examples
///
Expand All @@ -953,7 +957,7 @@ impl Builder {
/// # pub fn main() {}
/// ```
pub fn max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
self.reset_stream_max = max;
self.reset_stream_max = Some(max);
self
}

Expand Down
20 changes: 14 additions & 6 deletions src/proto/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) struct Config {
pub initial_max_send_streams: usize,
pub max_send_buffer_size: usize,
pub reset_stream_duration: Duration,
pub reset_stream_max: usize,
pub reset_stream_max: Option<usize>,
pub remote_reset_stream_max: usize,
pub local_error_reset_streams_max: Option<usize>,
pub settings: frame::Settings,
Expand Down Expand Up @@ -133,6 +133,10 @@ where
{
pub fn new(codec: Codec<T, Prioritized<B>>, config: Config) -> Connection<T, P, B> {
fn streams_config(config: &Config) -> streams::Config {
let remote_max_initiated = config
.settings
.max_concurrent_streams()
.map(|max| max as usize);
streams::Config {
initial_max_send_streams: config.initial_max_send_streams,
local_max_buffer_size: config.max_send_buffer_size,
Expand All @@ -143,13 +147,17 @@ where
.is_extended_connect_protocol_enabled()
.unwrap_or(false),
local_reset_duration: config.reset_stream_duration,
local_reset_max: config.reset_stream_max,
local_reset_max: config.reset_stream_max.unwrap_or_else(|| {
remote_max_initiated
.map(|max| {
max.saturating_mul(RESET_STREAM_LIMIT_MULTIPLIER)
.max(MIN_DEFAULT_RESET_STREAM_MAX)
})
.unwrap_or(DEFAULT_RESET_STREAM_MAX)
}),
remote_reset_max: config.remote_reset_stream_max,
remote_init_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
remote_max_initiated: config
.settings
.max_concurrent_streams()
.map(|max| max as usize),
remote_max_initiated,
local_max_error_reset_streams: config.local_error_reset_streams_max,
data_frame_budget: config.data_frame_budget,
}
Expand Down
6 changes: 3 additions & 3 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ pub const DEFAULT_LOCAL_RESET_COUNT_MAX: usize = 1024;
pub const DEFAULT_DATA_FRAME_OVERHEAD_THRESHOLD: usize = 256;
pub const DEFAULT_DATA_FRAME_BUDGET: usize = DEFAULT_DATA_FRAME_OVERHEAD_THRESHOLD * 100;
pub const MAX_RECV_EMPTY_DATA_FRAMES: usize = 100;
// RFC 9113 suggests allowing at minimum 100 streams, it seems reasonable to
// by default allow a portion of that to be remembered as reset for some time.
pub const DEFAULT_RESET_STREAM_MAX: usize = 50;
pub const RESET_STREAM_LIMIT_MULTIPLIER: usize = 2;
pub const MIN_DEFAULT_RESET_STREAM_MAX: usize = 50;
pub const DEFAULT_RESET_STREAM_MAX: usize = 8192;
// RFC 9113#5.4.2 suggests ~1 RTT. We don't track that closely, but use a
// reasonable guess of the average here.
pub const DEFAULT_RESET_STREAM_SECS: u64 = 5;
Expand Down
12 changes: 8 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub struct Builder {
reset_stream_duration: Duration,

/// Maximum number of locally reset streams to keep at a time.
reset_stream_max: usize,
reset_stream_max: Option<usize>,

/// Maximum number of remotely reset streams to allow in the pending
/// accept queue.
Expand Down Expand Up @@ -656,7 +656,7 @@ impl Builder {
pub fn new() -> Builder {
Builder {
reset_stream_duration: Duration::from_secs(proto::DEFAULT_RESET_STREAM_SECS),
reset_stream_max: proto::DEFAULT_RESET_STREAM_MAX,
reset_stream_max: None,
pending_accept_reset_stream_max: proto::DEFAULT_REMOTE_RESET_STREAM_MAX,
settings: Settings::default(),
initial_target_connection_window_size: None,
Expand Down Expand Up @@ -886,7 +886,11 @@ impl Builder {
/// received for that stream will result in a connection level protocol
/// error, forcing the connection to terminate.
///
/// The default value is currently 50.
/// If unset, this limit currently defaults to a value based on the
/// configured [maximum concurrent streams], or a larger fixed value
/// if that setting is also unset.
///
/// [maximum concurrent streams]: Self::max_concurrent_streams
///
/// # Examples
///
Expand All @@ -908,7 +912,7 @@ impl Builder {
/// # pub fn main() {}
/// ```
pub fn max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
self.reset_stream_max = max;
self.reset_stream_max = Some(max);
self
}

Expand Down