Resolver

Trait Resolver 

Source
pub trait Resolver:
    Clone
    + Send
    + 'static {
    type Key: Span;
    type PublicKey: PublicKey;

    // Required methods
    fn fetch(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send;
    fn fetch_all(
        &mut self,
        keys: Vec<Self::Key>,
    ) -> impl Future<Output = ()> + Send;
    fn fetch_targeted(
        &mut self,
        key: Self::Key,
        targets: NonEmptyVec<Self::PublicKey>,
    ) -> impl Future<Output = ()> + Send;
    fn fetch_all_targeted(
        &mut self,
        requests: Vec<(Self::Key, NonEmptyVec<Self::PublicKey>)>,
    ) -> impl Future<Output = ()> + Send;
    fn cancel(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send;
    fn clear(&mut self) -> impl Future<Output = ()> + Send;
    fn retain(
        &mut self,
        predicate: impl Fn(&Self::Key) -> bool + Send + 'static,
    ) -> impl Future<Output = ()> + Send;
}
Expand description

Responsible for fetching data and notifying a Consumer.

Required Associated Types§

Source

type Key: Span

Type used to uniquely identify data.

Source

type PublicKey: PublicKey

Type used to identify peers for targeted fetches.

Required Methods§

Source

fn fetch(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send

Initiate a fetch request for a single key.

Source

fn fetch_all(&mut self, keys: Vec<Self::Key>) -> impl Future<Output = ()> + Send

Initiate a fetch request for a batch of keys.

Source

fn fetch_targeted( &mut self, key: Self::Key, targets: NonEmptyVec<Self::PublicKey>, ) -> impl Future<Output = ()> + Send

Initiate a fetch request restricted to specific target peers.

Only target peers are tried, there is no fallback to other peers. Targets persist through transient failures (timeout, “no data” response, send failure) since the peer might be slow or might receive the data later.

If a fetch is already in progress for this key:

  • If the existing fetch has targets, the new targets are added to the set
  • If the existing fetch has no targets (can try any peer), it remains unrestricted (this call is ignored)

To clear targeting and fall back to any peer, call fetch.

Targets are automatically cleared when the fetch succeeds or is canceled. When a peer is blocked (sent invalid data), only that peer is removed from the target set.

Source

fn fetch_all_targeted( &mut self, requests: Vec<(Self::Key, NonEmptyVec<Self::PublicKey>)>, ) -> impl Future<Output = ()> + Send

Initiate fetch requests for multiple keys, each with their own targets.

See fetch_targeted for details on target behavior.

Source

fn cancel(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send

Cancel a fetch request.

Source

fn clear(&mut self) -> impl Future<Output = ()> + Send

Cancel all fetch requests.

Source

fn retain( &mut self, predicate: impl Fn(&Self::Key) -> bool + Send + 'static, ) -> impl Future<Output = ()> + Send

Retain only the fetch requests that satisfy the predicate.

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§

Source§

impl<K: Span, P: PublicKey> Resolver for Mailbox<K, P>