weirdnet-service
A service framework for Weird Brains servers on Weirdnet: 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.
- Typed services. Implement
Servicewith your own request and response enums (shared by server and clients). A session is one stream: credentials once, then concurrent calls with ids, cancellation, per-call deadlines, and a bounded queue that answersBusywhen full. - Authorization per request. Each request names an
Access(a permission, optionally on a resource such as an account). The hook returns who was admitted (user, device roles, role on the resource), and the handler gets it.RosterAuth(featureroster): the user's own linked devices and the device roles the user granted them, from the weirdnet-sync 0.8 roster.MembershipAuth(featureaccess): many people on one server. Owner-signed memberships from weirdnet-net and roles from weirdnet-access, checked in its enforcement order.AllOf,AnyOf,AllowAll, or a closure.
- Live feeds. A
Hubkeeps 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. Optional throttling, heartbeats, and periodic re-authorization, so a revoked device loses its stream. Live. A local copy of a topic's state that reconnects and resumes on its own, for a UI's background task.- Versioned protocol ids.
ProtocolId(/myapp/api/2), served side by side, withClient::session_anypicking the newest the server has. - Transport-neutral core. Services and feeds run over any
Channel; thenetfeature (default) addsServer,NetDialerand stream channels for weirdnet-net 0.8.
use Arc;
use ;
;
// On the server, inside a Tokio runtime:
// let server = weirdnet_service::net::Server::builder(&node)
// .service(&ProtocolId::new("/myapp/api", 1)?, Arc::new(Echo), auth.clone(), Default::default())
// .feed(&ProtocolId::new("/myapp/live", 1)?, hub, |topic| Access::new("read").on(topic.account()), auth, Default::default())
// .announce("myapp-server")
// .start()?;
// On a client:
// let session = client.session::<String, String>(&server_peer, &api).await?;
The protocol notes describe the messages, and the design notes explain the choices. API documentation is on docs.rs.
Features
| Feature | Default | Adds |
|---|---|---|
net |
yes | Server, NetDialer, stream channels and credential helpers over weirdnet-net |
roster |
no | RosterAuth (weirdnet-sync 0.8) |
access |
no | MembershipAuth (weirdnet-access) |
Status
The API may change before 1.0. The pattern comes from the model-node protocol in weirdnet-backends, which does not use this crate yet.
License
BSD-3-Clause, copyright Weird Brains LLC. See LICENSE.