Skip to main content

hick_reactor/
options.rs

1//! Caller-facing endpoint construction options.
2
3use mdns_proto::EndpointConfig;
4
5/// Build-time configuration for an mDNS [`Endpoint`](crate::Endpoint).
6///
7/// The defaults bind on **one** interface for both IPv4 and IPv6: the first
8/// up + multicast-capable, non-loopback interface reported by
9/// [`getifs::interfaces`] that has a usable address for each enabled
10/// family, falling back to the loopback interface if no other is eligible.
11/// Use [`Self::with_interface_index`] to pin a specific interface.
12///
13/// Multi-interface binding (one socket pair per interface) is not yet
14/// supported — callers who need to advertise on several NICs should
15/// construct one [`Endpoint`](crate::Endpoint) per interface.
16#[derive(Debug, Clone)]
17pub struct ServerOptions {
18  pub(crate) ipv4: bool,
19  pub(crate) ipv6: bool,
20  pub(crate) interface_index: Option<u32>,
21  pub(crate) max_payload_size: usize,
22  pub(crate) max_recv_packet_size: usize,
23  pub(crate) update_channel_capacity: usize,
24  pub(crate) endpoint_config: EndpointConfig,
25}
26
27impl Default for ServerOptions {
28  #[inline]
29  fn default() -> Self {
30    Self::new()
31  }
32}
33
34impl ServerOptions {
35  /// Build a new options bundle with defaults.
36  #[inline]
37  pub fn new() -> Self {
38    Self {
39      ipv4: true,
40      ipv6: true,
41      interface_index: None,
42      max_payload_size: 1500,
43      max_recv_packet_size: 9000,
44      update_channel_capacity: 64,
45      endpoint_config: EndpointConfig::new(),
46    }
47  }
48
49  /// Whether IPv4 is enabled.
50  #[inline]
51  pub const fn ipv4(&self) -> bool {
52    self.ipv4
53  }
54
55  /// Disable IPv4. At least one of v4/v6 must remain enabled.
56  #[inline]
57  pub fn with_ipv4(mut self, enable: bool) -> Self {
58    self.ipv4 = enable;
59    self
60  }
61
62  /// Whether IPv6 is enabled.
63  #[inline]
64  pub const fn ipv6(&self) -> bool {
65    self.ipv6
66  }
67
68  /// Disable IPv6.
69  #[inline]
70  pub fn with_ipv6(mut self, enable: bool) -> Self {
71    self.ipv6 = enable;
72    self
73  }
74
75  /// The pinned interface index, if any.
76  #[inline]
77  pub const fn interface_index(&self) -> Option<u32> {
78    self.interface_index
79  }
80
81  /// Pin the listener to a specific interface (by OS index). When `None`
82  /// (the default), the first multicast-capable, non-loopback interface is
83  /// picked.
84  #[inline]
85  pub fn with_interface_index(mut self, idx: Option<u32>) -> Self {
86    self.interface_index = idx;
87    self
88  }
89
90  /// Maximum outgoing-packet buffer size. RFC 6762 §17 recommends staying
91  /// within the path MTU on send (~1500 bytes for Ethernet).
92  #[inline]
93  pub const fn max_payload_size(&self) -> usize {
94    self.max_payload_size
95  }
96
97  /// Override the maximum outgoing packet size.
98  #[inline]
99  pub fn with_max_payload_size(mut self, size: usize) -> Self {
100    self.max_payload_size = size;
101    self
102  }
103
104  /// Maximum size of an inbound mDNS datagram that we will fully receive
105  /// without truncation. RFC 6762 §17 says implementations MUST be prepared
106  /// to receive messages up to 9000 bytes (jumbo-frame-sized) even though
107  /// outgoing messages should fit in the path MTU.
108  #[inline]
109  pub const fn max_recv_packet_size(&self) -> usize {
110    self.max_recv_packet_size
111  }
112
113  /// Override the recv buffer size.
114  #[inline]
115  pub fn with_max_recv_packet_size(mut self, size: usize) -> Self {
116    self.max_recv_packet_size = size;
117    self
118  }
119
120  /// Capacity of the per-handle update channel that the driver writes to.
121  ///
122  /// **Deprecated**: per-handle channels are now unbounded
123  /// so that critical events (Established/Renamed/Conflict/HostConflict/
124  /// Terminal) cannot be silently dropped under backpressure. This value
125  /// is preserved for API compatibility but has no effect.
126  #[inline]
127  #[deprecated(note = "per-handle channels are unbounded; this setting has no effect")]
128  pub const fn update_channel_capacity(&self) -> usize {
129    self.update_channel_capacity
130  }
131
132  /// Override the per-handle update channel capacity. **No-op** —
133  /// see [`Self::update_channel_capacity`].
134  #[inline]
135  #[deprecated(note = "per-handle channels are unbounded; this setting has no effect")]
136  pub fn with_update_channel_capacity(mut self, cap: usize) -> Self {
137    self.update_channel_capacity = cap;
138    self
139  }
140
141  /// The proto-layer [`EndpointConfig`].
142  #[inline]
143  pub const fn endpoint_config(&self) -> &EndpointConfig {
144    &self.endpoint_config
145  }
146
147  /// Override the proto-layer [`EndpointConfig`].
148  #[inline]
149  pub fn with_endpoint_config(mut self, cfg: EndpointConfig) -> Self {
150    self.endpoint_config = cfg;
151    self
152  }
153}
154
155#[cfg(test)]
156#[allow(deprecated)]
157mod tests;