nxtquic-api 0.1.1

High-level async API for NxtQuic
Documentation
//! Endpoint management and socket binding.

use std::net::SocketAddr;
use crate::connection::Connection;

/// Configuration for an endpoint.
#[derive(Default, Clone, Debug)]
pub struct EndpointConfig;

/// Configuration for a server endpoint.
#[derive(Default, Clone, Debug)]
pub struct ServerConfig;

/// Configuration for a client endpoint.
#[derive(Default, Clone, Debug)]
pub struct ClientConfig;

/// A QUIC endpoint.
pub struct Endpoint {
    config: EndpointConfig,
    server_config: Option<ServerConfig>,
}

/// An ongoing connection attempt.
pub struct Connecting;

/// An incoming connection attempt.
pub struct Incoming;

impl Endpoint {
    /// Creates a new endpoint.
    pub fn new(config: EndpointConfig, server_config: Option<ServerConfig>) -> Self {
        Self { config, server_config }
    }

    /// Binds the endpoint to a local socket address.
    pub async fn bind(_addr: SocketAddr) -> std::io::Result<Self> {
        Ok(Self::new(EndpointConfig::default(), None))
    }

    /// Connects to a remote endpoint.
    pub async fn connect(&self, _addr: SocketAddr, _server_name: &str) -> std::io::Result<Connecting> {
        Ok(Connecting)
    }

    /// Accepts an incoming connection.
    pub async fn accept(&self) -> Option<Incoming> {
        None
    }
}

impl Connecting {
    /// Waits for the connection attempt to complete.
    pub async fn await_connection(self) -> std::io::Result<Connection> {
        Ok(Connection::new())
    }
}

impl Incoming {
    /// Accepts the incoming connection.
    pub async fn accept(self) -> std::io::Result<Connection> {
        Ok(Connection::new())
    }
}