Trying to consolidate some of the more recent discussions we’ve had on discord here.
Some of these architecture choices have been pretty much settled, but I’m still open to feedback, especially on the last thing.
Wire Format — Settled (mostly)
We’re going to do JSON as a mandatory baseline, and Cap’n Proto as optional negotiated upgrade.
The idea is that JSON support keeps the barrier of entry low for devs because they can curl endpoints and read responses to understand what is going on. Given that we’re a federated protocol, I want to make things as simple as possible for 3rd party implementations.
Cap’n Proto is going to be available as an optional performance tier for clients and servers that want it. This is going to be especially useful in situations where we have more constrained transports – like meshtastic – where bytes actually matter.
Negotiation for this will happen via Content-Type/ Acceptheaders on HTTP endpoints and a negotiation step in the WebTransport/WebSocket handshake. Servers will advertise supported encodings in their .well-known/cryptid files.
When we actually get around to making the .capnpschema files, we must treat them as first-class spec artifacts, not an afterthought in the reference implementation. If someone wants to make a Cryptid server in, say, Go, the schema should be right there in the spec repo.
Transport Layer — Settled (for v1.0 at least)
We’ll be doing WebTransport (QUIC) as primary, WebSocket as fallback, and HTTP polling as last resort.
WebTransport gives us the same bidirectional streaming semantics as WebSockets but with QUIC underneath it. We want QUIC because it’ll give us better performance on flaky networks among other benefits. The existing WebSocket message protocol maps directly onto WebTransport with minimal changes.
So, the fallback ladder is going to be:
- WebTransport over QUIC
- WSS over HTTP/1.1
- Polling
GET /v1/messages
Servers will advertise support in their .well-known/cryptid under a supported_transports array. The one slightly awkward point here is going to be encoding negotiation on persistent connections, encoding is going to get settled during the auth handshake and end up sticking for the connection lifetime.
Transport Abstraction (TransportTrait) — Early Design Phase
@randomscientist gave me abstraction brainworms in the chat yesterday and I’ve been toying with the idea of having a pluggable transport layer. This would allow Cryptid messages to flow over things other than HTTP. Meshtastic nodes, radio, whatever.
The interface contract might end up looking roughly as follows:
send(address, payload): delivers an opaque blob to a deliver addressincoming(): stream of received envelopescan_reach(address): whether this transport can reach a given addresscapabilities(): MTU, latency class, reliability guarantee, store-and-forward support, etc
The client would have a transport router that, given a delivery address, picks the best available transport that claims it can reach that address.
This would require 2 breaking changes to the spec:
- Address system extension: The current
{uuid}@{domain}format implicitly assumes HTTP. Devices will be able to advertise alternate transport addresses in their announcement alongside their primary HTTP delivery address. So a device might be reachable ata1b2c3d4e5@chat.example.com(primary) and, say,mesh:!a1b2c3d4(alternate). The sending client’s router intersects what the recipient advertises with what it supports locally. - Announcement protocol extension:
POST /v1/announcegets analternate_transportsarray where devices can advertise non-HTTP reachability, including transport type, address, and capabilities (e.g., max payload size, whether fragmentation is needed, etc)
In addition to the above changes, we’ll need an extension for .well-known/cryptidso that servers can advertise gateway capability. For example, a server with a meshtastic radio attached, can act as a HTTP ←→ mesh bridge for clients that don’t have direct radio access.
Thankfully, the message envelope itself doesn’t need to change. It’s already transport-agnostic seeing as how it’s just opaque bytes. This means that the entire delivery stack stays the same regardless of what carries the bytes.