pub struct Peer { /* private fields */ }Expand description
The peer struct.
Implementations§
Source§impl Peer
impl Peer
Sourcepub fn new(
num_neighbors: usize,
pre_trust_score: f64,
pre_trust_weight: f64,
) -> Self
pub fn new( num_neighbors: usize, pre_trust_score: f64, pre_trust_weight: f64, ) -> Self
Creates a new peer.
Sourcepub fn add_neighbor(&mut self, peer_id: PeerId) -> Result<(), EigenError>
pub fn add_neighbor(&mut self, peer_id: PeerId) -> Result<(), EigenError>
Adds a neighbor in the first available spot.
Sourcepub fn remove_neighbor(&mut self, peer_id: PeerId)
pub fn remove_neighbor(&mut self, peer_id: PeerId)
Removes a neighbor, if found.
Sourcepub fn set_score(&mut self, peer_id: PeerId, score: u32)
pub fn set_score(&mut self, peer_id: PeerId, score: u32)
Set the local score towards a neighbor.
Sourcepub fn calculate_global_trust_score(&self, epoch: Epoch) -> f64
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.
Sourcepub fn calculate_local_opinions(&mut self, k: Epoch)
pub fn calculate_local_opinions(&mut self, k: Epoch)
Calculate the local trust score toward all neighbors in the specified epoch.
Sourcepub fn get_sum_of_scores(&self) -> u32
pub fn get_sum_of_scores(&self) -> u32
Returns sum of local scores.
Sourcepub fn get_normalized_score(&self, score: u32) -> f64
pub fn get_normalized_score(&self, score: u32) -> f64
Returns the normalized score.
Sourcepub fn get_local_opinion(&self, key: &(PeerId, Epoch)) -> Opinion
pub fn get_local_opinion(&self, key: &(PeerId, Epoch)) -> Opinion
Returns the local score towards a neighbor in a specified epoch.
Sourcepub fn cache_local_opinion(&mut self, key: (PeerId, Epoch), opinion: Opinion)
pub fn cache_local_opinion(&mut self, key: (PeerId, Epoch), opinion: Opinion)
Caches the local opinion towards a peer in a specified epoch.
Sourcepub fn get_neighbor_opinion(&self, key: &(PeerId, Epoch)) -> Opinion
pub fn get_neighbor_opinion(&self, key: &(PeerId, Epoch)) -> Opinion
Returns the neighbor’s opinion towards us in a specified epoch.
Sourcepub fn cache_neighbor_opinion(&mut self, key: (PeerId, Epoch), opinion: Opinion)
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> 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> 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