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
impl HydraServer
Sourcepub async fn bind_default() -> Result<(Self, SocketAddr)>
pub async fn bind_default() -> Result<(Self, SocketAddr)>
Binds the server with random local port and default HydraConfig, returns the port.
Sourcepub async fn bind(
socket_addr: SocketAddr,
hydra_config: HydraConfig,
) -> Result<(Self, SocketAddr)>
pub async fn bind( socket_addr: SocketAddr, hydra_config: HydraConfig, ) -> Result<(Self, SocketAddr)>
Binds the server to the specified SocketAddr with the provided HydraConfig.
Sourcepub async fn run(&self) -> Result<()>
pub async fn run(&self) -> Result<()>
Starts the server, accepting incoming connections and handling them concurrently. Overview:
- Accept incoming
TCP connections, spawn handler tasks andallocate read/write buffersor 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, withread_exact(), so it may truncate) and broadcast(cheap-copy)to all Consumers in the session (Write behavior is configured byChannelOverflowStrategy). - For Consumers: Validate session, read from
local ring bufferfrom producer handle, write to TCP stream. LOG_LEVEL&LOG_FILE_DIRenv vars can be set to controllogging verbosityand output file (defaults toinfolevel and stdout and file).- EOF check are gracefully handled by closing the connection without logging an error.
pub async fn shutdown(&self) -> Result<()>
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