Show known mesh names in traffic monitor endpoints
Index peer and VIP addresses from the agent status by network ID. Use the mesh DNS zone spelling in the IP flow columns, retain ports and show the numeric endpoint on hover or long press. A checkbox switches the display without changing capture keys, numeric sorting or stored history. Verified overlapping networks, external addresses, VIP withdrawal and the rendered checkbox and tooltip in the tsunagi-ui tests on macOS.
This commit is contained in:
1 parent
a1da4bf498
commit
21de427c62
5 files changed
+217
-19
No files matched your search
@@ -206,10 +206,15 @@ address/port pair and repeated ICMP echoes for an address pair into one row. Sel
|
|||||||
role to narrow it down. **Via exit node** shows your outgoing internet traffic.
|
role to narrow it down. **Via exit node** shows your outgoing internet traffic.
|
||||||
**Serving exit** shows traffic your device forwards for another peer.
|
**Serving exit** shows traffic your device forwards for another peer.
|
||||||
|
|
||||||
|
**Resolve names** shows known peers and VIPs by their network names in the
|
||||||
|
endpoint columns. Hover over a name, or press and hold on Android, to see the
|
||||||
|
IP address. Clear the checkbox to show all endpoints numerically.
|
||||||
|
|
||||||
**Transport** shows authenticated control sessions and encrypted datagrams
|
**Transport** shows authenticated control sessions and encrypted datagrams
|
||||||
forwarded between two other endpoints. For relay rows the arrows follow the
|
forwarded between two other endpoints. For relay rows the arrows follow the
|
||||||
two displayed endpoints in order. Rates update once per second. Select a row
|
two displayed endpoints in order. Rates update once per second. Use the
|
||||||
to see its packet counts. The monitor records header metadata and counters only.
|
**TX packets** and **RX packets** columns to see packet counts. The monitor
|
||||||
|
records header metadata and counters only.
|
||||||
|
|
||||||
Inactive rows expire after 60 seconds. **Keep until close** retains flows in a
|
Inactive rows expire after 60 seconds. **Keep until close** retains flows in a
|
||||||
private temporary table owned by the window. Closing it discards the table and
|
private temporary table owned by the window. Closing it discards the table and
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! Fields shared by the table, its column chooser and the history ordering.
|
//! Fields shared by the table, its column chooser and the history ordering.
|
||||||
use super::{Names, endpoints, role_name};
|
use super::{Names, endpoints, role_name};
|
||||||
use rusqlite::types::Value;
|
use rusqlite::types::Value;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
use tsunagi::traffic::{Flow, FlowKey, IpDetail};
|
use tsunagi::traffic::{Flow, FlowKey, IpDetail};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
@@ -86,21 +87,30 @@ impl Column {
|
|||||||
pub fn uses_names(self) -> bool {
|
pub fn uses_names(self) -> bool {
|
||||||
matches!(self, Self::Peer | Self::Network | Self::Near | Self::Far)
|
matches!(self, Self::Peer | Self::Network | Self::Near | Self::Far)
|
||||||
}
|
}
|
||||||
|
pub fn ip_endpoint(self, key: &FlowKey) -> Option<(Ipv4Addr, Option<u16>)> {
|
||||||
|
let Flow::Ip {
|
||||||
|
near, far, detail, ..
|
||||||
|
} = key.flow
|
||||||
|
else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
let ip = match self {
|
||||||
|
Self::Near => near,
|
||||||
|
Self::Far => far,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
let port = match detail {
|
||||||
|
IpDetail::Ports(a, b) => Some(if self == Self::Near { a } else { b }),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
Some((ip.into(), port))
|
||||||
|
}
|
||||||
// SQLite indexes this value only while sorting by a descriptive column.
|
// SQLite indexes this value only while sorting by a descriptive column.
|
||||||
// Numeric IPv4 address and port order is independent of their spelling.
|
// Numeric IPv4 address and port order is independent of their spelling.
|
||||||
pub fn label_key(self, key: &FlowKey, names: &Names) -> Value {
|
pub fn label_key(self, key: &FlowKey, names: &Names) -> Value {
|
||||||
if let Flow::Ip {
|
if let Some((ip, port)) = self.ip_endpoint(key) {
|
||||||
near, far, detail, ..
|
let port = port.map_or(0, |p| i64::from(p) + 1);
|
||||||
} = key.flow
|
return Value::Integer((i64::from(u32::from(ip)) << 17) + port);
|
||||||
&& matches!(self, Self::Near | Self::Far)
|
|
||||||
{
|
|
||||||
let near_side = self == Self::Near;
|
|
||||||
let ip = u32::from_be_bytes(if near_side { near } else { far });
|
|
||||||
let port = match detail {
|
|
||||||
IpDetail::Ports(a, b) => 1 + i64::from(if near_side { a } else { b }),
|
|
||||||
_ => 0,
|
|
||||||
};
|
|
||||||
return Value::Integer((i64::from(ip) << 17) + port);
|
|
||||||
}
|
}
|
||||||
let label = match self {
|
let label = match self {
|
||||||
Self::Peer => names.peer(&key.network, &key.peer),
|
Self::Peer => names.peer(&key.network, &key.peer),
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ use history::{Cursor, Filter};
|
|||||||
use std::{collections::BTreeMap, net::Ipv4Addr, path::PathBuf, sync::Arc, time::Duration};
|
use std::{collections::BTreeMap, net::Ipv4Addr, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use tsunagi::{
|
use tsunagi::{
|
||||||
NetworkId,
|
NetworkId,
|
||||||
ipc::StatusReport,
|
dns::ZoneName,
|
||||||
|
ipc::{NetworkReport, StatusReport},
|
||||||
iroh_types::EndpointId,
|
iroh_types::EndpointId,
|
||||||
traffic::{Flow, FlowKey, IpDetail, Role},
|
traffic::{Flow, FlowKey, IpDetail, Role},
|
||||||
};
|
};
|
||||||
@@ -31,6 +32,8 @@ struct Network {
|
|||||||
struct Names {
|
struct Names {
|
||||||
networks: BTreeMap<Id, Network>,
|
networks: BTreeMap<Id, Network>,
|
||||||
generation: Option<u64>,
|
generation: Option<u64>,
|
||||||
|
addresses: BTreeMap<(Id, Ipv4Addr), String>,
|
||||||
|
resolve_addresses: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn public_id(id: &Id) -> String {
|
fn public_id(id: &Id) -> String {
|
||||||
@@ -43,11 +46,13 @@ impl Names {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
self.generation = Some(generation);
|
self.generation = Some(generation);
|
||||||
|
self.addresses.clear();
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for n in &report.networks {
|
for n in &report.networks {
|
||||||
let Ok(id) = n.network_id.parse::<NetworkId>() else {
|
let Ok(id) = n.network_id.parse::<NetworkId>() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
self.index_addresses(*id.as_bytes(), n, &report.hostname);
|
||||||
let entry = self.networks.entry(*id.as_bytes()).or_default();
|
let entry = self.networks.entry(*id.as_bytes()).or_default();
|
||||||
if entry.name != n.name {
|
if entry.name != n.name {
|
||||||
entry.name.clone_from(&n.name);
|
entry.name.clone_from(&n.name);
|
||||||
@@ -97,6 +102,53 @@ impl Names {
|
|||||||
}
|
}
|
||||||
changed
|
changed
|
||||||
}
|
}
|
||||||
|
fn index_addresses(&mut self, id: Id, network: &NetworkReport, hostname: &str) {
|
||||||
|
let Ok(zone) = ZoneName::new(&network.name) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut add = |address: Option<Ipv4Addr>, name: Option<&str>| {
|
||||||
|
if let (Some(ip), Some(name)) = (
|
||||||
|
address,
|
||||||
|
name.map(|s| s.trim_matches('.')).filter(|s| !s.is_empty()),
|
||||||
|
) {
|
||||||
|
self.addresses
|
||||||
|
.entry((id, ip))
|
||||||
|
.or_insert_with(|| format!("{}.{}", name.to_ascii_lowercase(), zone.as_str()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if network.hostname_conflict.is_none()
|
||||||
|
&& let Some(own) = &network.overlay
|
||||||
|
{
|
||||||
|
add(
|
||||||
|
own.address.as_deref().and_then(|s| s.parse().ok()),
|
||||||
|
Some(hostname),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for member in &network.members {
|
||||||
|
if member.hostname_conflict.is_none() {
|
||||||
|
add(
|
||||||
|
member
|
||||||
|
.overlay_address_v4
|
||||||
|
.as_deref()
|
||||||
|
.and_then(|s| s.parse().ok()),
|
||||||
|
member.hostname.as_deref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for vip in &network.vips {
|
||||||
|
if vip.error.is_none() {
|
||||||
|
add(vip.address, Some(&vip.config.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn resolved_endpoint(&self, key: &FlowKey, column: Column) -> Option<String> {
|
||||||
|
let (ip, port) = column.ip_endpoint(key)?;
|
||||||
|
let name = self.addresses.get(&(key.network, ip))?;
|
||||||
|
Some(match port {
|
||||||
|
Some(port) => format!("{name}:{port}"),
|
||||||
|
None => name.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
fn network(&self, id: &Id) -> String {
|
fn network(&self, id: &Id) -> String {
|
||||||
let Some(n) = self.networks.get(id) else {
|
let Some(n) = self.networks.get(id) else {
|
||||||
return short(&NetworkId::from_bytes(*id).to_string());
|
return short(&NetworkId::from_bytes(*id).to_string());
|
||||||
@@ -207,7 +259,10 @@ impl Window {
|
|||||||
pub fn new(directory: Option<PathBuf>) -> Self {
|
pub fn new(directory: Option<PathBuf>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
worker: Worker::new(directory),
|
worker: Worker::new(directory),
|
||||||
names: Names::default(),
|
names: Names {
|
||||||
|
resolve_addresses: true,
|
||||||
|
..Names::default()
|
||||||
|
},
|
||||||
filter: Filter::default(),
|
filter: Filter::default(),
|
||||||
keep: false,
|
keep: false,
|
||||||
previous: Vec::new(),
|
previous: Vec::new(),
|
||||||
@@ -220,12 +275,16 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn controls(&mut self, ui: &mut Ui, grid: &table::Grid) {
|
fn controls(&mut self, ui: &mut Ui, grid: &table::Grid) {
|
||||||
if ui.available_width() < 540. {
|
if ui.available_width() < 620. {
|
||||||
ui.horizontal(|ui| self.layers(ui));
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
self.layers(ui);
|
||||||
|
self.resolve_option(ui);
|
||||||
|
});
|
||||||
ui.horizontal(|ui| self.history_controls(ui, grid));
|
ui.horizontal(|ui| self.history_controls(ui, grid));
|
||||||
} else {
|
} else {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
self.layers(ui);
|
self.layers(ui);
|
||||||
|
self.resolve_option(ui);
|
||||||
self.history_controls(ui, grid);
|
self.history_controls(ui, grid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -262,6 +321,15 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_option(&mut self, ui: &mut Ui) {
|
||||||
|
if !self.filter.transport {
|
||||||
|
widgets::hint(
|
||||||
|
ui.checkbox(&mut self.names.resolve_addresses, "Resolve names"),
|
||||||
|
"Show this network’s peer and VIP names. Hover or hold a name to see its IP address.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn history_controls(&mut self, ui: &mut Ui, grid: &table::Grid) {
|
fn history_controls(&mut self, ui: &mut Ui, grid: &table::Grid) {
|
||||||
widgets::hint(
|
widgets::hint(
|
||||||
ui.checkbox(&mut self.keep, "Keep until close"),
|
ui.checkbox(&mut self.keep, "Keep until close"),
|
||||||
|
|||||||
@@ -328,7 +328,19 @@ impl Grid {
|
|||||||
_ => &self.body,
|
_ => &self.body,
|
||||||
};
|
};
|
||||||
let bounds = slot.rect(row);
|
let bounds = slot.rect(row);
|
||||||
let response = cell(ui, bounds, &label, font, self.ink(col), numeric(col));
|
let resolved = if names.resolve_addresses {
|
||||||
|
names.resolved_endpoint(key, col)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let response = cell(
|
||||||
|
ui,
|
||||||
|
bounds,
|
||||||
|
resolved.as_deref().unwrap_or(&label),
|
||||||
|
font,
|
||||||
|
self.ink(col),
|
||||||
|
numeric(col),
|
||||||
|
);
|
||||||
if col == PeerId {
|
if col == PeerId {
|
||||||
let full = public_id(&key.peer);
|
let full = public_id(&key.peer);
|
||||||
let button = ui
|
let button = ui
|
||||||
@@ -344,6 +356,9 @@ impl Grid {
|
|||||||
if widgets::hint(button, &format!("Copy peer ID\n{full}")).clicked() {
|
if widgets::hint(button, &format!("Copy peer ID\n{full}")).clicked() {
|
||||||
ui.ctx().copy_text(full);
|
ui.ctx().copy_text(full);
|
||||||
}
|
}
|
||||||
|
} else if resolved.is_some() {
|
||||||
|
// A click sense also gives Android long presses a target.
|
||||||
|
widgets::hint(response.interact(Sense::click()), &label);
|
||||||
} else {
|
} else {
|
||||||
widgets::hint(response, &label);
|
widgets::hint(response, &label);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,6 +207,76 @@ fn a_stale_member_name_does_not_reindex_the_capture_every_refresh() {
|
|||||||
assert_eq!(names.peer(network.as_bytes(), peer.as_bytes()), "old");
|
assert_eq!(names.peer(network.as_bytes(), peer.as_bytes()), "old");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn endpoint_names_use_the_rows_network_and_current_peer_and_vip_records() {
|
||||||
|
use super::{Column, Names};
|
||||||
|
use tsunagi::ipc::{MemberReport, NetworkReport, OverlayReport, StatusReport};
|
||||||
|
use tsunagi::vip::{VipConfig, VipStatus};
|
||||||
|
|
||||||
|
let network = |id, name: &str, host: &str| NetworkReport {
|
||||||
|
network_id: tsunagi::NetworkId::from_bytes([id; 32]).to_string(),
|
||||||
|
name: name.into(),
|
||||||
|
members: vec![MemberReport {
|
||||||
|
hostname: Some(host.into()),
|
||||||
|
overlay_address_v4: Some("10.0.0.2".into()),
|
||||||
|
..Default::default()
|
||||||
|
}],
|
||||||
|
overlay: Some(OverlayReport {
|
||||||
|
address: Some("10.0.0.1".into()),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let mut report = StatusReport {
|
||||||
|
hostname: "laptop".into(),
|
||||||
|
networks: vec![network(1, "tsng", "music"), network(2, "vpn", "home")],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
report.networks[0].vips.push(VipStatus {
|
||||||
|
config: VipConfig::new("radio"),
|
||||||
|
revision: String::new(),
|
||||||
|
address: Some("10.0.0.3".parse().unwrap()),
|
||||||
|
error: None,
|
||||||
|
listeners: vec![],
|
||||||
|
});
|
||||||
|
let mut names = Names::default();
|
||||||
|
names.refresh(Some(&report), 1);
|
||||||
|
let mut key = sample(55201, true).key;
|
||||||
|
assert_eq!(
|
||||||
|
names.resolved_endpoint(&key, Column::Near).as_deref(),
|
||||||
|
Some("laptop.tsng:55201")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
names.resolved_endpoint(&key, Column::Far).as_deref(),
|
||||||
|
Some("music.tsng:443")
|
||||||
|
);
|
||||||
|
key.network = [2; 32];
|
||||||
|
assert_eq!(
|
||||||
|
names.resolved_endpoint(&key, Column::Far).as_deref(),
|
||||||
|
Some("home.vpn:443")
|
||||||
|
);
|
||||||
|
key.network = [1; 32];
|
||||||
|
key.flow = Flow::Ip {
|
||||||
|
near: [10, 0, 0, 3],
|
||||||
|
far: [1, 1, 1, 1],
|
||||||
|
protocol: 1,
|
||||||
|
detail: IpDetail::Echo,
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
names.resolved_endpoint(&key, Column::Near).as_deref(),
|
||||||
|
Some("radio.tsng")
|
||||||
|
);
|
||||||
|
assert_eq!(names.resolved_endpoint(&key, Column::Far), None);
|
||||||
|
report.networks[0].vips[0].error = Some("address conflict".into());
|
||||||
|
report.networks[0].members.clear();
|
||||||
|
names.refresh(Some(&report), 2);
|
||||||
|
assert_eq!(names.resolved_endpoint(&key, Column::Near), None);
|
||||||
|
assert_eq!(
|
||||||
|
names.resolved_endpoint(&sample(1, true).key, Column::Far),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sorting_uses_display_names_numeric_endpoints_and_live_rates() {
|
fn sorting_uses_display_names_numeric_endpoints_and_live_rates() {
|
||||||
use super::{Column, Names, Network, Sort};
|
use super::{Column, Names, Network, Sort};
|
||||||
@@ -280,7 +350,14 @@ fn monitor_rows_stay_on_one_line_and_headers_sort_in_both_themes() {
|
|||||||
let ctx = Context::default();
|
let ctx = Context::default();
|
||||||
ctx.set_theme(theme);
|
ctx.set_theme(theme);
|
||||||
ctx.set_fonts(crate::app_fonts());
|
ctx.set_fonts(crate::app_fonts());
|
||||||
|
ctx.style_mut(|s| {
|
||||||
|
s.interaction.tooltip_delay = 0.;
|
||||||
|
s.interaction.show_tooltips_only_when_still = false;
|
||||||
|
});
|
||||||
let mut win = Window::new(None);
|
let mut win = Window::new(None);
|
||||||
|
win.names
|
||||||
|
.addresses
|
||||||
|
.insert(([1; 32], [10, 0, 0, 2].into()), "music.lab".into());
|
||||||
win.names.networks.insert(
|
win.names.networks.insert(
|
||||||
[1; 32],
|
[1; 32],
|
||||||
Network {
|
Network {
|
||||||
@@ -366,6 +443,29 @@ fn monitor_rows_stay_on_one_line_and_headers_sort_in_both_themes() {
|
|||||||
wait(win);
|
wait(win);
|
||||||
};
|
};
|
||||||
let mut frame = draw(&mut win, vec![]);
|
let mut frame = draw(&mut win, vec![]);
|
||||||
|
let checkbox = label(&frame, "Resolve names").0.center();
|
||||||
|
if width > 900. {
|
||||||
|
let name = label(&frame, "music.lab:443").0.center();
|
||||||
|
draw(&mut win, vec![Event::PointerMoved(name)]);
|
||||||
|
frame = draw(&mut win, vec![]);
|
||||||
|
assert!(
|
||||||
|
frame.shapes.iter().any(
|
||||||
|
|s| matches!(&s.shape, Shape::Text(t) if t.galley.text() == "10.0.0.2:443")
|
||||||
|
),
|
||||||
|
"hovering a resolved name reveals the numeric endpoint"
|
||||||
|
);
|
||||||
|
click(&mut win, checkbox);
|
||||||
|
frame = draw(&mut win, vec![]);
|
||||||
|
label(&frame, "10.0.0.2:443");
|
||||||
|
assert!(
|
||||||
|
!frame.shapes.iter().any(
|
||||||
|
|s| matches!(&s.shape, Shape::Text(t) if t.galley.text() == "music.lab:443")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
click(&mut win, checkbox);
|
||||||
|
frame = draw(&mut win, vec![]);
|
||||||
|
label(&frame, "music.lab:443");
|
||||||
|
}
|
||||||
let chooser = frame
|
let chooser = frame
|
||||||
.shapes
|
.shapes
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in new issue
Block a user