Skip to main content

HydraServer

Struct HydraServer 

Source
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

Source

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
Source

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

Source

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_ms is 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_FILE env vars can be set to control logging verbosity and output file (defaults to info level and stdout, not file).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.