Skip to content

peerconn: carry destination in accept events for abuse-detection#256

Open
myleshorton wants to merge 2 commits into
mainfrom
fisk/peer-abuse-instrumentation
Open

peerconn: carry destination in accept events for abuse-detection#256
myleshorton wants to merge 2 commits into
mainfrom
fisk/peer-abuse-instrumentation

Conversation

@myleshorton
Copy link
Copy Markdown
Contributor

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:

  • One source making thousands of port-25 connections → spam relay
  • One source making millions of HTTPS connections to a fixed e-commerce list → credential stuffing
  • One source making heavy DNS-over-TLS traffic → possible DNS tunneling

API change

Old:

peerconn.Notify(state int, source string)

New:

peerconn.Notify(evt Event)            // lower-level
peerconn.NotifyAccept(source, destination string)
peerconn.NotifyClose(source string)

`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

  • All existing peerconn tests updated to the new signature, plus two new ones: `TestNotifyAccept_CarriesDestination` and `TestNotifyClose_OmitsDestination`
  • `samizdat/inbound` updated to use NotifyAccept/NotifyClose with the destination string already in scope
  • All existing samizdat tests pass
  • `go build ./...` clean

🤖 Generated with Claude Code

Adam Fisk and others added 2 commits May 7, 2026 12:34
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>
Copilot AI review requested due to automatic review settings May 8, 2026 03:03
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 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/peerconn with an Event{State, Source, Destination} API and global SetListener/Notify* helpers.
  • Adds unit tests validating listener behavior and destination propagation/omission semantics.
  • Emits NotifyAccept(source, destination) and deferred NotifyClose(source) from protocol/samizdat inbound 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.

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