Skip to main content

NatTraversalManager

Struct NatTraversalManager 

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

Production ICE traversal manager.

Renamed to NtmNatTraversalManager at crate root to avoid collision with nat_traversal::NatTraversalManager.

Implementations§

Source§

impl NatTraversalManager

Source

pub fn new(config: TraversalConfig) -> Self

Create a new manager with config.

Source

pub fn add_local_candidate( &mut self, addr: CandidateAddress, ) -> Result<(), TraversalError>

Add a local candidate.

Source

pub fn add_remote_candidate( &mut self, addr: CandidateAddress, ) -> Result<(), TraversalError>

Add a remote candidate.

Source

pub fn form_check_pairs(&mut self) -> Vec<IcePair>

Form the check list from the Cartesian product of local × remote candidates, sorted by descending RFC 5245 pair priority and capped to config.max_pairs.

Source

pub fn detect_nat_type(candidates: &[CandidateAddress]) -> NatType

Heuristic NAT type detection from a slice of gathered candidates.

Algorithm:

  1. No candidates → Unknown
  2. Only Host candidates → OpenInternet
  3. Multiple ServerReflexive candidates with different IP+port combinations (one per distinct STUN server) → Symmetric
  4. Exactly one ServerReflexive candidate → FullCone
  5. Both Host and ServerReflexive present with the same reflexive address per server → RestrictedCone
  6. Relayed candidates present (TURN allocation needed) → PortRestrictedCone
  7. Otherwise → Unknown
Source

pub fn check_pair(&self, pair: &mut IcePair, _current_ts: u64) -> PairState

Run a single connectivity check on pair.

Deterministic rule (no real network I/O):

  • Host, ServerReflexive, PeerReflexive, or Relayed candidates on both sides → Succeeded.
  • Any other combination → Failed.

The pair transitions through InProgress before the final state.

Source

pub fn nominate_best_pair(&mut self) -> Result<IcePair, TraversalError>

Among all Succeeded pairs in the current check list, nominate the one with the highest priority.

Source

pub fn run_checks(&mut self, current_ts: u64) -> Vec<(String, PairState)>

Run connectivity checks on all Waiting and InProgress pairs. Returns (pair_key, new_state) for every pair that was checked.

Source

pub fn encode_stun_message(&self, msg: &StunMessage) -> Vec<u8>

Encode a StunMessage to bytes (RFC 5389 §6 format).

Layout:

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0|     STUN Message Type     |         Message Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Magic Cookie                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                     Transaction ID (96 bits)                  |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Attributes …                         |
Source

pub fn decode_stun_message( &self, data: &[u8], ) -> Result<StunMessage, TraversalError>

Decode bytes into a StunMessage.

Source

pub fn stats(&self) -> TraversalStats

Return a snapshot of traversal statistics.

Trait Implementations§

Source§

impl Default for NatTraversalManager

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more