tokio_yamux/
config.rs

1//! Configuration of session and stream
2
3use std::time::Duration;
4
5/// Both sides assume the initial 256KB window size
6pub const INITIAL_STREAM_WINDOW: u32 = 256 * 1024;
7/// Default value for accept_backlog
8pub const DEFAULT_ACCEPT_BACKLOG: usize = 256;
9/// Default max stream count
10pub const DEFAULT_MAX_STREAM_COUNT: usize = 65535;
11/// Default keepalive interval duration
12pub const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30);
13/// Default write timeout duration
14pub const DEFAULT_WRITE_TIMEOUT: Duration = Duration::from_secs(10);
15
16/// Configuration of session and stream
17#[derive(Clone, Copy)]
18pub struct Config {
19    /// AcceptBacklog is used to limit how many streams may be
20    /// waiting an accept.
21    pub accept_backlog: usize,
22
23    /// EnableKeepalive is used to do a period keep alive
24    /// messages using a ping.
25    pub enable_keepalive: bool,
26
27    /// KeepAliveInterval is how often to perform the keep alive
28    pub keepalive_interval: Duration,
29
30    /// ConnectionWriteTimeout is meant to be a "safety valve" timeout after
31    /// we which will suspect a problem with the underlying connection and
32    /// close it. This is only applied to writes, where's there's generally
33    /// an expectation that things will move along quickly.
34    pub connection_write_timeout: Duration,
35
36    /// Max stream count
37    pub max_stream_count: usize,
38
39    /// MaxStreamWindowSize is used to control the maximum
40    /// window size that we allow for a stream.
41    /// Must be greater than or equal to 256 * 1024
42    pub max_stream_window_size: u32,
43}
44
45impl Default for Config {
46    fn default() -> Config {
47        Config {
48            accept_backlog: DEFAULT_ACCEPT_BACKLOG,
49            enable_keepalive: true,
50            keepalive_interval: DEFAULT_KEEPALIVE_INTERVAL,
51            connection_write_timeout: DEFAULT_WRITE_TIMEOUT,
52            max_stream_count: DEFAULT_MAX_STREAM_COUNT,
53            max_stream_window_size: INITIAL_STREAM_WINDOW,
54        }
55    }
56}