kitsune2_api/
peer_meta_store.rs

1use crate::{builder, config, BoxFut, K2Result, Timestamp, Url};
2use futures::future::BoxFuture;
3use std::sync::Arc;
4
5/// A store for peer metadata.
6///
7/// This is expected to be backed by a key-value store that keys by space, peer URL and key.
8pub trait PeerMetaStore: 'static + Send + Sync + std::fmt::Debug {
9    /// Store a key-value pair for a given space and peer.
10    fn put(
11        &self,
12        peer: Url,
13        key: String,
14        value: bytes::Bytes,
15        expiry: Option<Timestamp>,
16    ) -> BoxFuture<'_, K2Result<()>>;
17
18    /// Get a value by key for a given space and peer.
19    fn get(
20        &self,
21        peer: Url,
22        key: String,
23    ) -> BoxFuture<'_, K2Result<Option<bytes::Bytes>>>;
24
25    /// Delete a key-value pair for a given space and peer.
26    fn delete(&self, peer: Url, key: String) -> BoxFuture<'_, K2Result<()>>;
27}
28
29/// Trait-object version of kitsune2 [PeerMetaStore].
30pub type DynPeerMetaStore = Arc<dyn PeerMetaStore>;
31
32/// A factory for constructing [PeerMetaStore] instances.
33pub trait PeerMetaStoreFactory:
34    'static + Send + Sync + std::fmt::Debug
35{
36    /// Help the builder construct a default config from the chosen
37    /// module factories.
38    fn default_config(&self, config: &mut config::Config) -> K2Result<()>;
39
40    /// Validate configuration.
41    fn validate_config(&self, config: &config::Config) -> K2Result<()>;
42
43    /// Construct a meta store instance.
44    fn create(
45        &self,
46        builder: Arc<builder::Builder>,
47    ) -> BoxFut<'static, K2Result<DynPeerMetaStore>>;
48}
49
50/// Trait-object [PeerMetaStoreFactory].
51pub type DynPeerMetaStoreFactory = Arc<dyn PeerMetaStoreFactory>;