Skip to main content

nxtquic_api/
endpoint.rs

1//! Endpoint management and socket binding.
2
3use std::net::SocketAddr;
4use crate::connection::Connection;
5
6/// Configuration for an endpoint.
7#[derive(Default, Clone, Debug)]
8pub struct EndpointConfig;
9
10/// Configuration for a server endpoint.
11#[derive(Default, Clone, Debug)]
12pub struct ServerConfig;
13
14/// Configuration for a client endpoint.
15#[derive(Default, Clone, Debug)]
16pub struct ClientConfig;
17
18/// A QUIC endpoint.
19pub struct Endpoint {
20    config: EndpointConfig,
21    server_config: Option<ServerConfig>,
22}
23
24/// An ongoing connection attempt.
25pub struct Connecting;
26
27/// An incoming connection attempt.
28pub struct Incoming;
29
30impl Endpoint {
31    /// Creates a new endpoint.
32    pub fn new(config: EndpointConfig, server_config: Option<ServerConfig>) -> Self {
33        Self { config, server_config }
34    }
35
36    /// Binds the endpoint to a local socket address.
37    pub async fn bind(_addr: SocketAddr) -> std::io::Result<Self> {
38        Ok(Self::new(EndpointConfig::default(), None))
39    }
40
41    /// Connects to a remote endpoint.
42    pub async fn connect(&self, _addr: SocketAddr, _server_name: &str) -> std::io::Result<Connecting> {
43        Ok(Connecting)
44    }
45
46    /// Accepts an incoming connection.
47    pub async fn accept(&self) -> Option<Incoming> {
48        None
49    }
50}
51
52impl Connecting {
53    /// Waits for the connection attempt to complete.
54    pub async fn await_connection(self) -> std::io::Result<Connection> {
55        Ok(Connection::new())
56    }
57}
58
59impl Incoming {
60    /// Accepts the incoming connection.
61    pub async fn accept(self) -> std::io::Result<Connection> {
62        Ok(Connection::new())
63    }
64}