Fold network cards and show which peer carries exit traffic

Start the tray and Android overviews with each network folded under its
bold name. Keep the selected exit, its host name and its sent and received
byte totals visible. Put VIP beside Copy secret and Show devices.

Default to bytes and make the unit switch update the desktop traffic
column, totals, rates and plots together. Open the devices window at
1000 points wide and bound the network and per-peer plots. Use both sides
of the phone detail view for transport, latency, version and traffic.

Attach counters to the current network and exit peer. Count off-mesh IP
bytes after carrier acceptance and replies after local interface delivery.
Changing the selection starts new totals. Ordinary mesh traffic to the
same peer and rejected packets stay out of the exit counters.

Advertise the agent release as an optional bounded trailer on an
authenticated control v8 announcement. Older readers can ignore it and
older peers display an unknown version. Release labels live for the
session and do not participate in authentication or wire negotiation.
The new status fields require local IPC v25, so update the daemon, CLI
and tray together. Existing mesh identities and databases need no migration.

On Android, request system interface consent on the first app launch.
Respect an explicit stop or declined consent across launches. Start
Tsunagi Agent re-enables automatic startup.

Checked formatting and strict workspace Clippy on macOS arm64. The full
locked workspace suite passed 588 tests with four opt-in tests ignored.
Built the tray and Android debug APKs. Both instrumentation tests passed
on an Android 37 arm64 emulator, including app startup, stop and restart.
Checked the first-run permission prompt and the rendered phone and desktop
layouts. Native Linux and Windows tests were not run on this host.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-25 14:33:50 +02:00
1 parent f9f67f88b1
commit 8c4c2fa34e
39 files changed
+1144 -412

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
Source Sans Pro Bold
Copyright 2010, 2012, 2014 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name ‘Source’.
This Font Software is licensed under the SIL Open Font License,
Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font
creation efforts of academic and linguistic communities, and to
provide a free and open framework in which fonts may be shared and
improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply to
any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software
components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to,
deleting, or substituting -- in part or in whole -- any of the
components of the Original Version, by changing formats or by porting
the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed,
modify, redistribute, and sell modified and unmodified copies of the
Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in
Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the
corresponding Copyright Holder. This restriction only applies to the
primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created using
the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
+1 -1
View File
@@ -141,7 +141,7 @@ fn agent_table(ui: &mut egui::Ui, socket: Option<&str>, report: &StatusReport) {
ui.label(if socket.is_some() {
"can be managed (CAP_NET_ADMIN)"
} else {
"Android VPN service"
"Android foreground service"
});
}
PrivilegeReport::Missing(_) => {
+199 -121
View File
@@ -44,6 +44,7 @@ struct Device<'a> {
name_taken: Option<(&'a str, String)>,
/// The last hostname seen for it, kept while it is offline.
hostname: Option<&'a str>,
agent_version: Option<&'a str>,
/// What clicking the hostname copies: `hostname.network`, so it resolves.
copy: Option<String>,
/// The full endpoint id, which clicking the short form copies.
@@ -104,6 +105,11 @@ impl Device<'_> {
fn sort_key(&self) -> String {
self.hostname.unwrap_or(self.id).to_lowercase()
}
fn version_label(&self) -> String {
self.agent_version
.map_or_else(|| "v?".into(), |v| format!("v{}", format::short(v)))
}
}
/// The first characters of an endpoint id, enough to tell devices apart.
@@ -122,6 +128,11 @@ fn name_cell(ui: &mut egui::Ui, device: &Device<'_>) {
}
_ => format::copy_field(ui, &short_id(device.id), device.id),
}
ui.label(egui::RichText::new(device.version_label()).small().weak())
.on_hover_text(format!(
"Tsunagi {}",
device.agent_version.unwrap_or("version unknown")
));
if let Some((name, holder)) = &device.name_taken {
ui.label(egui::RichText::new(egui_phosphor::regular::WARNING).color(AMBER))
.on_hover_text(format!(
@@ -170,23 +181,23 @@ pub fn show(
});
return;
}
summary(ui, network);
ui.add_space(6.0);
ui.label(egui::RichText::new("traffic").strong());
format::sparkline(ui, traffic.network(&network.network_id), unit, 48.0);
ui.add_space(8.0);
let devices = devices(network, own_id);
let online = devices.iter().filter(|d| d.online).count();
ui.label(
egui::RichText::new(format!(
"devices ({} online / {} known)",
online,
ui.columns(2, |columns| {
columns[0].strong(format!(
"devices ({online} online / {} known)",
devices.len()
))
.strong(),
);
));
columns[0].collapsing("Network details", |ui| summary(ui, network));
let plot = &mut columns[1];
plot.label("Network traffic");
let width = plot.available_width().min(440.0);
plot.scope(|ui| {
ui.set_max_width(width);
format::sparkline(ui, traffic.network(&network.network_id), unit, 48.0);
});
});
ui.add_space(8.0);
egui::ScrollArea::both()
.auto_shrink([false, false])
.show(ui, |ui| {
@@ -335,7 +346,9 @@ fn summary(ui: &mut egui::Ui, network: &NetworkReport) {
.spacing([12.0, 3.0])
.show(ui, |ui| {
ui.weak("id");
let id = if ui.ctx().os() == egui::os::OperatingSystem::Android {
let id = if ui.ctx().os() == egui::os::OperatingSystem::Android
|| ui.available_width() < 440.0
{
format::short(&network.network_id)
} else {
network.network_id.clone()
@@ -460,6 +473,7 @@ fn devices<'a>(network: &'a NetworkReport, own_id: &str) -> Vec<Device<'a>> {
via_name,
name_taken,
hostname,
agent_version: peer.and_then(|p| p.agent_version.as_deref()),
copy: hostname.map(|h| format!("{h}.{}", network.name)),
id,
data_error: peer.and_then(|p| p.data_error.as_deref()),
@@ -484,44 +498,55 @@ fn devices<'a>(network: &'a NetworkReport, own_id: &str) -> Vec<Device<'a>> {
devices
}
const COLUMN_HEADERS: [&str; 10] = [
"device",
"exit",
"data",
"RTT data / control",
"address",
"data path",
"pkts",
"bytes",
"rate",
"plot",
];
fn column_headers(unit: Unit) -> [&'static str; 9] {
[
"device",
"exit",
"data",
"RTT data / control",
"address",
"data path",
match unit {
Unit::Bytes => "bytes (TX / RX)",
Unit::Packets => "pkts (TX / RX)",
},
"rate",
"plot",
]
}
/// Initial column floors; actual headers, values and totals can grow them.
const COLUMN_SAMPLES: [&str; 10] = [
const COLUMN_SAMPLES: [&str; 9] = [
"device",
"exit",
"data",
"9999 ms",
"255.255.255.255",
"data path",
"99999/99999",
"1023.9 MB / 1023.9 MB",
"1023.9 kB/s",
"plot",
];
fn traffic_pair(tx: u64, rx: u64, unit: Unit) -> String {
format!(
"{} / {}",
format::amount(tx, unit),
format::amount(rx, unit)
)
}
/// Column widths that only ever grow, kept across frames.
///
/// Live values can change width between frames. A value that
/// gets shorter — `14.4 MB/s` giving way to `382 pkt/s` — would pull the
/// column in and push every cell after it. Remembering the widest seen keeps
/// the table where it is.
fn column_widths(ui: &egui::Ui, id: egui::Id) -> [f32; 10] {
let stored: Option<[f32; 10]> = ui.memory(|m| m.data.get_temp(id));
fn column_widths(ui: &egui::Ui, id: egui::Id) -> [f32; 9] {
let stored: Option<[f32; 9]> = ui.memory(|m| m.data.get_temp(id));
stored.unwrap_or_else(|| {
let font = egui::FontSelection::Default.resolve(ui.style());
let mut widths = [0.0; 10];
let mut widths = [0.0; 9];
for (width, sample) in widths.iter_mut().zip(COLUMN_SAMPLES) {
if !sample.is_empty() {
*width = ui.fonts(|fonts| {
@@ -536,10 +561,9 @@ fn column_widths(ui: &egui::Ui, id: egui::Id) -> [f32; 10] {
})
}
fn stretch_columns(mut widths: [f32; 10], available: f32) -> [f32; 10] {
let gaps = 10.0 * (widths.len() - 1) as f32;
widths[9] = widths[9].max(100.0);
widths[9] += (available - gaps - widths.iter().sum::<f32>()).max(0.0);
fn stretch_columns(mut widths: [f32; 9], available: f32) -> [f32; 9] {
let gaps = crate::table::GAP * (widths.len() - 1) as f32;
widths[8] = (available - gaps - widths[..8].iter().sum::<f32>()).clamp(100.0, 180.0);
widths
}
@@ -618,16 +642,17 @@ fn device_table(
.x
})
};
for (column, header) in COLUMN_HEADERS.into_iter().enumerate() {
widths[column] = widths[column].max(measure(header.to_owned()));
let headers = column_headers(unit);
for (column, header) in headers.iter().enumerate() {
widths[column] = widths[column].max(measure((*header).to_owned()));
}
let (mut tx_packets, mut rx_packets, mut tx_bytes, mut rx_bytes): (u64, u64, u64, u64) =
(0, 0, 0, 0);
let (mut tx_total, mut rx_total) = (0_u64, 0_u64);
for device in devices {
let name = format!(
"{} ({}){}",
"{} ({}) {}{}",
device.name(),
short_id(device.id),
device.version_label(),
if !device.online { " Forget" } else { "" }
);
widths[0] = widths[0].max(measure(name) + 24.0);
@@ -641,59 +666,36 @@ fn device_table(
widths[column] = widths[column].max(measure(text));
}
if let Some(peer) = device.overlay {
tx_packets = tx_packets.saturating_add(peer.tx_packets);
rx_packets = rx_packets.saturating_add(peer.rx_packets);
tx_bytes = tx_bytes.saturating_add(peer.tx_bytes);
rx_bytes = rx_bytes.saturating_add(peer.rx_bytes);
for (column, text) in [
(6, format!("{}/{}", peer.tx_packets, peer.rx_packets)),
(
7,
format!(
"{} / {}",
format::bytes(peer.tx_bytes as f64),
format::bytes(peer.rx_bytes as f64)
),
),
(
8,
format::series_rate(traffic.peer(network_id, &peer.public_key), unit),
),
] {
widths[column] = widths[column].max(measure(text));
}
let (tx, rx) = unit.counters(peer);
tx_total = tx_total.saturating_add(tx);
rx_total = rx_total.saturating_add(rx);
widths[6] = widths[6].max(measure(traffic_pair(tx, rx, unit)));
widths[7] = widths[7].max(measure(format::series_rate(
traffic.peer(network_id, &peer.public_key),
unit,
)));
}
}
for (column, text) in [
(6, format!("{tx_packets}/{rx_packets}")),
(
7,
format!(
"{} / {}",
format::bytes(tx_bytes as f64),
format::bytes(rx_bytes as f64)
),
),
(8, format::series_rate(traffic.network(network_id), unit)),
] {
widths[column] = widths[column].max(measure(text));
}
let total = traffic_pair(tx_total, rx_total, unit);
let rate = format::series_rate(traffic.network(network_id), unit);
widths[6] = widths[6].max(measure(total.clone()));
widths[7] = widths[7].max(measure(rate.clone()));
if widths != previous_widths {
ui.ctx().request_repaint();
}
ui.memory_mut(|m| m.data.insert_temp(widths_id, widths));
let widths = stretch_columns(widths, ui.available_width());
crate::table::row(ui, "device headers", &widths, false, |column, ui| {
let response = ui.weak(COLUMN_HEADERS[column]);
let response = ui.weak(headers[column]);
match column {
2 => {
response.on_hover_text("Encrypted data channel readiness.");
}
3 => {
response.on_hover_text("Control-connection round-trip time.");
response.on_hover_text("Data-link and control-connection round-trip times.");
}
7 => {
response.on_hover_text("Plaintext IP bytes accepted by the encrypted channel in this counter lifetime; excludes relay transit, transport overhead and delivery probes.");
6 => {
response.on_hover_text("Sent / received IP traffic in the selected unit. Excludes relay transit and transport overhead.");
}
5 => {
response.on_hover_text("External data transport or relay route.");
@@ -731,16 +733,10 @@ fn device_table(
let series = traffic.peer(network_id, &peer.public_key);
match column {
6 => {
ui.label(format!("{}/{}", peer.tx_packets, peer.rx_packets));
let (tx, rx) = unit.counters(peer);
ui.label(traffic_pair(tx, rx, unit));
}
7 => {
ui.label(format!(
"{} / {}",
format::bytes(peer.tx_bytes as f64),
format::bytes(peer.rx_bytes as f64)
));
}
8 => {
ui.label(format::series_rate(series, unit));
}
_ => format::sparkline(ui, series, unit, 24.0),
@@ -762,17 +758,10 @@ fn device_table(
ui.strong("total");
}
6 => {
ui.strong(format!("{tx_packets}/{rx_packets}"));
ui.strong(&total);
}
7 => {
ui.strong(format!(
"{} / {}",
format::bytes(tx_bytes as f64),
format::bytes(rx_bytes as f64)
));
}
8 => {
ui.strong(format::series_rate(traffic.network(network_id), unit));
ui.strong(&rate);
}
_ => {}
},
@@ -903,17 +892,18 @@ mod tests {
}
}
struct ReadOnly;
impl Client for ReadOnly {
fn send(&self, _: Command) {
panic!("reading the devices view issued an action");
}
fn busy(&self) -> bool {
false
}
}
#[test]
fn phone_roster_fits_each_width_and_expands_only_the_tapped_member() {
struct ReadOnly;
impl Client for ReadOnly {
fn send(&self, _: Command) {
panic!("reading a row issued an action");
}
fn busy(&self) -> bool {
false
}
}
let mut network = NetworkReport {
network_id: "a".repeat(60),
name: "lab".into(),
@@ -933,9 +923,24 @@ mod tests {
m.overlay_address_v4 = Some(format!("192.168.254.{}", 240 + i));
network.members.push(m);
}
network.peers.push(tsunagi::ipc::PeerReport {
endpoint_id: "alpha".into(),
agent_version: Some("2.0.0-rc.1".into()),
..Default::default()
});
network.overlay = Some(tsunagi::ipc::OverlayReport {
peers: vec![OverlayPeerReport {
endpoint_id: "alpha".into(),
tx_bytes: 1024,
rx_bytes: 512,
..Default::default()
}],
..Default::default()
});
for width in [320.0, 360.0, 430.0, 870.0] {
let ctx = egui::Context::default();
ctx.set_os(egui::os::OperatingSystem::Android);
ctx.set_fonts(crate::app_fonts());
let frame = |events| {
ctx.run(
egui::RawInput {
@@ -950,7 +955,7 @@ mod tests {
show(
ctx,
&ReadOnly,
&mut Unit::Packets,
&mut Unit::Bytes,
(&mut None, &mut None),
&network,
"self",
@@ -999,8 +1004,22 @@ mod tests {
};
let expanded = click(a);
assert_eq!(positions(&expanded, "Endpoint ID").len(), 1);
assert_eq!(positions(&expanded, "2.0.0-rc.1").len(), 1);
let up = positions(&expanded, "1.0 kB")[0];
let down = positions(&expanded, "512 B")[0];
assert!(down.x - up.x > width * 0.25 && (up.y - down.y).abs() < 2.0);
for (arrow, caption, value) in [
(icon::ARROW_UP, "Sent", up),
(icon::ARROW_DOWN, "Received", down),
] {
let arrow = positions(&expanded, arrow)[0];
let caption = positions(&expanded, caption)[0];
assert!(arrow.x < caption.x && arrow.y < value.y);
assert!((arrow.x - value.x).abs() < 35.0);
}
let switched = click(positions(&expanded, "bravo")[0]);
assert_eq!(positions(&switched, "Endpoint ID").len(), 1);
assert_eq!(positions(&switched, "Unknown").len(), 1);
let closed = click(positions(&switched, "bravo")[0]);
assert!(positions(&closed, "Endpoint ID").is_empty());
}
@@ -1133,11 +1152,11 @@ mod tests {
}
#[test]
fn resized_table_fills_the_window_without_growing_fixed_columns() {
let minimum = [100.0; 10];
fn wider_windows_keep_a_compact_plot_and_narrow_windows_preserve_column_floors() {
let minimum = [100.0; 9];
let wide = stretch_columns(minimum, 1440.0);
assert!((wide.iter().sum::<f32>() + 90.0 - 1440.0).abs() < 0.1);
assert_eq!(&wide[..9], &minimum[..9]);
assert!((100.0..=190.0).contains(&wide[8]));
assert_eq!(&wide[..8], &minimum[..8]);
let narrow = stretch_columns(minimum, 800.0);
assert_eq!(
narrow, minimum,
@@ -1148,6 +1167,39 @@ mod tests {
wide,
"a resize does not accumulate padding"
);
let ctx = egui::Context::default();
for window_width in [800.0, 1000.0, 1440.0] {
let frame = ctx.run(
egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(
egui::Pos2::ZERO,
egui::vec2(window_width, 640.0),
)),
..Default::default()
},
|ctx| {
show(
ctx,
&ReadOnly,
&mut Unit::Bytes,
(&mut None, &mut None),
&NetworkReport::default(),
"self",
&Traffic::default(),
);
},
);
let chart = frame
.shapes
.iter()
.find_map(|s| match &s.shape {
egui::Shape::Rect(r) if r.rect.height() == 48.0 => Some(r.rect),
_ => None,
})
.expect("network traffic chart");
assert!((300.0..=440.0).contains(&chart.width()), "{chart:?}");
}
}
#[test]
@@ -1168,18 +1220,19 @@ mod tests {
}
let context = egui::Context::default();
for (width, packets, age) in [
(1600.0, 1569, 56),
(1600.0, 55_555, 172_800),
(1600.0, 137_245, 172_800),
(900.0, 9_876_543_210, 172_800),
(1600.0, 42, 56),
for (width, packets, age, unit) in [
(1600.0, 1569, 56, crate::home::UiState::default().unit),
(1600.0, 55_555, 172_800, Unit::Packets),
(1600.0, 137_245, 172_800, Unit::Bytes),
(900.0, 9_876_543_210, 172_800, Unit::Packets),
(1600.0, 42, 56, Unit::Bytes),
] {
let network = NetworkReport {
network_id: "network".into(),
peers: ["peer", "other"]
.into_iter()
.map(|id| PeerReport {
agent_version: (id == "peer").then(|| "2.0.0-rc.1".into()),
data_error: None,
endpoint_id: id.into(),
rtt_ms: Some(12_345),
@@ -1220,7 +1273,7 @@ mod tests {
ui.allocate_ui(egui::vec2(width, 480.0), |ui| {
device_table(
ui,
Unit::Packets,
unit,
&network,
&rows,
&Traffic::default(),
@@ -1234,11 +1287,36 @@ mod tests {
let shapes: Vec<_> = output.shapes.into_iter().map(|s| s.shape).collect();
let mut texts = Vec::new();
collect_text(&shapes, &mut texts);
let visible = |value: &str| texts.iter().any(|t| t.galley.text() == value);
assert!(visible("v2.0.0-rc.1"));
assert!(visible("v?"));
let packet_counts = format!("{packets} / {}", packets + 1);
let byte_counts = "117.7 MB / 941.9 MB";
if packets == 1569 {
assert!(visible("bytes (TX / RX)"));
assert!(visible(byte_counts));
}
assert_eq!(visible(&packet_counts), unit == Unit::Packets);
assert_eq!(visible(byte_counts), unit == Unit::Bytes);
for (label, next_column) in [
("RTT data / control".to_string(), "address"),
(rtt_pair(&rows[0]), "address"),
(format!("{packets}/{}", packets + 1), "bytes"),
(format!("{}/{}", packets * 2, (packets + 1) * 2), "bytes"),
(
if unit == Unit::Packets {
packet_counts
} else {
byte_counts.into()
},
"rate",
),
(
if unit == Unit::Packets {
format!("{} / {}", packets * 2, (packets + 1) * 2)
} else {
"235.5 MB / 1.8 GB".into()
},
"rate",
),
] {
let right = texts
.iter()
@@ -1403,7 +1481,7 @@ mod tests {
&mut None,
&mut None,
);
let stored: [f32; 10] = ui
let stored: [f32; 9] = ui
.memory(|memory| {
memory
.data
+97 -69
View File
@@ -130,74 +130,102 @@ fn details(
exit: &mut Option<ExitConfirm>,
forget: &mut Option<ForgetConfirm>,
) {
ui.horizontal_wrapped(|ui| {
ui.weak(if member.online { "online" } else { "offline" });
if let Some(name) = &member.copy {
format::copy_field(ui, &member.name(), name);
}
if let Some(address) = &member.address {
format::copy_field(ui, address, address);
}
});
ui.horizontal_wrapped(|ui| {
ui.weak("Endpoint ID");
format::copy_field(ui, &format::short(member.id), member.id);
});
let (path, _) = data_path_text(member.path, member.via_name.as_deref(), member.online);
ui.horizontal_wrapped(|ui| {
ui.label(path);
tunnel_cell(ui, member);
});
if member.online {
if let Some(path) = member.data_transport_detail {
ui.label(path);
}
ui.label(format!(
"Data RTT {} · Control RTT {}",
rtt_text(member.data_rtt_ms),
rtt_text(member.control_rtt_ms)
));
}
if let Some(error) = member.data_error {
ui.colored_label(AMBER, error);
}
if let Some((taken, holder)) = &member.name_taken {
ui.colored_label(AMBER, format!("Name {taken} belongs to {holder}."));
}
if let Some(peer) = member.overlay {
let series = traffic.peer(&network.network_id, &peer.public_key);
ui.horizontal_wrapped(|ui| {
ui.label(format!(
"TX {} · {} pkts",
format::bytes(peer.tx_bytes as f64),
peer.tx_packets
));
ui.label(format!(
"RX {} · {} pkts",
format::bytes(peer.rx_bytes as f64),
peer.rx_packets
));
ui.weak(format::series_rate(series, unit));
egui::Frame::new()
.fill(ui.visuals().faint_bg_color)
.inner_margin(egui::Margin::symmetric(10, 8))
.show(ui, |ui| {
ui.set_min_width(ui.available_width());
ui.spacing_mut().item_spacing.y = 4.0;
ui.columns(2, |cols| {
cols[0].small("Data path");
let (path, _) =
data_path_text(member.path, member.via_name.as_deref(), member.online);
cols[0].horizontal_wrapped(|ui| {
ui.label(path);
if member.online {
tunnel_cell(ui, member);
}
});
cols[1].small("Tsunagi version");
cols[1].label(member.agent_version.unwrap_or("Unknown"));
});
if let Some(path) = member.data_transport_detail {
ui.add(egui::Label::new(path).wrap());
}
if member.online {
ui.columns(2, |cols| {
cols[0].small("Data RTT");
cols[0].label(rtt_text(member.data_rtt_ms));
cols[1].small("Control RTT");
cols[1].label(rtt_text(member.control_rtt_ms));
});
}
if let Some(peer) = member.overlay.filter(|_| member.online) {
ui.separator();
let (tx, rx) = unit.counters(peer);
let sent_color = ui.visuals().hyperlink_color;
ui.columns(2, |cols| {
for (col, arrow, caption, count, color) in [
(0, icon::ARROW_UP, "Sent", tx, sent_color),
(1, icon::ARROW_DOWN, "Received", rx, exit::GOOD),
] {
cols[col].horizontal(|ui| {
ui.colored_label(color, arrow);
ui.label(caption);
});
let value = format::amount(count, unit);
let value = match unit {
Unit::Packets => format!("{value} pkts"),
Unit::Bytes => value,
};
let size = cols[col].text_style_height(&egui::TextStyle::Body) + 2.0;
cols[col].label(egui::RichText::new(value).size(size).strong());
}
});
format::sparkline(
ui,
traffic.peer(&network.network_id, &peer.public_key),
unit,
28.0,
);
}
ui.separator();
ui.columns(2, |cols| {
cols[0].small("Endpoint ID");
format::copy_field(&mut cols[0], &format::short(member.id), member.id);
cols[1].small("IPv4");
if let Some(address) = &member.address {
format::copy_field(&mut cols[1], address, address);
} else {
cols[1].weak("—");
}
});
if let Some(name) = &member.copy {
format::copy_field(ui, name, name);
}
if let Some(error) = member.data_error {
ui.colored_label(AMBER, error);
}
if let Some((taken, holder)) = &member.name_taken {
ui.colored_label(AMBER, format!("Name {taken} belongs to {holder}."));
}
if (member.exit_node || member.in_use)
&& ui
.button(if member.in_use {
"Stop using exit node"
} else {
"Use exit node"
})
.clicked()
{
*exit = Some(ExitConfirm {
network_id: network.network_id.clone(),
peer_id: member.id.into(),
name: member.name(),
stop: member.in_use,
main: false,
});
}
forget_button(ui, member, network, forget);
});
format::sparkline(ui, series, unit, 22.);
}
if (member.exit_node || member.in_use)
&& ui
.button(if member.in_use {
"Stop using exit node"
} else {
"Use exit node"
})
.clicked()
{
*exit = Some(ExitConfirm {
network_id: network.network_id.clone(),
peer_id: member.id.into(),
name: member.name(),
stop: member.in_use,
main: false,
});
}
forget_button(ui, member, network, forget);
ui.separator();
}
+8
View File
@@ -38,6 +38,14 @@ pub fn bytes(n: f64) -> String {
}
}
/// A cumulative amount in the selected unit.
pub(crate) fn amount(value: u64, unit: Unit) -> String {
match unit {
Unit::Bytes => bytes(value as f64),
Unit::Packets => value.to_string(),
}
}
/// A rate in the chosen unit, per second.
pub fn rate(value: f32, unit: Unit) -> String {
match unit {
+234 -120
View File
@@ -28,6 +28,8 @@ pub struct UiState {
pub join: JoinForm,
/// Whether rates and sparklines are shown in packets or bytes.
pub unit: Unit,
/// Network details opened during this run, keyed by identity even for namesakes.
expanded_networks: BTreeSet<String>,
/// An in-progress hostname edit (`None` when not editing).
pub host_edit: Option<String>,
/// Network ids whose devices window is open.
@@ -46,7 +48,8 @@ impl Default for UiState {
fn default() -> Self {
Self {
join: JoinForm::default(),
unit: Unit::Packets,
unit: Unit::Bytes,
expanded_networks: BTreeSet::new(),
host_edit: None,
open_devices: BTreeSet::new(),
vip_windows: Default::default(),
@@ -121,97 +124,153 @@ pub fn draw_network(
offer_exit: bool,
) -> bool {
let mut pick_exit = false;
ui.add_space(6.0);
egui::Frame::group(ui.style()).show(ui, |ui| {
ui.horizontal(|ui| {
format::copy_field(ui, network.name.as_str(), &network.name);
if ui.button("VIP").clicked(){state.vip_windows.entry(network.network_id.clone()).or_default();}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let leave =
egui::Button::new(egui::RichText::new("Leave").color(egui::Color32::WHITE))
.fill(LEAVE_RED);
if ui.add(leave).clicked() {
agent.send(Command::Leave {
ui.add_space(5.0);
ui.push_id(&network.network_id, |ui| {
egui::Frame::group(ui.style()).show(ui, |ui| {
ui.set_min_width(ui.available_width());
let mut open = state.expanded_networks.contains(&network.network_id);
let status = if network.active {
format!(
"{} online",
devices::online_count(network, &report.endpoint_id)
)
} else {
"Stopped".to_owned()
};
if network_header(ui, &network.name, &status, open).clicked() {
open = !open;
if open {
state.expanded_networks.insert(network.network_id.clone());
} else {
state.expanded_networks.remove(&network.network_id);
}
}
if let Some(via) = &network.exit.via {
draw_selected_exit(ui, network, via, state);
}
for warning in exit::warnings(network) {
draw_exit_warning(ui, &warning);
}
if !network.range_conflicts.is_empty() {
ui.colored_label(BAD, "Stopped: overlapping network ranges");
}
if !open {
return;
}
ui.separator();
draw_metadata(ui, network, &report.endpoint_id);
draw_protocols(ui, agent, network, &report.available_protocols);
format::sparkline(ui, traffic.network(&network.network_id), state.unit, 34.0);
pick_exit = network_settings(ui, agent, network, offer_exit);
ui.separator();
ui.horizontal_wrapped(|ui| {
if ui
.button(format!("{} Copy secret", icon::COPY))
.on_hover_text("Copy this network's secret to the clipboard")
.clicked()
{
agent.send(Command::CopySecret {
network_id: network.network_id.clone(),
});
}
if ui.button("Show devices").clicked() {
state.open_devices.insert(network.network_id.clone());
}
if ui.button("VIP").clicked() {
state
.vip_windows
.entry(network.network_id.clone())
.or_default();
}
});
});
});
pick_exit
}
let address = network.overlay.as_ref().and_then(|o| o.address.as_ref());
let series = traffic.network(&network.network_id);
egui::Grid::new(("net", &network.network_id))
.num_columns(2)
.spacing([10.0, 3.0])
.show(ui, |ui| {
ui.weak("id");
format::copy_field(ui, &format::short(&network.network_id), &network.network_id);
fn draw_metadata(ui: &mut egui::Ui, network: &NetworkReport, own_id: &str) {
egui::Grid::new(ui.id().with("metadata"))
.num_columns(2)
.spacing([10.0, 3.0])
.show(ui, |ui| {
ui.weak("name");
format::copy_field(ui, &network.name, &network.name);
ui.end_row();
ui.weak("id");
format::copy_field(ui, &format::short(&network.network_id), &network.network_id);
ui.end_row();
if let Some(range) = &network.range {
ui.weak("range");
format::copy_field(ui, range, range);
ui.end_row();
if let Some(range) = &network.range {
ui.weak("range");
format::copy_field(ui, range, range);
ui.end_row();
}
if let Some(address) = address {
ui.weak("addr");
format::copy_field(ui, address, address);
ui.end_row();
}
ui.weak("peers");
ui.label(format!(
"{} online · {} known",
devices::online_count(network, &report.endpoint_id),
devices::known_count(network, &report.endpoint_id)
));
ui.end_row();
});
draw_protocols(ui, agent, network, &report.available_protocols);
format::sparkline(ui, series, state.unit, 34.0);
if !network.range_conflicts.is_empty() {
ui.colored_label(BAD, "Stopped: overlapping network ranges");
for conflict in &network.range_conflicts {
ui.label(format!("{} ({}) uses {}", conflict.name, conflict.network_id, conflict.range));
}
ui.label("Switching suspends these networks until this network stops, then resumes them automatically.");
if network.auto_start { ui.weak("This network will resume automatically when its range is free."); }
if let Some(address) = network.overlay.as_ref().and_then(|o| o.address.as_ref()) {
ui.weak("addr");
format::copy_field(ui, address, address);
ui.end_row();
}
ui.weak("peers");
ui.label(format!("{} known", devices::known_count(network, own_id)));
ui.end_row();
});
}
fn network_settings(
ui: &mut egui::Ui,
agent: &dyn Client,
network: &NetworkReport,
offer_exit: bool,
) -> bool {
let mut pick_exit = false;
if !network.range_conflicts.is_empty() {
for conflict in &network.range_conflicts {
ui.label(format!(
"{} ({}) uses {}",
conflict.name, conflict.network_id, conflict.range
));
}
ui.horizontal_wrapped(|ui| {
if !network.active && !network.range_conflicts.is_empty() {
if ui.button("Switch to this network").clicked() {
agent.send(Command::SetActive { network_id: network.network_id.clone(), active: true });
}
if network.auto_start && ui.button("Keep stopped").clicked() {
agent.send(Command::SetActive { network_id: network.network_id.clone(), active: false });
}
} else {
let mut active = network.active;
if ui.checkbox(&mut active, "active").changed() {
agent.send(Command::SetActive {
network_id: network.network_id.clone(),
active,
});
}
}
let mut broadcast = network.broadcast;
if ui.checkbox(&mut broadcast, "broadcast").changed() {
agent.send(Command::SetBroadcast {
ui.label("Switching suspends these networks until this network stops, then resumes them automatically.");
if network.auto_start {
ui.weak("This network will resume automatically when its range is free.");
}
}
ui.horizontal_wrapped(|ui| {
if !network.active && !network.range_conflicts.is_empty() {
if ui.button("Switch to this network").clicked() {
agent.send(Command::SetActive {
network_id: network.network_id.clone(),
enabled: broadcast,
active: true,
});
}
if !offer_exit && ui.button("Exit node…").clicked() { pick_exit = true; }
if network.auto_start && ui.button("Keep stopped").clicked() {
agent.send(Command::SetActive {
network_id: network.network_id.clone(),
active: false,
});
}
} else {
let mut active = network.active;
if ui.checkbox(&mut active, "active").changed() {
agent.send(Command::SetActive {
network_id: network.network_id.clone(),
active,
});
}
}
let mut broadcast = network.broadcast;
if ui.checkbox(&mut broadcast, "broadcast").changed() {
agent.send(Command::SetBroadcast {
network_id: network.network_id.clone(),
enabled: broadcast,
});
}
if offer_exit {
let mut offering = network.exit.offering;
if offer_exit && ui
if ui
.checkbox(&mut offering, "exit node")
.on_hover_text(
"let other members send all their internet traffic through this \
device, which can see it",
)
.on_hover_text("Let members send all their internet traffic through this device, which can see it.")
.changed()
{
agent.send(Command::SetExitOffer {
@@ -219,54 +278,109 @@ pub fn draw_network(
enabled: offering,
});
}
});
ui.horizontal(|ui| {
// In the bottom left corner while this device sends its traffic through
// somebody: green while that works, red while it does not.
if let Some(via) = &network.exit.via {
let color = if network.exit.via_online {
exit::GOOD
} else {
exit::LOUD
};
let response = ui
.add(
egui::Label::new(
egui::RichText::new(icon::SIGN_OUT).size(18.0).color(color),
)
.sense(egui::Sense::click()),
)
.on_hover_cursor(egui::CursorIcon::PointingHand)
.on_hover_text(format!(
"exit node: {} — click to stop",
exit::name_of(network, via)
));
if response.clicked() {
state.exit_confirm = Some(devices::ExitConfirm::stop_from_tile(network, via));
}
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Show devices").clicked() {
state.open_devices.insert(network.network_id.clone());
}
if ui
.button(format!("{} Copy secret", icon::COPY))
.on_hover_text("copy this network's secret to the clipboard")
.clicked()
{
agent.send(Command::CopySecret {
network_id: network.network_id.clone(),
});
}
} else {
pick_exit = ui.button("Exit node…").clicked();
}
let leave = egui::Button::new(egui::RichText::new("Leave").color(egui::Color32::WHITE))
.fill(LEAVE_RED);
if ui.add(leave).clicked() {
agent.send(Command::Leave {
network_id: network.network_id.clone(),
});
});
for warning in exit::warnings(network) {
draw_exit_warning(ui, &warning);
}
});
pick_exit
}
fn network_header(ui: &mut egui::Ui, name: &str, status: &str, open: bool) -> egui::Response {
let height = ui.text_style_height(&egui::TextStyle::Heading).max(30.0);
let (rect, response) = ui.allocate_exact_size(
egui::vec2(ui.available_width(), height),
egui::Sense::click(),
);
response.widget_info(|| {
egui::WidgetInfo::labeled(egui::WidgetType::CollapsingHeader, ui.is_enabled(), name)
});
let visuals = ui.style().interact(&response);
if response.hovered() || response.has_focus() {
ui.painter().rect_filled(rect, 3.0, visuals.weak_bg_fill);
}
let font = egui::TextStyle::Body.resolve(ui.style());
ui.painter().text(
rect.left_center(),
egui::Align2::LEFT_CENTER,
if open {
icon::CARET_DOWN
} else {
icon::CARET_RIGHT
},
font.clone(),
visuals.text_color(),
);
let end = ui.painter().text(
rect.right_center(),
egui::Align2::RIGHT_CENTER,
status,
font.clone(),
ui.visuals().text_color(),
);
let left = rect.left() + font.size + 6.0;
let mut job = egui::text::LayoutJob::simple_singleline(
name.into(),
egui::FontId::new(font.size + 4.0, egui::FontFamily::Name("Bold".into())),
ui.visuals().strong_text_color(),
);
job.wrap.max_width = (end.left() - left - 8.0).max(0.0);
job.wrap.max_rows = 1;
job.wrap.break_anywhere = true;
let title = ui.painter().layout_job(job);
ui.painter().galley(
egui::pos2(left, rect.center().y - title.size().y / 2.0),
title,
visuals.text_color(),
);
response
.on_hover_cursor(egui::CursorIcon::PointingHand)
.on_hover_text(name)
}
fn draw_selected_exit(ui: &mut egui::Ui, network: &NetworkReport, via: &str, state: &mut UiState) {
ui.horizontal_wrapped(|ui| {
let color = if network.exit.via_online {
exit::GOOD
} else {
exit::LOUD
};
let name = exit::name_of(network, via);
let clicked = ui
.add(egui::Button::new(egui::RichText::new(icon::SIGN_OUT).color(color)).frame(false))
.on_hover_text("Stop using this exit node")
.clicked();
if ui
.link(format!("Exit via {name}"))
.on_hover_text("Stop using this exit node")
.clicked()
|| clicked
{
state.exit_confirm = Some(devices::ExitConfirm::stop_from_tile(network, via));
}
if let Some(t) = network.exit.traffic {
ui.label(format!(
"{} {}",
icon::ARROW_UP,
format::bytes(t.tx_bytes as f64)
))
.on_hover_text("Sent through this exit");
ui.label(format!(
"{} {}",
icon::ARROW_DOWN,
format::bytes(t.rx_bytes as f64)
))
.on_hover_text("Received through this exit");
}
});
}
fn draw_protocols(
ui: &mut egui::Ui,
agent: &dyn Client,
+10 -1
View File
@@ -11,9 +11,18 @@ mod table;
pub mod vip;
mod vip_status;
/// Install the tray's regular Phosphor glyphs alongside egui's standard fonts.
/// Install the Phosphor icons and bold network title face for both egui clients.
pub fn app_fonts() -> egui::FontDefinitions {
let mut fonts = egui::FontDefinitions::default();
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
let mut bold = fonts.families[&egui::FontFamily::Proportional].clone();
bold.insert(0, "Source Sans Pro Bold".into());
fonts.font_data.insert(
"Source Sans Pro Bold".into(),
egui::FontData::from_static(include_bytes!("../fonts/SourceSansPro-Bold.ttf")).into(),
);
fonts
.families
.insert(egui::FontFamily::Name("Bold".into()), bold);
fonts
}
+9
View File
@@ -23,6 +23,15 @@ pub enum Unit {
Bytes,
}
impl Unit {
pub(crate) fn counters(self, peer: &OverlayPeerReport) -> (u64, u64) {
match self {
Self::Packets => (peer.tx_packets, peer.rx_packets),
Self::Bytes => (peer.tx_bytes, peer.rx_bytes),
}
}
}
/// One series' rolling packet and byte rates.
#[derive(Default)]
pub struct Series {