Skip to content

mesh: answer a newcomer, keep presence 10 s apart (NFX-10 §6.6); §6.2 early gathering - #149

Draft
SovereignTechnology wants to merge 1 commit into
mainfrom
mesh/answer-newcomers
Draft

SovereignTechnology wants to merge 1 commit into
mainfrom
mesh/answer-newcomers

Conversation

@SovereignTechnology

Copy link
Copy Markdown
Owner

Two gaps the spec review of main (93f52f4) found in NFX-10 §6: one in how a newcomer meets a room, and one in how long a peer gathers candidates.

1. Telling a newcomer (§6.6)

Relays keep no ephemeral event, so a session that joins a room hears of a member only at the member's next presence, up to 30 s away. When the newcomer's key is the lower one, the newcomer is the one to offer (§6.6 glare), so it waits for that presence. nfxd already answered such a newcomer with an out-of-turn connect. The spec said nothing about it, and the web client did not do it.

  • Telling a newcomer. On a valid connect from a peer it held no presence for, whose key is lower, and with room for another peer, a session sends its own connect again, out of turn. A node does so each time; a page at most once per 30 s per room, since most members of a busy room are pages.
  • Spacing. A session never sends two connects in one room less than 10 s apart, out of turn or not. NFX-04 §2 admits one presence per 10 s per key, room and type, and nfxd's 5 s was under that, so a scoped relay could refuse it. A connect due sooner is sent when the 10 s have passed, not dropped, and one such serves every newcomer seen meanwhile. A connect sent only to a relay that has just been connected is not counted.

nfxd (nfx-node/src/mesh/mod.rs):

  • RoomState::presence_now gates the join, the 30 s round and the newcomer answer.
  • The tick sends a deferred presence when it falls due, and next_wake includes it.
  • The gap is nfx_proto::signal::PRESENCE_MIN_GAP (10 s), which replaces REANNOUNCE_EVERY (5 s, and dropped when early).

Page (signal-book.ts, signal-nostr.ts): PresenceClock does the same timing. The signaler now answers a newcomer that is to offer, when it has room for another peer.

2. Gathering (§6.2)

§6.2 said a peer waits for ICE gathering to finish, at most 5 s, so a STUN server that never answers cost 5 s per side. The page already stops 300 ms after its first server-reflexive candidate (#130). The text now allows that, and lets a native client gather once and reuse it, as nfxd does. No code changes for this part.

Nothing on the wire changes. NFX-10's changelog has the entry.

Tests

All in Kata:

  • fmt; cargo test --no-fail-fast for nfx-proto and nfx-wasm, nfx-node lib (104, presence_keeps_10_s_apart_and_one_due_sooner_waits new; the_lower_key_offers_and_its_offer_stands now checks that a second newcomer within 10 s is deferred, not dropped) and the mesh e2e (7);
  • clippy -D warnings; the nfxd and nfx-package build;
  • the player's wasm, typecheck and build; unit.ts 824/824 (the PresenceClock cases new), sources-unit.ts, fetcher-unit.ts, policy-unit.ts and book-unit.ts;
  • e2e:nostr-node, e2e:nostr, e2e:peer-first and e2e: PASS. e2e:nostr settles with no timers or sockets left, so the page's deferred presence is cleared when it leaves.

Merging

Held until the nfx 0.1.4 cut is fixed: this changes nfxd's mesh code and must not ship in 0.1.4. This touches mesh/mod.rs and signal-nostr.ts, as #142 (W2) does. W2's video-room presence (§6.9 in #133) follows the same 10 s rule, and #142 will take this from main.

…'s early gathering

From the spec review of main 93f52f4.

- NFX-10 §6.6 says how a member tells a newcomer it is there. Relays keep no ephemeral
  event, so a newcomer whose key is lower (it is the one to offer) waited for the member's
  next presence, up to 30 s. On a newcomer's `connect`, a member with room for another peer
  sends its own out of turn: a node each time, a page at most once per 30 s per room.
- No two `connect`s of a session in one room go less than 10 s apart, as NFX-04 §2 admits
  one presence per 10 s per key, room and type (nfxd answered every 5 s, which a scoped
  relay may refuse). One due sooner is deferred, never dropped, and serves every newcomer
  seen meanwhile.
- §6.2 allows what the page already does: stop gathering 300 ms after the first
  server-reflexive candidate, so a STUN server that never answers no longer costs 5 s per
  side; a native client may gather once and reuse it.

nfxd: `RoomState::presence_now` gates the join, the 30 s round and the newcomer answer, and
the tick sends a deferred presence when it falls due (nfx-proto `PRESENCE_MIN_GAP`). Page:
`PresenceClock` (signal-book.ts) does the same for the signaler, which now answers newcomers.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sovtechpro sovtechpro Bot added the size/L Lines changed by this pull request: L (sovtechpro[bot]) label Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Lines changed by this pull request: L (sovtechpro[bot])

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant