godrays 0.1.0

Peer Discovery library for Cluster Formation
Documentation
use std::sync::Arc;
use async_std::prelude::FutureExt;
use crossbeam_skiplist::SkipMap;
use libp2p::{identity};
use libp2p::swarm::NetworkBehaviour;
use crate::core::mdns::GodraysMdns;

pub mod core;
pub mod errors;

#[derive(Clone)]
pub struct Godrays {
    mdns: GodraysMdns
}

unsafe impl Send for Godrays {}
unsafe impl Sync for Godrays {}

impl Godrays {
    ///
    /// Create new Godrays instance.
    pub fn new() -> errors::Result<Godrays> {
        let local_key = identity::Keypair::generate_ed25519();

        let (tx, rx) = async_broadcast::broadcast(1_000);

        let mdns = GodraysMdns::new(local_key.clone(), tx)?;

        Ok(Self {
            mdns
        })
    }

    ///
    /// Get all discovered IPs in network
    pub fn get_discovered_ips(&self) -> Vec<String> {
        self.mdns.discovered_nodes.iter().map(|e| e.value().to_owned()).collect()
    }

    ///
    /// Launch Godrays instance.
    pub async fn launch(&self) {
        self.mdns.launch().await
    }
}