Skip to content

Cleanup review, and recover from a local address change (eg after sleep) - #86

Merged
ldemailly merged 12 commits into
mainfrom
cleanup-review
Nov 22, 2026
Merged

ldemailly merged 12 commits into
mainfrom
cleanup-review

Conversation

@ldemailly

@ldemailly ldemailly commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Code review cleanups and a fix for local address changes, no protocol change.

Fixes:

  • Panic on a truncated private key file.
  • ShortPath of a directory that only starts like home (eg /Users/dlx).
  • Stop is safe from a receiver goroutine (newer duplicate instance) and concurrently.
  • Recover from a local address change (eg new DHCP lease after sleep: every send failed with sendto: can't assign requested address). Sockets now always listen on all addresses (like with -peers), the route to -target is checked every discovery tick (nothing sent), and on change: new address used as ours (UI row too), multicast interface set and group rejoined, links from the old address closed so they reconnect. Our own discovery (same key and run id) is ignored from any address.

Cleanups:

  • Doc comments for the exported API; README directory sync section; -interval and -sync-watch help fixed.
  • tsnet uses syncdir's KeptMode, ParentKey, WindowsReservedName instead of copies.
  • One link up/run path for both dial directions, linkedLocked helper, change() without the unused version.
  • Unexported discovery internals (mcastSend, decodeDiscovery, peersCleanup), mcastListen rename.
  • Config built once for the UI and headless modes; unknown keys (eg Esc) show a notice and only log in verbose.
  • Split handleDiscovery, runSync, handleFileFrame.
  • Small ones: filepath in tcrypto storage, unused Ephemeral.Curve, percentOf, paths.go, fmt.Appendf.

Tested: lint (darwin/linux/windows), make test, make e2e.

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.88462% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.77%. Comparing base (df98f77) to head (7e6db72).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
main.go 26.82% 30 Missing ⚠️
tsnet/tsnet.go 88.29% 7 Missing and 4 partials ⚠️
paths.go 79.16% 7 Missing and 3 partials ⚠️
tsnet/link.go 86.20% 4 Missing ⚠️
tsnet/sync.go 88.23% 3 Missing and 1 partial ⚠️
syncui.go 50.00% 2 Missing and 1 partial ⚠️
fileui.go 66.66% 1 Missing and 1 partial ⚠️
headless.go 0.00% 2 Missing ⚠️
tcrypto/file.go 75.00% 2 Missing ⚠️
tsnet/files.go 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   72.19%   72.77%   +0.58%     
==========================================
  Files          31       32       +1     
  Lines        5779     5892     +113     
==========================================
+ Hits         4172     4288     +116     
+ Misses       1327     1321       -6     
- Partials      280      283       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression coverage is missing for receiver-triggered shutdown and concurrent or subsequent Stop() calls, leaving potential shutdown hangs untested.

1 open issue
What changed in this PR

This PR cleans up tsync’s networking, crypto, and terminal UI code without changing the wire protocol. It also fixes malformed-key handling, home-path shortening, and duplicate-instance shutdown.

Changes:

  • Consolidates shared helpers, configuration setup, and connection handling into smaller functions.
  • Rejects invalid private-key lengths, corrects ShortPath, and serializes shutdown while moving receiver-triggered shutdown off the receiver.
  • Expands API and directory-sync documentation, clarifies flag help, and adds notices for unknown keys.
File Description
tsnet/​tsnet.go Documents APIs, simplifies discovery, and revises shutdown handling.
tsnet/​syncwatch.go Reuses the shared parent-path helper.
tsnet/​syncpull.go Updates change notifications.
tsnet/​sync.go Extracts sync steps and reuses link and path helpers.
tsnet/​link.go Unifies link setup and execution for both connection directions.
tsnet/​link_internal_test.go Updates tests for renamed discovery internals.
tsnet/​handshake.go Simplifies status-change notifications.
tsnet/​files.go Extracts frame handling and reuses shared helpers.
tsnet/​dirs.go Reuses syncdir’s permission helper.
tcrypto/​identity.go Validates private-key length and documents identity APIs.
tcrypto/​identity_test.go Adds malformed-private-key regression cases.
tcrypto/​file.go Uses platform-aware paths and consolidates storage initialization.
tcrypto/​errors.go Documents crypto error types and constructors.
tcrypto/​encoding.go Documents encoding helpers.
tcrypto/​ecdh.go Removes the unused curve field and documents key exchange.
syncui.go Reuses percentage calculations and relocates path helpers.
syncdir/​index.go Exposes shared parent-path and Windows-name helpers.
SYNC_DETAILS.md Separates scanning and watching documentation.
README.md Expands directory-sync guidance and revises usage examples.
paths.go Centralizes path helpers and fixes home-prefix matching.
notice.go Adds notices without logging.
main.go Shares configuration setup and improves key and flag feedback.
main_test.go Tests key names and unknown-key notices.
logarea.go Documents the log-area constructor.
headless.go Accepts the shared, fully configured sync settings.
fileui.go Consolidates progress calculations and relocates path helpers.
fileui_test.go Tests home-path matching boundaries.
clipui.go Documents the clipboard-panel constructor.
clip.go Documents bracketed-paste markers.

Review effort: Balanced

Comment thread tsnet/tsnet.go Resolved
…listen on all addresses, check the route every tick, close links from the old address
@ldemailly ldemailly changed the title Cleanup review: doc comments, dedup, smaller functions, 2 fixes Cleanup review, and recover from a local address change (eg after sleep) Nov 22, 2026
@ldemailly
ldemailly requested a balanced review from Copilot November 22, 2026 21:08
…rver, concurrent and later Stop calls return

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The connection-closing logic disconnects healthy links on unrelated interfaces when the default-route address changes, disrupting active transfers; it should close only connections whose local IP matches old.IP.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread tsnet/tsnet.go Resolved
…not the ones from others (eg a VPN for -peers)
@ldemailly
ldemailly merged commit 4b4ba52 into main Nov 22, 2026
9 checks passed
@ldemailly
ldemailly deleted the cleanup-review branch November 22, 2026 21:35
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.

2 participants