Skip to main content

rtc_ice/agent/
agent_config.rs

1use std::net::IpAddr;
2use std::time::Duration;
3
4use super::*;
5use crate::mdns::*;
6use crate::network_type::NetworkType;
7use crate::url::*;
8
9/// The interval at which the agent performs candidate checks in the connecting phase.
10pub(crate) const DEFAULT_CHECK_INTERVAL: Duration = Duration::from_millis(200);
11
12/// The interval used to keep candidates alive.
13pub(crate) const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(2);
14
15/// The default time till an Agent transitions disconnected.
16pub(crate) const DEFAULT_DISCONNECTED_TIMEOUT: Duration = Duration::from_secs(5);
17
18/// The default time till an Agent transitions to failed after disconnected.
19pub(crate) const DEFAULT_FAILED_TIMEOUT: Duration = Duration::from_secs(25);
20
21/// Wait time before nominating a host candidate.
22pub(crate) const DEFAULT_HOST_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_secs(0);
23
24/// Wait time before nominating a srflx candidate.
25pub(crate) const DEFAULT_SRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(500);
26
27/// Wait time before nominating a prflx candidate.
28pub(crate) const DEFAULT_PRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(1000);
29
30/// Wait time before nominating a relay candidate.
31pub(crate) const DEFAULT_RELAY_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(2000);
32
33/// Max binding request before considering a pair failed.
34pub(crate) const DEFAULT_MAX_BINDING_REQUESTS: u16 = 7;
35
36/// The number of bytes that can be buffered before we start to error.
37pub(crate) const MAX_BUFFER_SIZE: usize = 1000 * 1000; // 1MB
38
39/// Wait time before binding requests can be deleted.
40pub(crate) const MAX_BINDING_REQUEST_TIMEOUT: Duration = Duration::from_millis(4000);
41
42pub(crate) fn default_candidate_types() -> Vec<CandidateType> {
43    vec![
44        CandidateType::Host,
45        CandidateType::ServerReflexive,
46        CandidateType::Relay,
47    ]
48}
49
50/// Collects the arguments to `ice::Agent` construction into a single structure, for
51/// future-proofness of the interface.
52#[derive(Default)]
53pub struct AgentConfig {
54    /// The STUN and TURN servers to gather reflexive and relay candidates from.
55    pub urls: Vec<Url>,
56
57    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
58    /// 128 bits of random number generator output used to generate the password, and at least 24
59    /// bits of output to generate the username fragment.
60    pub local_ufrag: String,
61    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
62    /// 128 bits of random number generator output used to generate the password, and at least 24
63    /// bits of output to generate the username fragment.
64    pub local_pwd: String,
65
66    /// Controls mDNS query timeout
67    /// If the duration is 0, we will never go to failed.
68    pub multicast_dns_query_timeout: Option<Duration>,
69
70    /// Controls mDNS behavior for the ICE agent.
71    pub multicast_dns_mode: MulticastDnsMode,
72
73    /// Controls the local name for this agent. If none is specified a random one will be generated.
74    pub multicast_dns_local_name: String,
75
76    /// Control mDNS local IP address
77    pub multicast_dns_local_ip: Option<IpAddr>,
78
79    /// Defaults to 5 seconds when this property is nil.
80    /// If the duration is 0, the ICE Agent will never go to disconnected.
81    pub disconnected_timeout: Option<Duration>,
82
83    /// Defaults to 25 seconds when this property is nil.
84    /// If the duration is 0, we will never go to failed.
85    pub failed_timeout: Option<Duration>,
86
87    /// Determines how often should we send ICE keepalives (should be less than connection timeout
88    /// above) when this is nil, it defaults to 10 seconds.
89    /// A keepalive interval of 0 means we never send keepalive packets
90    pub keepalive_interval: Option<Duration>,
91
92    /// An optional configuration for disabling or enabling support for specific candidate types.
93    pub candidate_types: Vec<CandidateType>,
94
95    /// An optional configuration for disabling or enabling support for specific network types.
96    /// If empty, all network types are supported.
97    pub network_types: Vec<NetworkType>,
98
99    /// Controls how often our internal task loop runs when in the connecting state.
100    /// Only useful for testing.
101    pub check_interval: Duration,
102
103    /// The max amount of binding requests the agent will send over a candidate pair for validation
104    /// or nomination, if after max_binding_requests the candidate is yet to answer a binding
105    /// request or a nomination we set the pair as failed.
106    pub max_binding_requests: Option<u16>,
107
108    /// Whether this agent takes the controlling role.
109    pub is_controlling: bool,
110
111    /// lite agents do not perform connectivity check and only provide host candidates.
112    pub lite: bool,
113
114    /// Specify a minimum wait time before selecting host candidates.
115    pub host_acceptance_min_wait: Option<Duration>,
116    /// Specify a minimum wait time before selecting srflx candidates.
117    pub srflx_acceptance_min_wait: Option<Duration>,
118    /// Specify a minimum wait time before selecting prflx candidates.
119    pub prflx_acceptance_min_wait: Option<Duration>,
120    /// Specify a minimum wait time before selecting relay candidates.
121    pub relay_acceptance_min_wait: Option<Duration>,
122
123    /// Controls if self-signed certificates are accepted when connecting to TURN servers via TLS or
124    /// DTLS.
125    pub insecure_skip_verify: bool,
126}