Skip to content

Trim dead code, unused re-exports and near-copies (lean audit) - #199

Merged
onyks-os merged 18 commits into
mainfrom
refactor/lean-audit
Nov 30, 2026
Merged

onyks-os merged 18 commits into
mainfrom
refactor/lean-audit

Conversation

@onyks-os

@onyks-os onyks-os commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Implements findings 1–7 of the lean audit. No behaviour change except the one noted under 6.

  1. restart takes start's options instead of a hand-kept copy of all 17 (it gets start's signature minus --require-vpn). ttp restart --help is byte-identical.
  2. tor_control.verify_tor removed — nothing called it; start verifies through probe.verify_session. get_exit_ip now reads netprobe.ENDPOINTS, so the endpoint list exists once.
  3. Dead definitions removed: watchdog.service._unit_state, evidence.DeliveryState, _common.EXIT_UNVERIFIED (tests use ExitCode.UNVERIFIED).
  4. Unused aliases/re-exports removed from ttp/cli.py (11 of 12; _setup_logging stays, tests patch it) and ttp/watchdog/__init__.py (stdlib and ttp modules no test patched through it).
  5. block_doh removed — passed through four functions, never False outside tests. The DoH map is unconditional, as it already was in practice.
  6. Tor UID resolved once: firewall.apply_rules returns the UID it exempted and start records it, replacing a second lookup behind an unreachable except Exception: pass. The Tor account names now live in tor_detect.TOR_ACCOUNTS only. Behaviour change: the teardown and BYOD fallbacks also try toranon and _tor, and try debian-tor before tor (changelog entry added).
  7. Near-copies folded: semanage add-then-modify, the four localhost bind probes, systemd-resolved's restart-and-flush. Same calls, order and log levels.

Net: +142 / -637 lines (-495). Full unit suite passes locally (1823 tests).

🤖 Generated with Claude Code

onyks-os and others added 18 commits November 30, 2026 19:29
The flag exempted root only in filter_out, so root's TCP and DNS still
went through Tor while its UDP left in cleartext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
A start that could not read its table back recorded None, and the
watchdog then skipped the #80 comparison for the whole session, so a
flushed table passed. Start now rolls back; the watchdog treats a missing
fingerprint or an unreadable table as a firewall failure. The chain-name
and bypass-rule checks, which the fingerprint covers, are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
do_stop deleted the lock in a finally even when destroy_rules failed, so
status and stop lost a session whose table was still loaded. It now keeps
the lock and exits 8. A failed DNS restore exits 1 instead of 0, and a
conntrack flush timeout no longer aborts the teardown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
transport_expressions (the guard's JSON) and transport_rules (TTP's nft
text) are written apart, and nothing compared them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Nothing reads them since watchdog status asks the live unit; they only
cost a lock rewrite on every watchdog start and stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Only a lock without session_id reached it, i.e. one written by 0.4.x and
still in /run after an upgrade mid-session. Every 0.5 session was already
refused with 'Session Already Present' and ended by 'ttp stop', which
also handles an old lock. The docs promising auto-recovery after kill -9
were wrong for 0.5 and are corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>

# Conflicts:
#	docs/architecture.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
state.py re-exported the star-message helpers and PERSISTENT_DIR 'for
backward compatibility'; only start, uninstall and one test used them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
restart redeclared all 17 of start's options and forwarded each by name;
nothing kept the two lists equal. It now takes start's signature minus
--require-vpn and forwards what it gets. `ttp restart --help` is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
start verifies through ttp.probe.verify_session; verify_tor had only its
own tests. get_exit_ip now reads netprobe.ENDPOINTS, so the endpoint list
exists once instead of twice plus a test keeping the copies equal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
_unit_state was called only by its tests, DeliveryState by nothing, and
EXIT_UNVERIFIED duplicated ExitCode.UNVERIFIED for two test modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
ttp.cli kept eleven `_name = name` aliases no test or script refers to;
only _setup_logging is patched. ttp.watchdog re-exposed stdlib and ttp
modules "for test mocks" that no test patches through it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
block_doh went through four functions and their docstrings, but nothing
in TTP ever set it to False; only tests did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
apply_rules returns the UID it exempted, and start records that one in
the lock, instead of resolving the name a second time behind an
`except Exception: pass` that production could not reach.

The Tor account names lived in four lists. tor_detect.TOR_ACCOUNTS is
now the only one; the teardown and BYOD fallbacks also try toranon and
_tor, and try debian-tor before tor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
semanage's add-then-modify, the four localhost bind probes, and
systemd-resolved's restart-and-flush were each written out twice. Same
calls, same order, same log levels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
@onyks-os
onyks-os merged commit 41854f6 into main Nov 30, 2026
39 checks passed
@onyks-os
onyks-os deleted the refactor/lean-audit branch November 30, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant