iroh_net::discovery

Module local_swarm_discovery

Source
👎Deprecated: This crate has been renamed from ‘iroh-net’ to ‘iroh’, please use the new crate
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 RemoteInfos.

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§

LocalSwarmDiscoveryDeprecated
Discovery using swarm-discovery, a variation on mdns

Constants§

NAMEDeprecated
Name of this discovery service.