pub struct MetaAddr { /* private fields */ }
Expand description
An address with metadata on its advertised services and last-seen time.
This struct can be created from addr
or addrv2
messages.
Implementations§
Source§impl MetaAddr
impl MetaAddr
Sourcepub fn new_initial_peer(addr: PeerSocketAddr) -> MetaAddrChange
pub fn new_initial_peer(addr: PeerSocketAddr) -> MetaAddrChange
Returns a [MetaAddrChange::NewInitial
] for a peer that was excluded from
the list of the initial peers.
Sourcepub fn new_gossiped_meta_addr(
addr: PeerSocketAddr,
untrusted_services: PeerServices,
untrusted_last_seen: DateTime32,
) -> MetaAddr
pub fn new_gossiped_meta_addr( addr: PeerSocketAddr, untrusted_services: PeerServices, untrusted_last_seen: DateTime32, ) -> MetaAddr
Returns a new MetaAddr
, based on the deserialized fields from a
gossiped peer [Addr
][crate::protocol::external::Message::Addr] message.
Sourcepub fn new_gossiped_change(self) -> Option<MetaAddrChange>
pub fn new_gossiped_change(self) -> Option<MetaAddrChange>
Sourcepub fn new_connected(
addr: PeerSocketAddr,
services: &PeerServices,
is_inbound: bool,
) -> MetaAddrChange
pub fn new_connected( addr: PeerSocketAddr, services: &PeerServices, is_inbound: bool, ) -> MetaAddrChange
Returns a [MetaAddrChange::UpdateConnected
] for a peer that has just successfully
connected.
§Security
This address must be the remote address from an outbound connection, and the services must be the services from that peer’s handshake.
Otherwise:
- malicious peers could interfere with other peers’
AddressBook
state, or - Zebra could advertise unreachable addresses to its own peers.
Sourcepub fn new_responded(addr: PeerSocketAddr) -> MetaAddrChange
pub fn new_responded(addr: PeerSocketAddr) -> MetaAddrChange
Returns a [MetaAddrChange::UpdateResponded
] for a peer that has just
sent us a message.
§Security
This address must be the remote address from an outbound connection.
Otherwise:
- malicious peers could interfere with other peers’
AddressBook
state, or - Zebra could advertise unreachable addresses to its own peers.
Sourcepub fn new_reconnect(addr: PeerSocketAddr) -> MetaAddrChange
pub fn new_reconnect(addr: PeerSocketAddr) -> MetaAddrChange
Returns a [MetaAddrChange::UpdateAttempt
] for a peer that we
want to make an outbound connection to.
Sourcepub fn new_local_listener_change(
addr: impl Into<PeerSocketAddr>,
) -> MetaAddrChange
pub fn new_local_listener_change( addr: impl Into<PeerSocketAddr>, ) -> MetaAddrChange
Returns a [MetaAddrChange::NewLocal
] for our own listener address.
Sourcepub fn new_errored(
addr: PeerSocketAddr,
services: impl Into<Option<PeerServices>>,
) -> MetaAddrChange
pub fn new_errored( addr: PeerSocketAddr, services: impl Into<Option<PeerServices>>, ) -> MetaAddrChange
Returns a [MetaAddrChange::UpdateFailed
] for a peer that has just had an error.
Sourcepub fn new_shutdown(addr: PeerSocketAddr) -> MetaAddrChange
pub fn new_shutdown(addr: PeerSocketAddr) -> MetaAddrChange
Create a new MetaAddr
for a peer that has just shut down.
Sourcepub fn addr(&self) -> PeerSocketAddr
pub fn addr(&self) -> PeerSocketAddr
Return the address for this MetaAddr
.
Sourcepub fn peer_preference(&self) -> Result<PeerPreference, &'static str>
pub fn peer_preference(&self) -> Result<PeerPreference, &'static str>
Return the address preference level for this MetaAddr
.
Sourcepub fn last_seen(&self) -> Option<DateTime32>
pub fn last_seen(&self) -> Option<DateTime32>
Returns the time of the last successful interaction with this peer.
Initially set to the unverified “last seen time” gossiped by the remote peer that sent us this address.
If the last_connection_state
has ever been Responded
, this field is
set to the last time we processed a message from this peer.
§Security
last_seen
times from peers that have never Responded
may be
incorrect due to clock skew, or buggy or malicious peers.
Sourcepub fn is_inbound(&self) -> bool
pub fn is_inbound(&self) -> bool
Returns whether the address is from an inbound peer connection
Sourcepub fn last_attempt(&self) -> Option<Instant>
pub fn last_attempt(&self) -> Option<Instant>
Returns the time of our last outbound connection attempt with this peer.
If the last_connection_state
has ever been AttemptPending
, this
field is set to the last time we started an outbound connection attempt
with this peer.
Sourcepub fn last_failure(&self) -> Option<Instant>
pub fn last_failure(&self) -> Option<Instant>
Returns the time of our last failed outbound connection with this peer.
If the last_connection_state
has ever been Failed
, this field is set
to the last time:
- a connection attempt failed, or
- an open connection encountered a fatal protocol error.
Sourcepub fn has_connection_recently_responded(&self, now: DateTime<Utc>) -> bool
pub fn has_connection_recently_responded(&self, now: DateTime<Utc>) -> bool
Have we had any recently messages from this peer?
Returns true
if the peer is likely connected and responsive in the peer
set.
constants::MIN_PEER_RECONNECTION_DELAY
represents the time interval in which
we should receive at least one message from a peer, or close the
connection. Therefore, if the last-seen timestamp is older than
constants::MIN_PEER_RECONNECTION_DELAY
ago, we know we should have
disconnected from it. Otherwise, we could potentially be connected to it.
Sourcepub fn was_connection_recently_attempted(&self, now: Instant) -> bool
pub fn was_connection_recently_attempted(&self, now: Instant) -> bool
Have we recently attempted an outbound connection to this peer?
Returns true
if this peer was recently attempted, or has a connection
attempt in progress.
Sourcepub fn has_connection_recently_failed(&self, now: Instant) -> bool
pub fn has_connection_recently_failed(&self, now: Instant) -> bool
Have we recently had a failed connection to this peer?
Returns true
if this peer has recently failed.
Sourcepub fn was_recently_live(&self, now: DateTime<Utc>) -> bool
pub fn was_recently_live(&self, now: DateTime<Utc>) -> bool
Returns true if this peer has recently sent us a message.
Sourcepub fn is_active_for_gossip(&self, now: DateTime<Utc>) -> bool
pub fn is_active_for_gossip(&self, now: DateTime<Utc>) -> bool
Has this peer been seen recently?
Returns true
if this peer has responded recently or if the peer was gossiped with a
recent reported last seen time.
constants::MAX_PEER_ACTIVE_FOR_GOSSIP
represents the maximum time since a peer was seen
to still be considered reachable.
Sourcepub fn was_recently_updated(
&self,
instant_now: Instant,
chrono_now: DateTime<Utc>,
) -> bool
pub fn was_recently_updated( &self, instant_now: Instant, chrono_now: DateTime<Utc>, ) -> bool
Returns true if any messages were recently sent to or received from this address.
Sourcepub fn is_ready_for_connection_attempt(
&self,
instant_now: Instant,
chrono_now: DateTime<Utc>,
network: &Network,
) -> bool
pub fn is_ready_for_connection_attempt( &self, instant_now: Instant, chrono_now: DateTime<Utc>, network: &Network, ) -> bool
Is this address ready for a new outbound connection attempt?
Sourcepub fn address_is_valid_for_outbound(&self, network: &Network) -> bool
pub fn address_is_valid_for_outbound(&self, network: &Network) -> bool
Is the PeerSocketAddr
we have for this peer valid for outbound
connections?
Since the addresses in the address book are unique, this check can be
used to permanently reject entire MetaAddr
s.
Sourcepub fn last_known_info_is_valid_for_outbound(&self, network: &Network) -> bool
pub fn last_known_info_is_valid_for_outbound(&self, network: &Network) -> bool
Is the last known information for this peer valid for outbound connections?
The last known info might be outdated or untrusted, so this check can only be used to:
- reject
NeverAttempted...
[MetaAddrChange
]s, and - temporarily stop outbound connections to a
MetaAddr
.
Sourcepub fn is_probably_reachable(&self, now: DateTime<Utc>) -> bool
pub fn is_probably_reachable(&self, now: DateTime<Utc>) -> bool
Should this peer considered reachable?
A peer is probably reachable if:
- it has never been attempted, or
- the last connection attempt was successful, or
- the last successful connection was less than 3 days ago.
§Security
This is used by Self::is_ready_for_connection_attempt
so that Zebra stops trying to
connect to peers that are likely unreachable.
The untrusted_last_seen
time is used as a fallback time if the local node has never
itself seen the peer. If the reported last seen time is a long time ago or None
, then the local
node will attempt to connect the peer once, and if that attempt fails it won’t
try to connect ever again. (The state can’t be Failed
until after the first connection attempt.)
Sourcepub fn last_seen_is_recent(&self, now: DateTime<Utc>) -> bool
pub fn last_seen_is_recent(&self, now: DateTime<Utc>) -> bool
Was this peer last seen recently?
Returns true
if this peer was last seen at most
MAX_RECENT_PEER_AGE
ago.
Returns false if the peer is outdated, or it has no last seen time.
Sourcepub fn misbehavior(&self) -> u32
pub fn misbehavior(&self) -> u32
Returns a score of misbehavior encountered in a peer at this address.
Trait Implementations§
Source§impl Ord for MetaAddr
impl Ord for MetaAddr
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
MetaAddr
s are sorted in approximate reconnection attempt order, but
with Responded
peers sorted first as a group.
But this order should not be used for reconnection attempts: use
reconnection_peers
instead.
See CandidateSet
for more details.
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for MetaAddr
impl PartialOrd for MetaAddr
impl Copy for MetaAddr
impl Eq for MetaAddr
Auto Trait Implementations§
impl Freeze for MetaAddr
impl RefUnwindSafe for MetaAddr
impl Send for MetaAddr
impl Sync for MetaAddr
impl Unpin for MetaAddr
impl UnwindSafe for MetaAddr
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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> 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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.