Add CLI functionality to check queried routes

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2025-04-02 14:33:21 +02:00
parent 15472959bd
commit 95a9da6ebd
2 changed files with 36 additions and 2 deletions
+1 -1
View File
@@ -8,4 +8,4 @@ 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_selected_routes};
pub use routes::{list_fallback_routes, list_queried_subnets, list_selected_routes};
+35 -1
View File
@@ -1,4 +1,4 @@
use mycelium_api::Route;
use mycelium_api::{QueriedSubnet, Route};
use prettytable::{row, Table};
use std::net::SocketAddr;
@@ -82,3 +82,37 @@ pub async fn list_fallback_routes(
}
Ok(())
}
pub async fn list_queried_subnets(
server_addr: SocketAddr,
json_print: bool,
) -> Result<(), Box<dyn std::error::Error>> {
let request_url = format!("http://{server_addr}/api/v1/admin/routes/queried");
match reqwest::get(&request_url).await {
Err(e) => {
error!("Failed to retrieve queried subnets");
return Err(e.into());
}
Ok(resp) => {
debug!("Listing queried routes");
if json_print {
// API call returns routes in JSON format by default
let queried_routes = resp.text().await?;
println!("{queried_routes}");
} else {
// Print routes in table format
let queries: Vec<QueriedSubnet> = resp.json().await?;
let mut table = Table::new();
table.add_row(row!["Subnet", "Query expiration"]);
for query in queries.iter() {
table.add_row(row![query.subnet, query.expiration,]);
}
table.printstd();
}
}
}
Ok(())
}