Skip to main content

krot_transport/
lib.rs

1//! QUIC transport layer for KROT.
2//!
3//! Wires the byte-level protocol from [`krot_proto`] onto `quinn` streams
4//! with the ALPN and transport parameters mandated by §2
5//! and §11.
6//!
7//! ## Modules
8//!
9//! - [`endpoint`] — [`KrotEndpoint`] wrapper around [`quinn::Endpoint`],
10//!   pre-configured with `krot/1` ALPN, 5s keep-alive, 15s idle timeout,
11//!   and the recommended stream/connection windows.
12//! - [`frame`] — asynchronous readers and writers for the length-prefixed
13//!   `postcard` frames that flow on Control streams.
14//! - [`relay`] — [`BidiStream`] adapter combining `quinn::SendStream` and
15//!   `quinn::RecvStream` into a single `AsyncRead + AsyncWrite`, plus
16//!   [`relay::run_bidirectional`] for the byte-shovel between a QUIC
17//!   stream and a local TCP socket.
18//!
19//! ## rustls crypto provider
20//!
21//! rustls 0.23 requires a process-wide crypto provider to be installed
22//! before any TLS configuration is constructed. Call
23//! [`install_crypto_provider`] once at binary startup.
24
25#![deny(missing_debug_implementations)]
26
27pub mod conn;
28pub mod endpoint;
29pub mod error;
30pub mod frame;
31pub mod relay;
32pub mod tcp_listener;
33pub mod tcp_mux;
34
35pub use conn::{Connection, Incoming, RecvStream, SendStream, TransportKind};
36pub use endpoint::{client_transport_config, server_transport_config, KrotEndpoint};
37pub use error::TransportError;
38pub use frame::{read_frame, write_frame};
39pub use relay::{run_bidirectional, run_bidirectional_with_first_byte_deadline, BidiStream};
40pub use tcp_listener::{connect_tcp_fallback, TcpFallbackListener};
41pub use tcp_mux::{TcpMuxConn, TcpMuxRecvStream, TcpMuxSendStream};
42
43pub use krot_proto;
44
45/// Install `rustls`'s ring-backed crypto provider as the process default.
46///
47/// Safe to call multiple times: subsequent calls after the first
48/// successful install are no-ops. Must be called before constructing any
49/// [`rustls::ClientConfig`] or [`rustls::ServerConfig`].
50pub fn install_crypto_provider() {
51    // Ignore the returned error: it means a provider is already installed,
52    // which is what we want.
53    let _ = rustls::crypto::ring::default_provider().install_default();
54}