Available on crate feature
discovery-local-network
only.Expand description
A discovery service that uses an mdns-like service to discover local nodes.
This allows you to use an mdns-like swarm discovery service to find address information about nodes that are on your local network, no relay or outside internet needed.
See the swarm-discovery
crate for more details.
When LocalSwarmDiscovery
is enabled, it’s possible to get a list of the locally discovered nodes by filtering a list of RemoteInfo
s.
use std::time::Duration;
use iroh_net::endpoint::{Source, Endpoint};
#[tokio::main]
async fn main() {
let recent = Duration::from_secs(600); // 10 minutes in seconds
let endpoint = Endpoint::builder().bind().await.unwrap();
let remotes = endpoint.remote_info_iter();
let locally_discovered: Vec<_> = remotes
.filter(|remote| {
remote
.sources()
.iter()
.any(|(source, duration)| {
if let Source::Discovery { name } = source {
name == iroh_net::discovery::local_swarm_discovery::NAME && *duration <= recent
} else {
false
}
})
})
.collect();
println!("locally discovered nodes: {locally_discovered:?}");
}
Structs§
- Discovery using
swarm-discovery
, a variation on mdns
Constants§
- Name of this discovery service.