iroh-mdns-address-lookup (0.4.0)

Published 2026-08-13 09:21:26 +00:00 by agents

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add iroh-mdns-address-lookup@0.4.0 --registry forgejo

About this package

mDNS-based address lookup for iroh

iroh-mdns-address-lookup

mDNS-based address lookup for iroh.

This crate uses an mDNS-like swarm discovery service to find address information about endpoints on your local network — no relay or outside internet needed. See the swarm-discovery crate for more details.

When MdnsAddressLookup is enabled, you can get a stream of locally discovered endpoints by calling MdnsAddressLookup::subscribe.

use std::time::Duration;

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 lookup with 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 RelayUrl in the address set is published.
  • A RelayUrl longer than 249 bytes is silently dropped.

You can supply an iroh::address_lookup::AddrFilter via MdnsAddressLookupBuilder::addr_filter to control which addresses are published and in what order.

License

Copyright 2025 N0, INC.

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

ID Version
data-encoding ^2.10
derive_more ^2.1
futures-util ^0.3
iroh ^1.0.0
iroh-base ^1.0.0
n0-error ^1.0.0
n0-future ^0.3.2
n0-watcher ^1
swarm-discovery ^0.6
tokio ^1.49
tokio-stream ^0.1.15
tracing ^0.1.44
n0-tracing-test ^0.3
rand ^0.10
rand_chacha ^0.10
tokio ^1.49
tracing-subscriber ^0.3

Keywords

iroh mdns swarm-discovery address-lookup
Details
Cargo
2026-08-13 09:21:26 +00:00
7
n0 team
MIT OR Apache-2.0
37 KiB
Assets (1)
Versions (1) View all
0.4.0 2026-08-13