Module discovery
Expand description
Node address discovery.
To connect to an iroh node a NodeAddr is needed, which may contain a
RelayUrl or one or more direct addresses in addition to the NodeId.
Since there is a conversion from NodeId to NodeAddr, you can also use
connect directly with a NodeId.
For this to work however, the endpoint has to get the addressing information by other means.
Node discovery is an automated system for an Endpoint to retrieve this addressing
information. Each iroh node will automatically publish their own addressing
information. Usually this means publishing which RelayUrl to use for their
NodeId, but they could also publish their direct addresses.
The Discovery trait is used to define node discovery. This allows multiple
implementations to co-exist because there are many possible ways to implement this.
Each Endpoint can use the discovery mechanisms most suitable to the application.
The Builder::add_discovery method is used to add a discovery mechanism to an
Endpoint.
Some generally useful discovery implementations are provided:
-
StaticProviderwhich allows application to add and remove out-of-band addressing information. -
The
DnsDiscoverywhich performs lookups via the standard DNS systems. To publish to this DNS server aPkarrPublisheris needed. Number 0 runs a public instance of aPkarrPublisherwith attached DNS server which is globally available and a reliable default choice. -
The
PkarrResolverwhich can perform lookups from designated pkarr relay servers using HTTP. -
MdnsDiscovery: mdns::MdnsDiscovery which uses the crateswarm-discovery, an opinionated mDNS implementation, to discover nodes on the local network. -
The
DhtDiscoveryalso uses thepkarrsystem but can also publish and lookup records to/from the Mainline DHT.
To use multiple discovery systems simultaneously you can call Builder::add_discovery.
This will use ConcurrentDiscovery under the hood, which performs lookups to all
discovery systems at the same time.
Builder::add_discovery takes any type that implements IntoDiscovery. You can
implement that trait on a builder struct if your discovery service needs information
from the endpoint it is mounted on. During endpoint construction, your discovery service
is built by calling IntoDiscovery::into_discovery, passing a DiscoveryContext to your
builder. The DiscoveryContext gives access to the endpoint’s secret key and DNS resolver.
If your discovery service does not need any information from its endpoint, you can
pass the discovery service directly to Builder::add_discovery: All types that
implement Discovery also have a blanket implementation of IntoDiscovery.
§Examples
A very common setup is to enable DNS discovery, which needs to be done in two parts as a
PkarrPublisher and DnsDiscovery:
use iroh::{
Endpoint, SecretKey,
discovery::{dns::DnsDiscovery, pkarr::PkarrPublisher},
};
let ep = Endpoint::builder()
.add_discovery(PkarrPublisher::n0_dns())
.add_discovery(DnsDiscovery::n0_dns())
.bind()
.await?;To also enable MdnsDiscovery it can be added as another service.
#[cfg(feature = "discovery-local-network")]
let ep = Endpoint::builder()
.add_discovery(PkarrPublisher::n0_dns())
.add_discovery(DnsDiscovery::n0_dns())
.add_discovery(MdnsDiscovery::builder())
.bind()
.await?;Modules§
- dns
- DNS node discovery for iroh
- pkarr
- A discovery service which publishes and resolves node information using a pkarr relay.
- static_
provider - A static node discovery to manually add node addressing information.
Structs§
- Concurrent
Discovery - A discovery service that combines multiple discovery sources.
- Discovery
Context - Context about the
Endpointfor discovery services. - Discovery
Item - Node discovery results from
Discoveryservices. - Node
Data - Data about a node that may be published to and resolved from discovery services.
- Node
Info - Information about a node that may be published to and resolved from discovery services.
- User
Data - Under the hood this is a UTF-8 String is no longer than
UserData::MAX_LENGTHbytes.
Enums§
- Discovery
Error - Discovery errors
- Into
Discovery Error - IntoDiscovery errors
- Parse
Error
Traits§
- Discovery
- Node discovery for
super::Endpoint. - Into
Discovery - Trait for structs that can be converted into
Discovery.