use libp2p::identity::Keypair;
use std::sync::Mutex;
use crate::{Satellite, TatamiError};
use super::Module;
pub struct Blueprint {
pub keypair: Keypair,
pub mdns_config: SatelliteMdnsConfig,
pub bootstrap: bool,
pub auto_connect: bool,
pub modules: Vec<Mutex<Box<dyn Module + Send>>>,
}
#[derive(Clone)]
pub struct SatelliteMdnsConfig {
pub auto_register: bool,
}
impl Default for SatelliteMdnsConfig {
fn default() -> Self {
Self {
auto_register: true,
}
}
}
impl Default for Blueprint {
fn default() -> Self {
Self {
keypair: crate::random_key(),
mdns_config: Default::default(),
bootstrap: true,
auto_connect: true,
modules: Default::default(),
}
}
}
impl Blueprint {
pub fn with_keypair(self, keypair: Keypair) -> Self {
Self { keypair, ..self }
}
pub fn with_module(self, module: Box<dyn Module + Send>) -> Self {
let mut modules = self.modules;
modules.push(Mutex::new(module));
Self { modules, ..self }
}
pub async fn build(self) -> Result<Satellite, TatamiError> {
Satellite::launch(self).await
}
}