pub struct MemoryLookup { /* private fields */ }Expand description
An in-memory address lookup system to manually add endpoint addressing information.
Often an application might get endpoint addressing information out-of-band in an
application-specific way. EndpointTicket’s are one common way used to achieve this.
This addressing information is often only usable for a limited time so needs to
be able to be removed again once know it is no longer useful.
This is where the MemoryLookup is useful: it allows applications to add and
retract endpoint addressing information that is otherwise out-of-band to iroh.
§Examples
use iroh::{
Endpoint, EndpointAddr, TransportAddr, address_lookup::memory::MemoryLookup,
endpoint::presets,
};
use iroh_base::SecretKey;
// Create the Address Lookup and endpoint.
let address_lookup = MemoryLookup::new();
let _ep = Endpoint::builder(presets::N0)
.address_lookup(address_lookup.clone())
.bind()
.await?;
// Sometime later add a RelayUrl for our endpoint.
let id = SecretKey::generate(&mut rand::rng()).public();
// You can pass either `EndpointInfo` or `EndpointAddr` to `add_endpoint_info`.
address_lookup.add_endpoint_info(EndpointAddr {
id,
addrs: [TransportAddr::Relay("https://example.com".parse()?)]
.into_iter()
.collect(),
});
Implementations§
Source§impl MemoryLookup
impl MemoryLookup
Sourcepub const PROVENANCE: &'static str = "memory_lookup"
pub const PROVENANCE: &'static str = "memory_lookup"
The provenance string for this Address Lookup implementation.
This is mostly used for debugging information and allows understanding the origin of
addressing information used by an iroh Endpoint.
Sourcepub fn with_provenance(provenance: &'static str) -> Self
pub fn with_provenance(provenance: &'static str) -> Self
Creates a new Memory Lookup instance with the provided provenance.
The provenance is part of address_lookup::Items returned from Self::resolve.
It is mostly used for debugging information and allows understanding the origin of
addressing information used by an iroh Endpoint.
Sourcepub fn from_endpoint_info(
infos: impl IntoIterator<Item = impl Into<EndpointInfo>>,
) -> Self
pub fn from_endpoint_info( infos: impl IntoIterator<Item = impl Into<EndpointInfo>>, ) -> Self
Creates a Memory Lookup instance from endpoint addresses.
§Examples
use std::{net::SocketAddr, str::FromStr};
use iroh::{Endpoint, EndpointAddr, address_lookup::memory::MemoryLookup, endpoint::presets};
// get addrs from somewhere
let addrs = get_addrs();
// create a MemoryLookup from the list of addrs.
let address_lookup = MemoryLookup::from_endpoint_info(addrs);
// create an endpoint with the memory lookup address_lookup
let endpoint = Endpoint::builder(presets::N0)
.address_lookup(address_lookup)
.bind()
.await?;Sourcepub fn set_endpoint_info(
&self,
endpoint_info: impl Into<EndpointInfo>,
) -> Option<EndpointData>
pub fn set_endpoint_info( &self, endpoint_info: impl Into<EndpointInfo>, ) -> Option<EndpointData>
Sets endpoint addressing information for the given endpoint ID.
This will completely overwrite any existing info for the endpoint.
Returns the EndpointData of the previous entry, or None if there was no previous
entry for this endpoint ID.
Sourcepub fn add_endpoint_info(&self, endpoint_info: impl Into<EndpointInfo>)
pub fn add_endpoint_info(&self, endpoint_info: impl Into<EndpointInfo>)
Augments endpoint addressing information for the given endpoint ID.
The provided addressing information is combined with the existing info in the memory lookup. Any new direct addresses are added to those already present while the relay URL is overwritten.
Sourcepub fn get_endpoint_info(&self, endpoint_id: EndpointId) -> Option<EndpointInfo>
pub fn get_endpoint_info(&self, endpoint_id: EndpointId) -> Option<EndpointInfo>
Returns endpoint addressing information for the given endpoint ID.
Sourcepub fn remove_endpoint_info(
&self,
endpoint_id: EndpointId,
) -> Option<EndpointInfo>
pub fn remove_endpoint_info( &self, endpoint_id: EndpointId, ) -> Option<EndpointInfo>
Removes all endpoint addressing information for the given endpoint ID.
Any removed information is returned.
Trait Implementations§
Source§impl AddressLookup for MemoryLookup
impl AddressLookup for MemoryLookup
Source§fn publish(&self, _data: &EndpointData)
fn publish(&self, _data: &EndpointData)
EndpointData to the Address Lookup mechanism. Read moreSource§impl Clone for MemoryLookup
impl Clone for MemoryLookup
Source§fn clone(&self) -> MemoryLookup
fn clone(&self) -> MemoryLookup
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MemoryLookup
impl Debug for MemoryLookup
Auto Trait Implementations§
impl Freeze for MemoryLookup
impl RefUnwindSafe for MemoryLookup
impl Send for MemoryLookup
impl Sync for MemoryLookup
impl Unpin for MemoryLookup
impl UnsafeUnpin for MemoryLookup
impl UnwindSafe for MemoryLookup
Blanket Implementations§
Source§impl<T> AddressLookupBuilder for Twhere
T: AddressLookup,
impl<T> AddressLookupBuilder for Twhere
T: AddressLookup,
Source§fn into_address_lookup(
self,
_endpoint: &Endpoint,
) -> Result<impl AddressLookup, AddressLookupBuilderError>
fn into_address_lookup( self, _endpoint: &Endpoint, ) -> Result<impl AddressLookup, AddressLookupBuilderError>
AddressLookup. Read more