Skip to main content

karyon_net/
stream.rs

1#[cfg(any(feature = "tls", feature = "quic"))]
2use rustls_pki_types::CertificateDer;
3
4use karyon_core::async_runtime::io::{AsyncRead, AsyncWrite};
5
6use crate::Endpoint;
7
8/// Byte-oriented bidirectional stream.
9///
10/// Implemented by TCP, TLS, Unix, and QUIC streams. Extends
11/// `AsyncRead + AsyncWrite` for compatibility with IO libraries.
12/// Use `framed()` to convert into a `FramedConn` with a codec.
13pub trait ByteStream: AsyncRead + AsyncWrite + Send + Sync + Unpin {
14    /// Remote peer address, if available.
15    fn peer_endpoint(&self) -> Option<Endpoint>;
16    /// Local address, if available.
17    fn local_endpoint(&self) -> Option<Endpoint>;
18    /// Peer certificate chain when the underlying transport authenticates
19    /// the peer with X.509 (TLS, QUIC). Returns `None` for plain
20    /// TCP/Unix and other unauthenticated transports.
21    #[cfg(any(feature = "tls", feature = "quic"))]
22    fn peer_certificates(&self) -> Option<Vec<CertificateDer<'static>>> {
23        None
24    }
25}