kitsune2_api/
bootstrap.rs

1//! Kitsune2 bootstrap related types.
2
3use crate::*;
4use std::sync::Arc;
5
6/// Method for bootstrapping WAN discovery of peers.
7///
8/// The internal implementation will take care of whatever polling
9/// or managing of message queues is required to be notified of
10/// remote peers both on initialization and over runtime.
11pub trait Bootstrap: 'static + Send + Sync + std::fmt::Debug {
12    /// Put an agent info onto a bootstrap server.
13    ///
14    /// This method takes responsibility for retrying the send operation in the case
15    /// of server error until such time as:
16    /// - the Put succeeds
17    /// - we receive a new info that supersedes the previous
18    /// - or the info expires
19    fn put(&self, info: Arc<AgentInfoSigned>);
20}
21
22/// Trait-object [Bootstrap].
23pub type DynBootstrap = Arc<dyn Bootstrap>;
24
25/// A factory for constructing Bootstrap instances.
26pub trait BootstrapFactory: 'static + Send + Sync + std::fmt::Debug {
27    /// Help the builder construct a default config from the chosen
28    /// module factories.
29    fn default_config(&self, config: &mut Config) -> K2Result<()>;
30
31    /// Validate configuration.
32    fn validate_config(&self, config: &Config) -> K2Result<()>;
33
34    /// Construct a bootstrap instance.
35    fn create(
36        &self,
37        builder: Arc<Builder>,
38        peer_store: DynPeerStore,
39        space: SpaceId,
40    ) -> BoxFut<'static, K2Result<DynBootstrap>>;
41}
42
43/// Trait-object [BootstrapFactory].
44pub type DynBootstrapFactory = Arc<dyn BootstrapFactory>;