1use mdns_proto::EndpointConfig;
7
8#[derive(Debug, Clone)]
16pub struct ServerOptions {
17 pub(crate) ipv4: bool,
18 pub(crate) ipv6: bool,
19 pub(crate) interface_index: Option<u32>,
20 pub(crate) max_payload_size: usize,
21 pub(crate) max_recv_packet_size: usize,
22 pub(crate) endpoint_config: EndpointConfig,
23}
24
25impl Default for ServerOptions {
26 #[inline]
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl ServerOptions {
33 #[inline]
35 pub fn new() -> Self {
36 Self {
37 ipv4: true,
38 ipv6: true,
39 interface_index: None,
40 max_payload_size: 1500,
41 max_recv_packet_size: 9000,
42 endpoint_config: EndpointConfig::new(),
43 }
44 }
45
46 #[inline]
48 pub const fn ipv4(&self) -> bool {
49 self.ipv4
50 }
51
52 #[inline]
54 pub const fn ipv6(&self) -> bool {
55 self.ipv6
56 }
57
58 #[inline]
60 pub const fn interface_index(&self) -> Option<u32> {
61 self.interface_index
62 }
63
64 #[inline]
67 pub const fn max_payload_size(&self) -> usize {
68 self.max_payload_size
69 }
70
71 #[inline]
75 pub const fn max_recv_packet_size(&self) -> usize {
76 self.max_recv_packet_size
77 }
78
79 #[inline]
81 pub const fn endpoint_config(&self) -> &EndpointConfig {
82 &self.endpoint_config
83 }
84
85 #[inline]
87 #[must_use]
88 pub const fn with_ipv4(mut self, enable: bool) -> Self {
89 self.ipv4 = enable;
90 self
91 }
92
93 #[inline]
95 #[must_use]
96 pub const fn with_ipv6(mut self, enable: bool) -> Self {
97 self.ipv6 = enable;
98 self
99 }
100
101 #[inline]
105 #[must_use]
106 pub const fn with_interface_index(mut self, idx: Option<u32>) -> Self {
107 self.interface_index = idx;
108 self
109 }
110
111 #[inline]
113 #[must_use]
114 pub const fn with_max_payload_size(mut self, size: usize) -> Self {
115 self.max_payload_size = size;
116 self
117 }
118
119 #[inline]
121 #[must_use]
122 pub const fn with_max_recv_packet_size(mut self, size: usize) -> Self {
123 self.max_recv_packet_size = size;
124 self
125 }
126
127 #[inline]
129 #[must_use]
130 pub fn with_endpoint_config(mut self, cfg: EndpointConfig) -> Self {
131 self.endpoint_config = cfg;
132 self
133 }
134}
135
136#[cfg(test)]
137mod tests;