diff --git a/mycelium-cli/src/lib.rs b/mycelium-cli/src/lib.rs index 7ee011d..983ef30 100644 --- a/mycelium-cli/src/lib.rs +++ b/mycelium-cli/src/lib.rs @@ -8,4 +8,6 @@ pub use inspect::inspect; #[cfg(feature = "message")] pub use message::{recv_msg, send_msg}; pub use peer::{add_peers, list_peers, remove_peers}; -pub use routes::{list_fallback_routes, list_queried_subnets, list_selected_routes}; +pub use routes::{ + list_fallback_routes, list_no_route_entries, list_queried_subnets, list_selected_routes, +}; diff --git a/mycelium-cli/src/routes.rs b/mycelium-cli/src/routes.rs index c38e2db..37c8d48 100644 --- a/mycelium-cli/src/routes.rs +++ b/mycelium-cli/src/routes.rs @@ -1,4 +1,4 @@ -use mycelium_api::{QueriedSubnet, Route}; +use mycelium_api::{NoRouteSubnet, QueriedSubnet, Route}; use prettytable::{row, Table}; use std::net::SocketAddr; @@ -116,3 +116,37 @@ pub async fn list_queried_subnets( } Ok(()) } + +pub async fn list_no_route_entries( + server_addr: SocketAddr, + json_print: bool, +) -> Result<(), Box> { + let request_url = format!("http://{server_addr}/api/v1/admin/routes/no_route"); + match reqwest::get(&request_url).await { + Err(e) => { + error!("Failed to retrieve subnets with no route entries"); + return Err(e.into()); + } + Ok(resp) => { + debug!("Listing no route entries"); + + if json_print { + // API call returns routes in JSON format by default + let nrs = resp.text().await?; + println!("{nrs}"); + } else { + // Print routes in table format + let no_routes: Vec = resp.json().await?; + let mut table = Table::new(); + table.add_row(row!["Subnet", "Entry expiration"]); + + for nrs in no_routes.iter() { + table.add_row(row![nrs.subnet, nrs.expiration,]); + } + + table.printstd(); + } + } + } + Ok(()) +} diff --git a/myceliumd/src/main.rs b/myceliumd/src/main.rs index 978ba6e..3f361d0 100644 --- a/myceliumd/src/main.rs +++ b/myceliumd/src/main.rs @@ -130,7 +130,7 @@ pub enum Command { command: PeersCommand, }, - /// Actions related to routes (selected, fallback) + /// Actions related to routes (selected, fallback, queried, no route) Routes { #[command(subcommand)] command: RoutesCommand, @@ -214,6 +214,12 @@ pub enum RoutesCommand { #[arg(long = "json", default_value_t = false)] json: bool, }, + /// Print all subnets which are explicitly marked as not having a route + NoRoute { + /// Print subnets in JSON format + #[arg(long = "json", default_value_t = false)] + json: bool, + }, } #[derive(Debug, Args)] @@ -575,6 +581,9 @@ async fn main() -> Result<(), Box> { RoutesCommand::Queried { json } => { return mycelium_cli::list_queried_subnets(cli.node_args.api_addr, json).await; } + RoutesCommand::NoRoute { json } => { + return mycelium_cli::list_no_route_entries(cli.node_args.api_addr, json).await; + } }, }, }