Advanced Integration

The hayate crate is a modular Rust library. Embed it directly into your application for completion-based QUIC transfers with full control over networking, crypto, and I/O.


Workspace Architecture

CratePurpose
hayateCore engine: QUIC transport, crypto, streaming, discovery
hayate-cliCLI binary wrapping the engine

Adding the Dependency

[dependencies]
hayate = "4.0"
compio = { version = "0.19", features = ["macros", "runtime", "fs", "net", "time"] }

Receiver Example

use std::net::SocketAddr;
use hayate::HayateReceiver;

#[compio::main]
async fn main() -> Result<(), hayate::EngineError> {
    let bind_addr: SocketAddr = "0.0.0.0:50001".parse().unwrap();

    let receiver = HayateReceiver::new()
        .bind(bind_addr)
        .code("apple-bravo-charlie".to_owned());

    let (checksum, output_path) = receiver.receive(
        "./downloads",
        |meta| {
            println!("Incoming: {} ({} bytes)", meta.filename, meta.total_size);
            true
        },
        |bytes_received| {
            println!("Received {bytes_received} bytes");
        },
    ).await?;

    println!("Saved to {}", output_path.display());
    println!("Checksum: {checksum}");
    Ok(())
}

Sender Example

use std::net::SocketAddr;
use hayate::HayateSender;

#[compio::main]
async fn main() -> Result<(), hayate::EngineError> {
    let target_addr: SocketAddr = "192.168.1.50:50001".parse().unwrap();

    let sender = HayateSender::new()
        .target(target_addr)
        .compress(true)
        .hash_algo("blake3".to_owned());

    let checksum = sender.send(
        "./photos.zip",
        |bytes_sent| {
            println!("Sent {bytes_sent} bytes");
        },
    ).await?;

    println!("Done. Checksum: {checksum}");
    Ok(())
}

Buffer Pooling

The hot path uses BufferPool to eliminate heap allocations:

use hayate::pool::BufferPool;
use hayate::protocol::CHUNK_SIZE;

let pool = BufferPool::new(32, CHUNK_SIZE);
let buf = pool.lease().await;
// ... use buffer ...
pool.release(buf);

Buffers are zeroed on release to prevent cryptographic plaintext leaks.


Concurrency Model

LayerStrategy
I/OSingle-thread compio event loop (io_uring / IOCP / kqueue)
CPU-bound workDedicated OS thread pool (std::thread::spawn) per worker
Transfer orderingBTreeMap-based out-of-order frame reassembly
DiscoverymDNS daemon thread + UDP broadcast task, background

Lower-Level API

For protocol-level control, use these modules directly:

ModulePurpose
hayate::transferHandshake, consent, send/receive payload pipelines
hayate::protocolWire constants, Metadata encode/decode, frame flags
hayate::cryptoX25519, HKDF, AEAD sealing/opening
hayate::networkQUIC endpoint binding, TLS config, transport params
hayate::discoverymDNS registration/browsing, UDP broadcast
hayate::tarStreaming tar pack/extract with path-traversal protection
hayate::errorEngineError enum — all error variants