Files
fips/docs/reference/nostr-events.md
Johnathan Corgan 51d34ac574 docs: correct documentation and comments that misstate the code
Corrections to the user, reference and design documentation and to
source comments where they disagree with the code. No behaviour or wire
change; the tests added here pin the behaviour the corrected text now
states.

Correct the OpenWrt tutorial on restricting port forwards.

The OpenWrt gateway tutorial said the FIPS mesh firewall is the layer
that limits which peers reach a port forward, pointed at the mesh
firewall how-to, and told readers to add a fips-firewall drop-in for
the listen port. None of that applies: the OpenWrt package ships
neither the mesh firewall baseline nor fips-firewall.service, and on
Linux the baseline hooks the input chain only and never sees a
forward to a LAN host. A reader following the text would leave the
forward open to every mesh peer that can reach the AP.

The tutorial now says that the package's fips zone accepts port
forwards from every mesh peer by default, and shows the fw4 rules
that restrict one: an accept for the allowed peer followed by a
REJECT for the rest, matching the target's port, with the note that
an accept alone restricts nothing because other peers fall through
to the packaged accept. The summary bullet and the troubleshooting
row point at fw4 instead of the mesh firewall, and Linux readers are
sent to the forward-hook recipe in deploy-gateway.md.

Describe conntrack-less pinning and BLE evictions correctly.

The gateway troubleshooting guide said that with no readable conntrack
source a mapping is reclaimed on its TTL and grace period alone. It
left out what the pool does on top of that: no mapping counts as
having carried traffic, so a re-query does not extend a name (only a
used mapping is refreshed, and the answer TTL is capped at the time
left since creation), and at the ceiling a new name can replace any
mapping. The guide now quotes the daemon's whole warning, states both
effects, and says when mappings count traffic again: those created
after conntrack reads have succeeded for three ticks in a row.

The doc comment on the BLE pool's eviction counter said it counts a
non-static peer being displaced. There is no static-peer notion in
the pool; it records the eviction of an unverified link past its
verify grace by a newcomer, which is the only kind the pool makes.

Bring the IPv6 adapter docs and comments in line with the code.

Several statements about the IPv6 adapter disagreed with the code:

- FIPS_IPV6_OVERHEAD was described as 77 bytes on top of the 106-byte
  FIPS_OVERHEAD; 77 is the total (106 + 4 + 7 - 40).
- The effective-MTU table called a 1472-byte transport the standard
  deployment; the UDP default is 1280.
- All ICMPv6 errors were said to be rate-limited by a per-source token
  bucket. Only Packet Too Big is limited, by a per-source minimum
  interval of 100 ms; Destination Unreachable is not limited.
- The TUN writer was said to clamp MSS on inbound SYN-ACKs only, and
  clamped SYN-ACKs were listed as one of its packet sources. The clamp
  acts on any SYN-flagged segment, in both the reader and the writer.
  The design docs, the MTU how-to, the writer's doc comments and its
  trace message now say so.
- The design doc said the reader needs no "is this for me?" check. It
  has one: a packet to the node's own address is written back to the
  TUN, which macOS utun needs.
- The app-owned TUN docs (design doc and the enable_app_owned_tun
  rustdoc) said FIPS neither filters off-mesh destinations nor answers
  them with ICMPv6 there, and that the embedder clamps only outbound
  SYNs. On that path an off-mesh destination is looked up and answered
  with Destination Unreachable on app_inbound_rx (an oversize packet
  with Packet Too Big), and no MSS is clamped in either direction.
- The transport_mtu fallback comment said "UDP first, then Ethernet";
  it takes a configured UDP instance's MTU, else 1280.

A new test pins the app-owned behaviour the rustdoc now states: an
off-mesh unicast destination is answered with Destination Unreachable
from the node's own address on app_inbound_rx, and a multicast
destination gets no answer.

State what the debug inject command and the outbound path do.

The debug_commands documentation (the config field's doc comment, the
configuration reference and the Inject parameters doc) said inject
writes only into one of the calling client's own flows, and so grants
the client nothing it does not already have. inject looks the flow up
by id in the node-wide flow table, so it can write into any flow on
the node, including one another client opened or a listener accepted;
the comment on the command itself and the native API reference already
said so. All three now say the same, and the claim that it grants
nothing new is gone.

The handle_native_outbound doc said an error is reported to the client
rather than as an ICMPv6 message. Nothing is reported: an oversize
datagram is counted in drop_oversize and dropped, a send or
session-initiation failure is logged at debug, and a datagram past the
pending-queue bounds is dropped. The doc now lists those.

Stop claiming a withdrawn advert is deleted with NIP-09.

The Nostr events reference, the discovery design doc and the generic
port-advertisement doc said the node withdraws its advert with a
NIP-09 kind 5 deletion when advertising is turned off or the responder
retires. The node never sends one. The delete plan is produced only
when advertising is off and an advert event id is recorded, but an id
is recorded only after a successful publish, which needs advertising
on, and the advertise flag is fixed when the advert machine is built.
A transient missing advert and shutdown both deliberately skip the
delete, because on relays that apply deletions strictly it can also
remove the replacement the next start publishes.

The docs now say that no deletion is sent, and that an advert the node
stops publishing stays on relays until its NIP-40 expiration,
advert_ttl_secs after publication, unless a newer advert replaces it.
The generic description keeps deletion as something a responder may
do, and says FIPS does not. The doc comments on the publish plan's
delete variant, plan_publish and clear_event_id now say that the
delete path is never reached by a running node, and why.

Correct the traversal signaling description.

The Nostr events reference and the design docs disagreed with the
signaling code in four places:

- inReplyTo was described as the offer's event id. The responder sets
  it to the offer's nonce, the initiator matches answers by nonce, and
  the validator refuses any other value as a session mismatch. An
  implementation written from the docs would have every answer dropped.
- The answer's PunchHint was said to tell both sides when to probe.
  Only the responder probes on it; the initiator does not read the
  hint and starts probing from its own punch_* settings when the
  answer arrives. Fixed in the reference, the port-advertisement doc
  and the discovery design doc.
- All three event kinds were said to be signed with the node's
  identity key. The kind 21059 wrap is signed by a one-time key; only
  the seal inside it is signed with the identity key.
- The FIPS advert example did not say that FIPS emits only the d,
  protocol, version and expiration tags and carries its signaling
  relays and STUN servers in the content as signalRelays and
  stunServers, present only with a udp:nat endpoint.

Two tests pin the behaviour the docs now state: an answer whose
inReplyTo is the offer's event id is refused as a session mismatch,
and a signal's wrap is signed by a key other than the sender's while
unwrapping recovers the sender's identity from the seal.

Label the second msg2 DH as a repeat of es, not se.

The IK msg2 code, the noise module doc, the wire-formats reference, the
mesh-layer design doc and the msg2 diagram all called the second DH in
msg2 `se`. Both sides actually pair the responder's static key with the
initiator's ephemeral key, which is msg1's `es` pairing, so the step
mixes the msg1 `es` value a second time and nothing computes Noise IK's
`se`.

Relabel it as `es` again everywhere, say in the code that it is not
Noise's `se`, that it is the FMP v1 wire format and cannot change
without breaking v1 peers, and that it leaves FMP v1 open to key
compromise impersonation (FRC-1201 Section 9.3). Rename the two local
bindings to `es2`. No behaviour or wire change.

Correct the path MTU notification doc and the fips-mtu design doc.

The PathMtuNotification doc said it is sent by a node that learns a path
MTU from transit router feedback or ICMP Packet Too Big. It is sent by
the session destination, echoing the forward-path minimum it saw in the
envelope's path_mtu; a received MtuExceeded only updates local state.

fips-mtu.md said TCP reports a per-connection MTU from TCP_MAXSEG. TCP
reports the configured mtu and checks sends against it. It also said the
TCP clamp mirror is tighter-only and never loosened. Entries are
released on PathBroken (at most once a second per destination), peer
removal and session timeout, discovery-learned entries expire with the
coordinate cache TTL, and a link seed from a different transport
replaces the stored value. Describe that lifecycle, and add a short
section on the defences against forged signals: the 256-byte floors,
the admission gate, corroboration against what this node has sent, and
the rate-limited release.

Correct transport comments and docs on TCP MTU, mDNS, BLE, Ethernet, Tor and UDP.

Several transport comments and docs described behaviour the code does
not have:

- TCP: the config doc, configuration reference and transport-layer doc
  said the per-connection MTU comes from TCP_MAXSEG. TCP reports the
  configured mtu to FMP and checks sends against it.
- mDNS: the module and supervisor comments said identity is proven by a
  Noise XX handshake. FMP here is Noise IK. Drop the note in the Nostr
  discovery doc that pointed at those comments.
- BLE: the pubkey-exchange prefix doc said it is distinguished from FMP
  packets of version 1 or more. FMP is version 0, so the framer cannot
  tell them apart, as the caution below it already says.
- Ethernet: the config doc said the runtime requires Linux. It is built
  for Linux (AF_PACKET) and macOS (BPF).
- Tor: the config and transport docs, and the onion-service how-to,
  said control_port mode runs an inbound onion service. It only adds
  control-port monitoring to SOCKS5 outbound; directory mode is the
  only inbound mode.
- UDP: the security reference said a UDP instance has no inbound
  exposure until bind_addr is set. A declared UDP instance listens on
  0.0.0.0:2121 by default unless outbound_only is set.

Correct the spanning tree docs on signatures, sequence, sizes, cache invalidation and flap dampening.

- The TreeAnnounce signature was described as covering the entire
  message. It covers SHA-256 of the 48-byte declaration (node_addr,
  parent, sequence, timestamp); version and ancestry are not signed.
- The sequence was said to increment on parent change. It also
  increments on becoming root and on an ancestry change under the same
  parent.
- The TreeAnnounce size table added msg_type twice in the link-overhead
  column. The measured sizes are 168/264/328/488 bytes; note the 36-byte
  link overhead under the table.
- Several design docs and a rate-limit comment said a parent change
  flushes the coordinate cache. The node drops only cached coordinates
  that route through it (parent switch or ancestry change) or sit under
  another root (becoming root), and both on parent loss or loop
  detection.
- Flap dampening was described as engaging after more than
  flap_threshold switches in a sliding window. It engages when the count
  reaches flap_threshold, within a fixed window opened by the first
  switch.

Correct the bloom filter frame size, triggers and propagation bound.

- The wire-formats reference gave the v1 FilterAnnounce with link
  overhead as 1,072 bytes. It is 1,071 (1,035 payload plus 16 header,
  4 timestamp and 16 tag), as the bloom design doc already says.
- The bloom design doc listed local state changes (new identity,
  leaf-only dependent changes) as a send trigger. The identity does not
  change at runtime and nothing outside the tests adds a leaf-only
  dependent, so drop it.
- The bloom and spanning tree docs bounded propagation at about 500 ms
  per hop. Announces leave only on the node's maintenance tick, so the
  bound is about one node.tick_interval_secs per hop (1 s by default);
  the 500 ms debounce is a floor below that.

Correct forwarding docs on ranking, loop freedom and the coordinate cache.

- The mesh-operation doc called link_cost an uncommon tie-breaker
  resolved by tree distance. Candidate ranking compares link cost first;
  tree distance and node_addr break ties.
- Several docs and comments said the strict-progress check prevents
  routing loops even with stale coordinates. Each hop judges progress on
  its own cached coordinates for the destination, so the check does not
  guarantee loop freedom when hops hold different coordinates. Say that,
  and that the TTL bounds any loop.
- The session-layer doc said FMP can fall back to bloom-only routing
  without cached coordinates. find_next_hop returns no next hop on a
  cache miss and the caller signals CoordsRequired.
- The insert_coord_hint doc said a foreign-root destination can never
  be selected by the bloom step. A peer advertising coordinates under
  that root can be; the refusal stands for the reflector reason given
  in the same paragraph.
- The find_next_hop and try_warm_coord_cache_ref doc blocks sat above
  the wrong functions, so rustdoc gave those two no docs and gave
  insert_coord_hint and warm_coord the wrong opening line. Move each
  block onto its function and fix the find_next_hop ranking wording.

Correct FSP restart handling, error datagram sizes and XK labels.

- The session-layer doc said an epoch mismatch on a later handshake
  marks a peer restart and triggers re-establishment. FSP exchanges the
  epoch but never reads it. A SessionSetup naming an established peer
  only arms a handshake beside the running session, and new keys are
  adopted at msg3 only when the authenticated static key matches.
  Describe that, and rename the status row accordingly.
- Wire-format sizes: SessionDatagram + CoordsRequired is 74 bytes, not
  70; SessionDatagram + PathBroken is 76 + 16n, not "70+"; PathBroken
  alone is 40 + 16n, not 35 + 16n; CoordsRequired with link overhead is
  110, not 111; and the CoordsWarmup example is 238, not 239. State in
  the summary table which rows include link overhead.
- Three FSP wire comments called the session handshake Noise IK. It is
  Noise XK, as the module's own phase table says.

Correct the rationale for dropping our own looped-back request.

The comment on the own-request check in classify_request, its test and
the handle_lookup_response doc said that without the check the answer to
our own lookup would be reverse-path forwarded to the peer that looped
the request, and that recent_requests decides originator status. That
stopped being true when classify_response began deciding originator
status from the pending lookup before it reads the transit record.

Say what the check still does: it stops the copy being forwarded a
second time and keeps our own id out of the transit record, so a
response after the lookup completes has nothing to be relayed by. Extend
the test to pin that: once the lookup is accepted, a later response for
the same id is unsolicited.
2026-10-23 04:48:35 +00:00

9.4 KiB
Raw Permalink Blame History

Nostr Event Reference

The Nostr-protocol surface FIPS uses for discovery and signaling. For the design of the discovery runtime and the rationale behind these event shapes, see ../design/fips-nostr-discovery.md. For operator activation recipes, see ../how-to/enable-nostr-discovery.md.

FIPS uses three Nostr event kinds:

Kind Name Encryption Storage Purpose
37195 Overlay advert None (signed only) Replaceable Publish reachable transport endpoints
21059 Traversal signaling NIP-44 inside NIP-59 gift wrap Ephemeral Carry TraversalOffer/TraversalAnswer payloads
10050 NIP-17 inbox relay list None (signed only) Replaceable Tell dialers where to publish offers

Kinds 37195 and 10050 are signed with the node's FIPS identity key (the same secp256k1 keypair Nostr uses); there is no separate Nostr key. A kind 21059 event carries a seal signed with that key inside a wrap signed by a one-time key, so relays do not see the sender (see Encryption envelope).

Kind 37195 — Overlay Advert

A parameterized replaceable event in the application-defined replaceable range 30000–39999 (the digits visually spell FIPS: 7=F, 1=I, 9=P, 5=S). Each node has a single in-place-updatable advert under its identity.

Tags

  • d — fixed to the literal fips-overlay-v1 (the application identifier baked into the binary). Together with pubkey, this identifies the unique replaceable event slot.
  • protocol: the configured node.rendezvous.nostr.app value (default fips-overlay-v1). Distinct from the d tag so the application string can evolve without breaking the replaceable event slot.
  • version — protocol version string (currently "1").
  • expiration — NIP-40 expiration timestamp set to now + node.rendezvous.nostr.advert_ttl_secs (default 3600 seconds). Conforming relays stop serving the event after this time.

Content

The event content is a JSON document shaped as OverlayAdvert:

{
  "identifier": "fips-overlay-v1",
  "version": 1,
  "endpoints": [
    {"transport": "udp", "addr": "203.0.113.45:2121"},
    {"transport": "tor", "addr": "xxxxx.onion:8443"},
    {"transport": "udp", "addr": "nat"}
  ],
  "signalRelays": ["wss://relay.damus.io", "wss://nos.lol"],
  "stunServers": ["stun:stun.l.google.com:19302"]
}

Field semantics:

Field Type Description
identifier string Application namespace; must match the d tag.
version integer Advert schema version (currently 1).
endpoints array List of transport endpoints. Each is {transport, addr} where transport is "udp", "tcp", or "tor", and addr is "host:port", ".onion:port", or the literal "nat" (for UDP NAT-punch).
signalRelays array? Optional. Relays the publisher prefers for offer/answer signaling. Present only when at least one endpoint is udp:nat.
stunServers array? Optional. STUN servers the publisher uses for reflexive discovery. Present only when at least one endpoint is udp:nat. Informational — peers do not use these to choose their own STUN targets.

Signature scope

The Nostr event signature covers the standard Nostr event ID (serialized [0, pubkey, created_at, kind, tags, content]), so the content JSON, tags, kind, and timestamp are all bound to the signing identity.

Replacement and deletion

Because kind 37195 is replaceable, a new advert replaces the prior one in the same (pubkey, d-tag) slot. The node sends no NIP-09 deletion for its advert. An advert it stops publishing (advertising turned off at a restart, no publicly usable endpoint left, or shutdown) stays on relays until its NIP-40 expiration, advert_ttl_secs after it was published, unless a newer advert replaces it first. A deletion is not sent because, on relays that apply it strictly, it can also remove the replacement the next start publishes.

Kind 21059 — Traversal Signaling

An ephemeral event (kinds in the 20000–29999 range are not stored by conforming relays). Used to deliver gift-wrapped, NIP-44-encrypted TraversalOffer and TraversalAnswer payloads between dialer and responder during a UDP NAT hole-punch.

Encryption envelope

The wire shape is the standard NIP-59 gift wrap:

  1. Rumor — the unsigned TraversalOffer/TraversalAnswer payload (JSON), authored by the actual sender's identity.
  2. Seal — a kind 13 event whose content is the rumor NIP-44-encrypted to the recipient's pubkey, signed by the sender.
  3. Gift wrap — a kind 21059 event whose content is the seal NIP-44-encrypted to the recipient under an ephemeral key, signed by that ephemeral key. The outer pubkey of the kind 21059 event is the ephemeral identity, not the sender's real identity.

Only the intended recipient can decrypt the wrap to recover the seal, and only the recipient can decrypt the seal to recover the rumor.

Wrapped payloads

The TraversalOffer carries:

  • type — message-type tag.
  • sessionId — unique identifier correlating offer and answer.
  • senderNpub / recipientNpub — bech32-encoded pubkeys, repeated inside the encrypted payload (the outer wrap pubkey is ephemeral).
  • issuedAt / expiresAt — Unix-ms timestamps; expiresAt is issuedAt + signal_ttl_secs * 1000.
  • nonce — random per-offer value.
  • reflexiveAddress — {protocol, ip, port} observed via STUN, or null if STUN failed or returned no usable address.
  • localAddresses — array of {protocol, ip, port} private candidates, populated when share_local_candidates is enabled.
  • stunServer — the STUN server actually used (informational).

The TraversalAnswer echoes sessionId and carries:

  • type, senderNpub, recipientNpub, issuedAt, expiresAt, nonce — same shape as the offer.
  • inReplyTo — the offer's nonce; an answer naming anything else is refused.
  • accepted — boolean; false when the responder has no usable addresses.
  • reflexiveAddress and localAddresses — the responder's candidates, in the same shape as the offer.
  • stunServer — informational.
  • punch — a PunchHint { startAtMs, intervalMs, durationMs }: the responder's own probing schedule, which the responder probes on. The initiator does not read the hint; it starts its own probing when the answer arrives, on its local punch_start_delay_ms, punch_interval_ms and punch_duration_ms. Absent on rejected offers.
  • reason — optional rejection string when accepted is false.
  • offerReceivedAt — optional responder wall-clock (Unix ms) at the moment it received the offer; the initiator uses this to derive a clock-skew estimate.

Relay selection

Dialer publishes offers to the merge of the recipient's inbox relay list (kind 10050), the signal relays its advert names, and the local node.rendezvous.nostr.dm_relays list, kept to relays already in the dialer's own relay pool. The responder, which has no advert for the dialer, answers the same way from the dialer's inbox relay list and its own dm_relays.

Kind 10050 — NIP-17 Inbox Relay List

A standard NIP-17 event used by FIPS to advertise which relays this node prefers for receiving direct-message-style signaling — for FIPS, the gift-wrapped traversal offers (kind 21059).

This is NIP-17 (kind 10050, inbox relays for DM delivery), not NIP-65 (kind 10002, general read/write relay list). The two serve different purposes:

  • Kind 10002 (NIP-65) — general read/write relays for ordinary event publication and subscription.
  • Kind 10050 (NIP-17) — relays the recipient prefers for receiving DM-shaped (NIP-59 wrapped) events.

FIPS publishes its own kind 10050 to its dm_relays on startup and every 24 hours after, so dialers can discover where to send traversal offers. When dialing a peer, FIPS fetches the peer's newest kind 10050 no older than 30 days from its own dm_relays and advert_relays, not from the peer's. It falls back to the local dm_relays list when the fetch fails or the list is absent or empty.

Tags

FIPS emits each relay as an r tag whose single value is the relay URL. This is not the NIP-17 form, which is a relay tag (["relay", "wss://nos.lol"]), so other NIP-17 clients do not read a list FIPS publishes. FIPS reads both forms; an r tag carrying a NIP-65 read or write marker is ignored.

["r", "wss://relay.damus.io"]
["r", "wss://nos.lol"]

Content

Empty per NIP-17.

See also