runsync-transfer 2026.1.0

High-throughput P2P file transfer engine: adaptive compression, end-to-end AEAD, parallel chunked pipeline over QUIC or any async transport.
Documentation
//! Transport abstraction.
//!
//! The engine needs exactly four things from a connection: open and accept
//! unidirectional streams (data), and open and accept a bidirectional stream
//! (control). Anything providing those can carry a transfer — QUIC is the
//! intended target, but the in-memory transport used by the test suite
//! implements the same trait, and so can an existing connection you already
//! own.
//!
//! This is deliberately a `dyn`-compatible trait taking `Box`ed streams. The
//! per-call cost is one virtual dispatch per *stream*, not per chunk, so it is
//! invisible next to the I/O — and in exchange a host application can hand the
//! engine its own live `quinn::Connection` instead of letting the engine dial
//! its own.

use crate::error::Result;
use tokio::io::{AsyncRead, AsyncWrite};

pub mod mem;
#[cfg(feature = "quic")]
pub mod quic;

/// Write half of a stream. Call `shutdown()` to signal a clean end of stream.
pub type BoxSend = Box<dyn AsyncWrite + Unpin + Send>;
/// Read half of a stream. Returns EOF when the peer finished it.
pub type BoxRecv = Box<dyn AsyncRead + Unpin + Send>;

#[async_trait::async_trait]
pub trait Transport: Send + Sync + 'static {
    /// Open a unidirectional stream for data frames.
    async fn open_uni(&self) -> Result<BoxSend>;

    /// Accept the next unidirectional stream the peer opened.
    async fn accept_uni(&self) -> Result<BoxRecv>;

    /// Open the bidirectional control stream.
    async fn open_bi(&self) -> Result<(BoxSend, BoxRecv)>;

    /// Accept the peer's bidirectional control stream.
    async fn accept_bi(&self) -> Result<(BoxSend, BoxRecv)>;

    /// Close the connection. Best-effort; never blocks.
    fn close(&self, code: u32, reason: &[u8]);

    /// Human-readable peer identity, for logs.
    fn peer_label(&self) -> String {
        "peer".to_string()
    }

    /// Bytes already sent on this connection, if the transport tracks it.
    /// Used to report true wire throughput against post-compression volume.
    fn bytes_sent(&self) -> Option<u64> {
        None
    }
}