Expand description
An address lookup service that uses an mdns-like service to discover and lookup the addresses of local endpoints.
This allows you to use an mdns-like swarm discovery service to find address information about endpoints that are on your local network, no relay or outside internet needed.
See the swarm-discovery crate for more details.
When MdnsAddressLookup is enabled, it’s possible to get a list of the locally discovered endpoints by filtering a list of RemoteInfos.
In order to get a list of locally discovered addresses, you must call MdnsAddressLookup::subscribe to subscribe
to a stream of discovered addresses.
use iroh::{Endpoint, endpoint::presets};
use iroh_mdns_address_lookup::{DiscoveryEvent, MdnsAddressLookup};
use n0_future::StreamExt;
#[tokio::main]
async fn main() {
let endpoint = Endpoint::bind(presets::Minimal).await.unwrap();
// Register the Address Lookupwith the endpoint
let mdns = MdnsAddressLookup::builder().build(endpoint.id()).unwrap();
endpoint.address_lookup().unwrap().add(mdns.clone());
// Subscribe to the mdns discovery events
let mut events = mdns.subscribe().await;
while let Some(event) = events.next().await {
match event {
DiscoveryEvent::Discovered { endpoint_info, .. } => {
println!("MDNS discovered: {:?}", endpoint_info);
}
DiscoveryEvent::Expired { endpoint_id } => {
println!("MDNS expired: {endpoint_id}");
}
_ => {}
}
}
}§Filtering
By default, MdnsAddressLookup publishes all addresses it receives:
direct IP addresses and up to one RelayUrl. The following constraints apply regardless
of any user-supplied filter:
- Only the first
RelayUrlin the address set is published. - A
RelayUrllonger than 249 bytes is silently dropped.
You can supply an AddrFilter via MdnsAddressLookupBuilder::addr_filter to
control which addresses are published and in what order. The filter is applied before the
constraints above, so for example you can use it to exclude relay URLs entirely or to
prioritize certain addresses.
Structs§
- Mdns
Address Lookup - Address Lookup using
swarm-discovery, a variation on mdns. - Mdns
Address Lookup Builder - Builder for
MdnsAddressLookup.
Enums§
- Discovery
Event - An event emitted from the
MdnsAddressLookupservice.
Constants§
- NAME
- Name of this address lookup service.