srt_protocol/options/
session.rs

1use std::time::Duration;
2
3use super::*;
4
5#[derive(Debug, Clone, Eq, PartialEq)]
6pub struct Session {
7    /// SRTO_PEERIDLETIMEO
8    /// The maximum time to wait until another packet is received from a peer since the last
9    /// such packet reception. If this time is passed, the connection is considered broken on
10    /// timeout.
11    ///
12    ///  The default value is 5000ms
13    pub peer_idle_timeout: Duration,
14
15    /// SRTO_MSS
16    /// Maximum Segment Size. Used for buffer allocation and rate calculation using packet counter
17    /// assuming fully filled packets. Each party can set its own MSS value independently. During a
18    /// handshake the parties exchange MSS values, and the lowest is used.
19    ///
20    /// Generally on the internet MSS is 1500 by default. This is the maximum size of a UDP packet
21    /// and can be only decreased, unless you have some unusual dedicated network settings. MSS is
22    /// not to be confused with the size of the UDP payload or SRT payload - this size is the size
23    /// of the IP packet, including the UDP and SRT headers
24    ///
25    /// THe value of SRTO_MSS must not exceed SRTO_UDP_SNDBUF or SRTO_UDP_RCVBUF.
26    pub max_segment_size: PacketSize,
27
28    pub statistics_interval: Duration,
29}
30
31impl Default for Session {
32    fn default() -> Self {
33        Self {
34            peer_idle_timeout: Duration::from_secs(5),
35            max_segment_size: PacketSize(1500),
36            statistics_interval: Duration::from_secs(1),
37        }
38    }
39}
40
41impl Validation for Session {
42    type Error = OptionsError;
43
44    fn is_valid(&self) -> Result<(), Self::Error> {
45        use OptionsError::*;
46        if self.max_segment_size > PacketSize(1500) {
47            Err(MaxSegmentSizeOutOfRange(self.max_segment_size))
48        } else if self.statistics_interval < Duration::from_millis(200) {
49            Err(StatisticsIntervalOutOfRange(self.statistics_interval))
50        } else {
51            Ok(())
52        }
53    }
54}