Skip to main content

HydraServer

Struct HydraServer 

Source
pub struct HydraServer { /* private fields */ }
Expand description

HydraServer- A light-weight, E2E (AES-GCM), multi-threaded SPMC broadcast server using TCP. It implements internal ring buffer configured by HydraConfig, uses little memory and minimal copy as possible.

use hydra_sync::server::HydraServer;

#[tokio::main]
async fn main() {
    let (server, addr) = HydraServer::bind_default().await.unwrap();
    println!("Server running on: {}", addr);
    tokio::spawn(async move { server.run().await });
}

Implementations§

Source§

impl HydraServer

Source

pub async fn bind_default() -> Result<(Self, SocketAddr)>

Binds the server with random local port and default HydraConfig, returns the port.

Source

pub async fn bind( socket_addr: SocketAddr, hydra_config: HydraConfig, ) -> Result<(Self, SocketAddr)>

Binds the server to the specified SocketAddr with the provided HydraConfig.

Source

pub async fn run(&self) -> Result<()>

Starts the server, accepting incoming connections and handling them concurrently. Overview:

  • Accept incoming TCP connections, spawn handler tasks and allocate read/write buffers or reject if max connections reached.
  • Perform handshake, read/decrypt JoinHeader, determine role (Producer/Consumer/Admin).
  • For Producers: Create valid session, read data (exactly fixed_packet_length, including AES-GCM (28 bytes) overhead, with read_exact(), so it may truncate) and broadcast (cheap-copy) to all Consumers in the session (Write behavior is configured by ChannelOverflowStrategy).
  • For Consumers: Validate session, read from local ring buffer from producer handle, write to TCP stream.
  • LOG_LEVEL & LOG_FILE_DIR env vars can be set to control logging verbosity and output file (defaults to info level and stdout and file).
  • EOF check are gracefully handled by closing the connection without logging an error.
Source

pub async fn shutdown(&self) -> Result<()>

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 = !

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.