Skip to main content

Crate udp_relay_core

Crate udp_relay_core 

Source
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 for Arc<TunnelClient> in a DashMap.
  • 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 a DashMap with 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§

QualityAnalyzer
Lock-free packet loss tracker with periodic counter halving to avoid overflow.
TunnelClient
A UDP tunnel client with lock-free atomic metrics.

Functions§

create_dashmap_with_capacity
Create a DashMap with 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.