rtc_ice/agent/
agent_config.rs

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