pub fn dump_state(env: EnvRead, cell_id: Option<CellId>) -> StateQueryResult<P2pAgentsDump> {
    use std::fmt::Write;
    let cell_id = cell_id.map(|c| c.into_saf_and_agent()).map(|c| {
        (
            (c.0.clone(), aingle_p2p::space_ai_to_kit(c.0)),
            (c.1.clone(), aingle_p2p::agent_ai_to_kit(c.1)),
        )
    });
    let agent_infos = all_agent_infos(env)?;
    let agent_infos = agent_infos.into_iter().filter(|a| match &cell_id {
        Some((s, _)) => s.1 == *a.space,
        None => true,
    });
    let mut this_agent_info = None;
    let mut peers = Vec::new();
    for info in agent_infos {
        let mut dump = String::new();

        use chrono::{DateTime, Duration, NaiveDateTime, Utc};
        let duration = Duration::milliseconds(info.signed_at_ms as i64);
        let s = duration.num_seconds() as i64;
        let n = duration.clone().to_std().unwrap().subsec_nanos();
        let dt = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(s, n), Utc);
        let duration = Duration::milliseconds(info.expires_at_ms as i64);
        let s = duration.num_seconds() as i64;
        let n = duration.clone().to_std().unwrap().subsec_nanos();
        let exp = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(s, n), Utc);
        let now = Utc::now();

        writeln!(dump, "signed at {}", dt).ok();
        writeln!(
            dump,
            "expires at {} in {}mins",
            exp,
            (exp - now).num_minutes()
        )
        .ok();
        writeln!(dump, "urls: {:?}", info.url_list).ok();
        let info = AgentInfoDump {
            kitsune_agent: info.agent.clone(),
            kitsune_space: info.space.clone(),
            dump,
        };
        match &cell_id {
            Some((s, a)) if *info.kitsune_agent == a.1 && *info.kitsune_space == s.1 => {
                this_agent_info = Some(info);
            }
            None | Some(_) => peers.push(info),
        }
    }

    Ok(P2pAgentsDump {
        this_agent_info,
        this_saf: cell_id.clone().map(|(s, _)| s),
        this_agent: cell_id.clone().map(|(_, a)| a),
        peers,
    })
}
/// Dump the agents currently in the peer store
Dump the agents currently in the peer store
Dump the agents currently in the peer store
pub fn dump_state(env: EnvRead, cell_id: Option<CellId>) -> StateQueryResult<P2pAgentsDump> {
    use std::fmt::Write;
    let cell_id = cell_id.map(|c| c.into_saf_and_agent()).map(|c| {
        (
            (c.0.clone(), aingle_p2p::space_ai_to_kit(c.0)),
            (c.1.clone(), aingle_p2p::agent_ai_to_kit(c.1)),
        )
    });
    let agent_infos = all_agent_infos(env)?;
    let agent_infos = agent_infos.into_iter().filter(|a| match &cell_id {
        Some((s, _)) => s.1 == *a.space,
        None => true,
    });
    let mut this_agent_info = None;
    let mut peers = Vec::new();
    for info in agent_infos {
        let mut dump = String::new();
        use chrono::{DateTime, Duration, NaiveDateTime, Utc};
        let duration = Duration::milliseconds(info.signed_at_ms as i64);
        let s = duration.num_seconds() as i64;
        let n = duration.clone().to_std().unwrap().subsec_nanos();
        let dt = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(s, n), Utc);
        let duration = Duration::milliseconds(info.expires_at_ms as i64);
        let s = duration.num_seconds() as i64;
        let n = duration.clone().to_std().unwrap().subsec_nanos();
        let exp = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(s, n), Utc);
        let now = Utc::now();
        writeln!(dump, "signed at {}", dt).ok();
        writeln!(
            dump,
            "expires at {} in {}mins",
            exp,
            (exp - now).num_minutes()
        )
        .ok();
        writeln!(dump, "urls: {:?}", info.url_list).ok();
        let info = AgentInfoDump {
            kitsune_agent: info.agent.clone(),
            kitsune_space: info.space.clone(),
            dump,
        };
        match &cell_id {
            Some((s, a)) if *info.kitsune_agent == a.1 && *info.kitsune_space == s.1 => {
                this_agent_info = Some(info);
            }
            None | Some(_) => peers.push(info),
        }
    }
    Ok(P2pAgentsDump {
        this_agent_info,
        this_saf: cell_id.clone().map(|(s, _)| s),
        this_agent: cell_id.clone().map(|(_, a)| a),
        peers,
    })
}
pub fn dump_state ( env : EnvRead , cell_id : Option < CellId > ) -> StateQueryResult < P2pAgentsDump > { use std :: fmt :: Write ; let cell_id = cell_id . map ( | c | c . into_saf_and_agent ( ) ) . map ( | c | { ( ( c . 0 . clone ( ) , aingle_p2p :: space_ai_to_kit ( c . 0 ) ) , ( c . 1 . clone ( ) , aingle_p2p :: agent_ai_to_kit ( c . 1 ) ) , ) } ) ; let agent_infos = all_agent_infos ( env ) ? ; let agent_infos = agent_infos . into_iter ( ) . filter ( | a | match & cell_id { Some ( ( s , _ ) ) => s . 1 == * a . space , None => true , } ) ; let mut this_agent_info = None ; let mut peers = Vec :: new ( ) ; for info in agent_infos { let mut dump = String :: new ( ) ; use chrono :: { DateTime , Duration , NaiveDateTime , Utc } ; let duration = Duration :: milliseconds ( info . signed_at_ms as i64 ) ; let s = duration . num_seconds ( ) as i64 ; let n = duration . clone ( ) . to_std ( ) . unwrap ( ) . subsec_nanos ( ) ; let dt = DateTime :: < Utc > :: from_utc ( NaiveDateTime :: from_timestamp ( s , n ) , Utc ) ; let duration = Duration :: milliseconds ( info . expires_at_ms as i64 ) ; let s = duration . num_seconds ( ) as i64 ; let n = duration . clone ( ) . to_std ( ) . unwrap ( ) . subsec_nanos ( ) ; let exp = DateTime :: < Utc > :: from_utc ( NaiveDateTime :: from_timestamp ( s , n ) , Utc ) ; let now = Utc :: now ( ) ; writeln ! ( dump " " dt ) . ok ( ) ; writeln ! ( dump " " exp ( exp now ) num_minutes ( ) ) . ok ( ) ; writeln ! ( dump " " info url_list ) . ok ( ) ; let info = AgentInfoDump { kitsune_agent : info . agent . clone ( ) , kitsune_space : info . space . clone ( ) , dump , } ; match & cell_id { Some ( ( s , a ) ) if * info . kitsune_agent == a . 1 && * info . kitsune_space == s . 1 => { this_agent_info = Some ( info ) ; } None | Some ( _ ) => peers . push ( info ) , } } Ok ( P2pAgentsDump { this_agent_info , this_saf : cell_id . clone ( ) . map ( | ( s , _ ) | s ) , this_agent : cell_id . clone ( ) . map ( | ( _ , a ) | a ) , peers , } ) }
Dump the agents currently in the peer store
Dump the agents currently in the peer store
env
EnvRead
cell_id
Option<CellId>
env
EnvRead
cell_id
Option<CellId>