fn ping_server(
    rally_point: &RallyPoint,
    input: &app_messages::RallyPointServer,
) -> impl Future<Output = Result<RallyPointServer>> {
    fn ping_server_string(
        rally_point: &RallyPoint,
        input: &Option<String>,
        port: u16,
    ) -> impl Future<Output = Result<RallyPointServer>> {
        match input {
            Some(s) => match s.parse::<IpAddr>() {
                Ok(ip) => {
                    let addr = SocketAddr::new(ip, port);
                    let future = rally_point
                        .ping_server(addr)
                        .map_ok(move |ping| RallyPointServer {
                            address: addr,
                            ping,
                        })
                        .map_err(|e| {
                            error!("Rally error {}", e);
                            NetworkError::ServerUnreachable
                        });
                    future.boxed()
                }
                Err(_) => future::err(NetworkError::NoServerAddress).boxed(),
            },
            None => future::err(NetworkError::NoServerAddress).boxed(),
        }
    }

    let future4 = ping_server_string(rally_point, &input.address4, input.port);
    let future6 = ping_server_string(rally_point, &input.address6, input.port);
    future::select_ok(vec![future4, future6]).map_ok(|x| x.0)
}
// Select ip4/6 address based on which finishses the ping faster
Select ip4/6 address based on which finishses the ping faster
Select ip4 / 6 address based on which finishses the ping faster
fn ping_server(
    rally_point: &RallyPoint,
    input: &app_messages::RallyPointServer,
) -> impl Future<Output = Result<RallyPointServer>> {
    fn ping_server_string(
        rally_point: &RallyPoint,
        input: &Option<String>,
        port: u16,
    ) -> impl Future<Output = Result<RallyPointServer>> {
        match input {
            Some(s) => match s.parse::<IpAddr>() {
                Ok(ip) => {
                    let addr = SocketAddr::new(ip, port);
                    let future = rally_point
                        .ping_server(addr)
                        .map_ok(move |ping| RallyPointServer {
                            address: addr,
                            ping,
                        })
                        .map_err(|e| {
                            error!("Rally error {}", e);
                            NetworkError::ServerUnreachable
                        });
                    future.boxed()
                }
                Err(_) => future::err(NetworkError::NoServerAddress).boxed(),
            },
            None => future::err(NetworkError::NoServerAddress).boxed(),
        }
    }
    let future4 = ping_server_string(rally_point, &input.address4, input.port);
    let future6 = ping_server_string(rally_point, &input.address6, input.port);
    future::select_ok(vec![future4, future6]).map_ok(|x| x.0)
}
fn ping_server ( rally_point : & RallyPoint , input : & app_messages :: RallyPointServer , ) -> impl Future < Output = Result < RallyPointServer > > { fn ping_server_string ( rally_point : & RallyPoint , input : & Option < String > , port : u16 , ) -> impl Future < Output = Result < RallyPointServer > > { match input { Some ( s ) => match s . parse :: < IpAddr > ( ) { Ok ( ip ) => { let addr = SocketAddr :: new ( ip , port ) ; let future = rally_point . ping_server ( addr ) . map_ok ( move | ping | RallyPointServer { address : addr , ping , } ) . map_err ( | e | { error ! ( " " e ) ; NetworkError :: ServerUnreachable } ) ; future . boxed ( ) } Err ( _ ) => future :: err ( NetworkError :: NoServerAddress ) . boxed ( ) , } , None => future :: err ( NetworkError :: NoServerAddress ) . boxed ( ) , } } let future4 = ping_server_string ( rally_point , & input . address4 , input . port ) ; let future6 = ping_server_string ( rally_point , & input . address6 , input . port ) ; future :: select_ok ( vec ! [ future4 future6 ] ) . map_ok ( | x | x . 0 ) }
Select ip4/6 address based on which finishses the ping faster
Select ip4 / 6 address based on which finishses the ping faster
rally_point
&RallyPoint
input
&app_messages::RallyPointServer
rally_point
&RallyPoint
input
&app_messages::RallyPointServer