AddressBook

Struct AddressBook 

Source
pub struct AddressBook { /* private fields */ }
Expand description

Manage node information, bootstraps and their associated transport addresses and topics.

§Example

To help an application to bootstrap into the network, it is possible to manually add node information and manage associated topics for nodes directly on the address book using AddressBook::insert_node_info:

let address_book = AddressBook::builder().spawn().await?;

let bootstrap_node = {
    let node_id = "c0f3ce745cee96e1e9c01a20746cd503bb2199c2459d8ff8697f5edb30569101"
        .parse()
        .expect("valid hex-encoded Ed25519 public key");
    let relay_url = "https://my.relay.org".parse().expect("valid relay url");

    let endpoint_addr = iroh::EndpointAddr::new(node_id)
       .with_relay_url(relay_url);

    NodeInfo::from(endpoint_addr).bootstrap()
};

address_book.insert_node_info(bootstrap_node).await?;

§Topic Discovery and Resolving Transport Info

The address book itself is populated with transport information and associated node topics by two “discovery” services:

  1. MdnsDiscovery: Resolve addresses of nearby devices on the local-area network.
  2. Discovery: Resolve addresses and confidentially exchange topics using random-walk strategy, exploring the network.

Implementations§

Source§

impl AddressBook

Source

pub fn builder() -> Builder

Source

pub async fn node_info( &self, node_id: NodeId, ) -> Result<Option<NodeInfo>, AddressBookError>

Returns information about a node.

Returns None if no information was found for this node.

Source

pub async fn insert_node_info( &self, node_info: NodeInfo, ) -> Result<bool, AddressBookError>

Inserts or updates node information into address book.

Use this method if adding node information from a local configuration or trusted, external source, etc.

Returns true if entry got newly inserted or false if existing entry was updated. Previous entries are simply overwritten. Entries with attached transport information get checked against authenticity and throw an error otherwise.

Source

pub async fn insert_transport_info( &self, node_id: NodeId, transport_info: TransportInfo, ) -> Result<bool, AddressBookError>

Inserts or updates attached transport info for a node. Use this method if adding transport information from an untrusted source.

Transport information is usually exchanged as part of a discovery protocol and should be considered untrusted.

This method checks if the given information is authentic and uses a timestamp to apply a “last write wins” rule. It retuns true if the given entry overwritten the previous one or false if the previous entry is already the latest.

Local data of the node information stay untouched if they already exist, only the “transports” aspect gets inserted / updated.

Source

pub async fn node_infos_by_topics( &self, topics: impl IntoIterator<Item = TopicId>, ) -> Result<Vec<NodeInfo>, AddressBookError>

Source

pub async fn set_topics( &self, node_id: NodeId, topics: impl IntoIterator<Item = TopicId>, ) -> Result<(), AddressBookError>

Source

pub async fn add_topic( &self, node_id: NodeId, topic: TopicId, ) -> Result<(), AddressBookError>

Source

pub async fn remove_topic( &self, node_id: NodeId, topic: TopicId, ) -> Result<(), AddressBookError>

Source

pub async fn watch_node_info( &self, node_id: NodeId, updates_only: UpdatesOnly, ) -> Result<WatcherReceiver<Option<NodeInfo>>, AddressBookError>

Subscribes to channel informing us about node info changes for a specific node.

Source

pub async fn watch_topic( &self, topic_id: TopicId, updates_only: UpdatesOnly, ) -> Result<WatcherReceiver<HashSet<NodeId>>, AddressBookError>

Subscribes to channel informing us about changes of the set of nodes interested in a topic.

Source

pub async fn watch_node_topics( &self, node_id: NodeId, updates_only: UpdatesOnly, ) -> Result<WatcherReceiver<HashSet<TopicId>>, AddressBookError>

Subscribes to channel informing us about topic changes for a particular node.

Source

pub async fn report( &self, node_id: NodeId, connection_outcome: ConnectionOutcome, ) -> Result<(), AddressBookError>

Report outcomes of incoming or outgoing connections.

This helps measuring the “quality” of nodes which will be recorded in the address book.

Trait Implementations§

Source§

impl ChildActor for AddressBook

Source§

fn on_start( &self, supervisor: ActorCell, thread_pool: ThreadLocalActorSpawner, ) -> ChildActorFut<'_>

Source§

impl Clone for AddressBook

Source§

fn clone(&self) -> AddressBook

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> OutputMessage for T
where T: Message + Clone,

Source§

impl<T> State for T
where T: Any + Send + 'static,