Skip to content

Add peerconn listener registry for inbound connection lifecycle events#255

Draft
myleshorton wants to merge 3 commits into
mainfrom
fisk/peer-connection-listener
Draft

Add peerconn listener registry for inbound connection lifecycle events#255
myleshorton wants to merge 3 commits 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

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>
Adam Fisk and others added 2 commits May 11, 2026 14:45
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>
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