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    pub urls: Vec<Url>,
55
56    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
57    /// 128 bits of random number generator output used to generate the password, and at least 24
58    /// bits of output to generate the username fragment.
59    pub local_ufrag: String,
60    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
61    /// 128 bits of random number generator output used to generate the password, and at least 24
62    /// bits of output to generate the username fragment.
63    pub local_pwd: String,
64
65    /// Controls mDNS query timeout
66    /// If the duration is 0, we will never go to failed.
67    pub multicast_dns_query_timeout: Option<Duration>,
68
69    /// Controls mDNS behavior for the ICE agent.
70    pub multicast_dns_mode: MulticastDnsMode,
71
72    /// Controls the local name for this agent. If none is specified a random one will be generated.
73    pub multicast_dns_local_name: String,
74
75    /// Control mDNS local IP address
76    pub multicast_dns_local_ip: Option<IpAddr>,
77
78    /// Defaults to 5 seconds when this property is nil.
79    /// If the duration is 0, the ICE Agent will never go to disconnected.
80    pub disconnected_timeout: Option<Duration>,
81
82    /// Defaults to 25 seconds when this property is nil.
83    /// If the duration is 0, we will never go to failed.
84    pub failed_timeout: Option<Duration>,
85
86    /// Determines how often should we send ICE keepalives (should be less than connection timeout
87    /// above) when this is nil, it defaults to 10 seconds.
88    /// A keepalive interval of 0 means we never send keepalive packets
89    pub keepalive_interval: Option<Duration>,
90
91    /// An optional configuration for disabling or enabling support for specific candidate types.
92    pub candidate_types: Vec<CandidateType>,
93
94    /// An optional configuration for disabling or enabling support for specific network types.
95    /// If empty, all network types are supported.
96    pub network_types: Vec<NetworkType>,
97
98    /// Controls how often our internal task loop runs when in the connecting state.
99    /// Only useful for testing.
100    pub check_interval: Duration,
101
102    /// The max amount of binding requests the agent will send over a candidate pair for validation
103    /// or nomination, if after max_binding_requests the candidate is yet to answer a binding
104    /// request or a nomination we set the pair as failed.
105    pub max_binding_requests: Option<u16>,
106
107    pub is_controlling: bool,
108
109    /// lite agents do not perform connectivity check and only provide host candidates.
110    pub lite: bool,
111
112    /// Specify a minimum wait time before selecting host candidates.
113    pub host_acceptance_min_wait: Option<Duration>,
114    /// Specify a minimum wait time before selecting srflx candidates.
115    pub srflx_acceptance_min_wait: Option<Duration>,
116    /// Specify a minimum wait time before selecting prflx candidates.
117    pub prflx_acceptance_min_wait: Option<Duration>,
118    /// Specify a minimum wait time before selecting relay candidates.
119    pub relay_acceptance_min_wait: Option<Duration>,
120
121    /// Controls if self-signed certificates are accepted when connecting to TURN servers via TLS or
122    /// DTLS.
123    pub insecure_skip_verify: bool,
124}