pub struct PeerDb { /* private fields */ }
Implementations§
Source§impl PeerDb
impl PeerDb
Sourcepub fn add_peer(&mut self, addr: PeerAddr) -> (&mut PeerStats, bool)
pub fn add_peer(&mut self, addr: PeerAddr) -> (&mut PeerStats, bool)
Register a peer address in the database
Returns true if we haven’t known this address before.
Sourcepub fn add_advertised_peers(&mut self, addrs: &[PeerAddr])
pub fn add_advertised_peers(&mut self, addrs: &[PeerAddr])
Register a list of peers that has been actively advertised to us
The database should always be written afterwards to last_advertised
is persisted properly.
pub fn peers(&self) -> &BTreeMap<PeerAddr, PeerStats>
Sourcepub fn sample(&self, max_success_age: Option<Duration>) -> Vec<PeerAddr>
pub fn sample(&self, max_success_age: Option<Duration>) -> Vec<PeerAddr>
Return a sample of random peers to connect to
Sourcepub fn expire_old_peers(&mut self, now: DateTime<Utc>) -> bool
pub fn expire_old_peers(&mut self, now: DateTime<Utc>) -> bool
Remove old peers that both:
- we couldn’t successfully connect/handshake with in a while
- haven’t been advertised anymore in a while
Peers that are still being advertised, but we couldn’t connect/handshake with in a while are still being kept around so we don’t stop toning down our connection attempts to them.
Returns true if any peers have been removed.
Auto Trait Implementations§
impl Freeze for PeerDb
impl RefUnwindSafe for PeerDb
impl Send for PeerDb
impl Sync for PeerDb
impl Unpin for PeerDb
impl UnwindSafe for PeerDb
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
Mutably borrows from an owned value. Read more
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>
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 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>
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