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 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 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.

Source

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

Adds a new remote candidate.

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 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 controlling role.

Determined by which side offered; the two agents must not agree, or nomination stalls.

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 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 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 Protocol<TransportMessage<BytesMut>, (), ()> for Agent

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 handle_read(&mut self, msg: TaggedBytesMut) -> Result<()>

Handle an incoming read message. 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 poll_write(&mut self) -> Option<Self::Wout>

Poll for a processed 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 Freeze for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.