tatami 0.1.5

A library for creating satellites and interacting with Tatami protocols.
Documentation
use crate::{shoji::ShojiCommand, Satellite, ShojiError};

impl Satellite {
	/// The single function to delegate and manage every Shoji command
	pub fn handle_shoji_command(&mut self, command: ShojiCommand) -> Result<(), ShojiError> {
		match command {
			// Command-to-Satellite
			ShojiCommand::GetClosestPeers(peer_id) => {
				self.get_closest_peers(peer_id);
			}
			// Command-to-Satellite
			ShojiCommand::DialPeer(peer_id, sender) => {
				sender
					.send(self.dial_peer(peer_id))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::LocalPeerId(sender) => {
				sender
					.send(self.local_peer_id())
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::DialAddress(address, sender) => {
				sender
					.send(self.dial_address(address))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::Listeners(sender) => {
				sender.send(self.listeners()).or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::ListenOn(address, sender) => {
				sender
					.send(self.listen_on(address))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::BanPeerId(peer_id) => self.ban_peer_id(peer_id),
			// Command-to-Satellite
			ShojiCommand::UnbanPeerId(peer_id) => self.unban_peer_id(peer_id),
			// Command-to-Satellite
			ShojiCommand::ConnectedPeers(sender) => {
				sender
					.send(self.connected_peers())
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::DisconnectPeerId(peer_id, sender) => {
				sender
					.send(self.disconnect_peer_id(peer_id))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::IsConnected(peer_id, sender) => {
				sender
					.send(self.is_connected(&peer_id))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::NetworkInfo(sender) => {
				sender.send(self.network_info()).or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::AddAddress(peer_id, multiaddr) => {
				self.add_address(&peer_id, multiaddr);
			}
			// Command-to-Satellite
			ShojiCommand::PublishMessage(message, sender) => {
				sender
					.send(self.publish_message(message))
					.or(Err(ShojiError::Tear))?;
			}
			// Command-to-Satellite
			ShojiCommand::Publish(payload, sender) => {
				sender
					.send(self.publish(payload))
					.or(Err(ShojiError::Tear))?;
			}
		}
		Ok(())
	}
}