Add peerconn listener registry for inbound connection lifecycle events#255
Open
myleshorton wants to merge 1 commit into
Open
Add peerconn listener registry for inbound connection lifecycle events#255myleshorton wants to merge 1 commit into
myleshorton wants to merge 1 commit into
Conversation
2 tasks
3201d6a to
49b8b02
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a process-wide listener registry (tracker/peerconn) that surfaces inbound connection accept/close lifecycle events to external consumers (notably the radiance peer client for Share My Connection). Wires the samizdat inbound to notify on accept and (via defer) on close.
Changes:
- New
tracker/peerconnpackage withSetListener/Notifyand a single global listener guarded bysync.RWMutex. - Unit tests covering nil-listener no-op, fire-on-notify, last-writer-wins, and nil-unregisters semantics.
- Samizdat inbound
handleConnectioncallspeerconn.Notify(+1, source)on accept and defers-1on close.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tracker/peerconn/listener.go | New package defining Listener type, SetListener, and Notify with a global mutex-guarded listener. |
| tracker/peerconn/listener_test.go | Unit tests for no-op, dispatch, replacement, and unregister semantics. |
| protocol/samizdat/inbound.go | Notify peerconn on connection accept and close in handleConnection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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>
85df335 to
0b63c0f
Compare
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