The pieces / weirdnet-service

weirdnet-service

A service framework: typed request/response services and live topic feeds behind an Authorize hook, over weirdnet-net.

v0.1.0 GitHub crates.io docs.rs weirdnet-service = "0.1.0"

What it brings

Use weirdnet-service when one server should serve many apps: typed calls and live feeds that desktop, terminal, mobile and MCP clients reach over weirdnet-net streams, with every call and subscription authorized first. The pattern comes from the model-node protocol in weirdnet-backends.

What it is

One server, many apps. A server exposes typed request/response services and live topic feeds; desktop, terminal, mobile and MCP clients connect over weirdnet-net streams, and every call and subscription goes through an Authorize hook first.

How it works

Services

Implement Service with request and response types shared by server and clients. access names the Access a request needs (a permission, optionally on a resource such as an account), and call gets the Admitted caller. A session is one stream: credentials once, then concurrent calls with ids, cancellation, per-call deadlines, and a bounded queue that answers Busy when full.

Authorization

The hook returns who was admitted: the user, device roles and the role on the resource. RosterAuth (roster) admits the user's own linked devices with the device roles the user granted them, from the weirdnet-sync 0.8 roster. MembershipAuth (access) checks owner-signed memberships from weirdnet-net and roles from weirdnet-access in its enforcement order. AllOf, AnyOf, AllowAll or a closure combine or replace them.

Live feeds

A Hub keeps each topic's state and a sequence number. Subscribers get a snapshot, then deltas; after a reconnect they resume from their last position, or get a fresh snapshot when the gap is too old or the server restarted. Publishing never waits: slow subscribers have their deltas coalesced by key and are re-snapshotted (or told to resume) when their queue overflows. Throttling, heartbeats and periodic re-authorization are optional, so a revoked device loses its stream. Live is a local copy of a topic's state that reconnects and resumes on its own.

Protocols

ProtocolId (/myapp/api/2) versions are served side by side, and Client::session_any picks the newest the server has. The core runs over any Channel; the net feature adds Server, NetDialer and stream channels. The protocol notes describe the messages.

Key types and modules

  • Service: your own request and response types. A session is one stream: credentials once, then concurrent calls with ids, cancellation, per-call deadlines and a bounded queue that answers Busy when full.
  • Access, Admitted, Authorize: each request names a permission, optionally on a resource; the hook says who was admitted and the handler gets it. RosterAuth, MembershipAuth, AllOf, AnyOf, AllowAll or a closure.
  • Hub: live feeds with a snapshot, then deltas, resume after a reconnect, coalescing for slow subscribers, throttling, heartbeats and periodic re-authorization. Live: a local copy of a topic that reconnects and resumes on its own.
  • ProtocolId: versioned protocol ids served side by side; Client::session_any picks the newest the server has.
  • Channel: the transport-neutral core; net adds Server, NetDialer and stream channels for weirdnet-net 0.8.

Feature flags

  • net (default): Server, NetDialer, stream channels and credential helpers over weirdnet-net 0.8.
  • roster: RosterAuth (weirdnet-sync 0.8).
  • access: MembershipAuth (weirdnet-access).

Usage

[dependencies]
weirdnet-service = "0.1.0"

Where it fits

Version 0.1.0 is on crates.io (docs.rs). The API may change before 1.0.