Add peerconn listener registry for inbound connection lifecycle events#255
Draft
myleshorton wants to merge 3 commits into
Draft
Add peerconn listener registry for inbound connection lifecycle events#255myleshorton wants to merge 3 commits into
myleshorton wants to merge 3 commits into
Conversation
The Share My Connection feature needs a stream of accept/close events across lantern-box's inbound protocols — for the globe visualization, abuse-detection aggregation, and metrics that need a per-connection stream rather than a snapshot. sing-box's adapter.ConnectionTracker abstraction would be the obvious fit but lives behind libbox's internal box.Router with no public hook for callers constructing a libbox.BoxService to register a tracker post-creation. Plumbing one through would require sing-box-minimal changes. This is a smaller hook: a process-wide listener registry under tracker/peerconn. Single active listener, last-writer-wins, nil to clear. The radiance peer client registers a listener at peer.Client.Start and clears it at Stop; lantern-box inbound code calls peerconn.Notify on accept (+1) and close (-1). samizdat/inbound.go is wired in this commit. TLS-masq, algeneva, water, and any future lantern-box inbound that grows peer-share support is a two-line addition (notify on accept, defer notify on close), keeping the hook protocol-agnostic across lantern-box's stack. Zero cost when no listener is registered — non-peer-share libbox consumers (cmd_run, the CLI, the radiance VPN client) pay only a mutex read per connection. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When MutableURLTest's underlying outbound fails to dial, the existing
path just dropped the URL-test history for that outbound — leaving the
group's selected* fields pointing at the dead outbound until the next
URL-test cycle. Replace with markFailedAndReselect(outbound), which
drops the history AND immediately reruns updateSelected so traffic
fails over to the next-best outbound in the group on the spot.
Extract mockOutbound + mockOutboundManager from fallback_test.go into
mock_outbound_test.go so both fallback and urltest tests can share them.
Adds Tag() and Network() methods needed by the urltest harness.
New urltest_test.go:
- TestUpdateSelected pins the selection ordering across a 7-outbound
spread (chosen from the historical delay bucket).
- TestMarkFailedAndReselect_SwitchesToHealthyOutbound exercises the
new path: alpha (50ms) is selected, alpha fails, expect beta (1000ms)
becomes selected.
- TestPickBestOutbound_FallbackSkipsCurrent locks in the
skip-current-on-pick behavior the fallback branch relies on.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
samizdat#10 plumbs the underlying TLS conn's RemoteAddr through serverStreamConn. Lantern-box's samizdat-in handleConnection now receives metadata.Source set to the real peer ip:port instead of the placeholder "client:0", so peerconn.Notify emits a unique source per peer for the Share My Connection globe UI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a process-wide listener registry for inbound connection lifecycle events under
tracker/peerconn. Used by the radiance peer client (Share My Connection) to surface accept/close events to the rest of the application — Flutter globe visualization, future abuse aggregation, metrics that need a stream rather than a snapshot.Why this and not adapter.ConnectionTracker
sing-box's tracker abstraction would be the obvious fit but lives behind libbox's internal
box.Routerwith no public hook for callers constructing alibbox.BoxServiceto register a tracker post-creation. Plumbing one through would require sing-box-minimal changes. This is a smaller hook: single global listener, last-writer-wins, nil to clear.The registry is callable from any lantern-box inbound — samizdat is wired in this commit; TLS-masq, algeneva, water, etc. is a two-line addition (notify on accept, defer notify on close), keeping the hook protocol-agnostic across lantern-box.
Cost when unused
Zero beyond a mutex read per connection. Standalone CLI / VPN-only consumers (cmd_run, the radiance VPN client) pay nothing meaningful.
Test plan
go test ./tracker/peerconn/...— 4 unit tests covering nil listener, fire on notify, last-writer-wins, nil unregistersgo test ./protocol/samizdat/...— existing samizdat tests unaffectedfisk/peer-connection-events), connection events flow from accept loop → globe (verified locally)Related
getlantern/radiance#TBD(consumes this listener)getlantern/lantern#TBD(Flutter UI subscribes to the FlutterEvent stream this ultimately feeds)🤖 Generated with Claude Code