Skip to main content

Candidate

Struct Candidate 

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

One ICE candidate: a transport address this agent can be reached at, or can reach a peer at, together with its type, priority and liveness bookkeeping.

Implementations§

Source§

impl Candidate

Source

pub fn foundation(&self) -> String

The candidate’s foundation (RFC 8445 Section 5.1.1.3): two candidates have the same one when they have the same type, their bases have the same IP address (ports may differ), they came from the same STUN or TURN server (reflexive and relayed ones) and they use the same transport protocol.

A host candidate’s base is itself (an mDNS name stands for its address); a reflexive candidate’s base is its related address; a relayed candidate’s base is the relayed address. A foundation groups equivalent candidates; it is deterministic bookkeeping rather than a secret, random identifier. CRC-32C is therefore intentional here.

Source

pub fn id(&self) -> &str

Returns Candidate ID.

Source

pub fn component(&self) -> u16

Returns candidate component.

Source

pub fn set_component(&mut self, component: u16)

Sets candidate component.

Source

pub fn last_received(&self) -> Option<Instant>

When traffic was last received on this candidate.

None until the first packet arrives. A freshly constructed or freshly parsed candidate has not received anything, and previously said it had — it was seeded with the construction instant, which also meant every candidate constructor needed a clock.

Source

pub fn last_sent(&self) -> Option<Instant>

When traffic was last sent on this candidate, or None if none ever has been.

Source

pub fn network_type(&self) -> NetworkType

Returns candidate NetworkType.

Source

pub fn address(&self) -> &str

Returns Candidate Address.

Source

pub fn port(&self) -> u16

Returns Candidate Port.

Source

pub fn priority(&self) -> u32

Computes the priority for this ICE Candidate.

Source

pub fn type_preference(&self, candidate_type: CandidateType) -> u16

The type preference of candidate_type on this candidate’s transport. RFC 6544 section 4.2: “the type preferences for the preferred transport protocol candidates SHOULD be increased and/or the type preferences for the other transport protocol candidates SHOULD be decreased … changing type preference values by one for the other transport protocol candidates is enough” when the candidate type matters more, and “For RTP-based media streams, it is RECOMMENDED that UDP candidates are preferred over TCP candidates”. A TCP candidate takes the UDP type preference less one (host 125, peer-reflexive 109, server-reflexive 99): a TCP host candidate still outranks a UDP server-reflexive one, a UDP candidate outranks the TCP one of its type. A relayed TCP candidate stays at 0 (“relayed candidates are still preferred lower than the other candidate types”), below the UDP relayed one by its local preference.

A TCP host candidate on a Teredo address (2001::/32, RFC 4380) is a UDP-tunnelled candidate (RFC 6544 Section 5.4: it “may appear to applications as host candidates from a local pseudo-interface. Treating these candidates as host candidates results in incorrect prioritization … Implementations may attempt to detect pseudo-interfaces, e.g., from the address prefix of the interface”): it takes the type preference Section 4.2 recommends for UDP-tunnelled candidates, UDP_TUNNELLED_TYPE_PREFERENCE.

Source

pub fn peer_reflexive_priority(&self) -> u32

The priority this candidate would have as a peer-reflexive one: the value of the PRIORITY attribute in a connectivity check sent from it (RFC 8445 Section 7.1.1). The peer-reflexive type preference (of its transport, RFC 6544 section 4.2), with this candidate’s local preference and component.

Source

pub fn related_address(&self) -> Option<CandidateRelatedAddress>

Returns Option<CandidateRelatedAddress>.

Source

pub fn candidate_type(&self) -> CandidateType

Returns candidate type.

Source

pub fn tcp_type(&self) -> TcpType

The TCP role for ICE-TCP candidates; Unspecified for UDP.

Source

pub fn set_tcp_type(&mut self, tcp_type: TcpType)

Sets the TCP role of an ICE-TCP candidate of any type (RFC 6544 Section 4.5: every TCP candidate is signalled with a tcptype).

Source

pub fn url(&self) -> Option<&str>

The STUN or TURN server this candidate was gathered from, if any.

Source

pub fn marshal(&self) -> String

Returns the string representation of the ICECandidate.

The related address to signal and to show in statistics: the candidate’s own, or, when its base is a host address hidden behind an mDNS name, 0.0.0.0 (::) and port 9 (draft-ietf-mmusic-mdns-ice-candidates Section 3.1.2.2: “the agent MUST set the rel-addr and rel-port fields of the candidate to 0.0.0.0/:: and 9”).

Source

pub fn addr(&self) -> SocketAddr

The candidate’s socket address.

Source

pub fn base_addr(&self) -> SocketAddr

Returns the candidate’s base address: the local transport address the candidate was derived from, i.e. the address packets for this candidate must be sent from (RFC 8445 §5.1.1).

For server-reflexive and peer-reflexive candidates this is the related (host) address; for host and relay candidates the base is the candidate address itself.

Source

pub fn seen(&mut self, now: Instant, outbound: bool)

Records traffic on this candidate, updating its last-sent or last-received time.

Feeds consent freshness — a pair that stops seeing traffic is eventually abandoned.

Source

pub fn equal(&self, other: &Candidate) -> bool

Used to compare two candidateBases.

Source

pub fn set_ip(&mut self, ip: &IpAddr) -> Result<()>

Sets the resolved IP, deriving the network type from it.

§Errors

Fails if ip’s family does not match this candidate’s network type.

Source§

impl Candidate

Source

pub fn last_authenticated(&self) -> Option<Instant>

When an authenticated Binding request or response last arrived from this candidate.

When a success response to one of our Binding requests last arrived from this candidate: the last time the peer granted consent (RFC 7675).

Source

pub fn set_last_received(&mut self, now: Instant)

Records that traffic was received on this candidate at now.

Source

pub fn set_last_sent(&mut self, now: Instant)

Records that traffic was sent on this candidate at now.

Source

pub fn set_local_preference_rank(&mut self, rank: u16)

Ranks this candidate among the local candidates of its type: 0 is the most preferred (local preference 65535 for UDP, other-pref 8191 for TCP), each further rank one less.

RFC 8445 Section 5.1.2.1 wants a unique local preference for each candidate of a type, and RFC 8421 wants candidates from an unreliable interface last. A candidate the application does not rank (and gives no priority) is ranked by Agent::add_local_candidate, in the order it is added, IPv4 and IPv6 interleaved.

Source

pub fn local_preference_rank(&self) -> Option<u16>

The rank set by Candidate::set_local_preference_rank or by the agent.

Source

pub fn local_preference(&self) -> u16

Returns the local preference for this candidate.

Trait Implementations§

Source§

impl Clone for Candidate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Candidate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Candidate

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Candidate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.