libsession 0.1.3

Session messenger core library - cryptography, config management, networking
Documentation
//! Transport layer trait definition.
//!
//! Defines the interface for sending raw bytes over the network.
//! Full implementations (e.g., QUIC) require live network testing.

use std::time::Duration;

/// Transport layer trait for sending/receiving raw data.
#[allow(async_fn_in_trait)]
pub trait Transport: Send + Sync {
    /// Sends raw data to the specified address and returns the response.
    async fn send(
        &self,
        address: &str,
        port: u16,
        data: &[u8],
        timeout: Duration,
    ) -> Result<Vec<u8>, TransportError>;

    /// Checks if the transport is currently connected.
    fn is_connected(&self) -> bool;

    /// Closes the transport connection.
    async fn close(&self);
}

/// Errors that can occur during transport operations.
#[derive(Debug, thiserror::Error)]
pub enum TransportError {
    #[error("Connection failed: {0}")]
    ConnectionFailed(String),
    #[error("Send failed: {0}")]
    SendFailed(String),
    #[error("Receive failed: {0}")]
    ReceiveFailed(String),
    #[error("Timeout")]
    Timeout,
    #[error("Connection closed")]
    ConnectionClosed,
    #[error("TLS error: {0}")]
    TlsError(String),
    #[error("{0}")]
    Other(String),
}