Skip to main content

vane_core/
l4.rs

1use std::net::SocketAddr;
2use std::sync::Arc;
3
4use bytes::Bytes;
5use tokio::net::{TcpStream, UdpSocket};
6
7use crate::fetch::AsyncReadWrite;
8
9pub enum L4Conn {
10	Tcp(TcpStream),
11	/// Cleartext stream that the listener-side peek prelude has already
12	/// drained part of, with those bytes rewound into the read side via
13	/// `PeekedStream`. Type-erased so `vane-core` doesn't need to know
14	/// the concrete adapter; downstream consumers see the connection
15	/// from byte zero.
16	Peeked(Box<dyn AsyncReadWrite + Send>),
17	/// TLS-terminated stream after a server-side handshake completed.
18	/// The trait object erases the concrete `tokio_rustls::TlsStream`
19	/// type so that `vane-core` doesn't need to depend on rustls
20	/// (the parsing + termination live in `vane-engine`). `AsyncReadWrite`
21	/// is the same trait `L4ForwardFetch` uses for byte-tunnel I/O,
22	/// auto-impl'd on any `AsyncRead + AsyncWrite + Unpin`. See
23	/// `spec/crates/engine-tls.md` § _Termination flow (L4 → L7 upgrade)_.
24	Tls(Box<dyn AsyncReadWrite + Send>),
25	Udp(UdpAssoc),
26}
27
28pub struct UdpAssoc {
29	/// Physical listener socket — vane-owned, shared via `Arc` with the
30	/// listener's recv loop. The fetch sends responses back to the peer
31	/// through this socket; the listener demuxes inbound datagrams to
32	/// the per-session forwarder via the dispatch table. See
33	/// `spec/crates/engine.md` § _`udp_dispatch`_.
34	pub socket: Arc<UdpSocket>,
35	pub peer: SocketAddr,
36	/// Datagrams that triggered the cold-path `FlowGraph` entry, in
37	/// arrival order. Length is `1` for the immediate cold-path; `> 1`
38	/// only when the listener went through the pending-peek state
39	/// machine and the buffered datagrams replay together (per
40	/// `spec/crates/engine.md` § _Multi-packet peek_ § _Multi-packet peek_). The `L4Forward` fetch sends every entry verbatim, in
41	/// this order, before subscribing to the inbound hot-path channel.
42	pub first_packets: Vec<Bytes>,
43}
44
45#[cfg(test)]
46mod tests {
47	use super::*;
48
49	// Compile-gate: if L4Conn's variant shape changes, this signature fails
50	// to type-check. No runtime assertion is warranted.
51	fn _accepts_l4_conn(_: &L4Conn) {}
52}