tatami 0.1.5

A library for creating satellites and interacting with Tatami protocols.
Documentation
use libp2p::identity::Keypair;
use tokio::sync::{mpsc, watch};

use crate::{swarm::Swarm, Blueprint, Satellite, Shoji, TatamiError};

use super::TatamiEvent;

impl Satellite {
	/// Uses the given configuration to assemble all parts of the satellite
	/// Make sure to run the satellite as well!
	pub async fn launch(config: Blueprint) -> Result<Self, TatamiError> {
		// Communication with Shoji
		let (shoji_commander, shoji_receiver) = mpsc::channel(100);
		// Event communications
		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.clone()),
			shoji_command_reciever: shoji_receiver,
			event_sender,
			event_watcher,
			config,
		})
	}

	/// A simple command that *blinks* a Satellite into existence with default configs
	pub async fn blink(keypair: Keypair) -> Result<Self, TatamiError> {
		Self::launch(Blueprint::default().with_keypair(keypair)).await
	}

	/// A simple command that *blinks* a random Satellite into existence
	pub async fn random() -> Result<Self, TatamiError> {
		Self::launch(Default::default()).await
	}
}