Expand description
Lock-free, cache-line-aligned core types for building high-performance UDP relay and tunnel servers.
§Overview
This crate provides the shared-state primitives you need when forwarding UDP packets between many clients at high throughput:
TunnelClient— per-client atomic metrics (bandwidth, latency, packet loss, priority scoring) designed forArc<TunnelClient>in aDashMap.QualityAnalyzer— lightweight packet loss tracker with automatic counter halving so counters never overflow.validate_address— rejects loopback, unspecified, broadcast, multicast, and port-0 addresses.create_dashmap_with_capacity— creates aDashMapwith a shard count tuned to the CPU count.
§Quick start
use std::sync::Arc;
use udp_relay_core::{TunnelClient, create_dashmap_with_capacity};
let clients = create_dashmap_with_capacity::<u32, Arc<TunnelClient>>(200);
let addr = "1.2.3.4:5678".parse().unwrap();
let client = Arc::new(TunnelClient::new_with_endpoint(addr, 30));
clients.insert(42, client.clone());
let now = TunnelClient::current_timestamp();
client.update_stats(512, 0, now);
client.set_last_receive_tick_at(now);
if client.is_timed_out() {
clients.remove(&42);
}Structs§
- Quality
Analyzer - Lock-free packet loss tracker with periodic counter halving to avoid overflow.
- Tunnel
Client - A UDP tunnel client with lock-free atomic metrics.
Functions§
- create_
dashmap_ with_ capacity - Create a
DashMapwith a shard count tuned to the CPU count. - validate_
address - Validate that a socket address is routable (not loopback/unspecified/broadcast/multicast) and has a non-zero port.