Skip to main content

vane_core/
l4.rs

1use std::net::SocketAddr;
2use std::sync::Arc;
3
4use tokio::net::{TcpStream, UdpSocket};
5
6#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, serde::Serialize, serde::Deserialize)]
7pub struct QuicAssocId(pub u64);
8
9pub enum L4Conn {
10	Tcp(TcpStream),
11	Udp(UdpAssoc),
12}
13
14pub struct UdpAssoc {
15	pub socket: Arc<UdpSocket>,
16	pub peer: SocketAddr,
17	pub quic: Option<QuicAssocId>,
18}
19
20#[cfg(test)]
21mod tests {
22	use super::*;
23
24	// Compile-gate: if L4Conn's variant shape changes, this signature fails
25	// to type-check. No runtime assertion is warranted.
26	fn _accepts_l4_conn(_: &L4Conn) {}
27
28	#[test]
29	fn quic_assoc_id_serde_round_trip() {
30		let id = QuicAssocId(0xdead_beef_cafe_babe);
31		let encoded = serde_json::to_string(&id).expect("serialize");
32		let decoded: QuicAssocId = serde_json::from_str(&encoded).expect("deserialize");
33		assert_eq!(decoded, id);
34	}
35
36	#[test]
37	fn quic_assoc_id_equality_is_structural() {
38		assert_eq!(QuicAssocId(42), QuicAssocId(42));
39		assert_ne!(QuicAssocId(42), QuicAssocId(43));
40	}
41}