use std::time::Duration;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Limits {
pub max_header_bytes: u64,
pub max_concurrent_uni_streams: u32,
pub max_concurrent_bidi_streams: u32,
pub stream_receive_window: u64,
pub connection_receive_window: u64,
pub keep_alive: Duration,
pub idle_timeout: Duration,
pub hello_timeout_ms: u64,
pub max_subscriptions: usize,
pub subscriber_buffer_bytes: usize,
pub max_sequence_scopes: usize,
pub max_reorder_hold: usize,
pub max_local_streams: usize,
pub max_parked_reverse: usize,
pub max_dedup_entries: usize,
}
impl Limits {
pub const fn worst_case_header_memory(&self) -> u64 {
self.max_header_bytes
* (self.max_concurrent_uni_streams as u64 + self.max_concurrent_bidi_streams as u64)
}
}
impl Default for Limits {
fn default() -> Self {
Limits {
max_header_bytes: 16 * 1024,
max_concurrent_uni_streams: 2048,
max_concurrent_bidi_streams: 1024,
stream_receive_window: 1024 * 1024,
connection_receive_window: 16 * 1024 * 1024,
keep_alive: Duration::from_secs(10),
idle_timeout: Duration::from_secs(30),
hello_timeout_ms: 10_000,
max_subscriptions: 256,
subscriber_buffer_bytes: 8 * 1024 * 1024,
max_sequence_scopes: 1024,
max_reorder_hold: 256,
max_local_streams: 255,
max_parked_reverse: 8,
max_dedup_entries: 4096,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_match_the_protocol_document() {
let l = Limits::default();
assert_eq!(l.max_header_bytes, 16384);
assert_eq!(l.max_concurrent_uni_streams, 2048);
assert_eq!(l.max_concurrent_bidi_streams, 1024);
assert_eq!(l.stream_receive_window, 1 << 20);
assert_eq!(l.connection_receive_window, 16 << 20);
assert_eq!(l.keep_alive, Duration::from_secs(10));
assert_eq!(l.idle_timeout, Duration::from_secs(30));
assert_eq!(l.hello_timeout_ms, 10_000);
assert_eq!(l.max_subscriptions, 256);
assert_eq!(l.subscriber_buffer_bytes, 8 << 20);
assert_eq!(l.max_sequence_scopes, 1024);
assert_eq!(l.max_reorder_hold, 256);
assert_eq!(l.max_local_streams, 255);
assert_eq!(l.max_parked_reverse, 8);
assert_eq!(l.max_dedup_entries, 4096);
}
#[test]
fn worst_case_header_memory_is_48_mib() {
assert_eq!(Limits::default().worst_case_header_memory(), 48 << 20);
}
}