peerconn: carry destination in accept events for abuse-detection#256
Open
myleshorton wants to merge 2 commits into
Open
peerconn: carry destination in accept events for abuse-detection#256myleshorton wants to merge 2 commits into
myleshorton wants to merge 2 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>
Extends the listener API from (state, source) to a typed Event with
(State, Source, Destination). The destination is the load-bearing
abuse-detection signal — source IP alone is insufficient since mobile
clients change IPs and NAT pools collapse to one address, but
destination distribution per source bucket is highly diagnostic
(thousands of port-25 connections from one source = spam relay,
millions of HTTPS connections to a fixed e-commerce list = credential
stuffing).
Aggregation lives in radiance/peer (separate change, engineering#3438
C3a follow-up); this just plumbs the field through the lantern-box
hook so the radiance peer client has the raw signal to bucket on.
API:
- Event{State, Source, Destination}
- Notify(Event) — lower-level, exported for future hooks like
byte-counting conn wrappers
- NotifyAccept(source, destination) / NotifyClose(source) — the
convenience callers inbounds use; samizdat updated.
Close events deliberately don't carry destination — the aggregator
pairs accepts and closes by source identity at +1 time.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new process-wide peer connection listener registry and plumbs destination information through Samizdat inbound accept events to support downstream abuse-detection bucketing in the radiance peer client.
Changes:
- Introduces
tracker/peerconnwith anEvent{State, Source, Destination}API and globalSetListener/Notify*helpers. - Adds unit tests validating listener behavior and destination propagation/omission semantics.
- Emits
NotifyAccept(source, destination)and deferredNotifyClose(source)fromprotocol/samizdatinbound handling.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tracker/peerconn/listener.go | Implements the global listener registry and event model including destination on accept events. |
| tracker/peerconn/listener_test.go | Adds coverage for no-op behavior, last-writer-wins semantics, and destination field behavior. |
| protocol/samizdat/inbound.go | Hooks Samizdat inbound connections into the peerconn accept/close notification stream. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Part of the Share My Connection security review C3 (engineering#3438). Extends the peerconn listener API to carry destination info on accept events so the radiance peer client can bucket per-(source, destination) for abuse detection.
Why destination matters
Source IP alone is insufficient for abuse pattern detection — mobile clients change IPs constantly, NAT pools collapse many users to one address. The destination distribution per source bucket is highly diagnostic:
API change
Old:
New:
`Event{State, Source, Destination}`. Close events deliberately don't carry destination — the abuse aggregator pairs accepts and closes by source identity at +1 time.
Aggregation lives elsewhere
This PR plumbs the field through. The radiance peer client builds the in-memory aggregator (separate PR, getlantern/radiance#TBD); the lantern-cloud endpoint that consumes the resulting summaries is C3b (a follow-up).
Test plan
🤖 Generated with Claude Code