Skip to main content

PeerBook

Struct PeerBook 

Source
pub struct PeerBook { /* private fields */ }

Implementations§

Source§

impl PeerBook

Source

pub const CAPACITY: usize = 1024

Source

pub const ADDRESSES: usize = 4

Source

pub const GROUP_LIMIT: usize = 2

Gossip entries per IPv4 /24 or IPv6 /48.

Source

pub const SEED_BACKOFF_CAP: u64 = 600

Seeds are operator configuration, never banned like gossip: their backoff stops growing at ten minutes.

Source

pub fn empty(chain_genesis: BlockHash) -> Self

Source

pub fn load(path: &Path, chain_genesis: BlockHash) -> Result<Self, Error>

Load a bounded regular JSON file for the caller’s explicit network. Only NotFound yields an empty book; any invalid file, including an older format version, is refused whole and preserved untouched.

Source

pub fn save(&self, path: &Path) -> Result<(), Error>

Atomically replace a bounded snapshot sorted by identity then address.

Source

pub fn entries(&self) -> &[BookEntry]

Source

pub fn add(&mut self, address: Multiaddr, origin: Origin) -> Result<bool, Error>

Add one address. A terminal /p2p names the peer; without it the entry stays unidentified until a dial succeeds. Gossip only accepts public literal IPs under the group cap; manual and seed accept any usable address including loopback and names. Returns whether memory changed; capacity is made by evicting the worst gossip entry only.

Source

pub fn merge( &mut self, peers: &[GossipPeer], local: PeerId, omitting: &[String], ) -> usize

Merge one peer’s gossip under the caps. The local identity and peers this archive found omitting records are never stored from gossip. Returns how many addresses changed memory; refusals are skipped.

Source

pub fn merge_identified( &mut self, peers: &[GossipPeer], local: PeerId, omitting: &[String], ) -> usize

Peers that identified themselves over a connection: like gossip, but a known peer may gain the addresses it reported for itself.

Source

pub fn succeeded( &mut self, address: &Multiaddr, peer: PeerId, local: PeerId, now: u64, )

A dial through address reached peer. Resets failures and records the success; an unidentified literal-IP entry learns the identity. An entry that turns out to be this node is dropped: the book never holds ourselves.

Source

pub fn failed(&mut self, address: &Multiaddr, now: u64)

A dial through address failed: back off 60 s × 2^(failures−1), so the first failure waits 60 s, capped at one day (ten minutes for seeds).

Source

pub fn failed_peer(&mut self, peer: PeerId, now: u64) -> bool

A peer misbehaved during sync: back its entry off like a failed dial. Returns whether the book holds that peer.

Source

pub fn candidates( &self, now: u64, connected: &[PeerId], omitting: &[String], count: usize, ) -> Vec<Multiaddr>

Up to count dial addresses for non-seed entries that are not banned, connected or omitting. Never-tried entries (picked at random) alternate with tried ones (oldest backoff expiry first), so fresh gossip cannot starve peers that were reached before.

Source

pub fn seeds(&self, omitting: &[String], now: Option<u64>) -> Vec<Multiaddr>

Seed dial addresses in random order, skipping seeds known to be this node’s omitters and, given now, seeds still backing off. A ban beyond the seed cap (persisted under an older policy) counts as expired.

Source

pub fn sync_addresses(&self, omitting: &[String]) -> Vec<PeerAddress>

Identified IP/TCP addresses for record, commit and inventory sources, one per peer, excluding peers this archive found omitting records.

Source

pub fn gossip(&self, limit: usize, omitting: &[String]) -> Vec<GossipPeer>

Verified, identified peers with public literal-IP addresses, most recently successful first, for answering a Peers request.

Source

pub fn stats(&self) -> BookStats

Source

pub fn listing(&self) -> Vec<ListedEntry>

Bounded JSON snapshot for the local control API.

Source

pub fn remove(&mut self, peer: PeerId) -> bool

Remove a peer’s entry from memory without persisting.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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