pub struct Peer {
pub public_key: CommsPublicKey,
pub node_id: NodeId,
pub addresses: MultiaddressesWithStats,
pub flags: PeerFlags,
pub banned_until: Option<NaiveDateTime>,
pub banned_reason: String,
pub features: PeerFeatures,
pub supported_protocols: Vec<ProtocolId>,
pub added_at: NaiveDateTime,
pub user_agent: String,
pub metadata: HashMap<u8, Vec<u8>>,
pub deleted_at: Option<NaiveDateTime>,
/* private fields */
}Expand description
A Peer represents a communication peer that is identified by a Public Key and NodeId. The Peer struct maintains a collection of the NetAddressesWithStats that this Peer can be reached by. The struct also maintains a set of flags describing the status of the Peer.
Fields§
§public_key: CommsPublicKeyPublic key of the peer
node_id: NodeIdNodeId of the peer
addresses: MultiaddressesWithStatsPeer’s addresses
flags: PeerFlagsFlags for the peer.
banned_until: Option<NaiveDateTime>§banned_reason: String§features: PeerFeaturesFeatures supported by the peer
supported_protocols: Vec<ProtocolId>Protocols supported by the peer. This should not be considered a definitive list of supported protocols and is used as information for more efficient protocol negotiation.
added_at: NaiveDateTimeTimestamp of when the peer was added to this nodes peer list
user_agent: StringUser agent advertised by the peer
metadata: HashMap<u8, Vec<u8>>Metadata field. This field is for use by upstream clients to record extra info about a peer. We use a hashmap here so that we can use more than one “info set”
deleted_at: Option<NaiveDateTime>If this peer has been deleted.
Implementations§
Source§impl Peer
impl Peer
Sourcepub fn new(
public_key: CommsPublicKey,
node_id: NodeId,
addresses: MultiaddressesWithStats,
flags: PeerFlags,
features: PeerFeatures,
supported_protocols: Vec<ProtocolId>,
user_agent: String,
) -> Peer
pub fn new( public_key: CommsPublicKey, node_id: NodeId, addresses: MultiaddressesWithStats, flags: PeerFlags, features: PeerFeatures, supported_protocols: Vec<ProtocolId>, user_agent: String, ) -> Peer
Constructs a new peer.
Sourcepub fn new_with_stats(
id: Option<PeerId>,
public_key: CommsPublicKey,
node_id: NodeId,
addresses: MultiaddressesWithStats,
flags: PeerFlags,
banned_until: Option<NaiveDateTime>,
banned_reason: String,
features: PeerFeatures,
supported_protocols: Vec<ProtocolId>,
added_at: NaiveDateTime,
user_agent: String,
metadata: HashMap<u8, Vec<u8>>,
deleted_at: Option<NaiveDateTime>,
) -> Peer
pub fn new_with_stats( id: Option<PeerId>, public_key: CommsPublicKey, node_id: NodeId, addresses: MultiaddressesWithStats, flags: PeerFlags, banned_until: Option<NaiveDateTime>, banned_reason: String, features: PeerFeatures, supported_protocols: Vec<ProtocolId>, added_at: NaiveDateTime, user_agent: String, metadata: HashMap<u8, Vec<u8>>, deleted_at: Option<NaiveDateTime>, ) -> Peer
Constructs a new peer with stats.
Sourcepub fn id(&self) -> PeerId
pub fn id(&self) -> PeerId
Returns the peers local id if this peer is persisted.
This method panics if the peer does not have a PeerId, and therefore is not persisted.
If the caller should be sure that the peer is persisted before calling this function.
This can be checked by using Peer::is_persisted.
Sourcepub fn merge(&mut self, other: &Peer)
pub fn merge(&mut self, other: &Peer)
Merges the data with another peer. This is usually used to update a peer before it is saved to the database so that data is not overwritten
pub fn is_persisted(&self) -> bool
Sourcepub fn supported_protocols(&self) -> &[ProtocolId] ⓘ
pub fn supported_protocols(&self) -> &[ProtocolId] ⓘ
Returns a slice of Protocols known to be supported by the peer. This should not be considered a definitive list of supported protocols
pub fn last_connect_attempt(&self) -> Option<NaiveDateTime>
Sourcepub fn last_address_used(&self) -> Option<Multiaddr>
pub fn last_address_used(&self) -> Option<Multiaddr>
The last address used to connect to the peer
Sourcepub fn is_offline(&self) -> bool
pub fn is_offline(&self) -> bool
Returns true if the peer is marked as offline
pub fn offline_at(&self) -> Option<NaiveDateTime>
Sourcepub fn offline_since(&self) -> Option<Duration>
pub fn offline_since(&self) -> Option<Duration>
The length of time since a peer was marked as offline
Sourcepub fn last_seen(&self) -> Option<NaiveDateTime>
pub fn last_seen(&self) -> Option<NaiveDateTime>
Provides that date time of the last successful interaction with the peer
Sourcepub fn all_addresses_failed(&self) -> bool
pub fn all_addresses_failed(&self) -> bool
Provides info about the failure status of all addresses
Sourcepub fn last_seen_since(&self) -> Option<Duration>
pub fn last_seen_since(&self) -> Option<Duration>
Provides that length of time since the last successful interaction with the peer
Sourcepub fn reason_banned(&self) -> &str
pub fn reason_banned(&self) -> &str
Returns the ban status of the peer
Sourcepub fn ban_for(&mut self, duration: Duration, reason: String)
pub fn ban_for(&mut self, duration: Duration, reason: String)
Bans the peer for a specified duration
pub fn banned_until(&self) -> Option<&NaiveDateTime>
Sourcepub fn set_metadata(&mut self, key: u8, data: Vec<u8>) -> Option<Vec<u8>>
pub fn set_metadata(&mut self, key: u8, data: Vec<u8>) -> Option<Vec<u8>>
This will store metadata inside of the metadata field in the peer. It will return None if the value was empty and the old value if the value was updated
Sourcepub fn get_metadata(&self, key: u8) -> Option<&Vec<u8>>
pub fn get_metadata(&self, key: u8) -> Option<&Vec<u8>>
This will return the value in the metadata field. It will return None if the key is not present
Sourcepub fn update_addresses(
&mut self,
addresses: &[Multiaddr],
source: &PeerAddressSource,
) -> &mut Self
pub fn update_addresses( &mut self, addresses: &[Multiaddr], source: &PeerAddressSource, ) -> &mut Self
Update the peer’s addresses. This call will invalidate the identity signature.
Sourcepub fn set_features(&mut self, features: PeerFeatures) -> &mut Self
pub fn set_features(&mut self, features: PeerFeatures) -> &mut Self
Update the peer’s features. This call will invalidate the identity signature if the features differ.
pub fn add_flags(&mut self, flags: PeerFlags) -> &mut Self
pub fn is_seed(&self) -> bool
pub fn to_short_string(&self) -> String
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Peer
impl<'de> Deserialize<'de> for Peer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Peer
Source§impl TryFrom<(NewPeerSql, Vec<NewMultiaddrWithStatsSql>)> for Peer
impl TryFrom<(NewPeerSql, Vec<NewMultiaddrWithStatsSql>)> for Peer
Source§type Error = StorageError
type Error = StorageError
Source§fn try_from(
(peer_query, addresses_query): (NewPeerSql, Vec<NewMultiaddrWithStatsSql>),
) -> Result<Self, Self::Error>
fn try_from( (peer_query, addresses_query): (NewPeerSql, Vec<NewMultiaddrWithStatsSql>), ) -> Result<Self, Self::Error>
Auto Trait Implementations§
impl !Freeze for Peer
impl RefUnwindSafe for Peer
impl Send for Peer
impl Sync for Peer
impl Unpin for Peer
impl UnsafeUnpin for Peer
impl UnwindSafe for Peer
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'a, T> DefaultFeatures<'a> for T
impl<'a, T> DefaultFeatures<'a> for T
Source§fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
Box
behind a trait object of this trait.impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> MessageFormat for Twhere
T: DeserializeOwned + Serialize,
impl<T> MessageFormat for Twhere
T: DeserializeOwned + Serialize,
Source§fn from_binary(msg: &[u8]) -> Result<T, MessageFormatError>
fn from_binary(msg: &[u8]) -> Result<T, MessageFormatError>
Source§fn from_base64(msg: &str) -> Result<T, MessageFormatError>
fn from_base64(msg: &str) -> Result<T, MessageFormatError>
Source§impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
Source§fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
Box
behind a trait object of this trait.