Peer

Struct Peer 

Source
pub struct Peer { /* private fields */ }
Expand description

The peer struct.

Implementations§

Source§

impl Peer

Source

pub fn new( num_neighbors: usize, pre_trust_score: f64, pre_trust_weight: f64, ) -> Self

Creates a new peer.

Source

pub fn add_neighbor(&mut self, peer_id: PeerId) -> Result<(), EigenError>

Adds a neighbor in the first available spot.

Source

pub fn remove_neighbor(&mut self, peer_id: PeerId)

Removes a neighbor, if found.

Source

pub fn neighbors(&self) -> Vec<PeerId>

Returns the neighbors of the peer.

Source

pub fn set_score(&mut self, peer_id: PeerId, score: u32)

Set the local score towards a neighbor.

Source

pub fn calculate_global_trust_score(&self, epoch: Epoch) -> f64

Calculate the global trust score of the peer in the specified epoch. We do this by taking the sum of neighbor’s opinions and weighting it by the pre trust weight. Then we are adding it with the weighted pre-trust score.

Source

pub fn calculate_local_opinions(&mut self, k: Epoch)

Calculate the local trust score toward all neighbors in the specified epoch.

Source

pub fn get_sum_of_scores(&self) -> u32

Returns sum of local scores.

Source

pub fn get_normalized_score(&self, score: u32) -> f64

Returns the normalized score.

Source

pub fn get_local_opinion(&self, key: &(PeerId, Epoch)) -> Opinion

Returns the local score towards a neighbor in a specified epoch.

Source

pub fn cache_local_opinion(&mut self, key: (PeerId, Epoch), opinion: Opinion)

Caches the local opinion towards a peer in a specified epoch.

Source

pub fn get_neighbor_opinion(&self, key: &(PeerId, Epoch)) -> Opinion

Returns the neighbor’s opinion towards us in a specified epoch.

Source

pub fn cache_neighbor_opinion(&mut self, key: (PeerId, Epoch), opinion: Opinion)

Caches the neighbor opinion towards us in specified epoch.

Auto Trait Implementations§

§

impl Freeze for Peer

§

impl RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl UnwindSafe for Peer

Blanket Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> ErasedDestructor for T
where T: 'static,