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
impl NatTraversalManager
Sourcepub fn new(config: TraversalConfig) -> Self
pub fn new(config: TraversalConfig) -> Self
Create a new manager with config.
Sourcepub fn add_local_candidate(
&mut self,
addr: CandidateAddress,
) -> Result<(), TraversalError>
pub fn add_local_candidate( &mut self, addr: CandidateAddress, ) -> Result<(), TraversalError>
Add a local candidate.
Sourcepub fn add_remote_candidate(
&mut self,
addr: CandidateAddress,
) -> Result<(), TraversalError>
pub fn add_remote_candidate( &mut self, addr: CandidateAddress, ) -> Result<(), TraversalError>
Add a remote candidate.
Sourcepub fn form_check_pairs(&mut self) -> Vec<IcePair>
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.
Sourcepub fn detect_nat_type(candidates: &[CandidateAddress]) -> NatType
pub fn detect_nat_type(candidates: &[CandidateAddress]) -> NatType
Heuristic NAT type detection from a slice of gathered candidates.
Algorithm:
- No candidates →
Unknown - Only
Hostcandidates →OpenInternet - Multiple
ServerReflexivecandidates with different IP+port combinations (one per distinct STUN server) →Symmetric - Exactly one
ServerReflexivecandidate →FullCone - Both
HostandServerReflexivepresent with the same reflexive address per server →RestrictedCone Relayedcandidates present (TURN allocation needed) →PortRestrictedCone- Otherwise →
Unknown
Sourcepub fn check_pair(&self, pair: &mut IcePair, _current_ts: u64) -> PairState
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, orRelayedcandidates on both sides →Succeeded.- Any other combination →
Failed.
The pair transitions through InProgress before the final state.
Sourcepub fn nominate_best_pair(&mut self) -> Result<IcePair, TraversalError>
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.
Sourcepub fn run_checks(&mut self, current_ts: u64) -> Vec<(String, PairState)>
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.
Sourcepub fn encode_stun_message(&self, msg: &StunMessage) -> Vec<u8> ⓘ
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 … |Sourcepub fn decode_stun_message(
&self,
data: &[u8],
) -> Result<StunMessage, TraversalError>
pub fn decode_stun_message( &self, data: &[u8], ) -> Result<StunMessage, TraversalError>
Decode bytes into a StunMessage.
Sourcepub fn stats(&self) -> TraversalStats
pub fn stats(&self) -> TraversalStats
Return a snapshot of traversal statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NatTraversalManager
impl RefUnwindSafe for NatTraversalManager
impl Send for NatTraversalManager
impl Sync for NatTraversalManager
impl Unpin for NatTraversalManager
impl UnsafeUnpin for NatTraversalManager
impl UnwindSafe for NatTraversalManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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