Skip to content

Add peerconn listener registry for inbound connection lifecycle events#255

Open
myleshorton wants to merge 1 commit into
mainfrom
fisk/peer-connection-listener
Open

Add peerconn listener registry for inbound connection lifecycle events#255
myleshorton wants to merge 1 commit into
mainfrom
fisk/peer-connection-listener

Conversation

@myleshorton
Copy link
Copy Markdown
Contributor

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.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: 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 unregisters
  • go test ./protocol/samizdat/... — existing samizdat tests unaffected
  • End-to-end: with the matching radiance branch (fisk/peer-connection-events), connection events flow from accept loop → globe (verified locally)

Related

  • radiance: getlantern/radiance#TBD (consumes this listener)
  • lantern: getlantern/lantern#TBD (Flutter UI subscribes to the FlutterEvent stream this ultimately feeds)

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/peerconn package with SetListener/Notify and a single global listener guarded by sync.RWMutex.
  • Unit tests covering nil-listener no-op, fire-on-notify, last-writer-wins, and nil-unregisters semantics.
  • Samizdat inbound handleConnection calls peerconn.Notify(+1, source) on accept and defers -1 on 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>
@myleshorton myleshorton force-pushed the fisk/peer-connection-listener branch from 85df335 to 0b63c0f Compare May 29, 2026 19:54
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