Skip to main content

Crate hydra_sync

Crate hydra_sync 

Source
Expand description

§hydra-sync

A lightweight, end-to-end encrypted (AES-GCM256) SPMC broadcast server over plain TCP.

One producer fans out fixed-size packets to many consumers through per-consumer lock-free ring buffers, while the server stays a blind relay — it never holds a key and never sees plaintext.

§Features

  • E2E encryptionX25519 key-exchange handshake + AES-GCM256 per packet; the server relays ciphertext only.
  • Zero-copy relayBytesMut handles move through cache-padded SPSC rings; no payload copies on the hot path.
  • Fixed-size framing — server reads/writes exact packet sizes; clients deal only in raw payload bytes, crypto overhead is internal.
  • Cross-language friendly — dumb, agreed wire protocol; any language can implement a client against it.

§Example

use hydra_sync::client::{Consumer, HydraClient, Producer};

#[tokio::main]
async fn main() {
    let (server, addr) = hydra_sync::server::HydraServer::bind_default().await.unwrap();
    tokio::spawn(async move { let _ = server.run().await; });

    let session_id = [0xFFu8; 64];
    let session_key = [0xAAu8; 32];

    // producer creates & owns the session
    let mut producer = HydraClient::<Producer>::connect(addr, session_id, session_key).await.unwrap();

    // consumers join it
    let mut consumer = HydraClient::<Consumer>::connect(addr, session_id, session_key).await.unwrap();

    let payload = vec![0u8; producer.get_server_read_write_length() as usize];
    producer.broadcast(&payload).await.unwrap(); // fan-out to every consumer

    let packet = consumer.recv().await.unwrap(); // next frame on the ring buffer
}

Modules§

channel
A single-producer, single-consumer (SPSC) lock-free ring buffer for Bytes handles.
client
Producer/Consumer client for the Hydra protocol, connects to the server, performs handshake, and sends/receives encrypted packets (AES-GCM).
crypto
AES-GCM256 cryptography primitives for encrypting and decrypting data in the HydraSync protocol.
server
Core implementation for the HydraSync server.

Macros§

assert_size
Asserts that the size of a type is equal to size.
debug
error
info
trace
warn

Enums§

ChannelOverflowStrategy
Determines what happens when a consumer’s channel is full and overflows, Issue.

Constants§

BUFFER_SIZE
READ_WRITE_TIMEOUT