| Crates.io | ant-quic |
| lib.rs | ant-quic |
| version | 0.20.0 |
| created_at | 2025-07-08 08:34:34.878673+00 |
| updated_at | 2026-01-24 22:03:35.382515+00 |
| description | QUIC transport protocol with advanced NAT traversal for P2P networks |
| homepage | |
| repository | https://github.com/dirvine/ant-quic |
| max_upload_size | |
| id | 1742204 |
| size | 8,145,823 |
Pure Post-Quantum QUIC transport with NAT traversal for P2P networks. Every node is symmetric - can connect AND accept connections.
use ant_quic::{P2pEndpoint, P2pConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a P2P endpoint - PQC is always on
let config = P2pConfig::builder()
.known_peer("peer.example.com:9000".parse()?)
.build()?;
let endpoint = P2pEndpoint::new(config).await?;
println!("Peer ID: {:?}", endpoint.peer_id());
// Connect to known peers for address discovery
endpoint.connect_bootstrap().await?;
// Your external address is now known
if let Some(addr) = endpoint.external_address() {
println!("External address: {}", addr);
}
Ok(())
}
ant-quic uses a symmetric P2P model where every node has identical capabilities:
┌─────────────┐ ┌─────────────┐
│ Node A │◄───────►│ Node B │
│ (peer) │ QUIC │ (peer) │
│ │ PQC │ │
└─────────────┘ └─────────────┘
│ │
│ OBSERVED_ADDRESS │
│◄──────────────────────┤
│ │
├──────────────────────►│
│ ADD_ADDRESS │
└───────────────────────┘
In v0.13.0, we removed all role distinctions:
EndpointRole::Client/Server/BootstrapNatTraversalRole enumThe term "known_peers" replaces "bootstrap_nodes" - they're just addresses to connect to first. Any connected peer can help with address discovery.
P2pEndpoint, P2pConfigant-quic v0.2 uses PURE post-quantum cryptography - no classical algorithms, no hybrid modes, no fallback.
This is a greenfield network with no legacy compatibility requirements.
| Algorithm | Standard | Purpose | Security Level | IANA Code |
|---|---|---|---|---|
| ML-KEM-768 | FIPS 203 | Key Exchange | NIST Level 3 (192-bit) | 0x0201 |
| ML-DSA-65 | FIPS 204 | Digital Signatures | NIST Level 3 (192-bit) | 0x0905 |
ant-quic uses saorsa-pqc for all PQC operations:
use ant_quic::crypto::pqc::PqcConfig;
let pqc = PqcConfig::builder()
.ml_kem(true) // ML-KEM-768 key exchange
.ml_dsa(true) // ML-DSA-65 signatures
.memory_pool_size(10) // Memory pool for crypto ops
.handshake_timeout_multiplier(2.0) // PQC handshakes are larger
.build()?;
See docs/guides/pqc-security.md for security analysis.
NAT traversal is built into the QUIC protocol via extension frames, not STUN/TURN.
| Frame | Type ID | Purpose |
|---|---|---|
ADD_ADDRESS |
0x3d7e90 (IPv4), 0x3d7e91 (IPv6) | Advertise candidate addresses |
PUNCH_ME_NOW |
0x3d7e92 (IPv4), 0x3d7e93 (IPv6) | Coordinate hole punching timing |
REMOVE_ADDRESS |
0x3d7e94 | Remove stale address |
OBSERVED_ADDRESS |
0x9f81a6 (IPv4), 0x9f81a7 (IPv6) | Report external address to peer |
| Parameter | ID | Purpose |
|---|---|---|
| NAT Traversal Capability | 0x3d7e9f0bca12fea6 | Negotiates NAT traversal support |
| RFC-Compliant Frames | 0x3d7e9f0bca12fea8 | Enables RFC frame format |
| Address Discovery | 0x9f81a176 | Configures address observation |
| NAT Type | Success Rate | Notes |
|---|---|---|
| Full Cone | >95% | Direct connection |
| Restricted Cone | 80-90% | Coordinated punch |
| Port Restricted | 70-85% | Port-specific coordination |
| Symmetric | 60-80% | Prediction algorithms |
| CGNAT | 50-70% | Relay fallback may be needed |
See docs/NAT_TRAVERSAL_GUIDE.md for detailed information.
Each node has a single ML-DSA-65 key pair for both identity and authentication:
// ML-DSA-65 keypair - used for everything
let (ml_dsa_pub, ml_dsa_sec) = generate_ml_dsa_65_keypair();
// PeerId = SHA-256(ML-DSA-65 public key) = 32 bytes
// Compact identifier for addressing and peer tracking
let peer_id = derive_peer_id_from_public_key(&ml_dsa_pub);
This follows our Pure PQC Authentication specification.
cargo add ant-quic
Download from GitHub Releases:
ant-quic-linux-x86_64, ant-quic-linux-aarch64ant-quic-windows-x86_64.exeant-quic-macos-x86_64, ant-quic-macos-aarch64git clone https://github.com/dirvine/ant-quic
cd ant-quic
cargo build --release
# Run as P2P node (auto-connects to default bootstrap nodes)
ant-quic --listen 0.0.0.0:9000
# Connect to specific known peers
ant-quic --listen 0.0.0.0:9000 --known-peers 1.2.3.4:9000 --known-peers 5.6.7.8:9000
# Show your external address (discovered via peers)
ant-quic --listen 0.0.0.0:9000
# Output: External address: YOUR.PUBLIC.IP:PORT
# Run with monitoring dashboard
ant-quic --dashboard --listen 0.0.0.0:9000
# Interactive commands while running:
# /status - Show connections and discovered addresses
# /peers - List connected peers
# /help - Show all commands
If no --known-peers are specified, ant-quic automatically connects to the Saorsa Labs bootstrap nodes:
saorsa-1.saorsalabs.com:9000saorsa-2.saorsalabs.com:9000These nodes run the same ant-quic software as any peer - they help with initial peer discovery and external address observation.
ant-quic maintains a local cache of discovered peers to improve startup time and resilience. The cache is stored as a JSON file:
| Platform | Cache Location |
|---|---|
| macOS | ~/Library/Caches/ant-quic/bootstrap_cache.json |
| Linux | ~/.cache/ant-quic/bootstrap_cache.json |
| Windows | %LOCALAPPDATA%\ant-quic\bootstrap_cache.json |
The cache includes:
The cache is automatically managed - stale entries are pruned and high-quality peers are prioritized for reconnection.
| Type | Purpose |
|---|---|
P2pEndpoint |
Main entry point for P2P networking |
P2pConfig |
Configuration builder |
P2pEvent |
Events from the endpoint |
PeerId |
32-byte peer identifier |
PqcConfig |
Post-quantum crypto tuning |
NatConfig |
NAT traversal tuning |
impl P2pEndpoint {
// Creation
async fn new(config: P2pConfig) -> Result<Self>;
// Identity
fn peer_id(&self) -> PeerId;
fn local_addr(&self) -> Option<SocketAddr>;
fn external_address(&self) -> Option<SocketAddr>;
// Connections
async fn connect_bootstrap(&self) -> Result<()>;
async fn connect_to_peer(&self, peer: PeerId) -> Result<Connection>;
fn connected_peers(&self) -> Vec<PeerId>;
// Events
fn subscribe(&self) -> broadcast::Receiver<P2pEvent>;
// Statistics
fn stats(&self) -> EndpointStats;
fn nat_stats(&self) -> NatTraversalStatistics;
}
let config = P2pConfig::builder()
.bind_addr("0.0.0.0:9000".parse()?) // Local address
.known_peer(addr1) // Add known peer
.known_peers(vec![addr2, addr3]) // Add multiple
.max_connections(100) // Connection limit
.pqc(pqc_config) // PQC tuning
.nat(nat_config) // NAT tuning
.mtu(MtuConfig::pqc_optimized()) // MTU for PQC
.build()?;
See docs/API_GUIDE.md for the complete API reference.
ant-quic implements these specifications:
| Specification | Status | Notes |
|---|---|---|
| RFC 9000 | Full | QUIC Transport Protocol |
| RFC 9001 | Full | QUIC TLS |
| Pure PQC Auth | Full | Raw Public Keys + Pure PQC (v0.2) |
| draft-seemann-quic-nat-traversal-02 | Full | NAT Traversal |
| draft-ietf-quic-address-discovery-00 | Full | Address Discovery |
| FIPS 203 | Full | ML-KEM (via saorsa-pqc) |
| FIPS 204 | Full | ML-DSA (via saorsa-pqc) |
See docs/review.md for detailed RFC compliance analysis.
| Metric | Value |
|---|---|
| Handshake (PQC) | ~50ms typical |
| Address Discovery | <100ms |
| NAT Traversal | 200-500ms |
| PQC Overhead | ~8.7% |
| Metric | Value |
|---|---|
| Send Throughput | 267 Mbps |
| Protocol Efficiency | 96.5% |
| Protocol Overhead | 3.5% |
| Connections | Memory | CPU |
|---|---|---|
| 100 | 56 KB | Minimal |
| 1,000 | 547 KB | Minimal |
| 5,000 | 2.7 MB | Linear |
# Simple chat application
cargo run --example simple_chat -- --listen 0.0.0.0:9000
# Chat with peer discovery
cargo run --example chat_demo -- --known-peers peer.example.com:9000
# Statistics dashboard
cargo run --example dashboard_demo
# Run all tests
cargo test
# Run with verbose output
cargo test -- --nocapture
# Specific test categories
cargo test nat_traversal
cargo test pqc
cargo test address_discovery
# Run benchmarks
cargo bench
Contributions welcome! Please see CONTRIBUTING.md.
# Development setup
git clone https://github.com/dirvine/ant-quic
cd ant-quic
cargo fmt --all
cargo clippy --all-targets -- -D warnings
cargo test
Licensed under either of:
at your option.
For security vulnerabilities, please email security@autonomi.com rather than filing a public issue.