tatami 0.1.5

A library for creating satellites and interacting with Tatami protocols.
Documentation
use libp2p::{identity::Keypair, swarm::SwarmBuilder, PeerId};

pub mod behaviour;
pub mod event;
mod transport;

use self::behaviour::SwarmBehaviour;
use crate::errors::TatamiError;

pub struct Swarm(pub libp2p::Swarm<SwarmBehaviour>);

impl Swarm {
	pub async fn create(keypair: Keypair, bootstrap: bool) -> Result<Self, TatamiError> {
		// Get the PeerId from the public key
		let local_peer_id = PeerId::from(keypair.public());

		// Transport and behaviour configs are in different functions
		let transport = Self::transport(&keypair)?;
		let behaviour = SwarmBehaviour::new(keypair, bootstrap).await?;

		// Libp2p Swarm
		let swarm = SwarmBuilder::new(transport, behaviour, local_peer_id)
			.executor(Box::new(|fut| {
				tokio::spawn(fut);
			}))
			.build();

		let swarm = Self(swarm);

		Ok(swarm)
	}
}