pub struct HydraServer { /* private fields */ }Expand description
A light-weight multi-threaded SPMC (Single Producer Multiple Consumer) E2E relay server.
HydraServer implements a zero-copy broadcast relay that:
- Accepts one producer and multiple consumers per session
- Routes data from producer → all connected consumers using Arc-backed
Bytes - Handles backpressure and slow consumers with broadcast channel lagging
- Enforces connection limits and per-payload size constraints
Internals
- Producer: Sends encrypted frames → broadcast channel
- Consumers: Subscribe to broadcast, receive clones of
Arc<Bytes>(zero-copy) - Sessions: Keyed by 64-byte session_id, one producer per session allowed
- Errors & Logs: Error are predictable and handled gracefully by closing connections and logging without crashing the server
Implementations§
Source§impl HydraServer
impl HydraServer
Sourcepub async fn bind_default() -> Result<(Self, SocketAddr)>
pub async fn bind_default() -> Result<(Self, SocketAddr)>
Binds the relay server with defaults
- addr: OS-assigned port
- max_connections: 32
- max_payload_length: 64 MiB
- broadcast_capacity: 256 messages
Sourcepub async fn bind(
addr: &SocketAddr,
max_payload_length: usize,
max_connections: usize,
broadcast_capacity: usize,
) -> Result<Self>
pub async fn bind( addr: &SocketAddr, max_payload_length: usize, max_connections: usize, broadcast_capacity: usize, ) -> Result<Self>
Binds the relay server to the specified socket address and initializes internal state
Sourcepub async fn run(self, connections_timeout_ms: u64) -> Result<()>
pub async fn run(self, connections_timeout_ms: u64) -> Result<()>
Main server loop to accept incoming connections, spawn thread handlers, perform handshakes & session creation
connections_timeout_msis the delay before client retries to accept new connections on server when the limit is reached- Producer errors; If read fails from client or broadcast send fails, the connection is closed and the error is logged.
- Producer errors; If writing to client fails or broadcast lags or closed, the connection is closed and the error is logged.
- EOF check are gracefully handled by closing the connection without logging an error.
LOG_LEVEL&LOG_FILEenv vars can be set to control logging verbosity and output file (defaults toinfolevel and stdout, not file).
Auto Trait Implementations§
impl !Freeze for HydraServer
impl !RefUnwindSafe for HydraServer
impl !UnwindSafe for HydraServer
impl Send for HydraServer
impl Sync for HydraServer
impl Unpin for HydraServer
impl UnsafeUnpin for HydraServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more