Fix peer speed measurements and fit compact traffic counters
A slow first download could make the rate search settle around 60 Mbit/s on a much faster link. A final faster train could also exhaust the byte budget before its feedback reached the sender. Reprobe above the first apparent limit and use unique payload actually delivered over sustained sender and receiver intervals. Count each submitted packet even when the tunnel is backpressured, and keep the unused part of the pacing batch available. The five-second deadline, metered limits and v1 wire format remain compatible with existing peers. Show achieved Mbit/s in the devices list and describe a lower bound in the tooltip. Reserve a font-measured TX/RX width independent of changing byte counts on narrow desktop windows and landscape Android. Support counters through exabytes and retain exact packet counts. Align the application, Android and Nix versions for 1.0.7. On a shaped 300/250 Mbit/s path with a cold download, the regression measured 295/247 Mbit/s after the fix and 59/244 on 1.0.6. The suite also covers trailing feedback, local tunnel pressure and compact layouts at multiple font sizes and display densities. Mixed 1.0.6/1.0.7 speed sessions completed in both roles. Two unmetered runs over real WireGuard on loopback measured 251 and 250 Mbit/s down and completed both directions in 3.0 and 3.1 seconds. On macOS arm64, workspace formatting and strict Clippy passed, and the locked all-targets suite passed 646 tests with six opt-in tests ignored. Cargo also reported the existing directories manifest warning. The GNU Windows workspace cross-check and Android arm64 debug APK build passed.
This commit is contained in:
1 parent
e3b74babba
commit
b47acb8321
23 files changed
+616
-207
No files matched your search
@@ -37,45 +37,82 @@ impl Column {
|
||||
}
|
||||
}
|
||||
|
||||
fn columns(ui: &Ui, width: f32, landscape: bool, unit: Unit) -> Vec<(Column, f32)> {
|
||||
fn columns(
|
||||
ui: &Ui,
|
||||
width: f32,
|
||||
landscape: bool,
|
||||
unit: Unit,
|
||||
members: &[Device<'_>],
|
||||
) -> Vec<(Column, f32)> {
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
let measure = |s: &str| {
|
||||
let text_width = |s: &str| {
|
||||
ui.painter()
|
||||
.layout_no_wrap(s.into(), font.clone(), Color32::WHITE)
|
||||
.size()
|
||||
.x
|
||||
+ 10.
|
||||
};
|
||||
let mut cols = vec![
|
||||
(Column::Device, 0.),
|
||||
(
|
||||
Column::Speed,
|
||||
if landscape {
|
||||
speed::WIDTH.min(width * 0.28)
|
||||
} else {
|
||||
speed::PORTRAIT_WIDTH.min(width * 0.18)
|
||||
},
|
||||
),
|
||||
];
|
||||
if landscape && width >= 510. {
|
||||
cols.push((Column::State, measure("Control only").min(width * 0.16)));
|
||||
let measure = |s: &str| text_width(s) + 10.;
|
||||
let disclosure = text_width(icon::CARET_RIGHT) + 3.;
|
||||
let name = 20. + text_width("device") + 3.;
|
||||
let available = width - name - disclosure;
|
||||
let small_speed = speed::PORTRAIT_WIDTH.min(width * 0.18);
|
||||
let address = measure("255.255.255.255").min(width * if landscape { 0.27 } else { 0.35 });
|
||||
let rtt = measure("Data RTT")
|
||||
.max(measure("9999 ms"))
|
||||
.min(width * if landscape { 0.15 } else { 0.22 });
|
||||
let traffic = (landscape && width >= 420.)
|
||||
.then(|| {
|
||||
// Account for both rounded values (up to 1024.0) and the unit
|
||||
// suffixes in the actual body font, independently of the live bytes.
|
||||
let digit = ui.fonts(|fonts| {
|
||||
('0'..='9')
|
||||
.max_by(|a, b| {
|
||||
fonts
|
||||
.glyph_width(&font, *a)
|
||||
.total_cmp(&fonts.glyph_width(&font, *b))
|
||||
})
|
||||
.unwrap_or('0')
|
||||
});
|
||||
let number = format!("{digit}{digit}{digit}{digit}.{digit}");
|
||||
let bytes_width = format::BYTE_UNITS.iter().fold(0.0_f32, |w, suffix| {
|
||||
w.max(measure(&format!("{number} {suffix} / {number} {suffix}")))
|
||||
});
|
||||
let floor = bytes_width.max(measure(Column::Traffic.title(unit)));
|
||||
match unit {
|
||||
Unit::Bytes => floor,
|
||||
Unit::Packets => members
|
||||
.iter()
|
||||
.filter(|m| m.online)
|
||||
.filter_map(|m| m.overlay)
|
||||
.fold(floor, |w, p| {
|
||||
w.max(measure(&traffic_pair(p.tx_packets, p.rx_packets, unit)))
|
||||
}),
|
||||
}
|
||||
})
|
||||
// An unusually long packet count can use the end of the device name,
|
||||
// but always leave room for its status icon and disclosure.
|
||||
.filter(|w| w + small_speed + 20. + text_width("…") + 3. + disclosure <= width);
|
||||
let mut spare = available - traffic.unwrap_or_default();
|
||||
let state = (landscape && width >= 510.).then(|| measure("Control only"));
|
||||
let speed = if landscape && speed::WIDTH + address + rtt + state.unwrap_or_default() <= spare {
|
||||
speed::WIDTH
|
||||
} else {
|
||||
small_speed
|
||||
};
|
||||
spare -= speed;
|
||||
let mut cols = vec![(Column::Device, 0.), (Column::Speed, speed)];
|
||||
for (column, want) in [(Column::Address, address), (Column::Rtt, rtt)] {
|
||||
if spare >= want {
|
||||
cols.push((column, want));
|
||||
spare -= want;
|
||||
}
|
||||
}
|
||||
cols.push((
|
||||
Column::Address,
|
||||
measure("255.255.255.255").min(width * if landscape { 0.27 } else { 0.35 }),
|
||||
));
|
||||
cols.push((
|
||||
Column::Rtt,
|
||||
measure("9999 ms").min(width * if landscape { 0.15 } else { 0.22 }),
|
||||
));
|
||||
if landscape && width >= 420. {
|
||||
cols.push((
|
||||
Column::Traffic,
|
||||
measure(Column::Traffic.title(unit))
|
||||
.max(measure("999 MB / 999 MB"))
|
||||
.min(width * 0.29),
|
||||
));
|
||||
let mut spare = width - cols.iter().map(|c| c.1).sum::<f32>() - 122.;
|
||||
if let Some(w) = state.filter(|w| *w <= spare) {
|
||||
cols.insert(2, (Column::State, w));
|
||||
spare -= w;
|
||||
}
|
||||
if let Some(w) = traffic {
|
||||
cols.push((Column::Traffic, w));
|
||||
for (column, desire) in [
|
||||
(Column::Version, measure("v1.0.4-rc.1")),
|
||||
(Column::Path, measure("tcp-tls direct")),
|
||||
@@ -90,7 +127,7 @@ fn columns(ui: &Ui, width: f32, landscape: bool, unit: Unit) -> Vec<(Column, f32
|
||||
}
|
||||
let other: f32 = cols.iter().map(|c| c.1).sum();
|
||||
// Reserve the disclosure arrow at the end, including on small split screens.
|
||||
cols[0].1 = (width - other - 16.).max(0.);
|
||||
cols[0].1 = (width - other - disclosure).max(0.);
|
||||
cols
|
||||
}
|
||||
|
||||
@@ -117,7 +154,7 @@ pub(super) fn roster(
|
||||
let id = egui::Id::new(("expanded device", &network.network_id));
|
||||
let mut selected = ui.data(|d| d.get_temp::<String>(id));
|
||||
let width = ui.available_width();
|
||||
let columns = columns(ui, width, widgets::landscape(ui.ctx()), unit);
|
||||
let columns = columns(ui, width, widgets::landscape(ui.ctx()), unit, members);
|
||||
let font = egui::TextStyle::Body.resolve(ui.style());
|
||||
let size = vec2(width, ui.text_style_height(&egui::TextStyle::Body) + 9.);
|
||||
ui.spacing_mut().item_spacing.y = 1.;
|
||||
|
||||
@@ -217,27 +217,25 @@ fn activity(ui: &Ui, rect: Rect, color: Color32) {
|
||||
|
||||
// Round positive lower bounds down so the displayed minimum is supported by
|
||||
// the measurement, including near a precision or unit boundary.
|
||||
fn rate_number(rate: SpeedRate, divisor: f64, precision: usize) -> String {
|
||||
let mut value = rate.bps as f64 / divisor;
|
||||
fn detailed_rate(rate: SpeedRate, divisor: f64) -> String {
|
||||
let value = rate.bps as f64 / divisor;
|
||||
if rate.lower_bound {
|
||||
let scale = 10_f64.powi(precision as i32);
|
||||
value = (value * scale).floor() / scale;
|
||||
format!("at least {:.2}", (value * 100.).floor() / 100.)
|
||||
} else {
|
||||
format!("{value:.2}")
|
||||
}
|
||||
format!("{value:.precision$}")
|
||||
}
|
||||
|
||||
fn compact_rate(rate: SpeedRate) -> String {
|
||||
let bound = if rate.lower_bound { "≥" } else { "" };
|
||||
let (unit, precision, suffix) = match rate.bps {
|
||||
0 => return "0".into(),
|
||||
1..10_000 if rate.lower_bound => return ">0".into(),
|
||||
1..10_000 => return "<0.01".into(),
|
||||
10_000..1_000_000 => (1e6, 2, ""),
|
||||
1_000_000..10_000_000 => (1e6, 1, ""),
|
||||
10_000_000..10_000_000_000 => (1e6, 0, ""),
|
||||
_ => (1e9, 0, "k"),
|
||||
};
|
||||
format!("{bound}{}{suffix}", rate_number(rate, unit, precision))
|
||||
format!("{:.precision$}{suffix}", rate.bps as f64 / unit)
|
||||
}
|
||||
|
||||
fn tooltip(
|
||||
@@ -265,10 +263,9 @@ fn tooltip(
|
||||
} else {
|
||||
(1e6, "Mbit/s")
|
||||
};
|
||||
let bound = if rate.lower_bound { "at least " } else { "" };
|
||||
hint.push_str(&format!(
|
||||
"\n{label} {bound}{} {suffix}",
|
||||
rate_number(rate, divisor, 2)
|
||||
"\n{label} {} {suffix}",
|
||||
detailed_rate(rate, divisor)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,15 +178,17 @@ fn live_and_completed_readings_keep_the_same_row_and_tapping_retests_a_non_exit_
|
||||
);
|
||||
}
|
||||
let done = s.frame(&n, vec![]);
|
||||
for value in ["125", "≥35"] {
|
||||
let lines = positions(&done, |s| s.ends_with(value));
|
||||
let down_text = format!("{} 125", icon::ARROW_DOWN);
|
||||
let up_text = format!("{} 36", icon::ARROW_UP);
|
||||
for value in [&down_text, &up_text] {
|
||||
let lines = positions(&done, |s| s == value);
|
||||
assert_eq!(lines.len(), 1);
|
||||
assert!((lines[0].x - button.x).abs() < 31.);
|
||||
assert!((lines[0].y - button.y).abs() < 12.);
|
||||
assert!(lines[0].x < width);
|
||||
}
|
||||
let down = positions(&done, |s| s.ends_with("125"))[0];
|
||||
let up = positions(&done, |s| s.ends_with("≥35"))[0];
|
||||
let down = positions(&done, |s| s == down_text)[0];
|
||||
let up = positions(&done, |s| s == up_text)[0];
|
||||
if width > 650. {
|
||||
assert!(
|
||||
(down.y - up.y).abs() < 1. && down.x < up.x,
|
||||
|
||||
@@ -22,19 +22,21 @@ pub fn short(id: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Display units for the whole range of the agent's 64-bit byte counters.
|
||||
pub(crate) const BYTE_UNITS: [&str; 7] = ["B", "kB", "MB", "GB", "TB", "PB", "EB"];
|
||||
|
||||
/// A byte count in binary units.
|
||||
pub fn bytes(n: f64) -> String {
|
||||
const UNITS: [&str; 5] = ["B", "kB", "MB", "GB", "TB"];
|
||||
let mut value = n.max(0.0);
|
||||
let mut unit = 0;
|
||||
while value >= 1024.0 && unit < UNITS.len() - 1 {
|
||||
while value >= 1024.0 && unit < BYTE_UNITS.len() - 1 {
|
||||
value /= 1024.0;
|
||||
unit += 1;
|
||||
}
|
||||
if unit == 0 {
|
||||
format!("{} B", value as u64)
|
||||
} else {
|
||||
format!("{value:.1} {}", UNITS[unit])
|
||||
format!("{value:.1} {}", BYTE_UNITS[unit])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,3 +260,109 @@ fn rotating_the_devices_view_keeps_the_peer_and_fits_traffic_and_states_on_scree
|
||||
}
|
||||
assert!(label(&draw(portrait, 4., vec![]), "Endpoint ID").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_roster_reserves_the_full_tx_rx_pair_as_counters_grow() {
|
||||
use egui::os::OperatingSystem::{Android, Mac};
|
||||
|
||||
for (os, width, font_size, density) in [
|
||||
(Android, 480., 13., 1.),
|
||||
(Mac, 600., 13., 2.),
|
||||
(Mac, 740., 13., 1.),
|
||||
(Android, 800., 19., 2.625),
|
||||
] {
|
||||
let ctx = Context::default();
|
||||
ctx.set_os(os);
|
||||
ctx.set_fonts(crate::app_fonts());
|
||||
ctx.style_mut(|style| {
|
||||
style
|
||||
.text_styles
|
||||
.insert(egui::TextStyle::Body, egui::FontId::proportional(font_size));
|
||||
});
|
||||
let mut net = NetworkReport {
|
||||
name: "lab".into(),
|
||||
peers: vec![PeerReport {
|
||||
endpoint_id: "alpha".into(),
|
||||
hostname: Some("alpha".into()),
|
||||
agent_version: Some("1.0.6".into()),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
let mut input = egui::RawInput {
|
||||
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, egui::vec2(width, 320.))),
|
||||
..Default::default()
|
||||
};
|
||||
input
|
||||
.viewports
|
||||
.get_mut(&egui::ViewportId::ROOT)
|
||||
.unwrap()
|
||||
.native_pixels_per_point = Some(density);
|
||||
let mut first_cell = None;
|
||||
for (mut unit, tx, rx, expected) in [
|
||||
(Unit::Bytes, 0, 0, "0 B / 0 B"),
|
||||
(Unit::Bytes, 293_069, 294_400, "286.2 kB / 287.5 kB"),
|
||||
(
|
||||
Unit::Bytes,
|
||||
(1 << 30) - 1,
|
||||
(1 << 20) - 1,
|
||||
"1024.0 MB / 1024.0 kB",
|
||||
),
|
||||
(Unit::Bytes, u64::MAX, 1 << 50, "16.0 EB / 1.0 PB"),
|
||||
(Unit::Packets, 1_234_567, 7_654_321, "1234567 / 7654321"),
|
||||
(
|
||||
Unit::Packets,
|
||||
u64::MAX,
|
||||
u64::MAX - 1,
|
||||
"18446744073709551615 / 18446744073709551614",
|
||||
),
|
||||
] {
|
||||
net.overlay = Some(OverlayReport {
|
||||
peers: vec![OverlayPeerReport {
|
||||
endpoint_id: "alpha".into(),
|
||||
tx_bytes: tx,
|
||||
rx_bytes: rx,
|
||||
tx_packets: tx,
|
||||
rx_packets: rx,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
});
|
||||
let output = ctx.run(input.clone(), |ctx| {
|
||||
devices::show(
|
||||
ctx,
|
||||
&ReadOnly,
|
||||
&mut unit,
|
||||
(&mut None, &mut None),
|
||||
&net,
|
||||
"self",
|
||||
&Traffic::default(),
|
||||
);
|
||||
});
|
||||
let (text, cell) = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == expected => Some((t, s.clip_rect)),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| panic!("missing {expected} at {width}"));
|
||||
assert!(!text.galley.elided, "{expected} truncated at {width}");
|
||||
assert!(
|
||||
cell.contains_rect(text.visual_bounding_rect()),
|
||||
"{expected} clipped"
|
||||
);
|
||||
assert!(cell.left() >= 0. && cell.right() <= width);
|
||||
if unit == Unit::Bytes {
|
||||
let bounds = (cell.left(), cell.right());
|
||||
assert_eq!(*first_cell.get_or_insert(bounds), bounds);
|
||||
}
|
||||
assert!(label(&output, "alpha").unwrap().right() <= cell.left());
|
||||
let disclosure = label(&output, icon::CARET_RIGHT).unwrap();
|
||||
assert!(cell.right() <= disclosure.left() && disclosure.right() <= width);
|
||||
if let Some(version) = label(&output, "v1.0.6") {
|
||||
assert!(cell.right() <= version.left() && version.right() <= disclosure.left());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user