tatami 0.1.2

A library for creating satellites and interacting with Tatami protocols.
Documentation
use libp2p::{Multiaddr, PeerId};
use std::fmt::Debug;
use tokio::sync::{mpsc, watch};

mod blueprint;
mod launch;
mod message;
mod methods;
mod module;
mod run;
mod utilities;

pub use self::message::Message;
pub use self::message::PeerMessage;
use crate::shoji::ShojiCommand;
use crate::swarm::Swarm;
use crate::Shoji;
pub use blueprint::Blueprint;
pub use module::Module;

#[derive(Debug, Clone)]
pub enum TatamiEvent {
	None,
	ConnectionEstablished(PeerId),
	ConnectionClosed(PeerId),
	UndiagnosedEvent,
	NewListenAddress(Multiaddr),
	MessageReceived(PeerMessage),
}

/// The central struct for running a Tatami Satellite.
/// ```rust
/// use tatami::{Satellite, SatelliteConfig};
///
/// #[tokio::main]
/// async fn main() {
///    let key = Satellite::random_key();
///    let config = SatelliteConfig::default().keypair(key);
///    let satellite = Satellite::launch(config).await.expect("Satellite to be launched");
/// }
/// ```
pub struct Satellite {
	/// A paper-door for interacting with the Satellite asynchronously
	pub shoji: Shoji,
	/// The p2p management supported by libp2p
	swarm: Swarm,
	/// A receiver of Shoji commands
	shoji_command_reciever: mpsc::Receiver<ShojiCommand>,
	/// Sender of various events
	event_sender: watch::Sender<TatamiEvent>,
	/// An event watcher, free to use by modules
	event_watcher: watch::Receiver<TatamiEvent>,
	/// Configuration
	config: Blueprint,
}

impl Debug for Satellite {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		f.debug_struct("Satellite")
			.field("shoji", &self.shoji)
			.field("shoji_command_reciever", &self.shoji_command_reciever)
			.field("event_sender", &self.event_sender)
			.finish()
	}
}