fastnet/
lib.rs

1//! # FastNet - Ultra-Low Latency Encrypted Networking
2//!
3//! FastNet is a high-performance networking library designed for real-time multiplayer games.
4//! It provides encrypted UDP communication with latencies as low as **15 microseconds**
5//! while maintaining strong security through TLS 1.3 and ChaCha20-Poly1305 encryption.
6//!
7//! ## Features
8//!
9//! - **Ultra-Low Latency**: ~15µs average RTT on localhost
10//! - **Built-in Encryption**: TLS 1.3 handshake + ChaCha20-Poly1305 AEAD
11//! - **Zero Configuration Security**: Encryption is always on
12//! - **Game Engine Ready**: C/C++ FFI for Unreal Engine, Unity, Godot
13//!
14//! ## Quick Start
15//!
16//! ### Server
17//!
18//! ```rust,no_run
19//! use fastnet::net::{SecureSocket, SecureEvent};
20//! use std::net::SocketAddr;
21//!
22//! #[tokio::main]
23//! async fn main() -> std::io::Result<()> {
24//!     let udp_addr: SocketAddr = "0.0.0.0:7777".parse().unwrap();
25//!     let tcp_addr: SocketAddr = "0.0.0.0:7778".parse().unwrap();
26//!     
27//!     // Load your TLS certificates
28//!     let certs = vec![]; // Load from file
29//!     let key = todo!();  // Load from file
30//!     
31//!     let mut socket = SecureSocket::bind_server(udp_addr, tcp_addr, certs, key).await?;
32//!     
33//!     loop {
34//!         for event in socket.poll().await? {
35//!             match event {
36//!                 SecureEvent::Connected(peer_id) => {
37//!                     println!("Peer {} connected", peer_id);
38//!                 }
39//!                 SecureEvent::Data(peer_id, channel, data) => {
40//!                     // Echo back
41//!                     socket.send(peer_id, channel, data).await?;
42//!                 }
43//!                 SecureEvent::Disconnected(peer_id) => {
44//!                     println!("Peer {} disconnected", peer_id);
45//!                 }
46//!             }
47//!         }
48//!     }
49//! }
50//! ```
51//!
52//! ### Client
53//!
54//! ```rust,no_run
55//! use fastnet::net::{SecureSocket, SecureEvent};
56//!
57//! #[tokio::main]
58//! async fn main() -> std::io::Result<()> {
59//!     let server_addr = "127.0.0.1:7778".parse().unwrap();
60//!     let mut socket = SecureSocket::connect(server_addr).await?;
61//!     
62//!     // Send data on channel 0
63//!     socket.send(1, 0, b"Hello!".to_vec()).await?;
64//!     
65//!     // Poll for events
66//!     for event in socket.poll().await? {
67//!         if let SecureEvent::Data(_, _, data) = event {
68//!             println!("Received: {:?}", data);
69//!         }
70//!     }
71//!     
72//!     Ok(())
73//! }
74//! ```
75//!
76//! ## Architecture
77//!
78//! ```text
79//! ┌─────────────────────────────────────────────────────────┐
80//! │                     SecureSocket                        │
81//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐ │
82//! │  │ TLS 1.3     │  │ ChaCha20    │  │ Channels        │ │
83//! │  │ Handshake   │──│ Poly1305    │──│ (Reliable/etc)  │ │
84//! │  └─────────────┘  └─────────────┘  └─────────────────┘ │
85//! │                          │                              │
86//! │                    ┌─────┴─────┐                       │
87//! │                    │    UDP    │                       │
88//! │                    └───────────┘                       │
89//! └─────────────────────────────────────────────────────────┘
90//! ```
91//!
92//! ## C/C++ Integration
93//!
94//! Build with the `ffi` feature to generate a C-compatible dynamic library:
95//!
96//! ```bash
97//! cargo build --release --features ffi
98//! ```
99//!
100//! See the `include/fastnet.h` header for the C API documentation.
101
102pub mod net;
103
104#[cfg(feature = "ffi")]
105pub mod ffi;
106
107// Re-export main types at crate root for convenience
108pub use net::{SecureSocket, SecureEvent};