pub struct DefaultNatStrategy { /* private fields */ }Expand description
Default NAT strategy using real STUN probing, UPnP, and bridge relay.
Implements the tier selection algorithm from spec 10.12.8:
- Probe NAT type via STUN.
- Attempt Tier 1 (UPnP/NAT-PMP) if a [
PortMapper] is configured. Run reachability self-test on the mapped address (spec 10.12.2 step 4). - If Tier 1 fails and NAT is non-symmetric, attempt Tier 2 (STUN address). Run reachability self-test on the STUN-discovered address (spec 10.12.3).
- If Tier 2 fails or NAT is symmetric, attempt Tier 3 (bridge relay).
The reachability self-test (SCP-242) sends a STUN Binding Request from the SAME socket that holds the NAT mapping to a STUN server intermediary. If the server confirms the expected external address, the mapping is valid.
Uses NatProber for STUN probing,
PortMapper for UPnP, and
ReachabilityProbe for self-test.
Implementations§
Source§impl DefaultNatStrategy
impl DefaultNatStrategy
Sourcepub fn new(stun_server: Option<String>, bridge_relay: Option<String>) -> Self
pub fn new(stun_server: Option<String>, bridge_relay: Option<String>) -> Self
Creates a new default NAT strategy with optional overrides.
Sourcepub fn with_port_mapper(self, mapper: Arc<dyn PortMapper>) -> Self
pub fn with_port_mapper(self, mapper: Arc<dyn PortMapper>) -> Self
Sets the UPnP/NAT-PMP port mapper for Tier 1 (spec 10.12.2).
Sourcepub fn with_reachability_probe(self, probe: Arc<dyn ReachabilityProbe>) -> Self
pub fn with_reachability_probe(self, probe: Arc<dyn ReachabilityProbe>) -> Self
Sets the reachability probe for self-test verification (SCP-242).
If not set, a DefaultReachabilityProbe
is constructed from the first STUN endpoint at probe time.
Trait Implementations§
Source§impl NatStrategy for DefaultNatStrategy
impl NatStrategy for DefaultNatStrategy
Auto Trait Implementations§
impl Freeze for DefaultNatStrategy
impl !RefUnwindSafe for DefaultNatStrategy
impl Send for DefaultNatStrategy
impl Sync for DefaultNatStrategy
impl Unpin for DefaultNatStrategy
impl UnsafeUnpin for DefaultNatStrategy
impl !UnwindSafe for DefaultNatStrategy
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
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>
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 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>
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 moreCreates a shared type from an unshared type.