pub struct NatTraversalConfig {
pub known_peers: Vec<SocketAddr>,
pub max_candidates: usize,
pub coordination_timeout: Duration,
pub enable_symmetric_nat: bool,
pub enable_relay_fallback: bool,
pub relay_nodes: Vec<SocketAddr>,
pub max_concurrent_attempts: usize,
pub bind_addr: Option<SocketAddr>,
pub prefer_rfc_nat_traversal: bool,
pub pqc: Option<PqcConfig>,
pub timeouts: TimeoutConfig,
pub identity_key: Option<(MlDsaPublicKey, MlDsaSecretKey)>,
}Expand description
Configuration for NAT traversal behavior
This configuration controls various aspects of NAT traversal including security, performance, and reliability settings. Recent improvements in version 0.6.1 include enhanced security through protocol obfuscation and robust error handling.
§Pure P2P Design (v0.13.0+)
All nodes are now symmetric - they can both connect and accept connections.
The role field is deprecated and ignored. Every node automatically:
- Accepts incoming connections
- Initiates outgoing connections
- Coordinates NAT traversal for connected peers
- Discovers its external address from any connected peer
§Security Features (Added in v0.6.1)
- Protocol Obfuscation: Random port binding prevents fingerprinting attacks
- Robust Error Handling: Panic-free operation with graceful error recovery
- Input Validation: Enhanced validation of configuration parameters
§Example
use ant_quic::nat_traversal_api::NatTraversalConfig;
use std::time::Duration;
use std::net::SocketAddr;
// Recommended secure configuration
let config = NatTraversalConfig {
known_peers: vec!["127.0.0.1:9000".parse::<SocketAddr>().unwrap()],
max_candidates: 10,
coordination_timeout: Duration::from_secs(10),
enable_symmetric_nat: true,
enable_relay_fallback: false,
max_concurrent_attempts: 5,
bind_addr: None, // Auto-select for security
prefer_rfc_nat_traversal: true,
timeouts: Default::default(),
..Default::default()
};Fields§
§known_peers: Vec<SocketAddr>Known peer addresses for initial discovery These peers are used to discover external addresses and coordinate NAT traversal. In v0.13.0+ all nodes are symmetric - any connected peer can help with discovery.
max_candidates: usizeMaximum number of address candidates to maintain
coordination_timeout: DurationTimeout for coordination rounds
enable_symmetric_nat: boolEnable symmetric NAT prediction algorithms
enable_relay_fallback: boolEnable automatic relay fallback
relay_nodes: Vec<SocketAddr>Known relay nodes for MASQUE CONNECT-UDP Bind fallback When direct NAT traversal fails, connections can be relayed through these nodes
max_concurrent_attempts: usizeMaximum concurrent NAT traversal attempts
bind_addr: Option<SocketAddr>Bind address for the endpoint
Some(addr): Bind to the specified addressNone: Auto-select random port for enhanced security (recommended)
When None, the system uses an internal method to automatically
select a random available port, providing protocol obfuscation and improved
security through port randomization.
§Security Benefits of None (Auto-Select)
- Protocol Obfuscation: Makes endpoint detection harder for attackers
- Port Randomization: Each instance gets a different port
- Fingerprinting Resistance: Reduces predictable network patterns
§Added in Version 0.6.1
Enhanced security through automatic random port selection
prefer_rfc_nat_traversal: boolPrefer RFC-compliant NAT traversal frame format When true, will send RFC-compliant frames if the peer supports it
pqc: Option<PqcConfig>Post-Quantum Cryptography configuration
timeouts: TimeoutConfigTimeout configuration for NAT traversal operations
identity_key: Option<(MlDsaPublicKey, MlDsaSecretKey)>Identity keypair for TLS authentication (ML-DSA-65)
v0.2: Pure PQC - Uses ML-DSA-65 for all authentication. v0.13.0+: This keypair is used for RFC 7250 Raw Public Key TLS authentication. If provided, peers will derive the same PeerId from this key via TLS handshake. If None, a random keypair is generated (not recommended for production as it won’t match the application-layer PeerId).
Trait Implementations§
Source§impl Clone for NatTraversalConfig
impl Clone for NatTraversalConfig
Source§fn clone(&self) -> NatTraversalConfig
fn clone(&self) -> NatTraversalConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more