pub struct AddressBook { /* private fields */ }Expand description
Ref-counted PeerId → Vec<Address> registry. Single source of
truth for “where can I reach this peer.”
Implementations§
Source§impl AddressBook
impl AddressBook
Sourcepub fn set_cap(&mut self, cap: usize)
pub fn set_cap(&mut self, cap: usize)
Override the entry cap. Production hosts can match the cap to their topology size (a small cluster + 2× headroom).
Sourcepub fn add_peer(
&mut self,
peer: PeerId,
addresses: Vec<Address>,
) -> Result<(), AddressBookError>
pub fn add_peer( &mut self, peer: PeerId, addresses: Vec<Address>, ) -> Result<(), AddressBookError>
Announce a peer with one or more addresses.
- New peer → entry created with
ref_count = 1, addresses inserted in the given order. - Known peer →
ref_count += 1. New addresses appended; duplicates dropped, existing entries preserve their position (first caller’s preference wins).
Errors with AddressBookError::EmptyAddressList if
addresses is empty.
Components MUST pair every add_peer with an eventual
Self::drop_peer so ref_count converges to zero.
Sourcepub fn drop_peer(&mut self, peer: PeerId) -> Result<(), AddressBookError>
pub fn drop_peer(&mut self, peer: PeerId) -> Result<(), AddressBookError>
Release one reference to peer. Decrements ref_count;
removes the entry (and all addresses) when the count
reaches zero. Errors with
AddressBookError::UnknownPeer if no entry exists.
Sourcepub fn register_address(
&mut self,
peer: PeerId,
address: Address,
) -> Result<(), AddressBookError>
pub fn register_address( &mut self, peer: PeerId, address: Address, ) -> Result<(), AddressBookError>
Append address to the peer’s list. Idempotent - duplicates
are dropped. Does NOT change ref_count. Errors with
AddressBookError::UnknownPeer if the peer has no entry.
Sourcepub fn forget_address(
&mut self,
peer: PeerId,
address: &Address,
) -> Result<(), AddressBookError>
pub fn forget_address( &mut self, peer: PeerId, address: &Address, ) -> Result<(), AddressBookError>
Prune one unreachable address from the peer’s list.
Transport adapters call this after observing a
transport-level failure on a specific address. Does NOT
change ref_count and does NOT remove the entry even if
pruning leaves the address list empty - Self::drop_peer
is the only path that removes entries. Errors with
AddressBookError::UnknownPeer if no entry exists.
Sourcepub fn lookup(&self, peer: PeerId) -> Option<&[Address]>
pub fn lookup(&self, peer: PeerId) -> Option<&[Address]>
Ordered slice of every address bound to peer. Returns
None for an unknown peer OR a peer whose address list is
empty (e.g. all addresses pruned via forget_address and
nothing re-added). Both cases mean “can’t route” to the
wire syscall.
Sourcepub fn lookup_first(&self, peer: PeerId) -> Option<&Address>
pub fn lookup_first(&self, peer: PeerId) -> Option<&Address>
Convenience: the first (highest-preference) address.
Sourcepub fn ref_count(&self, peer: PeerId) -> u64
pub fn ref_count(&self, peer: PeerId) -> u64
Current reference count for peer, or 0 if unregistered.
Sourcepub fn iter(&self) -> impl Iterator<Item = (PeerId, &[Address], u64)>
pub fn iter(&self) -> impl Iterator<Item = (PeerId, &[Address], u64)>
Iterate (peer, &[Address], ref_count) triples for every
registered peer. Used by snapshot capture.
Sourcepub fn restore_entry(
&mut self,
peer: PeerId,
addresses: Vec<Address>,
ref_count: u64,
)
pub fn restore_entry( &mut self, peer: PeerId, addresses: Vec<Address>, ref_count: u64, )
Snapshot-restore setter - reconstructs an entry with the
recorded addresses + ref_count without going through
Self::add_peer (which would force ref_count = 1).
Used exclusively by Node::restore.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AddressBook
impl RefUnwindSafe for AddressBook
impl Send for AddressBook
impl Sync for AddressBook
impl Unpin for AddressBook
impl UnsafeUnpin for AddressBook
impl UnwindSafe for AddressBook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedComponent for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request