Skip to content

feat(ws): opt-in includeRepeats streams later hearings over new paths - #178

Merged
MrAlders0n merged 1 commit into
devfrom
feat/ws-include-repeats
Sep 28, 2026
Merged

MrAlders0n merged 1 commit into
devfrom
feat/ws-include-repeats

Conversation

@MrAlders0n

Copy link
Copy Markdown
Member

A flood packet reaches an observer more than once: first from the nearest repeater, then again whenever a repeater further out rebroadcasts it, each time over a different path. We only store and stream the first hearing per (packet, observer), because the observation insert is ON CONFLICT DO NOTHING and the event is only built when the row went in. That's the right behaviour for storage, but a live map that animates a packet spreading through the mesh never sees most of the spread.

This adds a connection-wide opt-in, configure { includeRepeats: true }. Clients that send it also get those later hearings as ordinary packetObservation events with packet.isRepeat: true. Clients that don't opt in see byte-identical events.

How it works:

  • Nothing is stored for a repeat. It's built from values handlePacket already has in hand for duplicates, and it skips GetPacketObservationCount, so observationCount is 0 on repeats.
  • Exact copies are skipped. Most duplicates are the same hearing arriving via another broker, or the same path twice. The hub keeps a small shared set of (packet, observer, path) it sent in the last 2 minutes, capped at 200k hashed keys, and only new paths go out.
  • Repeats can't cost first hearings. They go through BroadcastRepeat, which drops the repeat once the broadcast channel is half full. Those drops are counted and logged at most once a minute.
  • Nearly free when nobody opts in. A duplicate costs one atomic load, with no JSON encoding and no query.

The protocol change is backwards compatible. An older server ignores the unknown includeRepeats field, and the new field is omitempty.

Tests cover hub routing and the opt-in counter, the drop-first path, the sent-path store (window, new path, size bound), handlePacket end to end (first hearing, broker copy, new path, same path again, opt-in off, no count query on repeats), and a real configure round trip through the handler. No API or swagger changes.

Duplicate observations are dropped before the hub today, so a live map only sees each packet's first hearing per observer. Clients that configure includeRepeats also get later hearings whose path is new; nothing is stored, repeats skip the count query, and they are dropped first when the broadcast channel is half full.
@MrAlders0n
MrAlders0n requested a review from 446564 as a code owner September 28, 2026 00:33
@MrAlders0n
MrAlders0n merged commit 876d997 into dev Sep 28, 2026
3 checks passed
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