Skip to main content

rtci_ice/agent/
agent_config.rs

1use std::net::IpAddr;
2use std::time::Duration;
3
4use super::*;
5use crate::agent::remote_policy::{IceAddressPolicy, RemoteAddressFilter};
6use crate::external_ip_mapper::ExternalIpMapper;
7use crate::mdns::*;
8use crate::network_type::NetworkType;
9use crate::url::*;
10
11/// How often the agent looks at its state while connecting, when nothing else wakes it sooner
12/// (a check to send, a retransmission, a transaction that times out).
13pub(crate) const DEFAULT_CHECK_INTERVAL: Duration = Duration::from_millis(200);
14
15/// Ta, the pacing timer of connectivity checks (RFC 8445 Section 14.2: "ICE agents SHOULD use a
16/// default Ta value, 50 ms").
17pub(crate) const DEFAULT_TA: Duration = Duration::from_millis(50);
18
19/// RFC 8445 Section 14.2: "regardless of the Ta value chosen for each agent, the combination of
20/// all transactions from all agents (if a given implementation runs several concurrent agents)
21/// will not be sent more often than once every 5 ms".
22pub(crate) const MIN_TA: Duration = Duration::from_millis(5);
23
24/// RFC 8445 Section 14.3: "RTO = MAX (500ms, Ta * N * (Num-Waiting + Num-In-Progress))", and
25/// the RTO is never under 500 ms.
26pub(crate) const MIN_RTO: Duration = Duration::from_millis(500);
27
28/// Rm of RFC 8489 Section 6.2.1: after the last request of a transaction the agent waits
29/// Rm times the RTO for a response.
30pub(crate) const STUN_RM: u32 = 16;
31
32/// Ti of RFC 8489 Section 6.2.2: how long a transaction over a reliable transport (TCP) waits
33/// for its response; such a request is never retransmitted (RFC 6544 Section 7.1).
34pub(crate) const STUN_TI: Duration = Duration::from_millis(39_500);
35
36/// RFC 8445 Section 6.1.2.5: "The limit MUST default to 100" candidate pairs.
37pub(crate) const DEFAULT_MAX_CANDIDATE_PAIRS: usize = 100;
38
39/// Most local peer-reflexive candidates learned from the mapped addresses of responses.
40pub(crate) const MAX_LOCAL_PEER_REFLEXIVE_CANDIDATES: usize = 16;
41
42/// The basic period of the consent checks on the selected pair (RFC 7675 Section 5.1:
43/// "Implementations SHOULD set a default interval of 5 seconds, resulting in a period between
44/// checks of 4 to 6 seconds"). Also the smallest period that can be configured.
45pub(crate) const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(5);
46
47/// RFC 7675 Section 5.1: "Implementations MUST NOT set the period between checks to less than 4
48/// seconds."
49pub(crate) const MIN_CONSENT_INTERVAL: Duration = Duration::from_secs(4);
50
51/// RFC 8445 Section 11: "Tr SHOULD be configurable and SHOULD have a default of 15 seconds",
52/// and never less. A full agent's consent checks are its keepalives and come sooner; this is
53/// how long a lite agent stays silent on its selected pair before a Binding indication.
54pub(crate) const KEEPALIVE_TR: Duration = Duration::from_secs(15);
55
56/// RFC 7675 Section 5.1: "Consent expires after 30 seconds."
57pub(crate) const CONSENT_EXPIRY: Duration = Duration::from_secs(30);
58
59/// The default time till an Agent transitions disconnected.
60pub(crate) const DEFAULT_DISCONNECTED_TIMEOUT: Duration = Duration::from_secs(5);
61
62/// The default time till an Agent transitions to failed after disconnected.
63pub(crate) const DEFAULT_FAILED_TIMEOUT: Duration = Duration::from_secs(25);
64
65/// Wait time before nominating a host candidate.
66pub(crate) const DEFAULT_HOST_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_secs(0);
67
68/// Wait time before nominating a srflx candidate.
69pub(crate) const DEFAULT_SRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(500);
70
71/// Wait time before nominating a prflx candidate.
72pub(crate) const DEFAULT_PRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(1000);
73
74/// Wait time before nominating a relay candidate.
75pub(crate) const DEFAULT_RELAY_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(2000);
76
77/// Rc of RFC 8489 Section 6.2.1: the requests of one STUN transaction (the first and its
78/// retransmissions) before the pair is considered failed. "Rc SHOULD be configurable and SHOULD
79/// have a default of 7."
80pub(crate) const DEFAULT_MAX_BINDING_REQUESTS: u16 = 7;
81
82/// The number of bytes that can be buffered before we start to error.
83pub(crate) const MAX_BUFFER_SIZE: usize = 1000 * 1000; // 1MB
84
85/// The most open transactions the agent tracks beyond one per candidate pair: consent requests
86/// and cancelled transactions still waiting out their timeout. Past it the oldest of those is
87/// forgotten (its response, if it ever arrives, is then ignored). Consent requests alone stay
88/// far under it: they are at least 4 seconds apart and none is kept past the consent expiry
89/// (30 seconds) with [`ConsentResponseWait::Rto`], or past the fixed wait otherwise.
90pub(crate) const MAX_PENDING_BINDING_REQUESTS: usize = 50;
91
92impl AgentConfig {
93    /// Builds the 1:1 NAT mapper and checks it can take effect: a `Host` mapping cannot be used
94    /// with mDNS host names (the address would be hidden anyway) and needs host candidates, a
95    /// `ServerReflexive` one needs server-reflexive candidates.
96    pub(crate) fn init_ext_ip_mapping(
97        &self,
98        mdns_mode: MulticastDnsMode,
99        candidate_types: &[CandidateType],
100    ) -> Result<Option<ExternalIpMapper>> {
101        let Some(ext_ip_mapper) =
102            ExternalIpMapper::new(self.nat_1to1_ip_candidate_type, &self.nat_1to1_ips)?
103        else {
104            return Ok(None);
105        };
106        if ext_ip_mapper.candidate_type == CandidateType::Host {
107            if mdns_mode == MulticastDnsMode::QueryAndGather {
108                return Err(Error::ErrMulticastDnsWithNat1to1IpMapping);
109            }
110            if !candidate_types.contains(&CandidateType::Host) {
111                return Err(Error::ErrIneffectiveNat1to1IpMappingHost);
112            }
113        } else if ext_ip_mapper.candidate_type == CandidateType::ServerReflexive
114            && !candidate_types.contains(&CandidateType::ServerReflexive)
115        {
116            return Err(Error::ErrIneffectiveNat1to1IpMappingSrflx);
117        }
118        Ok(Some(ext_ip_mapper))
119    }
120}
121
122/// Which nomination a controlled agent uses when the controlling agent makes more than one.
123#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
124#[non_exhaustive]
125pub enum NominationAcceptance {
126    /// RFC 8445 Section 8.1.1: "If more than one candidate pair is nominated by the
127    /// controlling agent, and if the controlled agent accepts multiple nominations requests,
128    /// the agents MUST produce the selected pairs and use the pairs with the highest
129    /// priority." Every nomination is accepted; the selected pair is the nominated valid pair
130    /// with the highest priority. A nominated pair of lower priority takes over only when
131    /// consent is lost on the selected one (RFC 7675: that pair may no longer be sent on).
132    #[default]
133    HighestPriority,
134    /// libwebrtc's behaviour: the latest nomination wins, and with the `NOMINATION` attribute
135    /// (libwebrtc's renomination) the highest value does. libwebrtc moves a session to another
136    /// pair after it connected by nominating that pair, whatever its priority.
137    Latest,
138}
139
140/// A pacing budget several agents share (RFC 8445 Section 14.2: "all agents together send
141/// no more than one transaction per 5 ms" — the "global" Ta of an implementation that runs
142/// several agents). Give the same `Arc` to every agent (through
143/// [`AgentConfig::pacing_group`] or the peer connection's
144/// `SettingEngineBuilder::with_ice_pacing_group`): each starts a connectivity check only when
145/// none of them has started one in the last 5 ms, on top of its own Ta. An agent without a
146/// group paces alone, by its Ta.
147#[derive(Debug, Default)]
148pub struct PacingGroup {
149    next: std::sync::Mutex<Option<std::time::Instant>>,
150}
151
152impl PacingGroup {
153    /// A new budget, shared by every agent given it.
154    pub fn new() -> std::sync::Arc<Self> {
155        std::sync::Arc::new(Self::default())
156    }
157
158    /// Takes the budget at `now` if it is free: `Ok(())`, or `Err(at)` with when it next is.
159    pub(crate) fn take(
160        &self,
161        now: std::time::Instant,
162    ) -> std::result::Result<(), std::time::Instant> {
163        let mut next = self
164            .next
165            .lock()
166            .unwrap_or_else(|poisoned| poisoned.into_inner());
167        match *next {
168            Some(at) if at > now => Err(at),
169            _ => {
170                *next = Some(now + MIN_TA);
171                Ok(())
172            }
173        }
174    }
175}
176
177/// How long a consent request (RFC 7675) waits for its response: how long its transaction is
178/// in progress, so that a matching, authenticated success response still renews consent (RFC
179/// 8489 Section 6.3: a response is processed when "the transaction ID matches a transaction
180/// that is still in progress"). A consent request is sent once; a response to an earlier one
181/// than the latest counts as well (RFC 7675 Section 5.1: "a response might be for a previous
182/// request (rather than for the most recently sent request)").
183///
184/// Whatever the wait, consent expires 30 seconds after the last response that renewed it, and
185/// every open consent transaction is discarded then.
186#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
187#[non_exhaustive]
188pub enum ConsentResponseWait {
189    /// RFC 7675 Section 5.1 (the default): "An endpoint SHOULD await a binding response for
190    /// each request it sends for a time based on the estimated round-trip time (RTT) (see
191    /// Section 7.2.1 of [RFC5389]) with an allowance for variation in network delay." The
192    /// wait is what RFC 8489 Section 6.2.1 gives a transaction after its last request, `Rm`
193    /// (16) times the RTO, the RTO being the pair's (RFC 6298: the smoothed round-trip time
194    /// plus four times its variation, 500 ms at least, from every request that was answered
195    /// without having been retransmitted): 8 seconds at least, and never longer than the
196    /// consent expiry.
197    #[default]
198    Rto,
199    /// A fixed time, whatever the round-trip time is. libwebrtc's is 60 seconds.
200    Fixed(Duration),
201}
202
203/// What an agent does when a nomination fails (RFC 8445 Section 7.2.5.2): the controlling
204/// agent's check with USE-CANDIDATE on a valid pair, or the controlled agent's check that a
205/// received USE-CANDIDATE triggered (Section 7.3.1.5). The check fails when its transaction times out (`Rc` requests, the
206/// last given `Rm` times the RTO, Section 14.3 and RFC 8489 Section 6.2.1: 39.5 seconds at an
207/// RTO of 500 ms), it is answered with an unrecoverable error response, or the response is
208/// not symmetric.
209#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
210#[non_exhaustive]
211pub enum FailedNomination {
212    /// RFC 8445 Section 7.2.5.3.4 (the default), for both roles: "If the request fails
213    /// (Section 7.2.5.2), the agent MUST remove the candidate pair from the valid list, set
214    /// the candidate pair state to Failed, and set the checklist state to Failed", and for
215    /// the controlled agent "If the triggered request fails, [...] set the checklist state to
216    /// Failed". The agent fails; the peer may stay connected until its consent expires (RFC
217    /// 7675).
218    #[default]
219    FailChecklist,
220    /// The pair stays valid (it has received a success response, RFC 8445 Section
221    /// 7.2.5.3.3) and a nomination that times out is sent again, for as long as the peer is
222    /// heard from on it (an authenticated request or response less than the consent expiry,
223    /// 30 seconds, ago). Once the peer has not been heard from for that long, or the
224    /// nomination is answered with an error or from the wrong address, the pair fails and
225    /// the next valid pair is nominated; with none left the checklist fails. Under heavy
226    /// loss every request of a transaction, or every response, can be lost while the peer is
227    /// there and has accepted the nomination: this keeps both sides connected then. A
228    /// controlled agent whose triggered check fails fails that pair only: the checklist keeps
229    /// running, and the controlling agent may nominate another pair.
230    Retry,
231}
232
233/// What the agent does with a Binding request that fails the short-term credential check.
234#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
235#[non_exhaustive]
236pub enum UnauthenticatedRequests {
237    /// RFC 8489 Section 9.1.3 (which RFC 8445 Section 7.3 makes the ICE procedure): a request
238    /// without MESSAGE-INTEGRITY or USERNAME is answered 400 (Bad Request), one with an
239    /// unknown username or a wrong MESSAGE-INTEGRITY 401 (Unauthenticated). The error
240    /// responses are rate limited (a token bucket of
241    /// [`MAX_UNAUTHENTICATED_RESPONSE_BURST`] responses, one more every
242    /// [`UNAUTHENTICATED_RESPONSE_INTERVAL`]), each is smaller than the request it answers,
243    /// and past the limit the request is dropped: the agent cannot be made to reflect traffic
244    /// at a spoofed source.
245    #[default]
246    Reject,
247    /// Such a request is dropped without an answer (what this crate did before, and what
248    /// libwebrtc does for a request whose username is not for it).
249    Drop,
250}
251
252/// The error responses to unauthenticated requests the agent may send in a burst.
253pub const MAX_UNAUTHENTICATED_RESPONSE_BURST: u32 = 5;
254
255/// How often the agent may send one more error response to an unauthenticated request.
256pub const UNAUTHENTICATED_RESPONSE_INTERVAL: Duration = Duration::from_millis(200);
257
258pub(crate) fn default_candidate_types() -> Vec<CandidateType> {
259    vec![
260        CandidateType::Host,
261        CandidateType::ServerReflexive,
262        CandidateType::Relay,
263    ]
264}
265
266/// Collects the arguments to `ice::Agent` construction into a single structure, for
267/// future-proofness of the interface.
268#[derive(Default)]
269pub struct AgentConfig {
270    /// The STUN and TURN servers to gather reflexive and relay candidates from.
271    pub urls: Vec<Url>,
272
273    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
274    /// 128 bits of random number generator output used to generate the password, and at least 24
275    /// bits of output to generate the username fragment.
276    pub local_ufrag: String,
277    /// It is used to perform connectivity checks. The values MUST be unguessable, with at least
278    /// 128 bits of random number generator output used to generate the password, and at least 24
279    /// bits of output to generate the username fragment.
280    pub local_pwd: String,
281
282    /// Controls mDNS query timeout
283    /// If the duration is 0, we will never go to failed.
284    pub multicast_dns_query_timeout: Option<Duration>,
285
286    /// Controls mDNS behavior for the ICE agent.
287    pub multicast_dns_mode: MulticastDnsMode,
288
289    /// Controls the local name for this agent. If none is specified a random one will be generated.
290    pub multicast_dns_local_name: String,
291
292    /// Control mDNS local IP address
293    pub multicast_dns_local_ip: Option<IpAddr>,
294
295    /// How long a consent request on the selected pair may go unanswered before the agent is
296    /// `Disconnected` (a lite agent: how long without an authenticated request from the peer).
297    /// Defaults to 5 seconds when this property is nil.
298    /// If the duration is 0, the ICE Agent will never go to disconnected.
299    pub disconnected_timeout: Option<Duration>,
300
301    /// With `disconnected_timeout`, how long the agent goes without the peer's consent before
302    /// it is `Failed`, and how long it may stay `Checking`. Defaults to 25 seconds when this
303    /// property is nil. If the duration is 0, a checking agent never goes to failed.
304    ///
305    /// A connected full agent fails 30 seconds after the last consent response at the latest,
306    /// whatever is configured here, a zero included: RFC 7675 Section 5.1 forbids sending
307    /// without consent for longer. A shorter sum fails it sooner.
308    pub failed_timeout: Option<Duration>,
309
310    /// The basic period of the consent checks on the selected pair (RFC 7675), which are also
311    /// the keepalives of RFC 8445 Section 11. Each interval is drawn from 0.8 to 1.2 times
312    /// this. Defaults to 5 seconds when this is nil, and a shorter period is raised to 5
313    /// seconds: RFC 7675 forbids less than 4 seconds between two checks.
314    /// A keepalive interval of 0 means we never send keepalive packets (and consent then
315    /// expires 30 seconds after the pair was validated).
316    pub keepalive_interval: Option<Duration>,
317
318    /// An optional configuration for disabling or enabling support for specific candidate types.
319    pub candidate_types: Vec<CandidateType>,
320
321    /// An optional configuration for disabling or enabling support for specific network types.
322    /// If empty, all network types are supported.
323    pub network_types: Vec<NetworkType>,
324
325    /// Controls how often our internal task loop runs when in the connecting state and nothing
326    /// is due sooner. Only useful for testing.
327    pub check_interval: Duration,
328
329    /// Ta, the pacing of connectivity checks: one check is started per Ta (RFC 8445 Section
330    /// 6.1.4.2). 50 ms when nil; never under 5 ms (Section 14.2).
331    pub ta: Option<Duration>,
332
333    /// The most candidate pairs the checklist holds (RFC 8445 Section 6.1.2.5). 100 when nil.
334    /// When it is full a new pair replaces a Failed one, else a lower-priority one that has
335    /// not been checked yet, else it is dropped.
336    pub max_candidate_pairs: Option<usize>,
337
338    /// The requests of one connectivity-check transaction, the first and its retransmissions
339    /// (Rc of RFC 8489 Section 6.2.1; 7 when nil). They go out RTO, 2 RTO, 4 RTO, ... apart
340    /// (RTO is at least 500 ms), and the pair fails 16 RTO after the last one. Over TCP a
341    /// request is sent once.
342    pub max_binding_requests: Option<u16>,
343
344    /// Whether this agent takes the controlling role.
345    pub is_controlling: bool,
346
347    /// lite agents do not perform connectivity check and only provide host candidates.
348    pub lite: bool,
349
350    /// webrtc-extensions 7 `icecandidatepairnominate`, cancelable: when true, a controlling
351    /// agent that has picked a pair to nominate proposes it first
352    /// ([`Event::CandidatePairNominationProposed`](crate::agent::Event)) and waits for
353    /// [`Agent::resolve_nomination_proposal`](crate::agent::Agent::resolve_nomination_proposal);
354    /// a declined pair is not nominated, and the agent keeps checking. False (the default):
355    /// the agent nominates at once, as for an event nobody cancels.
356    pub candidate_pair_proposals: bool,
357
358    /// Specify a minimum wait time before selecting host candidates.
359    pub host_acceptance_min_wait: Option<Duration>,
360    /// Specify a minimum wait time before selecting srflx candidates.
361    pub srflx_acceptance_min_wait: Option<Duration>,
362    /// Specify a minimum wait time before selecting prflx candidates.
363    pub prflx_acceptance_min_wait: Option<Duration>,
364    /// Specify a minimum wait time before selecting relay candidates.
365    pub relay_acceptance_min_wait: Option<Duration>,
366
367    /// Controls if self-signed certificates are accepted when connecting to TURN servers via TLS or
368    /// DTLS.
369    pub insecure_skip_verify: bool,
370
371    /// External addresses a 1:1 NAT gives this host (a cloud instance's public IP), each
372    /// `"<external ip>"` or `"<external ip>/<local ip>"`. The host candidates the application
373    /// adds are advertised with them, as `nat_1to1_ip_candidate_type` says. Empty: no mapping.
374    pub nat_1to1_ips: Vec<String>,
375
376    /// How `nat_1to1_ips` are advertised: [`CandidateType::Host`] (the default, also for
377    /// `Unspecified`) replaces a mapped host candidate's address with the external one;
378    /// [`CandidateType::ServerReflexive`] adds a server-reflexive candidate on the external
379    /// address beside it. Any other type is refused by [`Agent::new`](crate::Agent::new).
380    pub nat_1to1_ip_candidate_type: CandidateType,
381
382    /// Lets connectivity checks go to a loopback remote address (`127.0.0.0/8`, `::1`) from a
383    /// local candidate that is not itself on loopback. Off by default: a loopback remote
384    /// candidate is then paired only with a loopback local candidate, so a peer cannot make
385    /// this host send checks to its own services. See the [`remote_policy`] module.
386    pub allow_loopback_remote_candidates: bool,
387
388    /// Lets connectivity checks go to a link-local remote address (`169.254.0.0/16`,
389    /// `fe80::/10`) from a local candidate that is not itself link-local. Off by default.
390    pub allow_link_local_remote_candidates: bool,
391
392    /// Asked about every remote candidate's address (an mDNS candidate's once resolved) before
393    /// the agent holds it; `false` drops the candidate. Addresses that are never a valid unicast
394    /// destination (unspecified, multicast, broadcast, port 0) are dropped before it is asked.
395    pub remote_address_filter: Option<RemoteAddressFilter>,
396
397    /// The embedder's address policy, for both directions: remote candidates (an mDNS one's
398    /// resolved address) and peer-reflexive sources it refuses are never held or paired, and a
399    /// datagram from a source it refuses is dropped before the agent reads it (no response, no
400    /// candidate, no consent, no data accepted). The default allows everything. See
401    /// [`IceAddressPolicy`].
402    pub address_policy: IceAddressPolicy,
403
404    /// The tiebreaker of RFC 8445 Section 5.2 ("a random number between 0 and 2**64 - 1",
405    /// drawn when nil). A fixed one makes the outcome of a role conflict reproducible; the
406    /// agent still draws a new one when a 487 (Role Conflict) tells it to (Section 7.2.5.1).
407    pub tie_breaker: Option<u64>,
408
409    /// Whether an ICE restart draws a new tiebreaker (RFC 8445 Section 16.1: "The agent MAY
410    /// change the number when an ICE restart occurs"). Off by default: the tiebreaker stays
411    /// for the agent's life, as libwebrtc keeps it; a fixed [`AgentConfig::tie_breaker`] is
412    /// replaced at the first restart when this is on.
413    pub new_tie_breaker_on_restart: bool,
414
415    /// Which of several nominations a controlled agent uses. The default is RFC 8445's rule
416    /// (the nominated pair with the highest priority); [`NominationAcceptance::Latest`] is
417    /// libwebrtc's.
418    pub nomination_acceptance: NominationAcceptance,
419
420    /// What the controlling agent does when its nomination fails:
421    /// [`FailedNomination::FailChecklist`] (the default) is RFC 8445 Section 7.2.5.3.4, the
422    /// pair and the checklist fail; [`FailedNomination::Retry`] nominates the pair again
423    /// while the peer is heard from.
424    pub failed_nomination: FailedNomination,
425
426    /// A pacing budget shared with other agents (RFC 8445 Section 14.2), if the application
427    /// runs several: see [`PacingGroup`]. `None`, the default, paces this agent alone.
428    pub pacing_group: Option<std::sync::Arc<PacingGroup>>,
429
430    /// The controlling agent's consent checks on the selected pair carry USE-CANDIDATE, as
431    /// libwebrtc's do. Off by default: RFC 8445 Section 7.1.2 asks for the attribute "in order
432    /// to nominate a candidate pair", which is done once (Section 8.1.1), and RFC 7675 asks
433    /// for nothing more than a Binding request. The agent repeats its nomination by itself
434    /// where the peer has shown that it lost it (a role conflict the agent wins after it
435    /// nominated).
436    pub nominate_on_consent_checks: bool,
437
438    /// How long a consent request waits for its response: see [`ConsentResponseWait`].
439    pub consent_response_wait: ConsentResponseWait,
440
441    /// What a Binding request that fails authentication gets: an error response (RFC 8489
442    /// Section 9.1.3, rate limited; the default) or nothing.
443    pub unauthenticated_requests: UnauthenticatedRequests,
444
445    /// Accept data (DTLS, SRTP) only from the selected pair's remote address. Off by default:
446    /// RFC 8445 Section 12.2 says an agent "SHOULD by default be prepared to receive data on
447    /// any of the candidates provided in the most recent candidate exchange", and the agent
448    /// accepts it from the remote candidate of any valid pair (a pair one of its own checks
449    /// succeeded on). See [`Agent::accepts_data`].
450    pub data_from_selected_pair_only: bool,
451
452    /// Whether the first mDNS query for a remote `.local` candidate waits a random 20 to 120
453    /// ms (RFC 6762 Section 5.2: every participant of a call is told of the name at the same
454    /// moment). `None` is on, as the RFC recommends; `Some(false)` sends it from the
455    /// `handle_timeout` that follows the candidate.
456    pub multicast_dns_first_query_delay: Option<bool>,
457
458    /// Whether the agent's mDNS answers to a query of more than one question (an A and an
459    /// AAAA question for its name, as browsers ask) wait a random 20 to 120 ms (RFC 6762
460    /// Section 6.3). `None` is on, as the RFC recommends; `Some(false)` answers a query about
461    /// its own names only at once.
462    pub multicast_dns_multi_question_delay: Option<bool>,
463
464    /// The driver hands every mDNS datagram to `handle_read` with the datagram's destination
465    /// in `local_addr` (from `IP_PKTINFO` / `IPV6_PKTINFO`): `224.0.0.251:5353` or
466    /// `[ff02::fb]:5353` for one that arrived on the group, the host's own address for one
467    /// sent to it by unicast. The mDNS connection then holds a unicast arrival to the rules
468    /// RFC 6762 has for it (Sections 5.5 and 6). Off by default: a socket's bound address
469    /// says nothing about how a datagram reached it.
470    pub multicast_dns_destination_reported: bool,
471
472    /// The first query for a name asks for a unicast response (the QU bit, RFC 6762 Section
473    /// 5.4, which draft-ietf-mmusic-mdns-ice-candidates Section 3.2.1 suggests). Off by
474    /// default: a unicast response reaches one socket on port 5353 only (RFC 6762 Section
475    /// 15.1), so beside a system responder the answer can be lost. Turn it on, with
476    /// `multicast_dns_destination_reported`, when the application's socket is the only one.
477    pub multicast_dns_unicast_response: bool,
478
479    /// The limit on the mDNS messages sent, to share between every agent of a process
480    /// (draft-ietf-mmusic-mdns-ice-candidates Section 7.1: the limit is the implementation's,
481    /// not one agent's): give each agent a clone of one [`mdns::MdnsRateLimit`]. `None`: a
482    /// limit of this agent's own (40 messages at once, 10 a second). The crate keeps no
483    /// process-wide state of its own, so it cannot share one unasked.
484    pub multicast_dns_rate_limit: Option<mdns::MdnsRateLimit>,
485
486    /// `QueryAndGather`: what a host candidate becomes when the name of its address cannot be
487    /// registered (no mDNS for its address family, [`MulticastDnsPublishing`]; or the
488    /// responder holds the most names it can, 64). Off, the default: the candidate is provided
489    /// under a `<uuid>.local` name that is not published, so neither its address nor the
490    /// failure shows (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.1: "the ICE agent
491    /// SHOULD still provide mDNS candidates in step 6 even if the local network does not
492    /// support mDNS or mDNS registration fails in step 4"). On: the agent provides no host
493    /// candidate for that address at all (UDP and TCP), as an embedder that must never offer
494    /// a candidate the peer cannot resolve may want; its server-reflexive and relayed
495    /// candidates are still gathered from it. A page that sees host candidates appear or
496    /// not learns whether mDNS works on the host, which is what the draft's form avoids.
497    pub multicast_dns_fail_closed: bool,
498
499    /// `QueryAndGather`: leave unwrapped a host address that the gathering before the current
500    /// ICE generation showed to be public (draft-ietf-mmusic-mdns-ice-candidates Section
501    /// 3.1.2.2: "once an address has been identified as public, the ICE agent MAY cache this
502    /// information and skip mDNS protection for that address in future ICE gathering
503    /// phases"). Off by default, in every behaviour profile; no effect in the other modes.
504    ///
505    /// An address is shown public when the application adds a server-reflexive candidate
506    /// whose address is its base's ("If the STUN response returns the same value as the local
507    /// IP address, this indicates the address is in fact public") and that base is the
508    /// address of a host candidate this agent holds: a STUN server cannot make the agent
509    /// unwrap an address it does not have. It is never one [`crate::mdns::is_global_unicast`]
510    /// refuses. The gathering that shows it is not changed: its mDNS candidate has been
511    /// provided already, and the server-reflexive candidate on the same address follows it
512    /// as Section 3.1.2.2 describes (raddr `0.0.0.0` / `::`, rport 9). From the next ICE
513    /// restart on, host candidates on that address go out with the address itself, while
514    /// each restart's own gathering shows it again; the knowledge is the agent's alone (no
515    /// process-wide cache) and is dropped by [`crate::Agent::set_ice_servers`] when the set
516    /// of STUN / TURN servers changes.
517    ///
518    /// What it exposes, and to whom: the address is already the server-reflexive candidate's,
519    /// which the remote peer and the application (a web page, in a browser) received in the
520    /// earlier generation; what the later host candidates add is that the address is the
521    /// host's own interface (type `host`, no NAT), the same thing an equal port already
522    /// suggested.
523    pub multicast_dns_expose_known_public_addresses: bool,
524
525    /// `QueryAndGather`: leave unwrapped a host address the application marked as an RFC 4941
526    /// temporary IPv6 address ([`crate::Agent::set_temporary_ipv6_addresses`])
527    /// (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.2.3: "implementations MAY choose to
528    /// not conceal [RFC4941] addresses with mDNS names as a tradeoff for improved
529    /// peer-to-peer connectivity"). Off by default, in every behaviour profile; no effect in
530    /// the other modes. The engine cannot tell a temporary address from a stable one by its
531    /// bits: only an address the application marked is unwrapped, and never one
532    /// [`crate::mdns::is_global_unicast`] refuses. An address not marked stays hidden.
533    ///
534    /// What it exposes, and to whom: the temporary address itself, to the remote peer and to
535    /// the application (a web page, in a browser), for as long as the operating system keeps
536    /// it (a day of preferred lifetime by default on most systems); not the host's stable
537    /// address, nor the private IPv4 ones.
538    pub multicast_dns_expose_temporary_ipv6_addresses: bool,
539
540    /// Whether the application can send mDNS for each address family (both by default); see
541    /// [`MulticastDnsPublishing`] and [`Agent::set_multicast_dns_publishing`](crate::Agent::set_multicast_dns_publishing).
542    pub multicast_dns_publishing: MulticastDnsPublishing,
543
544    /// Send data on the best valid pair before a pair is selected (RFC 8445 Section 12.1: "An
545    /// ICE agent MAY send data on any valid pair before selected pairs have been produced").
546    /// Off by default: data is sent once a pair is selected.
547    pub send_data_before_nomination: bool,
548
549    /// [`Agent::add_local_candidate`](crate::agent::Agent::add_local_candidate) holds the
550    /// candidate as [`Agent::add_unconveyed_local_candidate`](crate::agent::Agent::add_unconveyed_local_candidate)
551    /// does: unpaired until the caller says it has been conveyed to the peer (RFC 8838
552    /// Section 10). Off by default: a caller of `add_local_candidate` conveys the candidate
553    /// with that call. A driver that hands candidates to an application to trickle (the peer
554    /// connection does) turns it on.
555    pub hold_local_candidates_until_conveyed: bool,
556
557    /// The path MTU in bytes, when the application knows it. RFC 8489 Section 6.1: a STUN
558    /// message over UDP fits it; `None` assumes 576 bytes for IPv4 and 1280 for IPv6, the
559    /// RFC's figures when it is not known. A check that would not fit is not sent and its pair
560    /// fails; no other STUN message larger than that is sent over UDP.
561    pub path_mtu: Option<usize>,
562
563    /// The SOFTWARE attribute of the agent's connectivity checks and of its success responses
564    /// to the peer's (RFC 8489 Sections 6.1, 6.3.1.1: requests and responses "SHOULD" carry
565    /// one; Section 16.1.2: its use "SHOULD" be configurable). `None`: `rtci-ice` and its
566    /// version. `Some("")`: none, for an application that would not tell its software to the
567    /// path (Section 16.1.2).
568    pub software: Option<String>,
569}