tuwunel_admin/query/resolver/
destinations_cache.rs1use futures::{StreamExt, TryStreamExt};
2use ruma::OwnedServerName;
3use tuwunel_core::{
4 Result,
5 utils::{stream::ReadyExt, time::format as format_time},
6};
7use tuwunel_service::resolver::cache::CachedDest;
8
9use crate::admin_command;
10
11#[admin_command]
12pub(super) async fn destinations_cache(&self, server_name: Option<OwnedServerName>) -> Result {
13 writeln!(self, "| Server Name | Destination | Hostname | Expires |").await?;
14 writeln!(self, "| ----------- | ----------- | -------- | ------- |").await?;
15
16 self.services
17 .resolver
18 .cache
19 .destinations()
20 .ready_filter(|(name, _)| {
21 server_name
22 .as_deref()
23 .is_none_or(|wanted| *name == wanted)
24 })
25 .map(|(name, CachedDest { dest, host, expire, .. })| {
26 let expire = format_time(expire, "%+");
27
28 Ok(format!("| {name} | {dest} | {host} | {expire} |\n"))
29 })
30 .try_for_each(async |row: String| self.write_str(&row).await)
31 .await
32}