pub struct Agent { /* private fields */ }Expand description
Represents the ICE agent.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn checklist_state(&self) -> ChecklistState
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.
Sourcepub fn handle_transport_error(
&mut self,
now: Instant,
transport: TransportContext,
error: TransportError,
) -> bool
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.
Sourcepub fn handle_non_stun_before_validation(
&mut self,
now: Instant,
transport: TransportContext,
) -> bool
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
impl Agent
Sourcepub fn get_candidate_pairs_stats(&self, now: Instant) -> Vec<CandidatePairStats>
pub fn get_candidate_pairs_stats(&self, now: Instant) -> Vec<CandidatePairStats>
Returns a list of candidate pair stats.
Sourcepub fn get_local_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
pub fn get_local_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
Returns a list of local candidates stats.
Sourcepub fn get_remote_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
pub fn get_remote_candidates_stats(&self, now: Instant) -> Vec<CandidateStats>
Returns a list of remote candidates stats.
Source§impl Agent
impl Agent
Sourcepub fn apply_restart_revertible(
&mut self,
now: Instant,
keep_local_candidates: bool,
) -> Result<()>
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.
Sourcepub fn has_revertible_restart(&self) -> bool
pub fn has_revertible_restart(&self) -> bool
Whether a restart applied by Agent::apply_restart_revertible can still be taken
back.
Sourcepub fn commit_restart(&mut self)
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.
Sourcepub fn revert_restart(&mut self, now: Instant) -> bool
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
impl Agent
Sourcepub fn new(
now: Instant,
config: Arc<AgentConfig>,
crypto_provider: Arc<dyn RTCCryptoProvider>,
) -> Result<Self>
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.
Sourcepub fn add_local_candidate(&mut self, c: Candidate) -> Result<bool>
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.
Sourcepub fn add_unconveyed_local_candidate(&mut self, c: Candidate) -> Result<bool>
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.
Sourcepub fn local_candidate_conveyed(&mut self, id: &str) -> bool
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.
Sourcepub fn all_local_candidates_conveyed(&mut self)
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.
Sourcepub fn stop_for_ice_mismatch(&mut self, now: Instant) -> bool
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.
Sourcepub fn is_local_candidate_unconveyed(&self, id: &str) -> bool
pub fn is_local_candidate_unconveyed(&self, id: &str) -> bool
Whether the local candidate id is held unconveyed (and so unpaired).
Sourcepub fn set_temporary_ipv6_addresses(&mut self, addresses: Vec<Ipv6Addr>)
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.
Sourcepub fn set_ice_servers(&mut self, urls: Vec<Url>)
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”).
Sourcepub fn add_local_candidates(
&mut self,
candidates: Vec<Candidate>,
) -> Result<Vec<bool>>
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.
Sourcepub fn set_multicast_dns_publishing(
&mut self,
publishing: MulticastDnsPublishing,
)
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.
Sourcepub fn set_multicast_dns_destination_reported(&mut self, reported: bool)
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.
Sourcepub fn multicast_dns_withholds(&self, ip: IpAddr) -> bool
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).
Sourcepub fn add_remote_candidate(&mut self, c: Candidate) -> Result<bool>
pub fn add_remote_candidate(&mut self, c: Candidate) -> Result<bool>
Adds a new remote candidate.
Sourcepub fn pending_mdns_candidates(&self) -> impl Iterator<Item = &Candidate>
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).
Sourcepub fn set_remote_end_of_candidates(&mut self)
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.
Sourcepub fn set_local_gathering_complete(&mut self)
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.
Sourcepub fn set_remote_trickles(&mut self, trickles: bool)
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.)
Sourcepub fn set_failed_without_end_of_candidates(&mut self, enabled: bool)
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.
Sourcepub fn failed_without_end_of_candidates(&self) -> bool
pub fn failed_without_end_of_candidates(&self) -> bool
Sourcepub fn is_signalled_remote_ip(&self, ip: IpAddr) -> bool
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.
Sourcepub fn get_local_candidates_to_signal(&self) -> Vec<Candidate>
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.
Sourcepub fn set_remote_credentials(
&mut self,
remote_ufrag: String,
remote_pwd: String,
) -> Result<()>
pub fn set_remote_credentials( &mut self, remote_ufrag: String, remote_pwd: String, ) -> Result<()>
Sets the credentials of the remote agent.
Sourcepub fn get_remote_credentials(&self) -> Option<&Credentials>
pub fn get_remote_credentials(&self) -> Option<&Credentials>
Returns the remote credentials.
Sourcepub fn get_local_credentials(&self) -> &Credentials
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.
Sourcepub fn get_candidate_pairs(&self) -> Vec<(Candidate, Candidate)>
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.
Sourcepub fn proposal_pending(&self) -> bool
pub fn proposal_pending(&self) -> bool
Whether a nomination proposal waits for Self::resolve_nomination_proposal
(webrtc-extensions 7 [[ProposalPending]]).
Sourcepub fn resolve_nomination_proposal(&mut self, now: Instant, accept: bool)
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.
Sourcepub fn select_candidate_pair(
&mut self,
now: Instant,
local: &Candidate,
remote: &Candidate,
) -> Result<()>
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).
Sourcepub fn remove_candidate_pair(
&mut self,
now: Instant,
local: &Candidate,
remote: &Candidate,
) -> Result<()>
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
Sourcepub fn withdraw_local_candidate(
&mut self,
now: Instant,
addr: SocketAddr,
protocol: TransportProtocol,
) -> bool
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 call | after the next apply_restart | |
|---|---|---|
| the candidate | held, flagged withdrawn | dropped |
| its selected (or nominated) pair in the current session | kept: data and consent go on | gone with the session; the restart’s previous media path still runs on it |
| its other pairs in the current session | removed (as remove_candidate_pair) | — |
| new pairs with it (remote candidates, checks that reach it) | none | — |
get_local_candidates_to_signal | without it | without it |
discard_restart_credentials | flag kept: the next restart drops it | — |
revert_restart | the session restored as it was when the restart was applied (a withdrawal made after that is undone; the engine withdraws again) | — |
| the candidate gathered again | stays withdrawn | — |
Sourcepub fn role(&self) -> bool
pub fn role(&self) -> bool
Whether this agent is the controlling one, which decides nomination.
Sourcepub fn set_role(&mut self, is_controlling: bool)
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.
Sourcepub fn tie_breaker(&self) -> u64
pub fn tie_breaker(&self) -> u64
The tiebreaker the agent’s checks carry (RFC 8445 Section 5.2).
Sourcepub fn is_remote_lite(&self) -> bool
pub fn is_remote_lite(&self) -> bool
Whether the peer is a lite implementation (Agent::set_remote_lite).
Sourcepub fn awaits_lite_update(&self) -> bool
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).
Sourcepub fn set_remote_lite(&mut self, lite: bool)
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.
Sourcepub fn pacing(&self) -> Duration
pub fn pacing(&self) -> Duration
Ta, the pacing of connectivity checks in use (RFC 8445 Section 14.2).
Sourcepub fn proposed_pacing(&self) -> Option<Duration>
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).
Sourcepub fn set_remote_pacing(&mut self, proposed: Option<Duration>)
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.
Sourcepub fn replace_remote_candidates(
&mut self,
now: Instant,
candidates: Vec<Candidate>,
) -> bool
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.
Sourcepub fn replace_remote_candidates_pinning(
&mut self,
now: Instant,
candidates: Vec<Candidate>,
local: Option<SocketAddr>,
) -> bool
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.
Sourcepub fn set_candidate_types(&mut self, candidate_types: Vec<CandidateType>)
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: a new ICE transport policy takes effect at the next gathering (RFC 9429, Section 4.1.18). A lite agent keeps host candidates only.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
The agent’s current connection state.
Sourcepub fn is_valid_non_stun_traffic(
&mut self,
now: Instant,
transport: TransportContext,
) -> bool
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.
Sourcepub fn media_path(&self) -> Option<MediaPath>
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.
RFC 8445 Section 9: “the ICE agent continues to use the previously selected candidate
pair until a new pair is selected by the restart”. 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).
Sourcepub fn retired_media_path(&self) -> Option<MediaPath>
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.
Sourcepub fn accepts_data(&self, transport: TransportContext) -> bool
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.
Sourcepub fn data_path(&self, transport: TransportContext) -> Option<DataPath<'_>>
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).
Sourcepub fn get_selected_candidate_pair(&self) -> Option<(&Candidate, &Candidate)>
pub fn get_selected_candidate_pair(&self) -> Option<(&Candidate, &Candidate)>
Returns the selected pair (local_candidate, remote_candidate) or none
Sourcepub fn get_best_available_candidate_pair(
&self,
) -> Option<(&Candidate, &Candidate)>
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.
Sourcepub fn start_connectivity_checks(
&mut self,
now: Instant,
is_controlling: bool,
remote_ufrag: String,
remote_pwd: String,
) -> Result<()>
pub fn start_connectivity_checks( &mut self, now: Instant, is_controlling: bool, remote_ufrag: String, remote_pwd: String, ) -> Result<()>
start connectivity checks
Sourcepub fn generate_restart_credentials(
&mut self,
ufrag: String,
pwd: String,
) -> Result<()>
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.
Sourcepub fn has_pending_restart(&self) -> bool
pub fn has_pending_restart(&self) -> bool
Whether Agent::generate_restart_credentials has staged a restart that is not yet applied.
Sourcepub fn discard_restart_credentials(&mut self)
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.
Sourcepub fn get_restart_generation_local_candidates(&self) -> Vec<Candidate>
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.
Sourcepub fn apply_restart(
&mut self,
now: Instant,
keep_local_candidates: bool,
) -> Result<()>
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.
Sourcepub fn restart(
&mut self,
now: Instant,
ufrag: String,
pwd: String,
keep_local_candidates: bool,
) -> Result<()>
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.
Sourcepub fn get_local_candidates(&self) -> &[Candidate]
pub fn get_local_candidates(&self) -> &[Candidate]
Returns the local candidates.
Sourcepub fn get_remote_candidates(&self) -> &[Candidate]
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 Protocol<TransportMessage<BytesMut>, (), ()> for Agent
impl Protocol<TransportMessage<BytesMut>, (), ()> for Agent
Source§fn handle_read(&mut self, msg: TaggedBytesMut) -> Result<()>
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>
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.)