kitsune2_api/peer_store.rs
1//! Peer-store related types.
2
3use crate::*;
4use std::sync::Arc;
5
6/// Represents the ability to store and query agents.
7pub trait PeerStore: 'static + Send + Sync + std::fmt::Debug {
8 /// Insert agents into the store.
9 fn insert(
10 &self,
11 agent_list: Vec<Arc<agent::AgentInfoSigned>>,
12 ) -> BoxFut<'_, K2Result<()>>;
13
14 /// Get an agent from the store.
15 fn get(
16 &self,
17 agent: id::AgentId,
18 ) -> BoxFut<'_, K2Result<Option<Arc<agent::AgentInfoSigned>>>>;
19
20 /// Get all agents from the store.
21 fn get_all(&self)
22 -> BoxFut<'_, K2Result<Vec<Arc<agent::AgentInfoSigned>>>>;
23
24 /// Get the complete list of agents we know about that
25 /// claim storage_arcs that overlap the provided storage arc.
26 /// This function, provided with the storage arc of a currently active
27 /// local agent, will return a list of agents with whom
28 /// to gossip (and also the local agent). If there are multiple
29 /// local agents in this space, you'll need to call this function
30 /// multiple times and union the results.
31 fn get_by_overlapping_storage_arc(
32 &self,
33 arc: arc::DhtArc,
34 ) -> BoxFut<'_, K2Result<Vec<Arc<agent::AgentInfoSigned>>>>;
35
36 /// Get a list of agents sorted by nearness to a target basis location.
37 /// Offline (tombstoned) agents, and agents with zero arcs are not
38 /// included in the returned list.
39 fn get_near_location(
40 &self,
41 loc: u32,
42 limit: usize,
43 ) -> BoxFut<'_, K2Result<Vec<Arc<agent::AgentInfoSigned>>>>;
44}
45
46/// Trait-object [PeerStore].
47pub type DynPeerStore = Arc<dyn PeerStore>;
48
49/// A factory for constructing [PeerStore] instances.
50pub trait PeerStoreFactory: 'static + Send + Sync + std::fmt::Debug {
51 /// Help the builder construct a default config from the chosen
52 /// module factories.
53 fn default_config(&self, config: &mut config::Config) -> K2Result<()>;
54
55 /// Validate configuration.
56 fn validate_config(&self, config: &config::Config) -> K2Result<()>;
57
58 /// Construct a peer store instance.
59 fn create(
60 &self,
61 builder: Arc<builder::Builder>,
62 ) -> BoxFut<'static, K2Result<DynPeerStore>>;
63}
64
65/// Trait-object [PeerStoreFactory].
66pub type DynPeerStoreFactory = Arc<dyn PeerStoreFactory>;