Skip to content

FMSG-006 indicators over UDP 4930 - #53

Merged
markmnl merged 1 commit into
mainfrom
fmsg-006-indicators
Oct 31, 2026
Merged

markmnl merged 1 commit into
mainfrom
fmsg-006-indicators

Conversation

@markmnl

@markmnl markmnl commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Implements FMSG-006 Indicators host to host, paired with markmnl/fmsg-webapi#64.

Receive (UDP on the TCP listen address and FMSG_PORT), following the spec's steps in order and dropping silently at the first that fails:

  1. A per-source-IP token bucket (50/s, burst 100). Idle sources are pruned and the table is capped.
  2. Parse the fixed layout; trailing bytes are invalid. The data must be one emoji (FMSG-005 rules, via a copy of fmsg-webapi's internal/emoji) of at most 64 bytes.
  3. Find the subject by msg.sha256, then by msg_add_to_batch.sha256. Participants are read from that row's stored wire header (From, To, then AddToFrom and AddTo for a batch), not from loadMsg, which merges batches.
  4. Resolve the index to an address. Out of range: drop. An address this host serves: drop.
  5. Check the source IP is in fmsg.<that domain>, using a 60 s indicator-only DNS cache. FMSG_SKIP_AUTHORISED_IPS is honoured.
  6. Clamp the ttl to 120, then NOTIFY indicator with {id, from, emoji, ttl} for the web API's hub.

It never replies and never stores anything.

Send:

  • A pq.Listener on indicator. It ignores notices whose from this host doesn't serve, which is the loop guard.
  • For each remote participant domain it picks the subject that domain holds and that contains from: the original, else the first add-to batch with both. The index is from's lowest position.
  • Rate limits:
    • 1 per (subject, index) per 2 s, coalesced to the latest; clears are exempt;
    • 20/s per receiving domain.
  • Sends from the listening socket (WriteTo) to FMSG_REMOTE_PORT, alternating between the domain's addresses. ICMP is ignored.
  • FMSG_INDICATORS=false turns both directions off. If the UDP bind fails, fmsgd logs it and keeps TCP running.

Tests:

  • datagram round trip, exact bytes and every invalid shape;
  • participant order and subject selection;
  • the limiters and the DNS cache, with a fake clock;
  • sending: interval and coalescing, the clear exemption, the per-domain limit, address alternation, loopback UDP;
  • against Postgres:
    • a NOTIFY for an original and for a batch recipient;
    • drops for a wrong source, an unknown hash, a local participant and an out-of-range index;
    • the skip flag and the per-IP limit;
    • end-to-end over loopback.

go test -race ./... and go vet pass. README: new section, plus FMSG_INDICATORS. Firewalls need UDP 4930 in and out.

Notes:

  • Original received only via add-to: an original whose own wire form wasn't stored is still used as a subject. Its participants come from its first batch's From and To (SPEC §12: an add-to repeats them unchanged).
  • Forks: isIndicatorLocalDomain is the one function to change for a multi-domain host.

🤖 Generated with Claude Code

Listen for indicator datagrams on UDP at the TCP address and port, and
send local participants' indicators from the same socket.

Receiving drops a datagram at the first failing step: a per-source rate
limit (50/s, burst 100); parsing (version 1, exact fields, data empty or
a single emoji of at most 64 bytes); the subject by hash, as a message or
an add-to batch message; the participant index in that subject's exact
wire header, which must not be on this host's domain; and the source
address against fmsg.<domain> (cached 60s, skipped with
FMSG_SKIP_AUTHORISED_IPS). An accepted indicator, ttl clamped to 120, is
published on the PostgreSQL NOTIFY channel "indicator" as
{"id","from","emoji","ttl"} for the client API to deliver.

Sending LISTENs on the same channel. For an address this host hosts, it
picks per remote participant domain the subject that domain holds and
the indicating participant is in (the original, else the first add-to
batch with both), uses the lowest index, and sends to one address of
fmsg.<domain>, alternating. At most one datagram per subject and index
every 2s, coalescing to the latest; clears go at once; at most 20 per
second per receiving domain.

FMSG_INDICATORS=false or 0 turns both off. The emoji package is the one
used for FMSG-005 reactions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markmnl
markmnl merged commit eea3c97 into main Oct 31, 2026
2 checks passed
@markmnl
markmnl deleted the fmsg-006-indicators branch October 31, 2026 09:27
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