Skip to main content

NatStrategy

Trait NatStrategy 

Source
pub trait NatStrategy: Send + Sync {
    // Required method
    fn select_tier(
        &self,
        relay_port: u16,
    ) -> Pin<Box<dyn Future<Output = Result<ReachabilityTier, NodeError>> + Send + '_>>;
}
Expand description

Strategy for NAT probing and tier selection (spec section 10.12.8).

Abstracted as a trait to enable mock implementations in tests. Production code uses DefaultNatStrategy; tests provide pre-computed results.

Required Methods§

Source

fn select_tier( &self, relay_port: u16, ) -> Pin<Box<dyn Future<Output = Result<ReachabilityTier, NodeError>> + Send + '_>>

Probes NAT type and selects the best reachability tier.

Steps per §10.12.8:

  1. Probe NAT type via STUN.
  2. Attempt Tier 1 (UPnP/NAT-PMP).
  3. If Tier 1 fails and NAT is non-symmetric, attempt Tier 2 (STUN).
  4. If Tier 2 fails or NAT is symmetric, attempt Tier 3 (bridge).

Implementors§