rtc_ice/agent/
agent_config.rs

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