Skip to main content

PeerSampling

Trait PeerSampling 

Source
pub trait PeerSampling {
    type Peer: Clone;
    type PeerView<'a>
       where Self: 'a;
    type SamplingMode;
    type SelectPeerRef<'a>: OpRef
       where Self: 'a;

    // Required methods
    fn view(&self) -> Self::PeerView<'_>;
    fn view_len(&self) -> usize;
    fn select_peer(
        &mut self,
        mode: &Self::SamplingMode,
    ) -> Self::SelectPeerRef<'_>;
    fn broadcast(&self) -> Vec<Self::Peer>;
}
Expand description

Capability trait for protocols that can sample peers from their view.

The selection strategy is passed as a parameter to each selection call, making the trait stateless with respect to selection mode.

Required Associated Types§

Source

type Peer: Clone

The peer type exposed by this protocol’s view.

Source

type PeerView<'a> where Self: 'a

Immutable reference to the current peer view.

Source

type SamplingMode

The type used to choose between peer selection strategies.

Source

type SelectPeerRef<'a>: OpRef where Self: 'a

Handle to an in-flight peer selection operation.

Required Methods§

Source

fn view(&self) -> Self::PeerView<'_>

Return an immutable reference to the current peer view.

Source

fn view_len(&self) -> usize

Number of peers currently in the view.

Source

fn select_peer(&mut self, mode: &Self::SamplingMode) -> Self::SelectPeerRef<'_>

Select a single peer using the given selection strategy.

Source

fn broadcast(&self) -> Vec<Self::Peer>

Return all peers known to this sampler for broadcast operations.

Unlike select_peer which returns a single peer, this returns all peers in the view. Useful for protocols that need to send messages to multiple peers (e.g., gossip push-pull).

The caller is responsible for limiting fan-out if needed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§