/// Function to process the list-connections command
Function to process the list-connections command
Function to process the list - connections command
pub fn list_connections(&self) {
        let mut connectivity = self.connectivity.clone();
        let peer_manager = self.peer_manager.clone();
        self.executor.spawn(async move {
            match connectivity.get_active_connections().await {
                Ok(conns) if conns.is_empty() => {
                    println!("No active peer connections.");
                },
                Ok(conns) => {
                    println!();
                    let num_connections = conns.len();
                    let mut table = Table::new();
                    table.set_titles(vec![
                        "NodeId",
                        "Public Key",
                        "Address",
                        "Direction",
                        "Age",
                        "Role",
                        "User Agent",
                        "Chain Height",
                    ]);
                    for conn in conns {
                        let peer = peer_manager
                            .find_by_node_id(conn.peer_node_id())
                            .await
                            .expect("Unexpected peer database error or peer not found");
                        let chain_height = if let Some(metadata) = peer
                            .get_metadata(1)
                            .and_then(|v| bincode::deserialize::<PeerMetadata>(v).ok())
                        {
                            Some(format!("Height = #{}", metadata.metadata.height_of_longest_chain()))
                        } else {
                            None
                        };
                        table.add_row(row![
                            peer.node_id,
                            peer.public_key,
                            conn.address(),
                            conn.direction(),
                            format_duration_basic(conn.age()),
                            {
                                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(),
                            chain_height.unwrap_or_default(),
                        ]);
                    }
                    table.print_std();
                    println!("{} active connection(s)", num_connections);
                },
                Err(err) => {
                    println!("Failed to list connections: {:?}", err);
                    error!(target: LOG_TARGET, "Could not list connections: {:?}", err);
                },
            }
        });
    }
pub fn list_connections ( & self ) { let mut connectivity = self . connectivity . clone ( ) ; let peer_manager = self . peer_manager . clone ( ) ; self . executor . spawn ( async move { match connectivity . get_active_connections ( ) . await { Ok ( conns ) if conns . is_empty ( ) => { println ! ( " " ) ; } , Ok ( conns ) => { println ! ( ) ; let num_connections = conns . len ( ) ; let mut table = Table :: new ( ) ; table . set_titles ( vec ! [ " " " " " " " " " " " " " " " " ] ) ; for conn in conns { let peer = peer_manager . find_by_node_id ( conn . peer_node_id ( ) ) . await . expect ( " " ) ; let chain_height = if let Some ( metadata ) = peer . get_metadata ( 1 ) . and_then ( | v | bincode :: deserialize :: < PeerMetadata > ( v ) . ok ( ) ) { Some ( format ! ( " " metadata metadata height_of_longest_chain ( ) ) ) } else { None } ; table . add_row ( row ! [ peer node_id peer public_key conn address ( ) conn direction ( ) format_duration_basic ( conn age ( ) ) { if peer features PeerFeatures COMMUNICATION_CLIENT { " " } else { " " } } Some ( peer user_agent ) map ( ua if ua is_empty ( ) { " " to_string ( ) } else { ua } ) unwrap ( ) chain_height unwrap_or_default ( ) ] ) ; } table . print_std ( ) ; println ! ( " " num_connections ) ; } , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; } , } } ) ; }
Function to process the list-connections command
Function to process the list - connections command
&self