zlayer_proxy/stream/
config.rs1use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct TcpListenerConfig {
9 pub port: u16,
11
12 #[serde(default)]
14 pub protocol_hint: Option<String>,
15
16 #[serde(default)]
18 pub tls: bool,
19
20 #[serde(default)]
22 pub proxy_protocol: bool,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct UdpListenerConfig {
28 pub port: u16,
30
31 #[serde(default)]
33 pub protocol_hint: Option<String>,
34
35 #[serde(default, with = "optional_duration_serde")]
37 pub session_timeout: Option<Duration>,
38}
39
40pub const DEFAULT_UDP_SESSION_TIMEOUT: Duration = Duration::from_secs(60);
42
43mod optional_duration_serde {
45 use serde::{Deserialize, Deserializer, Serialize, Serializer};
46 use std::time::Duration;
47
48 #[allow(clippy::ref_option)]
49 pub fn serialize<S>(value: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error>
50 where
51 S: Serializer,
52 {
53 match value {
54 Some(d) => d.as_secs().serialize(serializer),
55 None => serializer.serialize_none(),
56 }
57 }
58
59 pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
60 where
61 D: Deserializer<'de>,
62 {
63 let opt: Option<u64> = Option::deserialize(deserializer)?;
64 Ok(opt.map(Duration::from_secs))
65 }
66}