rasi_ext/net/quic/
config.rs

1use std::{ops, time::Duration};
2
3/// An wrapper for quiche [`Config`](quiche::Config).
4pub struct Config {
5    quiche_config: quiche::Config,
6    /// The time interval for sending ping packets.
7    pub ping_packet_send_interval: Option<Duration>,
8    /// `max_udp_payload_size transport` parameter.
9    pub max_recv_udp_payload_size: usize,
10    /// `max_udp_payload_size transport` parameter.
11    pub max_send_udp_payload_size: usize,
12}
13
14impl ops::Deref for Config {
15    type Target = quiche::Config;
16
17    fn deref(&self) -> &Self::Target {
18        &self.quiche_config
19    }
20}
21
22impl ops::DerefMut for Config {
23    fn deref_mut(&mut self) -> &mut Self::Target {
24        &mut self.quiche_config
25    }
26}
27
28impl Config {
29    /// Create new quic config instance with default config.
30    pub fn new() -> Self {
31        let mut config = Config {
32            quiche_config: quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap(),
33            ping_packet_send_interval: None,
34            max_recv_udp_payload_size: 65527,
35            max_send_udp_payload_size: 1200,
36        };
37
38        config.set_initial_max_stream_data_bidi_local(1024 * 1024);
39        config.set_initial_max_stream_data_bidi_remote(1024 * 1024);
40        config.set_initial_max_streams_bidi(100);
41        config.set_initial_max_streams_uni(100);
42
43        config
44    }
45
46    /// Sets the `max_idle_timeout` transport parameter, in milliseconds.
47    ///
48    /// The default value is infinite, that is, no timeout is used.
49    ///
50    /// This function also set the `ping_packet_send_interval` as `max_idle_timeout` / 2
51    pub fn set_max_idle_timeout(&mut self, v: u64) {
52        self.ping_packet_send_interval = Some(Duration::from_millis(v / 2));
53        self.quiche_config.set_max_idle_timeout(v)
54    }
55
56    /// Sets the `max_udp_payload_size transport` parameter.
57    ///
58    /// The default value is `65527`.
59    pub fn set_max_recv_udp_payload_size(&mut self, v: usize) {
60        self.max_recv_udp_payload_size = v;
61        self.quiche_config.set_max_recv_udp_payload_size(v)
62    }
63
64    /// Sets the maximum outgoing UDP payload size.
65    ///
66    /// The default and minimum value is `1200`.
67    pub fn set_max_send_udp_payload_size(&mut self, v: usize) {
68        self.max_send_udp_payload_size = v;
69        self.quiche_config.set_max_send_udp_payload_size(v)
70    }
71}