fn ping(ctxt: zmq::Context, my_ep: String, rcp: sync::Arc<sync::Mutex<Vec<String>>>) {
    loop {
        let mut peers: sync::MutexGuard<Vec<String>> = rcp.lock().unwrap();
        let joined = peers.join(",");
        let msg = Msg::Ping(joined);

        let fut_values: _ = async {
            let mut futures: Vec<_> = vec![];
            for peer in peers.iter() {
                if peer != &my_ep {
                    futures.push(ping_peer(&ctxt, peer, &msg));
                }
            }
            let res: Vec<String> = future::try_join_all(futures).await.unwrap();
            res
        };
        let dead_peers: Vec<String> = executor::block_on(fut_values);
        peers.retain(|x: &String| !dead_peers.contains(x));

        if peers.is_empty() {
            break;
        }

        drop(peers);
        thread::sleep(time::Duration::from_secs(TIMEOUT));
    }
}
///
/// Will on a given timout try to ping the host it knows and if needed remove peers from the list
/// of known neighbours.
///
/// Could be optimized by only sending delta in data between last msg and new one.
///
Will on a given timout try to ping the host it knows and if needed remove peers from the list
of known neighbours.

Could be optimized by only sending delta in data between last msg and new one.
Will on a given timout try to ping the host it knows and if needed remove peers from the list of known neighbours . Could be optimized by only sending delta in data between last msg and new one .
fn ping(ctxt: zmq::Context, my_ep: String, rcp: sync::Arc<sync::Mutex<Vec<String>>>) {
    loop {
        let mut peers: sync::MutexGuard<Vec<String>> = rcp.lock().unwrap();
        let joined = peers.join(",");
        let msg = Msg::Ping(joined);
        let fut_values: _ = async {
            let mut futures: Vec<_> = vec![];
            for peer in peers.iter() {
                if peer != &my_ep {
                    futures.push(ping_peer(&ctxt, peer, &msg));
                }
            }
            let res: Vec<String> = future::try_join_all(futures).await.unwrap();
            res
        };
        let dead_peers: Vec<String> = executor::block_on(fut_values);
        peers.retain(|x: &String| !dead_peers.contains(x));
        if peers.is_empty() {
            break;
        }
        drop(peers);
        thread::sleep(time::Duration::from_secs(TIMEOUT));
    }
}
fn ping ( ctxt : zmq :: Context , my_ep : String , rcp : sync :: Arc < sync :: Mutex < Vec < String > > > ) { loop { let mut peers : sync :: MutexGuard < Vec < String > > = rcp . lock ( ) . unwrap ( ) ; let joined = peers . join ( " " ) ; let msg = Msg :: Ping ( joined ) ; let fut_values : _ = async { let mut futures : Vec < _ > = vec ! [ ] ; for peer in peers . iter ( ) { if peer != & my_ep { futures . push ( ping_peer ( & ctxt , peer , & msg ) ) ; } } let res : Vec < String > = future :: try_join_all ( futures ) . await . unwrap ( ) ; res } ; let dead_peers : Vec < String > = executor :: block_on ( fut_values ) ; peers . retain ( | x : & String | ! dead_peers . contains ( x ) ) ; if peers . is_empty ( ) { break ; } drop ( peers ) ; thread :: sleep ( time :: Duration :: from_secs ( TIMEOUT ) ) ; } }
Will on a given timout try to ping the host it knows and if needed remove peers from the list
of known neighbours.
Will on a given timout try to ping the host it knows and if needed remove peers from the list of known neighbours .
ctxt
zmq::Context
my_ep
String
rcp
sync::Arc<sync::Mutex<Vec<String>>>
ctxt
zmq::Context
my_ep
String
rcp
sync::Arc<sync::Mutex<Vec<String>>>