pub trait PeerSelector: Send + Sync {
type Error: Error + Display + Send + Sync + 'static;
// Required methods
fn select(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
params: SelectParams,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error>;
fn current_view(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error>;
// Provided method
fn sample(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
n: u32,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error> { ... }
}Expand description
User-facing Contract trait for a peer-selection protocol.
Required Associated Types§
Required Methods§
Sourcefn select(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
params: SelectParams,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error>
fn select( &mut self, ctx: &mut RuntimeResourceRef<'_>, params: SelectParams, completion: CompletionHandle<Vec<PeerId>, Self::Error>, ) -> ContractResponse<Vec<PeerId>, Self::Error>
Generic selection — params carries selector-specific
config. Concrete impls handle the variants they support
and fail the unsupported ones via ContractResponse::Now
carrying an error. ctx exposes ctx.peers.addresses
(the framework’s AddressBook), the engine’s per-op
runtime surface, and ctx.dependency::<T>(slot) for
reaching any concrete bound via #[depends(...)].
Sourcefn current_view(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error>
fn current_view( &mut self, ctx: &mut RuntimeResourceRef<'_>, completion: CompletionHandle<Vec<PeerId>, Self::Error>, ) -> ContractResponse<Vec<PeerId>, Self::Error>
Snapshot the current view of known peers (owned snapshot — async serialization needs owned values).
Provided Methods§
Sourcefn sample(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
n: u32,
completion: CompletionHandle<Vec<PeerId>, Self::Error>,
) -> ContractResponse<Vec<PeerId>, Self::Error>
fn sample( &mut self, ctx: &mut RuntimeResourceRef<'_>, n: u32, completion: CompletionHandle<Vec<PeerId>, Self::Error>, ) -> ContractResponse<Vec<PeerId>, Self::Error>
Sample n peers from the current view. Calls
land on select(SelectParams::Random { n }) by default.
Concrete impls may override to keep an optimized fast path.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".