Module address_lookup

Module address_lookup 

Source
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:

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§

pub use dns::*;Non-wasm_browser
pub use memory::*;
pub use pkarr::*;

Modules§

dnsNon-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§

AddrFilter
A filter and/or reordering function applied to transport addresses, typically used by AddressLookup services in iroh before publishing.
AddressLookupServices
Registry for address lookup services for an Endpoint.
EndpointData
Data about an endpoint that may be published to and resolved from discovery services.
EndpointInfo
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.
FilteredAddressLookup
An AddressLookup wrapper that filters addresses before publishing.
Item
Address lookup results from AddressLookups.
Metrics
Metrics collected by address lookup.
ServiceLabels
Labels identifying an address lookup service by its provenance string, see crate::address_lookup::Item::provenance.
UserData
User-defined data that can be published and resolved through endpoint discovery.

Enums§

AddressLookupBuilderError
AddressLookupBuilder errors
AddressLookupFailed
AddressLookup errors
ParseError

Traits§

AddressLookup
AddressLookup system for super::Endpoint.
AddressLookupBuilder
Trait for structs that can be converted into AddressLookups.