Skip to content

feat(core): gossip directory, self-advert and extension rules in the Rust session - #438

Merged
Mearman merged 6 commits into
mainfrom
feat/rust-gossip-directory
Nov 26, 2026
Merged

Mearman merged 6 commits into
mainfrom
feat/rust-gossip-directory

Conversation

@Mearman

@Mearman Mearman commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Merging publishes a patch of wire-mesh-core with no change to its content (a test file under ts/packages/core/test changes), plus the range rewrites of the packages that depend on it; nothing from rust/ is published.

Gives a Rust session the gossip role: it sends its own signed advert after its handshake, verifies each advert it receives and keeps the newest per device in a peer directory, and answers version.get without a handler. Fixes #376. Refs #432.

The rules the TypeScript session applies are ported as three modules, each with a test that fails by name when its rule is broken:

  • gossip_extensions refuses an extension key that would shadow a mandatory advert field, the session-managed topology or the reserved version key, or that is not <domain>/<field> in lowercase kebab-case, and names the first key refused.
  • gossip_directory verifies every advert on its own, so one that does not verify is dropped alone. The newest advert per device wins by its signed snapshot time, never by arrival, and a re-advert replaces in place, so the directory keeps first-heard order. Unlike the TypeScript it is bounded, since adverts come from a hub that is not trusted to bound them: a device count and an encoded size per advert, refused and not evicted beyond either (a full directory stays full until the session ends). The decisions that need no signature (size, snapshot range, an older advert, a full directory) come before the signature check, so replayed or flooding adverts cost no verification. A frame yields one AdvertsRefused event with the count and the first refusal, however many adverts it carries.
  • self_advert builds and signs the node's own advert with its version and its topology, recomputed on every call, and refuses a clock before 2001, which is not a wall clock. The first advertised peer is taken as the direct peer only on an accepted connection; the connection port has no authenticated peer, so a peer that first sends a genuine advert of another device makes the node's adverts name that device as direct, a misstated edge and nothing more, which an authenticating transport removes.

Session::accept_with takes SessionOptions for a relay client, gossip, or both. A peer that sends no handshake within the timeout is reported as HandshakeUnanswered, which is what a relay-only hub produces and not an error.

conformance/gossip-directory.v1.json is new and both implementations run it: the extension rules, the directory scenarios and the self-advert structure, with really signed adverts under fixed keys. The size cap is a scenario only the Rust runner applies. The interop test gains a case where the Rust example joins the TypeScript hub, learns a TypeScript peer from the hub's gossip, and its own advert verifies there and names its version.

The first commit is the cleanup the interop review asked for: a case that fails to start no longer leaves the relay peer process or the hub listener behind, and the build output limit is a named constant.

Not in this change: the per-request refusal (#428), and the unbounded events queue and the task per manage-request (#431, whose scope now includes the gossip events).

…e fails to start

`serving()` started the hub, spawned the Rust node and awaited its output before the caller's
try, so a rejection there left the child running and the hub listening.
It now stops the node, closes the peer and the hub itself and rethrows, and a case that forces a
failure after the node has announced asserts that no process and no listener is left.
The build call also sets `maxBuffer`, since it prints a JSON line per artefact and the default
limit is easily passed.
…lf-advert

`domain::gossip_extensions` refuses an extension key that would shadow a mandatory advert field, the
session-managed topology or the reserved version key, or that is not `<domain>/<field>` in lowercase
kebab-case.
`domain::gossip_directory` verifies each advert of a gossip frame alone and keeps the newest advert
per device by its signed snapshot time, in first-heard order.
It is bounded in devices and in the size of an advert, and refuses beyond either without evicting.
`domain::self_advert` builds and signs this node's own advert with its version and its topology.
`SessionOptions` carries a relay client, gossip, or both into `Session::accept_with`.
A session that gossips sends its own signed advert after its handshake, verifies each advert it
receives and keeps the newest per device in a directory (`Session::directory`), and reports
`DirectoryChanged` and `AdvertRefused` events.
`send_gossip_update` sends a fresh advert with extensions the caller's validated keys.
A peer that sends no handshake within the timeout is reported as `HandshakeUnanswered`, which is
what a relay-only hub produces, and every session answers `version.get` without a handler.
…ementations

`gossip-directory.v1.json` holds the extension rules, the directory scenarios and the self-advert
structure, with adverts really signed under fixed keys.
Both runners read it, and the interop test gains a case where the Rust node learns a TypeScript
peer from the hub's gossip and its own advert verifies there.
…refusals once per frame

The directory checks size, snapshot range, an older advert for a known device and a full
directory before it verifies a signature, so replayed or flooding adverts cost no signature check.
A frame yields one `AdvertsRefused` event with the count and the first refusal, and one
`DirectoryChanged` per distinct device, so its size no longer sets the number of events.
A self-advert is refused for a clock before 2001, which is not a wall clock.
The example reads the system clock, and the docs say what a full directory and a replayed first
advert do.
@Mearman
Mearman force-pushed the feat/rust-gossip-directory branch from 3026b45 to c30daff Compare November 26, 2026 10:52
@Mearman
Mearman marked this pull request as ready for review November 26, 2026 11:00
@Mearman
Mearman merged commit 355e5fd into main Nov 26, 2026
11 checks passed
@Mearman
Mearman deleted the feat/rust-gossip-directory branch November 26, 2026 11:01
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.

Rust: gossip directory in the session runtime

1 participant