vane_core/
protocol_detect.rs1use bytes::Bytes;
11
12#[derive(Clone, Debug)]
13pub struct PeekResult {
14 pub buffer: Bytes,
15 pub detected: Option<DetectedProtocol>,
16 pub tls: Option<TlsClientHello>,
17}
18
19#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
20pub enum DetectedProtocol {
21 TlsClientHello,
22 Http1,
23 Http2Preface,
24 QuicInitial,
25 Dns,
26 Unknown,
27}
28
29#[derive(Clone, Debug, Default)]
30pub struct TlsClientHello {
31 pub sni: Option<String>,
32 pub alpn: Vec<Vec<u8>>,
34}
35
36pub const MAX_PEEK_BYTES: usize = 8 * 1024;
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn peek_result_is_clone_send_sync_static() {
47 fn assert_bounds<T: Clone + Send + Sync + 'static>() {}
48 assert_bounds::<PeekResult>();
49 }
50
51 #[test]
52 fn detected_protocol_variants_are_distinct() {
53 let all = [
54 DetectedProtocol::TlsClientHello,
55 DetectedProtocol::Http1,
56 DetectedProtocol::Http2Preface,
57 DetectedProtocol::QuicInitial,
58 DetectedProtocol::Dns,
59 DetectedProtocol::Unknown,
60 ];
61 for (i, a) in all.iter().enumerate() {
62 for (j, b) in all.iter().enumerate() {
63 assert_eq!(a == b, i == j);
64 }
65 }
66 }
67
68 #[test]
69 fn tls_client_hello_default_is_empty() {
70 let h = TlsClientHello::default();
71 assert!(h.sni.is_none());
72 assert!(h.alpn.is_empty());
73 }
74
75 #[test]
76 fn max_peek_bytes_matches_spec() {
77 assert_eq!(MAX_PEEK_BYTES, 8 * 1024);
78 }
79}