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
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.
Each address lookup service receives the full set of transport addresses when publishing, but may only publish a subset of them based on its own constraints.
To control which addresses are published to a particular service, you can supply an
AddrFilter on its builder (e.g. PkarrPublisherBuilder::addr_filter). The filter
receives the full set of addresses and returns an ordered Vec, allowing you to both
remove addresses you don’t want published and prioritize the ones you do. Each service
may apply additional filtering on top based on its own constraints, but will not publish
addresses outside of what the filter returns. See each service’s documentation for details.
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.
mDNS-based and Mainline-DHT-based Address Lookup services live in
separate crates: iroh-mdns-address-lookup and
iroh-mainline-address-lookup.
To use multiple Address Lookups simultaneously you can call Builder::address_lookup.
This will use AddressLookupServices under the hood, which performs lookups to all
Address Lookup systems at the same time.
Builder::address_lookup takes any type that implements AddressLookupBuilder. 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 AddressLookupBuilder::into_address_lookup, passing the finished Endpoint to your
builder.
If your Address Lookup does not need any information from its endpoint, you can
pass the Address Lookup service directly to Builder::address_lookup: All types that
implement AddressLookup also have a blanket implementation of AddressLookupBuilder.
§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, AddrFilter, PkarrPublisher},
endpoint::{RelayMode, presets},
};
let ep = Endpoint::builder(presets::Minimal)
.addr_filter(AddrFilter::relay_only())
.address_lookup(PkarrPublisher::n0_dns())
.address_lookup(address_lookup::DnsAddressLookup::n0_dns())
.bind()
.await?;Re-exports§
Modules§
- dns
Non- wasm_browser - DNS endpoint discovery for iroh
- 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§
- Addr
Filter - A filter and/or reordering function applied to transport addresses, typically used by AddressLookup services in iroh before publishing.
- Address
Lookup Services - Registry for address lookup services for an
Endpoint. - 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.
- Error
- Error returned by address lookup services when failing to perform the lookup.
- Filtered
Address Lookup - An
AddressLookupwrapper that filters addresses before publishing. - Item
- Address lookup results from
AddressLookups. - Metrics
- Metrics collected by address lookup.
- Service
Labels - Labels identifying an address lookup service by its provenance string,
see
crate::address_lookup::Item::provenance. - User
Data - User-defined data that can be published and resolved through endpoint discovery.
Enums§
- Address
Lookup Builder Error AddressLookupBuildererrors- Address
Lookup Failed AddressLookuperrors- Parse
Error
Traits§
- Address
Lookup - AddressLookup system for
super::Endpoint. - Address
Lookup Builder - Trait for structs that can be converted into
AddressLookups.