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§
Sourcetype SamplingMode
type SamplingMode
The type used to choose between peer selection strategies.
Sourcetype SelectPeerRef<'a>: OpRef
where
Self: 'a
type SelectPeerRef<'a>: OpRef where Self: 'a
Handle to an in-flight peer selection operation.
Required Methods§
Sourcefn select_peer(&mut self, mode: &Self::SamplingMode) -> Self::SelectPeerRef<'_>
fn select_peer(&mut self, mode: &Self::SamplingMode) -> Self::SelectPeerRef<'_>
Select a single peer using the given selection strategy.
Sourcefn broadcast(&self) -> Vec<Self::Peer>
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.