Skip to main content

h2/proto/streams/
mod.rs

1mod buffer;
2mod counts;
3mod flow_control;
4mod prioritize;
5mod recv;
6mod send;
7mod state;
8mod store;
9mod stream;
10#[allow(clippy::module_inception)]
11mod streams;
12
13pub(crate) use self::prioritize::Prioritized;
14pub(crate) use self::recv::Open;
15pub(crate) use self::send::PollReset;
16pub(crate) use self::streams::{DynStreams, OpaqueStreamRef, RecvOutcome, StreamRef, Streams};
17
18use self::buffer::Buffer;
19use self::counts::Counts;
20use self::flow_control::FlowControl;
21use self::prioritize::Prioritize;
22use self::recv::Recv;
23use self::send::Send;
24use self::state::State;
25use self::store::Store;
26use self::stream::Stream;
27
28use crate::frame::{StreamId, StreamIdOverflow};
29use crate::proto::*;
30
31use bytes::Bytes;
32use std::time::Duration;
33
34#[derive(Debug, Eq, PartialEq)]
35pub(super) enum BufferStatus {
36    Complete,
37    CodecFull,
38}
39
40#[derive(Debug)]
41pub struct Config {
42    /// Initial maximum number of locally initiated streams.
43    /// After receiving a Settings frame from the remote peer,
44    /// the connection will overwrite this value with the
45    /// MAX_CONCURRENT_STREAMS specified in the frame.
46    pub initial_max_send_streams: usize,
47
48    /// Max amount of DATA bytes to buffer per stream.
49    pub local_max_buffer_size: usize,
50
51    /// The stream ID to start the next local stream with
52    pub local_next_stream_id: StreamId,
53
54    /// If the local peer is willing to receive push promises
55    pub local_push_enabled: bool,
56
57    /// If extended connect protocol is enabled.
58    pub extended_connect_protocol_enabled: bool,
59
60    /// How long a locally reset stream should ignore frames
61    pub local_reset_duration: Duration,
62
63    /// Maximum number of locally reset streams to keep at a time
64    pub local_reset_max: usize,
65
66    /// Maximum number of remotely reset "pending accept" streams to keep at a
67    /// time. Going over this number results in a connection error.
68    pub remote_reset_max: usize,
69
70    /// Initial window size of remote initiated streams
71    pub remote_init_window_sz: WindowSize,
72
73    /// Maximum number of remote initiated streams
74    pub remote_max_initiated: Option<usize>,
75
76    /// Maximum number of locally reset streams due to protocol error across
77    /// the lifetime of the connection.
78    ///
79    /// When this gets exceeded, we issue GOAWAYs.
80    pub local_max_error_reset_streams: Option<usize>,
81
82    /// Connection-level budget policy for DATA framing overhead.
83    pub(crate) data_frame_budget: DataFrameBudget,
84}
85
86trait DebugStructExt<'a, 'b> {
87    // h2_ prefixes to protect against possible future name collisions
88    fn h2_field_if(&mut self, name: &str, val: &bool) -> &mut std::fmt::DebugStruct<'a, 'b>;
89
90    fn h2_field_if_then<T: std::fmt::Debug>(
91        &mut self,
92        name: &str,
93        cond: bool,
94        val: &T,
95    ) -> &mut std::fmt::DebugStruct<'a, 'b>;
96
97    fn h2_field_some<T: std::fmt::Debug>(
98        &mut self,
99        name: &str,
100        val: &Option<T>,
101    ) -> &mut std::fmt::DebugStruct<'a, 'b>;
102}
103
104impl<'a, 'b> DebugStructExt<'a, 'b> for std::fmt::DebugStruct<'a, 'b> {
105    fn h2_field_if(&mut self, name: &str, val: &bool) -> &mut std::fmt::DebugStruct<'a, 'b> {
106        if *val {
107            self.field(name, val)
108        } else {
109            self
110        }
111    }
112
113    fn h2_field_if_then<T: std::fmt::Debug>(
114        &mut self,
115        name: &str,
116        cond: bool,
117        val: &T,
118    ) -> &mut std::fmt::DebugStruct<'a, 'b> {
119        if cond {
120            self.field(name, val)
121        } else {
122            self
123        }
124    }
125
126    fn h2_field_some<T: std::fmt::Debug>(
127        &mut self,
128        name: &str,
129        val: &Option<T>,
130    ) -> &mut std::fmt::DebugStruct<'a, 'b> {
131        if val.is_some() {
132            self.field(name, val)
133        } else {
134            self
135        }
136    }
137}