pub struct NatTraversalManager { /* private fields */ }Expand description
Central manager for NAT traversal operations
Implementations§
Source§impl NatTraversalManager
impl NatTraversalManager
Sourcepub fn new(config: NatTraversalConfig) -> Self
pub fn new(config: NatTraversalConfig) -> Self
Create a new manager with the given configuration.
Sourcepub fn detect_nat_type(bindings: &[StunBinding]) -> NatType
pub fn detect_nat_type(bindings: &[StunBinding]) -> NatType
Analyse a set of STUN bindings to determine the NAT type.
The algorithm compares mapped addresses across bindings:
- All identical mapped addresses => FullCone (or Open if mapped == local)
- Same IP but different ports => PortRestricted
- Different IPs => Symmetric
- Single binding or ambiguous => RestrictedCone or Unknown
Sourcepub fn add_binding(&mut self, binding: StunBinding)
pub fn add_binding(&mut self, binding: StunBinding)
Record a new STUN binding and re-detect the NAT type.
Sourcepub fn initiate_punch(
&mut self,
peer_id: &str,
remote_addr: &str,
local_port: u16,
) -> Result<(), String>
pub fn initiate_punch( &mut self, peer_id: &str, remote_addr: &str, local_port: u16, ) -> Result<(), String>
Begin a hole-punch attempt to a peer.
Returns an error if a punch is already active for this peer.
Sourcepub fn predict_port(&self, base_port: u16, sample_ports: &[u16]) -> Vec<u16>
pub fn predict_port(&self, base_port: u16, sample_ports: &[u16]) -> Vec<u16>
Predict the next allocated port(s) based on observed samples.
If the samples show a linear pattern (constant delta), predict the next port and return a range around it. Otherwise return a range around the base port.
Sourcepub fn update_attempt(
&mut self,
peer_id: &str,
status: HolePunchStatus,
) -> Result<(), String>
pub fn update_attempt( &mut self, peer_id: &str, status: HolePunchStatus, ) -> Result<(), String>
Update the status of an active hole-punch attempt.
Sourcepub fn get_attempt(&self, peer_id: &str) -> Option<&HolePunchAttempt>
pub fn get_attempt(&self, peer_id: &str) -> Option<&HolePunchAttempt>
Look up an active punch attempt by peer ID.
Sourcepub fn active_punch_count(&self) -> usize
pub fn active_punch_count(&self) -> usize
Number of currently active (non-terminal) punch attempts.
Sourcepub fn cleanup_expired(&mut self, now: u64) -> usize
pub fn cleanup_expired(&mut self, now: u64) -> usize
Remove expired or completed attempts older than now - stun_timeout_ms.
Returns the number of entries removed.
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Fraction of successful punches out of total (0.0 if none attempted).
Sourcepub fn stats(&self) -> &NatTraversalStats
pub fn stats(&self) -> &NatTraversalStats
Reference to aggregated stats.
Sourcepub fn detected_nat_type(&self) -> &NatType
pub fn detected_nat_type(&self) -> &NatType
Reference to the currently detected NAT type.
Sourcepub fn best_strategy(&self) -> TraversalStrategy
pub fn best_strategy(&self) -> TraversalStrategy
Recommend the best traversal strategy based on the detected NAT type.
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