srt_protocol/options/
connect.rs

1use std::{
2    net::{Ipv4Addr, SocketAddr},
3    time::Duration,
4};
5
6use super::*;
7
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub struct Connect {
10    pub local: SocketAddr,
11
12    /// Connect timeout. This option applies to the caller and rendezvous connection modes.
13    /// For the rendezvous mode (see SRTO_RENDEZVOUS) the effective connection timeout will be 10 times
14    /// the value set with SRTO_CONNTIMEO.
15    ///
16    /// Default is 3 seconds.
17    pub timeout: Duration,
18
19    /// SRTO_MINVERSION
20    /// The minimum SRT version that is required from the peer. A connection to a peer that does not
21    /// satisfy the minimum version requirement will be rejected. See SRTO_VERSION for the version
22    /// format.
23    ///
24    /// The default value is 0x010000 (SRT v1.0.0).
25    pub min_version: SrtVersion,
26
27    /// SRTO_UDP_RCVBUF
28    ///
29    /// UDP Socket Receive Buffer Size. Configured in bytes, maintained in packets based on MSS value.
30    /// Receive buffer must not be greater than FC size.
31    ///
32    /// Default is 64k
33    pub udp_recv_buffer_size: ByteCount,
34
35    /// SRT_UDP_SNDBUF
36    ///
37    /// UDP Socket Send Buffer Size. Configured in bytes, maintained in packets based on SRTO_MSS value.
38    ///
39    /// Default is 64k
40    pub udp_send_buffer_size: ByteCount,
41
42    /// SRTO_IPTTL
43    ///
44    /// IPv4 Time To Live (see IP_TTL option for IP) or IPv6 unicast hops (see IPV6_UNICAST_HOPS for IPv6) depending on socket address family. Applies to sender only.
45    ///
46    /// When getting, the returned value is the user preset for non-connected sockets and the actual value for connected sockets.
47    /// Sender: user configurable, default: 64
48    pub ip_ttl: u8,
49
50    /// Linger time on close (see [SO_LINGER](http://man7.org/linux/man-pages/man7/socket.7.html)).
51    /// Set to None to disable linger
52    ///
53    /// Default is 180s
54    pub linger: Option<Duration>,
55}
56
57impl Connect {}
58impl Default for Connect {
59    fn default() -> Self {
60        Self {
61            local: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
62            timeout: Duration::from_secs(3),
63            min_version: SrtVersion::new(1, 0, 0),
64            udp_recv_buffer_size: ByteCount(65536),
65            udp_send_buffer_size: ByteCount(65536),
66            ip_ttl: 64,
67            linger: Some(Duration::from_secs(180)),
68        }
69    }
70}
71
72impl Validation for Connect {
73    type Error = OptionsError;
74
75    fn is_valid(&self) -> Result<(), Self::Error> {
76        if self.ip_ttl == 0 {
77            return Err(OptionsError::InvalidIpTtl);
78        }
79
80        Ok(())
81    }
82}
83
84#[cfg(test)]
85mod test {
86    use super::*;
87
88    #[test]
89    fn ttl_validate() {
90        assert_eq!(
91            Connect {
92                ip_ttl: 0,
93                ..Default::default()
94            }
95            .is_valid(),
96            Err(OptionsError::InvalidIpTtl)
97        );
98    }
99}