Skip to main content

Peer

Struct Peer 

Source
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: CommsPublicKey

Public key of the peer

§node_id: NodeId

NodeId of the peer

§addresses: MultiaddressesWithStats

Peer’s addresses

§flags: PeerFlags

Flags for the peer.

§banned_until: Option<NaiveDateTime>§banned_reason: String§features: PeerFeatures

Features 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: NaiveDateTime

Timestamp of when the peer was added to this nodes peer list

§user_agent: String

User 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

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn is_persisted(&self) -> bool

Source

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

Source

pub fn last_connect_attempt(&self) -> Option<NaiveDateTime>

Source

pub fn last_address_used(&self) -> Option<Multiaddr>

The last address used to connect to the peer

Source

pub fn is_offline(&self) -> bool

Returns true if the peer is marked as offline

Source

pub fn offline_at(&self) -> Option<NaiveDateTime>

Source

pub fn offline_since(&self) -> Option<Duration>

The length of time since a peer was marked as offline

Source

pub fn last_seen(&self) -> Option<NaiveDateTime>

Provides that date time of the last successful interaction with the peer

Source

pub fn all_addresses_failed(&self) -> bool

Provides info about the failure status of all addresses

Source

pub fn last_seen_since(&self) -> Option<Duration>

Provides that length of time since the last successful interaction with the peer

Source

pub fn is_banned(&self) -> bool

Returns the ban status of the peer

Source

pub fn reason_banned(&self) -> &str

Returns the ban status of the peer

Source

pub fn ban_for(&mut self, duration: Duration, reason: String)

Bans the peer for a specified duration

Source

pub fn unban(&mut self)

Unban the peer

Source

pub fn banned_until(&self) -> Option<&NaiveDateTime>

Source

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

Source

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

Source

pub fn update_addresses( &mut self, addresses: &[Multiaddr], source: &PeerAddressSource, ) -> &mut Self

Update the peer’s addresses. This call will invalidate the identity signature.

Source

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.

Source

pub fn add_flags(&mut self, flags: PeerFlags) -> &mut Self

Source

pub fn is_seed(&self) -> bool

Source

pub fn to_short_string(&self) -> String

Trait Implementations§

Source§

impl Clone for Peer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Peer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Peer

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Peer

Display Peer as [peer_id]: <pubkey>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Peer

Source§

impl Hash for Peer

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Peer

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Peer

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<(NewPeerSql, Vec<NewMultiaddrWithStatsSql>)> for Peer

Source§

type Error = StorageError

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

fn try_from( (peer_query, addresses_query): (NewPeerSql, Vec<NewMultiaddrWithStatsSql>), ) -> Result<Self, Self::Error>

Performs the conversion.

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

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'a, T> DefaultFeatures<'a> for T
where T: 'a + Send + Sync + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> MessageFormat for T

Source§

fn to_binary(&self) -> Result<Vec<u8>, MessageFormatError>

Convert to binary.
Source§

fn to_json(&self) -> Result<String, MessageFormatError>

Convert to json.
Source§

fn to_base64(&self) -> Result<String, MessageFormatError>

Convert to base64.
Source§

fn from_binary(msg: &[u8]) -> Result<T, MessageFormatError>

Convert from binary.
Source§

fn from_json(msg: &str) -> Result<T, MessageFormatError>

Convert from json.
Source§

fn from_base64(msg: &str) -> Result<T, MessageFormatError>

Convert from base64.
Source§

impl<'a, T> NonSyncFeatures<'a> for T
where T: 'a + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SafeBorrow<T> for T
where T: ?Sized,

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
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