1use std::io;
29
30#[derive(Clone)]
32pub struct Config {
33 pub host_port: String,
36 pub omit_sni: bool,
38 pub connect_to: Option<String>,
40 pub source_port: u32,
42 pub verify_peer: bool,
44 pub idle_timeout: u64,
46 pub send_capacity_factor: f64,
48 pub max_data: u64,
50 pub max_stream_data_bidi_local: u64,
52 pub max_stream_data_bidi_remote: u64,
55 pub max_stream_data_uni: u64,
57 pub max_streams_bidi: u64,
59 pub max_streams_uni: u64,
62 pub max_window: u64,
64 pub max_stream_window: u64,
66 pub session: Option<Vec<u8>>,
68 pub enable_early_data: bool,
70 pub enable_dgram: bool,
72 pub dgram_recv_queue_len: usize,
74 pub dgram_send_queue_len: usize,
76}
77
78impl Config {
79 pub fn new() -> Self {
81 Self::default()
82 }
83
84 pub fn with_host_port(mut self, host_port: String) -> Self {
85 self.host_port = host_port;
86 self
87 }
88
89 pub fn omit_sni(mut self) -> Self {
90 self.omit_sni = true;
91 self
92 }
93
94 pub fn with_connect_to(mut self, connect_to: String) -> Self {
95 self.connect_to = Some(connect_to);
96 self
97 }
98
99 pub fn with_source_port(mut self, port: u32) -> Self {
100 self.source_port = port;
101 self
102 }
103
104 pub fn verify_peer(mut self, verify_peer: bool) -> Self {
105 self.verify_peer = verify_peer;
106 self
107 }
108
109 pub fn with_idle_timeout(mut self, idle_timeout: u64) -> Self {
110 self.idle_timeout = idle_timeout;
111 self
112 }
113
114 pub fn with_send_capacity_factor(mut self, factor: f64) -> Self {
115 self.send_capacity_factor = factor;
116 self
117 }
118
119 pub fn with_max_data(mut self, max_data: u64) -> Self {
120 self.max_data = max_data;
121 self
122 }
123
124 pub fn with_max_stream_data_bidi_local(
125 mut self, max_stream_data_bidi_local: u64,
126 ) -> Self {
127 self.max_stream_data_bidi_local = max_stream_data_bidi_local;
128 self
129 }
130
131 pub fn with_max_stream_data_bidi_remote(
132 mut self, max_stream_data_bidi_remote: u64,
133 ) -> Self {
134 self.max_stream_data_bidi_remote = max_stream_data_bidi_remote;
135 self
136 }
137
138 pub fn with_max_stream_data_uni(mut self, max_stream_data_uni: u64) -> Self {
139 self.max_stream_data_uni = max_stream_data_uni;
140 self
141 }
142
143 pub fn with_max_streams_bidi(mut self, max_streams_bidi: u64) -> Self {
144 self.max_streams_bidi = max_streams_bidi;
145 self
146 }
147
148 pub fn with_max_streams_uni(mut self, max_streams_uni: u64) -> Self {
149 self.max_streams_uni = max_streams_uni;
150 self
151 }
152
153 pub fn with_max_window(mut self, max_window: u64) -> Self {
154 self.max_window = max_window;
155 self
156 }
157
158 pub fn with_max_stream_window(mut self, max_stream_window: u64) -> Self {
159 self.max_stream_window = max_stream_window;
160 self
161 }
162
163 pub fn enable_dgram(mut self, enable_dgram: bool) -> Self {
164 self.enable_dgram = enable_dgram;
165 self
166 }
167
168 pub fn with_dgram_recv_queue_len(
169 mut self, dgram_recv_queue_len: usize,
170 ) -> Self {
171 self.dgram_recv_queue_len = dgram_recv_queue_len;
172 self
173 }
174
175 pub fn with_dgram_send_queue_len(
176 mut self, dgram_send_queue_len: usize,
177 ) -> Self {
178 self.dgram_send_queue_len = dgram_send_queue_len;
179 self
180 }
181
182 pub fn build(self) -> Result<Self, io::Error> {
183 if self.host_port.is_empty() {
184 return Err(io::Error::new(
185 io::ErrorKind::InvalidInput,
186 "Must provide a <host:port> to connect".to_string(),
187 ));
188 }
189
190 Ok(Config {
191 host_port: self.host_port,
192 omit_sni: self.omit_sni,
193 connect_to: self.connect_to,
194 source_port: self.source_port,
195 verify_peer: self.verify_peer,
196 idle_timeout: self.idle_timeout,
197 send_capacity_factor: self.send_capacity_factor,
198 max_data: self.max_data,
199 max_stream_data_bidi_local: self.max_stream_data_bidi_local,
200 max_stream_data_bidi_remote: self.max_stream_data_bidi_remote,
201 max_stream_data_uni: self.max_stream_data_uni,
202 max_streams_bidi: self.max_streams_bidi,
203 max_streams_uni: self.max_streams_uni,
204 max_window: self.max_window,
205 max_stream_window: self.max_stream_window,
206 session: None,
207 enable_early_data: self.enable_early_data,
208 enable_dgram: self.enable_dgram,
209 dgram_recv_queue_len: self.dgram_recv_queue_len,
210 dgram_send_queue_len: self.dgram_send_queue_len,
211 })
212 }
213}
214
215impl Default for Config {
216 fn default() -> Self {
217 Self {
219 host_port: "".to_string(),
220 omit_sni: false,
221 connect_to: None,
222 source_port: 0,
223 verify_peer: true,
224 idle_timeout: 5000,
225 send_capacity_factor: 1.0,
226 max_data: 10000000,
227 max_stream_data_bidi_local: 10000000,
228 max_stream_data_bidi_remote: 10000000,
229 max_stream_data_uni: 10000000,
230 max_streams_bidi: 100,
231 max_streams_uni: 100,
232 max_window: 25165824,
233 max_stream_window: 16777216,
234 session: None,
235 enable_early_data: false,
236 enable_dgram: true,
237 dgram_recv_queue_len: 65536,
238 dgram_send_queue_len: 65536,
239 }
240 }
241}