Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

Represents the ICE agent.

Implementations§

Source§

impl Agent

Source

pub fn checklist_state(&self) -> ChecklistState

The state of the checklist, in RFC 8445’s terms: Running until a pair is nominated, Completed from then on, Failed when the agent is.

Agent::state is the W3C transport state, which is Connected once a pair is nominated and Completed only when, in addition, both sides have said they have no more candidates.

Source

pub fn handle_transport_error( &mut self, now: Instant, transport: TransportContext, error: TransportError, ) -> bool

What the transport learned about the path transport (its local address the base of a local candidate, its peer address a remote candidate):

  • TransportError::IcmpHardError, RFC 8445 Section 7.2.5.2.2: “if a Binding request generates a hard ICMP error, the agent SHOULD set the state of the candidate pair to Failed”. Only a pair whose check is in flight fails, and never a valid one: an ICMP error is not authenticated (“ICMP errors can be used as a method for Denial-of-Service attacks”), so it cannot take away a pair a check has validated. Consent decides for those.
  • TransportError::ConnectionFailed, RFC 6544 Section 7.1: “If the TCP connection cannot be established, the check is considered to have failed, and a full-mode agent MUST update the pair state to Failed”. The pair fails whether or not its check has started; a valid pair is left to consent, as above.
  • TransportError::NotStun, RFC 6544 Section 7.1: “If the response to the first connectivity check on the established TCP connection is something other than a STUN message, the remote candidate address apparently was not one of the peer’s addresses, and the agent SHOULD close the connection and consider all pairs with that remote candidate as failed.” Every pair with that remote candidate that is not valid fails; closing the connection is the caller’s.

Returns whether a pair failed.

Source

pub fn handle_non_stun_before_validation( &mut self, now: Instant, transport: TransportContext, ) -> bool

Something other than STUN arrived over TCP on transport, on no valid pair: what a driver that demultiplexes the connection itself (the peer connection does) calls instead of deciding on TransportError::NotStun on its own.

RFC 6544 Section 7.1 concludes from “the response to the first connectivity check on the established TCP connection”. Only on a connection this agent opened (its local candidate is active) are the peer’s first bytes that response: the agent sends its check as soon as the connection is up, and the peer has nothing to send before it. On a connection the peer opened (a passive local candidate) the peer may send DTLS before it answers this agent’s triggered check, so nothing is concluded there. Returns whether a pair failed; closing the connection is the caller’s.

Source§

impl Agent

Source

pub fn get_candidate_pairs_stats(&self, now: Instant) -> Vec<CandidatePairStats>

Returns a list of candidate pair stats.

Source

pub fn get_local_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>

Returns a list of local candidates stats.

Source

pub fn get_remote_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>

Returns a list of remote candidates stats.

Source§

impl Agent

Source

pub fn apply_restart_revertible( &mut self, now: Instant, keep_local_candidates: bool, ) -> Result<()>

Agent::apply_restart, remembering the session it replaces so that Agent::revert_restart can bring it back: the restart belongs to a local offer that may still be rolled back (RFC 9429 section 5.7: “any resources allocated by the abandoned local description are discarded”). A second restart before the first is committed keeps the session the first one replaced.

Source

pub fn has_revertible_restart(&self) -> bool

Whether a restart applied by Agent::apply_restart_revertible can still be taken back.

Source

pub fn commit_restart(&mut self)

Keeps the restart Agent::apply_restart_revertible applied: the answer to its offer arrived. A no-op without one.

Source

pub fn revert_restart(&mut self, now: Instant) -> bool

Takes back the restart Agent::apply_restart_revertible applied: the local offer was rolled back, so the agent goes on with the session it had (RFC 9429 section 5.7), its credentials, candidates, pairs and selected pair, and what the new generation gathered or learned is dropped. Consent on the selected pair carries over what the previous-generation checks of the meantime established (RFC 7675). Returns whether there was a restart to take back; a closed agent stays closed.

Source§

impl Agent

Source

pub fn new( now: Instant, config: Arc<AgentConfig>, crypto_provider: Arc<dyn RTCCryptoProvider>, ) -> Result<Self>

Creates a new Agent.

The crypto provider is supplied by the caller; this crate never resolves a default. Builds an agent whose clock starts at now.

now is a constructor argument rather than an AgentConfig field because it is a value consumed once at construction, not a setting that persists for the agent’s lifetime — and because Instant has no Default, so a config field would force AgentConfig to drop #[derive(Default)] and break every ..Default::default() in its 31 call sites.

Source

pub fn add_local_candidate(&mut self, c: Candidate) -> Result<bool>

Adds a new local candidate that the caller conveys to the peer with this call (trickles it, or writes it into the description it sends): the agent pairs it at once.

RFC 8838 Section 10: “A Trickle ICE agent MUST NOT pair a local candidate until it has been trickled to the remote party.” A caller that gathers a candidate before it can convey it adds it with Agent::add_unconveyed_local_candidate and tells the agent with Agent::local_candidate_conveyed when it has.

With AgentConfig::hold_local_candidates_until_conveyed this is Agent::add_unconveyed_local_candidate.

Source

pub fn add_unconveyed_local_candidate(&mut self, c: Candidate) -> Result<bool>

Adds a new local candidate that is not conveyed to the peer yet: the agent holds it, answers checks that reach it, and pairs it once Agent::local_candidate_conveyed (or Agent::all_local_candidates_conveyed) says it has been trickled (RFC 8838 Section 10). Otherwise as Agent::add_local_candidate; a server-reflexive candidate the agent adds next to it for a 1:1 NAT mapping is held too.

Source

pub fn local_candidate_conveyed(&mut self, id: &str) -> bool

The local candidate id has been conveyed to the peer: it is paired now with the remote candidates known (RFC 8838 Section 10, steps 2 and 3). Returns whether the agent held such a candidate unconveyed.

Source

pub fn all_local_candidates_conveyed(&mut self)

Every local candidate the agent holds has been conveyed to the peer (a description listing them was applied, say): each one held unconveyed is paired now.

Source

pub fn stop_for_ice_mismatch(&mut self, now: Instant) -> bool

RFC 8839 Sections 4.2.5, 4.3.3 and 5.3: the answer carries a=ice-mismatch for the data stream this agent serves (the offer arrived at the peer with a default destination that no candidate matched), so “ICE procedures MUST NOT be used for this data stream”. The agent stops: no more checks or consent requests, no candidates, state Failed. The RFC 3264 fallback the RFC then calls for (media to the m= / c= destination without checks) is not taken: a WebRTC endpoint sends nothing without consent (RFC 7675 Section 5.1), so the stream ends with the agent. Returns whether the agent was running.

Source

pub fn is_local_candidate_unconveyed(&self, id: &str) -> bool

Whether the local candidate id is held unconveyed (and so unpaired).

Source

pub fn set_temporary_ipv6_addresses(&mut self, addresses: Vec<Ipv6Addr>)

Marks the local addresses that are RFC 4941 temporary IPv6 addresses (replacing what was marked before). The operating system knows which they are, the engine cannot tell from the bits: the application (rtci-stream-driver’s PeerDriver does it from the interface list) says so before it adds their host candidates. Only with AgentConfig::multicast_dns_expose_temporary_ipv6_addresses in QueryAndGather does it change anything: host candidates added afterwards on a marked address that is a global unicast address keep the address (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.2.3). Candidates added before keep their form.

Source

pub fn set_ice_servers(&mut self, urls: Vec<Url>)

The STUN / TURN servers the application gathers with now (AgentConfig::urls at first). When the set differs from the one before (credentials aside), what gatherings showed about public addresses is discarded (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.2.2: “if the set of STUN servers changes, any cached information SHOULD be discarded, as the new set may return different results”).

Source

pub fn add_local_candidates( &mut self, candidates: Vec<Candidate>, ) -> Result<Vec<bool>>

Adds local candidates gathered together: those without a priority or a rank of their own are ranked first as RFC 8421 Section 4 recommends for a dual-stack host (an IPv6 head start, then the families alternating; see rank_local_candidates), around the ranks of the candidates the agent holds, and then each is added as by Agent::add_local_candidate, whose results are returned in order.

Source

pub fn set_multicast_dns_publishing( &mut self, publishing: MulticastDnsPublishing, )

Tells the agent for which address families the application can send mDNS (an mDNS socket is open; both by default, AgentConfig::multicast_dns_publishing). In QueryAndGather, the name of a host candidate added afterwards on an address of a family it cannot send on is not registered (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.1 step 4 fails): the candidate goes out under an unpublished name, or not at all with AgentConfig::multicast_dns_fail_closed. Names registered before stay.

Source

pub fn set_multicast_dns_destination_reported(&mut self, reported: bool)

Declares, from now on, whether the application hands each mDNS datagram to handle_read with its destination address in local_addr (as AgentConfig::multicast_dns_destination_reported): the mDNS group’s for one that arrived by multicast (on the link whatever its source, RFC 6762 section 11), the host’s own for a unicast one, the unspecified address when it does not know.

Source

pub fn handle_mdns_datagram( &mut self, msg: TaggedBytesMut, destination: IpAddr, ) -> Result<()>

Feeds a datagram received on the host’s mDNS socket (local port 5353) together with the destination address of its IP header, as the driver read it (IP_PKTINFO, IPV6_PKTINFO, IP_RECVDSTADDR): 224.0.0.251 or ff02::fb for one that arrived on the group, the host’s own address for one sent to it by unicast. Otherwise as handle_read, and a datagram that is not the mDNS socket’s (its local address is a local candidate’s, or not on port 5353) is read as handle_read reads it.

With the destination known, the mDNS connection applies the RFC 6762 rules that turn on it, whatever AgentConfig::multicast_dns_destination_reported says: a query received by direct unicast is answered as a “QU” question, and only when its source is on the link (section 5.5); a unicast response is taken only for a recent question that asked for one (section 6); a response that arrived on the group is on the link whatever its source (section 11). The link is the one set_multicast_dns_on_link_subnets gives, else the scope of the source address.

Source

pub fn multicast_dns_network_changed(&mut self)

The host’s network may have changed: it woke from sleep, a link came up or changed, an address changed. The agent’s mDNS responder and resolver start over (Mdns::network_changed of rtci-mdns): the address cache is emptied (RFC 6762 section 10.3, “cache flush on topology change”), and every published name is probed for again and announced (section 8: “whenever a Multicast DNS responder starts up, wakes up from sleep, receives an indication of a network interface ‘Link Change’ event, or has any other reason to believe that its network connectivity may have changed in some relevant way, it MUST perform the two startup steps”; section 10.2: the announcements after reconnection). A no-op without mDNS.

Sets the subnets of the link the mDNS socket is on, as (address, prefix length) pairs (the driver enumerates the interfaces; the agent cannot know their prefixes). RFC 6762 section 5.5: a responder checks “that the source address in the query packet matches the local subnet for that link (or, in the case of IPv6, the source address has an on-link prefix) and silently ignore[s] the packet if not”; section 11 holds the senders of answers to the same test. Empty (the default): the scope of the source address decides (private, shared, link-local and loopback IPv4; link-local, unique-local and loopback IPv6).

Source

pub fn multicast_dns_withholds(&self, ip: IpAddr) -> bool

Whether the agent withheld the host candidates of ip because their mDNS name could not be registered (AgentConfig::multicast_dns_fail_closed). The application may still gather server-reflexive and relayed candidates from that address: they do not carry it (Section 3.1.2.2).

Source

pub fn add_remote_candidate(&mut self, c: Candidate) -> Result<bool>

Adds a new remote candidate.

Source

pub fn pending_mdns_candidates(&self) -> impl Iterator<Item = &Candidate>

The remote mDNS candidates whose names have not resolved yet. They are held by no pair, but they were submitted: statistics list them (mDNS draft Section 3.3.1).

Source

pub fn set_remote_end_of_candidates(&mut self)

The peer has no more candidates for this generation (an end-of-candidates indication, RFC 8838 Section 14). Remote candidates signalled after it are ignored, and a checking agent whose pairs have all failed (or that has none) fails without waiting for its timeout, once local gathering is complete too and the PAC timer has expired (RFC 8863: 39.5 s after checking began, with the defaults), unless a check from the peer may still form a pair (a tcptype active candidate of the peer that dials ours, a .local name not resolved): then its timeout ends it. With local gathering complete it is also the indication W3C webrtc-pc 5.6.4 makes “failed” and “completed” wait for (see Agent::set_failed_without_end_of_candidates). An ICE restart starts a new generation.

Source

pub fn discard_gathering(&mut self)

RFC 9429 Section 5.7: the local description that began this agent’s gathering was rolled back before any answer (“Any resources or candidates that were allocated by the abandoned local description are discarded”). Its local candidates go, with the pairs and what the checks taught; the credentials stay; local gathering starts again with the candidates added next.

Source

pub fn set_local_gathering_complete(&mut self)

Local gathering is complete for this generation (RFC 8838 Section 13): no local candidate is accepted after it. An ICE restart starts a new generation.

Source

pub fn set_remote_trickles(&mut self, trickles: bool)

Whether the peer’s description says it can trickle candidates (a=ice-options:trickle, RFC 9429 Sections 4.1.17 and 5.10), true until told otherwise. A peer that cannot trickle gave all its candidates in its description: W3C webrtc-pc 5.6.4 counts canTrickleIceCandidates false as the indication that there are no more remote candidates, which “failed” and “completed” need. (Candidates signalled later are still taken: only an end-of-candidates indication makes the agent ignore them, RFC 8838 Section 14.)

Source

pub fn set_failed_without_end_of_candidates(&mut self, enabled: bool)

Whether the agent reports Failed without the indications W3C webrtc-pc 5.6.4 makes “failed” wait for, once the PAC timer (RFC 8863) has expired. Off by default.

By default (off) the transport is “failed” only when it “has finished gathering, received an indication that there are no more remote candidates, finished checking all candidate pairs, and all pairs have either failed connectivity checks or lost consent”: local gathering complete (Agent::set_local_gathering_complete) and the peer’s end-of-candidates (Agent::set_remote_end_of_candidates) or a peer that cannot trickle (Agent::set_remote_trickles). Before that, checks that have all failed (the checking timeout, a failed nomination) or consent that expired make the agent Disconnected (“it is still gathering and/or waiting for additional remote candidates”); it fails as soon as the indications are in, checks again (Checking) when a new pair is formed, and an ICE restart starts it over. A peer that never sends its end-of-candidates leaves it Disconnected until the application restarts or closes.

On, the PAC timer serves as the end-of-candidates fallback RFC 8863 Section 5 allows (“ICE agents MAY use the PAC timer to also serve as an end-of-candidates fallback”): once it has expired (39.5 s after the checks began, with the defaults; at once for a lite agent, which has none) those events fail the agent without the indications, as libwebrtc’s transports do.

Source

pub fn failed_without_end_of_candidates(&self) -> bool

Source

pub fn is_signalled_remote_ip(&self, ip: IpAddr) -> bool

Whether this IP address is one the peer’s signalling led to: the address of a candidate it signalled, or the address a .local name it signalled has been resolved to. A peer-reflexive remote candidate’s address may be shown in statistics only then (draft-ietf-mmusic-mdns-ice-candidates Section 3.3.1: “a peer-reflexive remote candidate could be constructed from a remote host IP address as a result of an ICE connectivity check”; before the peer’s name resolves, such a candidate would reveal what the name hides). Once the agent has resolved the name itself, the address is no news; the mDNS candidate’s own entry still shows the name, never the address.

Source

pub fn get_local_candidates_to_signal(&self) -> Vec<Candidate>

The local candidates to signal to the peer: the ones the application added (with their 1:1 NAT companions), not the peer-reflexive ones the agent learned from the mapped address of a response (RFC 8445 Section 7.2.5.3.1), which need no signalling.

Source

pub fn set_remote_credentials( &mut self, remote_ufrag: String, remote_pwd: String, ) -> Result<()>

Sets the credentials of the remote agent.

Source

pub fn get_remote_credentials(&self) -> Option<&Credentials>

Returns the remote credentials.

Source

pub fn get_local_credentials(&self) -> &Credentials

Returns the local credentials. The credentials to advertise, which is what SDP generation wants.

Returns credentials staged by Agent::generate_restart_credentials when an ICE restart is pending, so an offer carries the new ufrag/pwd. Inbound STUN validation deliberately does not go through here — it reads local_credentials directly, so the live session keeps working until Agent::apply_restart installs the new pair.

Source

pub fn get_candidate_pairs(&self) -> Vec<(Candidate, Candidate)>

The candidate pairs on the agent’s list (webrtc-extensions 7 [[CandidatePairs]]): (local, remote), in the order they were formed. A pair the application removed is not listed.

Source

pub fn proposal_pending(&self) -> bool

Whether a nomination proposal waits for Self::resolve_nomination_proposal (webrtc-extensions 7 [[ProposalPending]]).

Source

pub fn resolve_nomination_proposal(&mut self, now: Instant, accept: bool)

Answers the pending nomination proposal: accept nominates the pair (a check with USE-CANDIDATE); otherwise the pair is not nominated and the agent keeps checking (webrtc-extensions 7, a cancelled icecandidatepairnominate). Nothing when no proposal is pending.

Source

pub fn select_candidate_pair( &mut self, now: Instant, local: &Candidate, remote: &Candidate, ) -> Result<()>

webrtc-extensions 7 selectCandidatePair(pair): the agent sends data on the pair of local and remote from now on; the selected pair changes, with its SelectedCandidatePairChange event, and the state with its event when it was not connected. Connectivity checks on other pairs stop, as they do once a pair is selected; consent keeps being checked on this one.

§Errors

InvalidStateError when the agent is closed, or new or failed; NotFoundError when the pair is not on the list (Self::get_candidate_pairs).

Source

pub fn remove_candidate_pair( &mut self, now: Instant, local: &Candidate, remote: &Candidate, ) -> Result<()>

webrtc-extensions 7 removeCandidatePair(pair): the agent stops the checks on the pair of local and remote (an In-Progress transaction is cancelled, no check is sent or answered on it any more, data from it is not accepted through it), then queues CandidatePairRemoved. When it was the selected pair the best other valid pair takes its place, or none: the state then follows consent as for a lost path.

§Errors

As Self::select_candidate_pair.

Source

pub fn remove_proposed_candidate_pair( &mut self, now: Instant, local: &Candidate, remote: &Candidate, ) -> Result<()>

webrtc-extensions 7, the accepted removal of a pair the agent’s freeing proposed (a cancelable icecandidatepairremove the application did not cancel): as Self::remove_candidate_pair, without a second CandidatePairRemoved (the proposal was the event).

§Errors

As Self::remove_candidate_pair.

Source

pub fn withdraw_local_candidate( &mut self, now: Instant, addr: SocketAddr, protocol: TransportProtocol, ) -> bool

Withdraws the local candidate whose transport address is addr (of protocol): no session after the current one has it, and the current one keeps of it only what carries its data. For a relayed candidate whose allocation is to be let go (its server left the configuration), which a restart that keeps the local candidates would otherwise carry into the next session. Returns whether such a candidate was there (and not withdrawn already).

What each part of the agent sees, whether or not a restart is staged (credentials generated, not applied: get_local_credentials gives the staged ones):

from the callafter the next apply_restart
the candidateheld, flagged withdrawndropped
its selected (or nominated) pair in the current sessionkept: data and consent go ongone with the session; the restart’s previous media path still runs on it
its other pairs in the current sessionremoved (as remove_candidate_pair)—
new pairs with it (remote candidates, checks that reach it)none—
get_local_candidates_to_signalwithout itwithout it
discard_restart_credentialsflag kept: the next restart drops it—
revert_restartthe session restored as it was when the restart was applied (a withdrawal made after that is undone; the engine withdraws again)—
the candidate gathered againstays withdrawn—
Source

pub fn role(&self) -> bool

Whether this agent is the controlling one, which decides nomination.

Source

pub fn set_role(&mut self, is_controlling: bool)

Sets the role, when the roles are determined (RFC 8445 Section 6.1.1): the agent that started the ICE processing is controlling, unless exactly one of the two is lite (the full one is controlling then).

“Once the roles are determined for a session, they persist throughout the lifetime of the session”: an ICE restart keeps them (the agent does, by itself), and they are determined again at a restart only when an agent changed between full and lite. A role conflict is repaired by the agent (Section 7.3.1.1).

The pairs the agent holds get the priority of the new role (Section 6.1.2.3), and a nomination that was being made is dropped: only the controlling agent nominates.

Source

pub fn tie_breaker(&self) -> u64

The tiebreaker the agent’s checks carry (RFC 8445 Section 5.2).

Source

pub fn is_lite(&self) -> bool

Whether this agent is a lite implementation.

Source

pub fn is_remote_lite(&self) -> bool

Whether the peer is a lite implementation (Agent::set_remote_lite).

Source

pub fn awaits_lite_update(&self) -> bool

Two lite agents, this one controlled, with several pairs: the controlling agent’s updated candidate exchange is still to come (RFC 8445 Section 8.2: “ICE processing is complete after and only after the updated candidate exchange is complete”), and with it the pair. A TCP connection the controlling agent opened in parallel with that exchange waits for it (RFC 6544 Section 6.1).

Source

pub fn set_remote_lite(&mut self, lite: bool)

Tells the agent whether the peer is a lite implementation (in SDP, a=ice-lite).

It matters to a lite agent: with a full peer it answers checks and waits for the nomination; with a lite peer “no connectivity checks are ever sent. Rather, once the candidates are exchanged, each agent performs the processing described in Section 8 without connectivity checks” (RFC 8445 Section 6.1.1). See Event::LiteCandidateUpdate and Agent::replace_remote_candidates.

Source

pub fn pacing(&self) -> Duration

Ta, the pacing of connectivity checks in use (RFC 8445 Section 14.2).

Source

pub fn proposed_pacing(&self) -> Option<Duration>

The Ta this agent proposes to its peer, when it is not the default of 50 ms: “If an agent wants to use a Ta value other than the default value, the agent MUST indicate the proposed value to its peer during the establishment of the ICE session” (RFC 8445 Section 14.2; in SDP, a=ice-pacing, RFC 8839 Section 5.5, in milliseconds).

Source

pub fn set_remote_pacing(&mut self, proposed: Option<Duration>)

The peer’s proposal for Ta (None: it proposed nothing, which is the default, 50 ms). “Both agents MUST use the higher out of the two proposed values” (RFC 8445 Section 14.2): from now on Ta is the larger of this agent’s own and the peer’s.

Until this is called the agent paces by its own configuration alone: it cannot know that the peer was told. An application that configures a Ta under 50 ms and never calls this is pacing faster than the peer agreed to.

Source

pub fn replace_remote_candidates( &mut self, now: Instant, candidates: Vec<Candidate>, ) -> bool

Two lite agents: replaces the remote candidates with those of an updated candidate exchange (RFC 8445 Section 8.2: “the controlling agent MUST send an updated candidate list to reconcile different agents selecting different candidate pairs. ICE processing is complete after and only after the updated candidate exchange is complete”), and selects again. Returns false, and changes nothing, unless both agents are lite.

Source

pub fn replace_remote_candidates_pinning( &mut self, now: Instant, candidates: Vec<Candidate>, local: Option<SocketAddr>, ) -> bool

Agent::replace_remote_candidates, with the local side of the pair given: RFC 8839 Section 4.4.2.2, a lite answerer offered a=remote-candidates forms the pair from the offer’s default destination and, as its local candidate, the transport address the attribute names (the controlling agent’s remote candidate is this agent’s local one). A pair with a local candidate at local is chosen over any other; None (or an address no local candidate has) leaves the choice to the RFC 6724 preference.

Source

pub fn set_candidate_types(&mut self, candidate_types: Vec<CandidateType>)

Replaces the candidate types the agent accepts as local candidates from now on (AgentConfig::candidate_types; empty means the default set).

Candidates already added stay, and so does the pair in use: a new ICE transport policy takes effect at the next gathering (RFC 9429, Section 4.1.18; W3C webrtc-pc “set the configuration”: “no action will be taken until the next gathering phase. If a script wants this to happen immediately, it should do an ICE restart”). The next ICE restart (Agent::apply_restart) drops the local candidates of a type no longer allowed, and does not keep the path in use when its local candidate is of such a type (the W3C “relay” policy: “The ICE Agent uses only media relay candidates”). A lite agent keeps host candidates only.

Source

pub fn state(&self) -> ConnectionState

The agent’s current connection state.

Source

pub fn is_valid_non_stun_traffic( &mut self, now: Instant, transport: TransportContext, ) -> bool

Whether a non-STUN datagram on transport should be accepted as media.

Guards against accepting media from an address that has not passed a connectivity check.

Source

pub fn media_path(&self) -> Option<MediaPath>

The path data (DTLS, SRTP) is sent on and accepted from: the selected pair’s, and during an ICE restart, until the restart selects a pair, the one the session had when the restart was applied, if the candidate types allowed then still allow its local candidate (Agent::set_candidate_types).

RFC 8445 Section 9: “during the restart, data can continue to be sent using existing data sessions”. Without it every packet between apply_restart and the first nomination of the new generation was dropped, on both sides, for as long as the offer/answer exchange took.

While the controlling agent’s nomination is in flight, it is the nominated pair’s. That pair is valid, so Section 12.1 allows it (“An ICE agent MAY send data on any valid pair before selected pairs have been produced for the data stream”), and it is the pair the controlled agent selected when the nomination’s first request reached it: the peer sends on it from then on (its DTLS handshake starts), and Section 12.2 asks for that data to be received (“ICE implementations SHOULD by default be prepared to receive data on any of the candidates”). Without it, while the responses to the nomination were lost, the controlling agent dropped everything the peer sent and could answer nothing: the peer’s DTLS retransmissions went unanswered and its timer backed off for nothing, so that after a few more losses at 10 % the data channel had not opened in 30 seconds.

With AgentConfig::send_data_before_nomination, and before the first pair is selected, it is the best valid pair’s (Section 12.1).

Source

pub fn retired_media_path(&self) -> Option<MediaPath>

The path an ICE restart replaced, while data on it is still taken after the restart’s pair was selected (RETIRED_MEDIA_PATH_GRACE); nothing is sent on it.

Source

pub fn accepts_data(&self, transport: TransportContext) -> bool

Whether data (anything that is not STUN: DTLS, SRTP) that arrived on transport is accepted.

RFC 8445 Section 12.2: “ICE implementations SHOULD by default be prepared to receive data on any of the candidates provided in the most recent candidate exchange with the peer”, and “an agent will be able to determine that a data stream is from the same peer as a consequence of the STUN exchange that proceeds media data transmission”. So, once there is a path to send on (Agent::media_path), data is accepted on any local candidate, from that path’s remote address and from the remote candidate of any valid pair: an address one of the agent’s own checks was answered from, by someone who holds the peer’s password. A source that only sent requests, or that no check reached, is not accepted.

With AgentConfig::data_from_selected_pair_only only the remote address of the path data is sent on is accepted.

Source

pub fn data_path(&self, transport: TransportContext) -> Option<DataPath<'_>>

As Agent::accepts_data, saying which pair the data arrived on: the one in use, or another valid pair (its local and remote candidates).

Source

pub fn get_selected_candidate_pair(&self) -> Option<(&Candidate, &Candidate)>

Returns the selected pair (local_candidate, remote_candidate) or none

Source

pub fn get_best_available_candidate_pair( &self, ) -> Option<(&Candidate, &Candidate)>

The highest-priority pair that is still usable, whether or not it has been nominated.

Source

pub fn start_connectivity_checks( &mut self, now: Instant, is_controlling: bool, remote_ufrag: String, remote_pwd: String, ) -> Result<()>

start connectivity checks

Source

pub fn generate_restart_credentials( &mut self, ufrag: String, pwd: String, ) -> Result<()>

Restarts the ICE Agent with the provided ufrag/pwd If no ufrag/pwd is provided the Agent will generate one itself. Stages new local credentials for an ICE restart, without disturbing the live session.

This is the half of an ICE restart that an offerer needs before generating SDP: the offer must carry the new ufrag/pwd. It deliberately does not touch local_credentials, candidate pairs, or connection state, because JSEP requires createOffer to be free of side effects — and because inbound STUN is still being validated against the current credentials until the local description is applied.

Empty ufrag / pwd are filled from the crypto provider’s RNG. Call Agent::apply_restart to install them.

Source

pub fn has_pending_restart(&self) -> bool

Whether Agent::generate_restart_credentials has staged a restart that is not yet applied.

Source

pub fn discard_restart_credentials(&mut self)

Forgets the credentials Agent::generate_restart_credentials staged, so that no restart is pending: the description they were staged for was abandoned (a rolled-back remote offer, RFC 9429 section 5.7). The live session is untouched.

Source

pub fn get_restart_generation_local_candidates(&self) -> Vec<Candidate>

The local candidates gathered for the staged ICE restart (see Agent::generate_restart_credentials): added, or added again, since it was staged. The restart keeps them whether or not it keeps the others.

Source

pub fn apply_restart( &mut self, now: Instant, keep_local_candidates: bool, ) -> Result<()>

Applies a staged ICE restart, tearing down the old session and starting a new one at now.

Installs the credentials staged by Agent::generate_restart_credentials, if any, then discards the remote credentials, pending binding requests, candidate pairs and selected pair, and restarts the agent’s timers. With nothing staged, the current credentials are kept and only the session is restarted.

Source

pub fn restart( &mut self, now: Instant, ufrag: String, pwd: String, keep_local_candidates: bool, ) -> Result<()>

Generates and immediately applies an ICE restart.

Equivalent to Agent::generate_restart_credentials followed by Agent::apply_restart. A JSEP-conformant offerer wants the two halves separately — credentials at createOffer, application at setLocalDescription — but this remains the right call for anything that restarts in one step.

Source

pub fn get_local_candidates(&self) -> &[Candidate]

Returns the local candidates.

Source

pub fn get_remote_candidates(&self) -> &[Candidate]

The remote candidates this agent has been given, in the order they were added.

Trait Implementations§

Source§

impl Drop for Agent

The agent’s copies of the TURN passwords are overwritten when it is dropped (its ICE passwords are in [ErasedCredentials]).

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Protocol<TransportMessage<BytesMut>, (), ()> for Agent

Source§

fn handle_read(&mut self, msg: TaggedBytesMut) -> Result<()>

Reads one datagram. msg.transport.local_addr is the transport address of the local candidate the datagram arrived on, matched exactly (RFC 8445 Section 7.3.1.4): the address of a host candidate, or, for a datagram a TURN allocation relayed (taken out of its Data indication or ChannelData), the relayed address of the relayed candidate. A socket bound to the unspecified address reports the concrete address the datagram was received on, not 0.0.0.0:port / [::]:port. A datagram on an address that is no local candidate’s is discarded with Error::ErrUnhandledStunpacket.

Source§

fn poll_write(&mut self) -> Option<Self::Wout>

The next datagram to send. transport.local_addr is the base of the local candidate it leaves from (RFC 8445 Section 6.1.2): a host candidate’s address (send it from that socket), or a relayed candidate’s relayed address, in which case it goes through that candidate’s TURN allocation (a Send indication or ChannelData to peer_addr), not directly from a socket. (mDNS datagrams leave from port 5353, the host’s mDNS socket.)

Source§

type Rout = TransportMessage<BytesMut>

Output read message type Read more
Source§

type Wout = TransportMessage<BytesMut>

Output write message type Read more
Source§

type Eout = TaggedEvent

Output event type Read more
Source§

type Error = Error

Error type for protocol operations
Source§

type Time = Instant

Time/Instant type for timeout handling Read more
Source§

fn poll_read(&mut self) -> Option<Self::Rout>

Poll for a processed read message. Read more
Source§

fn handle_write(&mut self, _msg: ()) -> Result<(), Self::Error>

Handle an outgoing write message. Read more
Source§

fn handle_event(&mut self, _evt: ()) -> Result<(), Self::Error>

Handle a custom event. Read more
Source§

fn poll_event(&mut self) -> Option<Self::Eout>

Poll for a generated event. Read more
Source§

fn handle_timeout(&mut self, now: Self::Time) -> Result<(), Self::Error>

Handle a timeout event. Read more
Source§

fn poll_timeout(&mut self) -> Option<Self::Time>

Poll for the next timeout deadline. Read more
Source§

fn close(&mut self) -> Result<(), Self::Error>

Close the protocol. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Forget for Agent

§

impl Freeze for Agent
where *const ArcInner<dyn RTCCryptoProvider> is !null: Freeze, PhantomData<ArcInner<dyn RTCCryptoProvider>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Candidate>: Freeze, PhantomData<CandidatePair>: Freeze, PhantomData<usize>: Freeze, PhantomData<PreviousConsentRequest>: Freeze, *const RestartUndo is !null: Freeze, PhantomData<RestartUndo>: Freeze, PhantomData<BindingRequest>: Freeze, PhantomData<(usize, usize)>: Freeze, PhantomData<UnpairedRemote>: Freeze, PhantomData<EarlyRequest>: Freeze, PhantomData<String>: Freeze, *const ArcInner<Mutex<Bucket>> is !null: Freeze, PhantomData<ArcInner<Mutex<Bucket>>>: Freeze, PhantomData<(IpAddr, u8)>: Freeze, PhantomData<LocalRecord>: Freeze, PhantomData<Goodbye>: Freeze, PhantomData<Instant>: Freeze, PhantomData<Query>: Freeze, PhantomData<Cached>: Freeze, PhantomData<Reconfirm>: Freeze, PhantomData<TransportMessage<BytesMut>>: Freeze, PhantomData<MdnsEvent>: Freeze, PhantomData<(u64, Candidate)>: Freeze, PhantomData<(IpAddr, String)>: Freeze, PhantomData<(String, String)>: Freeze, PhantomData<IpAddr>: Freeze, PhantomData<(IpAddr, u64)>: Freeze, PhantomData<Ipv6Addr>: Freeze, PhantomData<CandidateType>: Freeze, PhantomData<NetworkType>: Freeze, PhantomData<Url>: Freeze, *const ArcInner<dyn Fn(SocketAddr) -> bool + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(SocketAddr) -> bool + Sync + Send>>: Freeze, *const ArcInner<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send>>: Freeze, *const ArcInner<PacingGroup> is !null: Freeze, PhantomData<ArcInner<PacingGroup>>: Freeze, PhantomData<(IpAddr, IpAddr)>: Freeze, PhantomData<TaggedEvent>: Freeze,

§

impl Move for Agent

§

impl Send for Agent
where Arc<dyn RTCCryptoProvider>: Send, RawVecInner: Send, BoxRaw<RestartUndo>: Send, BytesMut: Send, Arc<Mutex<Bucket>>: Send, RawTable<(u64, Candidate)>: Send, Arc<dyn Fn(SocketAddr) -> bool + Sync + Send>: Send, Arc<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send>: Send, Arc<PacingGroup>: Send, RawTable<(IpAddr, IpAddr)>: Send, BoxRaw<Candidate>: Send,

§

impl Sync for Agent
where Arc<dyn RTCCryptoProvider>: Sync, RawVecInner: Sync, BoxRaw<RestartUndo>: Sync, BytesMut: Sync, Arc<Mutex<Bucket>>: Sync, RawTable<(u64, Candidate)>: Sync, Arc<dyn Fn(SocketAddr) -> bool + Sync + Send>: Sync, Arc<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send>: Sync, Arc<PacingGroup>: Sync, RawTable<(IpAddr, IpAddr)>: Sync, BoxRaw<Candidate>: Sync,

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent
where *const ArcInner<dyn RTCCryptoProvider> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn RTCCryptoProvider>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<Candidate>: UnsafeUnpin, PhantomData<CandidatePair>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, PhantomData<PreviousConsentRequest>: UnsafeUnpin, *const RestartUndo is !null: UnsafeUnpin, PhantomData<RestartUndo>: UnsafeUnpin, PhantomData<BindingRequest>: UnsafeUnpin, PhantomData<(usize, usize)>: UnsafeUnpin, PhantomData<UnpairedRemote>: UnsafeUnpin, PhantomData<EarlyRequest>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const ArcInner<Mutex<Bucket>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Bucket>>>: UnsafeUnpin, PhantomData<(IpAddr, u8)>: UnsafeUnpin, PhantomData<LocalRecord>: UnsafeUnpin, PhantomData<Goodbye>: UnsafeUnpin, PhantomData<Instant>: UnsafeUnpin, PhantomData<Query>: UnsafeUnpin, PhantomData<Cached>: UnsafeUnpin, PhantomData<Reconfirm>: UnsafeUnpin, PhantomData<TransportMessage<BytesMut>>: UnsafeUnpin, PhantomData<MdnsEvent>: UnsafeUnpin, PhantomData<(u64, Candidate)>: UnsafeUnpin, PhantomData<(IpAddr, String)>: UnsafeUnpin, PhantomData<(String, String)>: UnsafeUnpin, PhantomData<IpAddr>: UnsafeUnpin, PhantomData<(IpAddr, u64)>: UnsafeUnpin, PhantomData<Ipv6Addr>: UnsafeUnpin, PhantomData<CandidateType>: UnsafeUnpin, PhantomData<NetworkType>: UnsafeUnpin, PhantomData<Url>: UnsafeUnpin, *const ArcInner<dyn Fn(SocketAddr) -> bool + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(SocketAddr) -> bool + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send>>: UnsafeUnpin, *const ArcInner<PacingGroup> is !null: UnsafeUnpin, PhantomData<ArcInner<PacingGroup>>: UnsafeUnpin, PhantomData<(IpAddr, IpAddr)>: UnsafeUnpin, PhantomData<TaggedEvent>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.