refactor: cut what a whole-repo audit proved dead, padded, or hand-rolled

Seven region audits, every finding adversarially verified against the
whole workspace before being applied; 80 landed and the two that failed
in application were refuted honestly (ParseError has a from_str_radix
producer the audit missed; NatPmpError's Display is the only reader of
its diagnostic payloads).

The bigger cuts:

- The NewPeer/PierceFireWall cluster: an operation variant nothing ever
  sent, its 77-line arm, a protocol-wrong Client::pierce_firewall that
  wrote a peer-init frame down the server socket, and the struct only
  they used. The live paths in peer/listen.rs are untouched.
- The ops loop reads `for operation in reader` instead of hand-rolling
  recv/break, de-indenting the whole dispatch body.
- Dead lib surface: Message::print_hex and four unused accessors,
  UploadFailed, registry and actor getters, build_watch_user,
  strip_ansi_codes, delegating shims on ClientContext. Removing public
  items makes this a semver major, which the release pipeline enforces.
- Never-used flexibility: the state-migration framework that never held
  a migration, border-type helpers that all answered Rounded, the TUI's
  max_concurrent_downloads field nothing read.
- Convergence: six poll loops into poll_until, three wrap-around
  navigation blocks into cycle, hit tests into Rect::contains, char
  walkers into floor/ceil_char_boundary, five Download literals into
  one helper, the suites' shared scaffolding into tests/common.

Deliberately not taken: swapping the hand-rolled zlib inflate and MD5
for crates (they replace wire-facing machinery whose tolerance of
real-world peer quirks no local test exercises) and pulling chrono into
the lib for a log timestamp. Recorded for their own decision.

Net -1002 lines. Both e2e modes stay green: 94 CLI tests each way, 16
protocol, 33 lib, unit suites, clippy pedantic clean, aislop 100/100
with the four scanner false positives suppressed inline where they
fire.
This commit is contained in:
Michel de Graaf
2026-07-28 12:52:18 +02:00
parent cd56fb3b39
commit f1b667f7f9
62 changed files with 1367 additions and 2319 deletions
+4 -4
View File
@@ -1,13 +1,13 @@
use crate::models::{AppState, MessageDirection};
use crate::ui::{
accent_style, border_style, border_type, dimmed_style, highlight_style,
info_style, primary_style,
accent_style, border_style, dimmed_style, highlight_style, info_style,
primary_style,
};
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
widgets::{Block, BorderType, Borders, Paragraph},
};
/// Render the private-message chat box: title is the conversation partner,
@@ -28,7 +28,7 @@ pub fn render_chat_pane(
let block = Block::default()
.borders(Borders::ALL)
.border_style(border_style(true))
.border_type(border_type(true))
.border_type(BorderType::Rounded)
.title(title);
let inner = block.inner(area);
frame.render_widget(block, area);
+13 -14
View File
@@ -229,7 +229,12 @@ fn build_info_lines(
speed_bytes_per_sec,
} => {
lines.push(Line::from(""));
push_progress_lines(&mut lines, *bytes_downloaded, *total_bytes);
push_transfer_progress(
&mut lines,
"Downloaded",
*bytes_downloaded,
*total_bytes,
);
lines.push(label_value(
"Speed",
&format_speed(*speed_bytes_per_sec),
@@ -246,7 +251,12 @@ fn build_info_lines(
total_bytes,
} => {
lines.push(Line::from(""));
push_progress_lines(&mut lines, *bytes_downloaded, *total_bytes);
push_transfer_progress(
&mut lines,
"Downloaded",
*bytes_downloaded,
*total_bytes,
);
}
DownloadStatus::Failed(reason) => {
if let Some(reason) = reason {
@@ -268,10 +278,7 @@ fn build_info_lines(
}
fn label_value(label: &str, value: &str) -> Line<'static> {
Line::from(vec![
Span::styled(format!("{label:<LABEL_WIDTH$}"), dimmed_style()),
Span::styled(value.to_string(), primary_style()),
])
label_value_styled(label, value.to_string(), primary_style())
}
fn label_value_styled(
@@ -285,14 +292,6 @@ fn label_value_styled(
])
}
fn push_progress_lines(
lines: &mut Vec<Line<'static>>,
bytes_downloaded: u64,
total_bytes: u64,
) {
push_transfer_progress(lines, "Downloaded", bytes_downloaded, total_bytes);
}
/// A progress bar plus a `<label> <done> / <total>` line, shared by the
/// download ("Downloaded") and upload ("Sent") views.
fn push_transfer_progress(
+11 -17
View File
@@ -56,7 +56,16 @@ pub fn render_downloads_pane(
let progress_text = match &download.status {
DownloadStatus::Queued => "Queued".to_string(),
DownloadStatus::InProgress { .. } => {
DownloadStatus::InProgress { .. }
| DownloadStatus::Paused { .. } => {
let prefix = if matches!(
download.status,
DownloadStatus::Paused { .. }
) {
"Paused "
} else {
""
};
let percent = if download.size > 0 {
(download.bytes_downloaded() as f64
/ download.size as f64
@@ -65,22 +74,7 @@ pub fn render_downloads_pane(
0
};
format!(
"{}/{} ({}%)",
format_bytes(download.bytes_downloaded()),
format_bytes(download.size),
percent
)
}
DownloadStatus::Paused { .. } => {
let percent = if download.size > 0 {
(download.bytes_downloaded() as f64
/ download.size as f64
* 100.0) as u8
} else {
0
};
format!(
"Paused {}/{} ({}%)",
"{prefix}{}/{} ({}%)",
format_bytes(download.bytes_downloaded()),
format_bytes(download.size),
percent