fn process_list_peers<'a, I: Iterator<Item = &'a str>>(&mut self, mut args: I) {
        let peer_manager = self.peer_manager.clone();
        let filter = args.next().map(ToOwned::to_owned);

        self.executor.spawn(async move {
            let mut query = PeerQuery::new();
            if let Some(f) = filter {
                let filter = f.to_lowercase();
                query = query.select_where(move |p| match filter.as_str() {
                    "basenode" | "basenodes" | "base_node" | "base-node" | "bn" => {
                        p.features == PeerFeatures::COMMUNICATION_NODE
                    },
                    "wallet" | "wallets" | "w" => p.features == PeerFeatures::COMMUNICATION_CLIENT,
                    _ => false,
                })
            }
            match peer_manager.perform_query(query).await {
                Ok(peers) => {
                    let num_peers = peers.len();
                    println!();
                    let mut table = Table::new();
                    table.set_titles(vec!["NodeId", "Public Key", "Flags", "Role", "User Agent", "Info"]);

                    for peer in peers {
                        let info_str = {
                            let mut s = vec![];

                            if peer.is_offline() {
                                if !peer.is_banned() {
                                    s.push("OFFLINE".to_string());
                                }
                            } else if let Some(dt) = peer.last_seen() {
                                s.push(format!(
                                    "LAST_SEEN = {}",
                                    Utc::now()
                                        .signed_duration_since(dt)
                                        .to_std()
                                        .map(format_duration_basic)
                                        .unwrap_or_else(|_| "?".into())
                                ));
                            }

                            if let Some(dt) = peer.banned_until() {
                                s.push(format!(
                                    "BANNED({}, {})",
                                    dt.signed_duration_since(Utc::now().naive_utc())
                                        .to_std()
                                        .map(format_duration_basic)
                                        .unwrap_or_else(|_| "∞".to_string()),
                                    peer.banned_reason
                                ));
                            }

                            if let Some(metadata) = peer
                                .get_metadata(1)
                                .and_then(|v| bincode::deserialize::<PeerMetadata>(v).ok())
                            {
                                s.push(format!(
                                    "chain height = {}",
                                    metadata.metadata.height_of_longest_chain()
                                ));
                            }

                            if s.is_empty() {
                                "--".to_string()
                            } else {
                                s.join(", ")
                            }
                        };
                        table.add_row(row![
                            peer.node_id,
                            peer.public_key,
                            format!("{:?}", peer.flags),
                            {
                                if peer.features == PeerFeatures::COMMUNICATION_CLIENT {
                                    "Wallet"
                                } else {
                                    "Base node"
                                }
                            },
                            Some(peer.user_agent)
                                .map(|ua| if ua.is_empty() { "<unknown>".to_string() } else { ua })
                                .unwrap(),
                            info_str,
                        ]);
                    }
                    table.print_std();

                    println!("{} peer(s) known by this node", num_peers);
                },
                Err(err) => {
                    println!("Failed to list peers: {:?}", err);
                    error!(target: LOG_TARGET, "Could not list peers: {:?}", err);
                    return;
                },
            }
        });
    }
/// Function to process the list-peers command
Function to process the list-peers command
Function to process the list - peers command
fn process_list_peers<'a, I: Iterator<Item = &'a str>>(&mut self, mut args: I) {
        let peer_manager = self.peer_manager.clone();
        let filter = args.next().map(ToOwned::to_owned);
        self.executor.spawn(async move {
            let mut query = PeerQuery::new();
            if let Some(f) = filter {
                let filter = f.to_lowercase();
                query = query.select_where(move |p| match filter.as_str() {
                    "basenode" | "basenodes" | "base_node" | "base-node" | "bn" => {
                        p.features == PeerFeatures::COMMUNICATION_NODE
                    },
                    "wallet" | "wallets" | "w" => p.features == PeerFeatures::COMMUNICATION_CLIENT,
                    _ => false,
                })
            }
            match peer_manager.perform_query(query).await {
                Ok(peers) => {
                    let num_peers = peers.len();
                    println!();
                    let mut table = Table::new();
                    table.set_titles(vec!["NodeId", "Public Key", "Flags", "Role", "User Agent", "Info"]);
                    for peer in peers {
                        let info_str = {
                            let mut s = vec![];
                            if peer.is_offline() {
                                if !peer.is_banned() {
                                    s.push("OFFLINE".to_string());
                                }
                            } else if let Some(dt) = peer.last_seen() {
                                s.push(format!(
                                    "LAST_SEEN = {}",
                                    Utc::now()
                                        .signed_duration_since(dt)
                                        .to_std()
                                        .map(format_duration_basic)
                                        .unwrap_or_else(|_| "?".into())
                                ));
                            }
                            if let Some(dt) = peer.banned_until() {
                                s.push(format!(
                                    "BANNED({}, {})",
                                    dt.signed_duration_since(Utc::now().naive_utc())
                                        .to_std()
                                        .map(format_duration_basic)
                                        .unwrap_or_else(|_| "∞".to_string()),
                                    peer.banned_reason
                                ));
                            }
                            if let Some(metadata) = peer
                                .get_metadata(1)
                                .and_then(|v| bincode::deserialize::<PeerMetadata>(v).ok())
                            {
                                s.push(format!(
                                    "chain height = {}",
                                    metadata.metadata.height_of_longest_chain()
                                ));
                            }
                            if s.is_empty() {
                                "--".to_string()
                            } else {
                                s.join(", ")
                            }
                        };
                        table.add_row(row![
                            peer.node_id,
                            peer.public_key,
                            format!("{:?}", peer.flags),
                            {
                                if peer.features == PeerFeatures::COMMUNICATION_CLIENT {
                                    "Wallet"
                                } else {
                                    "Base node"
                                }
                            },
                            Some(peer.user_agent)
                                .map(|ua| if ua.is_empty() { "<unknown>".to_string() } else { ua })
                                .unwrap(),
                            info_str,
                        ]);
                    }
                    table.print_std();
                    println!("{} peer(s) known by this node", num_peers);
                },
                Err(err) => {
                    println!("Failed to list peers: {:?}", err);
                    error!(target: LOG_TARGET, "Could not list peers: {:?}", err);
                    return;
                },
            }
        });
    }
fn process_list_peers < ' a , I : Iterator < Item = & ' a str > > ( & mut self , mut args : I ) { let peer_manager = self . peer_manager . clone ( ) ; let filter = args . next ( ) . map ( ToOwned :: to_owned ) ; self . executor . spawn ( async move { let mut query = PeerQuery :: new ( ) ; if let Some ( f ) = filter { let filter = f . to_lowercase ( ) ; query = query . select_where ( move | p | match filter . as_str ( ) { " " | " " | " " | " " | " " => { p . features == PeerFeatures :: COMMUNICATION_NODE } , " " | " " | " " => p . features == PeerFeatures :: COMMUNICATION_CLIENT , _ => false , } ) } match peer_manager . perform_query ( query ) . await { Ok ( peers ) => { let num_peers = peers . len ( ) ; println ! ( ) ; let mut table = Table :: new ( ) ; table . set_titles ( vec ! [ " " " " " " " " " " " " ] ) ; for peer in peers { let info_str = { let mut s = vec ! [ ] ; if peer . is_offline ( ) { if ! peer . is_banned ( ) { s . push ( " " . to_string ( ) ) ; } } else if let Some ( dt ) = peer . last_seen ( ) { s . push ( format ! ( " " Utc now ( ) signed_duration_since ( dt ) to_std ( ) map ( format_duration_basic ) unwrap_or_else ( " " into ( ) ) ) ) ; } if let Some ( dt ) = peer . banned_until ( ) { s . push ( format ! ( " " dt signed_duration_since ( Utc now ( ) naive_utc ( ) ) to_std ( ) map ( format_duration_basic ) unwrap_or_else ( " t _string() ) , peer banned_reason ) ) ; } if let Some ( metadata ) = peer . get_metadata ( 1 ) . and_then ( | v | bincode :: deserialize :: < PeerMetadata > ( v ) . ok ( ) ) { s . push ( format ! ( " " metadata metadata height_of_longest_chain ( ) ) ) ; } if s . is_empty ( ) { " " . to_string ( ) } else { s . join ( " " ) } } ; table . add_row ( row ! [ peer node_id peer public_key format ( " " peer flags ) { if peer features PeerFeatures COMMUNICATION_CLIENT { " " } else { " " } } Some ( peer user_agent ) map ( ua if ua is_empty ( ) { " " to_string ( ) } else { ua } ) unwrap ( ) info_str ] ) ; } table . print_std ( ) ; println ! ( " " num_peers ) ; } , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; return ; } , } } ) ; }
Function to process the list-peers command
Function to process the list - peers command
&mut self
args
I
&mut self
args
I