pub struct DeviceDiscovery { /* private fields */ }Expand description
Discovers Enpose tracker devices on the local network.
On every call to Self::discover the API sends discovery
requests to every directed-broadcast address of every up,
non-loopback IPv4 interface on the host (e.g. 192.168.10.255 on
a host with enp1s0 192.168.10.10/24), plus the limited-broadcast
address 255.255.255.255. This reaches the cluster network on
multi-NIC hosts where the kernel’s default route would otherwise
send the limited broadcast out the wrong interface (typically the
wifi default route, leaving the cluster ethernet unreachable).
A single instance can be reused for many discovery rounds; the API holds no persistent network state between calls.
Implementations§
Source§impl DeviceDiscovery
impl DeviceDiscovery
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new DeviceDiscovery that, on each Self::discover
call, broadcasts to every directed-broadcast on the host plus
255.255.255.255 — all on BROADCAST_PORT.
Sourcepub fn discover(&self) -> Result<Vec<DeviceInfo>>
pub fn discover(&self) -> Result<Vec<DeviceInfo>>
Broadcast discovery requests and collect replies.
Sends the discovery request to BROADCAST_PORT up to three times,
150 ms apart, and listens on the same socket for
PKT_TYPE_PEER_INFO replies. Resending guards against a dropped
request or reply on a lossy segment. Only the elected primary of a
cluster replies, so a cluster contributes one entry; multiple clusters
on the same L2 segment each contribute one. Replies are de-duplicated
by serial.
Timing: returns 50 ms after the last reply (whichever cluster replies last), or — if nothing replies — only at the hard 500 ms cap, having retransmitted the request in the meantime.
§Errors
Returns an io::Error only for unrecoverable socket failures
(bind, send, or unexpected recv errors). A normal “no devices
found” outcome returns Ok(vec![]).