use libp2p::identity::Keypair;
use tokio::sync::{mpsc, watch};
use crate::{swarm::Swarm, Satellite, SatelliteConfig, Shoji, TatamiError};
use super::TatamiEvent;
impl Satellite {
pub async fn launch(config: SatelliteConfig) -> Result<Self, TatamiError> {
let (shoji_commander, shoji_receiver) = mpsc::channel(100);
let (event_sender, event_watcher) = watch::channel(TatamiEvent::None);
Ok(Self {
swarm: Swarm::create(config.keypair.clone(), config.bootstrap).await?,
shoji: Shoji::new(shoji_commander, event_watcher),
shoji_command_reciever: shoji_receiver,
event_sender,
config,
})
}
pub async fn blink(keypair: Keypair) -> Result<Self, TatamiError> {
Self::launch(SatelliteConfig::with_keypair(keypair)).await
}
pub async fn random() -> Result<Self, TatamiError> {
Self::launch(Default::default()).await
}
}