Choose an mDNS lookup
Local discovery is optional in iroh 1.x. Neither of these crates is enabled by default; add one when your application needs to find peers on the same network. They make different performance trade-offs:
For mobile devices, weigh connection setup time against how long discovery stays
active and its effect on battery use. A mobile app participating in a large local
mesh may prefer bounded multicast traffic; an app that wakes briefly to connect
may prefer faster initial lookup. These crates use different discovery formats,
so check that the endpoints you want to find use a compatible lookup.
Both examples below use
presets::N0, which enables the default DNS lookup and
relay servers alongside local discovery. Neither mDNS crate is enabled by the
preset.
mDNS shares local dialing addresses with peers on the local network. Publishing
IP addresses to a global address lookup is not required for iroh’s hole punching:
endpoints exchange IP information after a connection is established, including
when that connection starts through a relay. A connected peer may learn your IP
addresses; take this into account if your application authenticates peers after
accepting connections.
Using iroh-mdns-address-lookup
Add the crate alongside iroh:
MdnsAddressLookup::builder() to
Endpoint::builder(presets::N0).address_lookup(...)
before binding if you do not need to retain the mDNS handle for subscribe().
For discovery events and address filtering, see the
iroh-mdns-address-lookup documentation.
Using iroh-mdns-peer-lookup
The peer lookup crate
uses standard DNS-SD records. Its announce option lets a listening endpoint
advertise itself while a client can perform lookup without advertising:
.announce(false) for a client that only looks up peers. See the
crate documentation
for its other options.