commonware_resolver/lib.rs
1//! Resolve data identified by a fixed-length key.
2
3use commonware_utils::Array;
4use std::future::Future;
5
6pub mod p2p;
7
8/// Notified when data is available, and must validate it.
9pub trait Consumer: Clone + Send + 'static {
10 /// Type used to uniquely identify data.
11 type Key: Array;
12
13 /// Type of data to retrieve.
14 type Value;
15
16 /// Type used to indicate why data is not available.
17 type Failure;
18
19 /// Deliver data to the consumer.
20 ///
21 /// Returns `true` if the data is valid.
22 fn deliver(&mut self, key: Self::Key, value: Self::Value) -> impl Future<Output = bool> + Send;
23
24 /// Let the consumer know that the data is not being fetched anymore.
25 ///
26 /// The failure is used to indicate why.
27 fn failed(&mut self, key: Self::Key, failure: Self::Failure)
28 -> impl Future<Output = ()> + Send;
29}
30
31/// Responsible for fetching data and notifying a `Consumer`.
32pub trait Resolver: Clone + Send + 'static {
33 /// Type used to uniquely identify data.
34 type Key: Array;
35
36 /// Initiate a fetch request.
37 fn fetch(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send;
38
39 /// Cancel a fetch request.
40 fn cancel(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send;
41}