pub struct PeerBook { /* private fields */ }Implementations§
Source§impl PeerBook
impl PeerBook
pub const CAPACITY: usize = 1024
Sourcepub const CIRCUIT_CAPACITY: usize = 256
pub const CIRCUIT_CAPACITY: usize = 256
Entries reachable only through relays, out of CAPACITY.
pub const ADDRESSES: usize = 4
Sourcepub const GROUP_LIMIT: usize = 2
pub const GROUP_LIMIT: usize = 2
Gossip entries per IPv4 /24 or IPv6 /48.
Sourcepub const SEED_BACKOFF_CAP: u64 = 600
pub const SEED_BACKOFF_CAP: u64 = 600
Seeds are operator configuration, never banned like gossip: their backoff stops growing at ten minutes.
pub fn empty(chain_genesis: BlockHash) -> Self
Sourcepub fn load(path: &Path, chain_genesis: BlockHash) -> Result<Self, Error>
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.
Sourcepub fn save(&self, path: &Path) -> Result<(), Error>
pub fn save(&self, path: &Path) -> Result<(), Error>
Atomically replace a bounded snapshot sorted by identity then address.
pub fn entries(&self) -> &[BookEntry]
Sourcepub fn add(&mut self, address: Multiaddr, origin: Origin) -> Result<bool, Error>
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, and is the only origin of
circuit addresses; manual and seed accept any usable direct address
including loopback and names. Returns whether memory changed; capacity
is made by evicting the worst gossip entry only.
Sourcepub fn merge(
&mut self,
peers: &[GossipPeer],
local: PeerId,
omitting: &[String],
) -> usize
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.
Sourcepub fn merge_identified(
&mut self,
peers: &[GossipPeer],
local: PeerId,
omitting: &[String],
) -> usize
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.
Sourcepub fn succeeded(
&mut self,
address: &Multiaddr,
peer: PeerId,
local: PeerId,
now: u64,
)
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.
Sourcepub fn failed(&mut self, address: &Multiaddr, now: u64)
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).
The address moves to the back, so the next dial tries another one.
Sourcepub fn failed_peer(&mut self, peer: PeerId, now: u64) -> bool
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.
Sourcepub fn candidates(
&self,
now: u64,
connected: &[PeerId],
omitting: &[String],
count: usize,
) -> Vec<Multiaddr>
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. Entries with a direct address come before
circuit-only ones. Within each, never-tried entries (picked at random)
alternate with tried ones (oldest backoff expiry first), so fresh
gossip cannot starve peers that were reached before.
Sourcepub fn seeds(&self, omitting: &[String], now: Option<u64>) -> Vec<Multiaddr>
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.
Sourcepub fn sync_addresses(&self, omitting: &[String]) -> Vec<PeerAddress>
pub fn sync_addresses(&self, omitting: &[String]) -> Vec<PeerAddress>
Identified direct IP addresses for record, commit and inventory sources, one per peer, excluding peers this archive found omitting records. Circuit addresses never become sync sources.
Sourcepub fn gossip(&self, limit: usize, omitting: &[String]) -> Vec<GossipPeer>
pub fn gossip(&self, limit: usize, omitting: &[String]) -> Vec<GossipPeer>
Verified, identified peers with public literal-IP addresses (circuits through public relays included), most recently successful first, for answering a Peers request.
pub fn stats(&self) -> BookStats
Sourcepub fn listing(&self) -> Vec<ListedEntry>
pub fn listing(&self) -> Vec<ListedEntry>
Bounded JSON snapshot for the local control API.
Auto Trait Implementations§
impl Freeze for PeerBook
impl RefUnwindSafe for PeerBook
impl Send for PeerBook
impl Sync for PeerBook
impl Unpin for PeerBook
impl UnsafeUnpin for PeerBook
impl UnwindSafe for PeerBook
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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