Expand description
Lookup the address of an Endpoint ID.
To connect to an iroh endpoint a EndpointAddr is needed, which may contain a
RelayUrl or one or more direct addresses in addition to the EndpointId.
Since there is a conversion from EndpointId to EndpointAddr, you can also use
connect directly with a EndpointId.
For this to work however, the endpoint has to get the addressing information by other means.
AddressLookup is an automated system for an Endpoint to retrieve this addressing
information. Each iroh endpoint will automatically publish their own addressing
information. Usually this means publishing which RelayUrl to use for their
EndpointId, but they could also publish their direct addresses.
The AddressLookup trait is used to define an address lookup system. This allows multiple
implementations to co-exist because there are many possible ways to implement this.
Each Endpoint can use the address lookup mechanisms most suitable to the application.
The Builder::address_lookup method is used to add an address lookup mechanism to an
Endpoint.
Some generally useful Address Lookup implementations are provided:
-
MemoryLookupwhich allows application to add and remove out-of-band addressing information. -
The
address_lookup::DnsAddressLookupwhich 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. -
address_lookup::MdnsAddressLookup: mdns::MdnsAddressLookup which uses the crateswarm-discovery, an opinionated mDNS implementation, to discover endpoints on the local network. -
The
address_lookup::DhtAddressLookupalso uses thepkarrsystem but can also publish and lookup records to/from the Mainline DHT. It requires enabling theaddress-lookup-pkarr-dhtfeature.
To use multiple Address Lookup’ssimultaneously you can call Builder::address_lookup.
This will use ConcurrentAddressLookup under the hood, which performs lookups to all
Address Lookupsystems at the same time.
Builder::address_lookup takes any type that implements IntoAddressLookup. You can
implement that trait on a builder struct if your Address Lookup needs information
from the endpoint it is mounted on. After endpoint construction, your Address Lookup
is built by calling IntoAddressLookup::into_address_lookup, passing the finished Endpoint to your
builder.
If your Address Lookupdoes not need any information from its endpoint, you can
pass the Address Lookupservice directly to Builder::address_lookup: All types that
implement AddressLookup also have a blanket implementation of IntoAddressLookup.
§Examples
A very common setup is to enable DNS Address Lookup, which needs to be done in two parts as a
PkarrPublisher and address_lookup::DnsAddressLookup:
use iroh::{
Endpoint, SecretKey,
address_lookup::{self, PkarrPublisher},
endpoint::RelayMode,
};
let ep = Endpoint::empty_builder(RelayMode::Default)
.address_lookup(PkarrPublisher::n0_dns())
.address_lookup(address_lookup::DnsAddressLookup::n0_dns())
.bind()
.await?;To also enable address_lookup::MdnsAddressLookup it can be added as another service.
#[cfg(feature = "address-lookup-mdns")]
let ep = Endpoint::empty_builder(RelayMode::Default)
.address_lookup(PkarrPublisher::n0_dns())
.address_lookup(address_lookup::DnsAddressLookup::n0_dns())
.address_lookup(address_lookup::MdnsAddressLookup::builder())
.bind()
.await?;Re-exports§
pub use dns::*;Non- wasm_browserpub use mdns::*;address-lookup-mdnspub use memory::*;pub use pkarr::dht::*;address-lookup-pkarr-dhtpub use pkarr::*;
Modules§
- dns
Non- wasm_browser - DNS endpoint discovery for iroh
- mdns
address-lookup-mdns - An address lookup service that uses an mdns-like service to discover and lookup the addresses of local endpoints.
- memory
- An in-memory address lookup system to manually add endpoint addressing information.
- pkarr
- An address lookup service which publishes and resolves endpoint information using a pkarr relay.
Structs§
- Concurrent
Address Lookup - An Address Lookup service that combines multiple Address Lookup sources.
- Endpoint
Data - Data about an endpoint that may be published to and resolved from discovery services.
- Endpoint
Info - Information about an endpoint that may be published to and resolved from discovery services.
- Item
- Address lookup results from
AddressLookups. - User
Data - Under the hood this is a UTF-8 String is no longer than
UserData::MAX_LENGTHbytes.
Enums§
Traits§
- Address
Lookup - AddressLookup system for
super::Endpoint. - Into
Address Lookup - Trait for structs that can be converted into
AddressLookups.