Skip to main content

Crate spotproto

Crate spotproto 

Source
Expand description

Wire protocol for the Spot real-time messaging network.

Each client establishes one or more websocket connections to spot servers. Packets are already encapsulated (known length), so every packet starts with a single byte carrying the protocol version (high 4 bits, currently 0) and the packet type (low 4 bits), followed by type-specific data:

  • 0x0 ping (C→S) / pong (S→C)
  • 0x1 handshake request (S→C) or response (C→S), CBOR encoded
  • 0x2 instant message, binary encoded

This crate is a Rust port of the Go package github.com/KarpelesLab/spotproto and is wire compatible with it.

Structs§

ClientId
A client identifier in the protocol, in the form type.target or type.server_id.target.
HandshakeRequest
Handshake request, sent from server to client to initiate (or complete) the handshake (packet type 0x1, S→C). CBOR map with fields rdy, srv, cid, rnd and grp.
HandshakeResponse
Handshake response, sent from client to server (packet type 0x1, C→S). CBOR map with fields id, key and sig.
Message
An instant message exchanged between hosts (packet type 0x2).

Enums§

Error
Errors returned by the protocol parser and serializers.
Packet
A parsed protocol packet.

Constants§

HANDSHAKE
Handshake request or response packet type id.
INSTANT_MSG
Instant message packet type id.
MSG_FLAG_ERROR
The message body contains an error string.
MSG_FLAG_NOT_BOTTLE
Body is not an encrypted bottle. Normally messages must be encrypted for the recipient and signed by the sender using a bottlers::Bottle, but some protocols skip this for efficiency or when payloads are already encrypted by another mechanism.
MSG_FLAG_RESPONSE
This is a response message that must not trigger further responses.
PING_PONG
Ping/pong keep-alive packet type id.

Functions§

base64url_decode
Decodes url-safe base64 without padding. Returns None on invalid input.
base64url_encode
Encodes bytes as url-safe base64 without padding.
parse
Decodes a raw buffer into the appropriate Packet. is_client indicates whether this is parsed on the client side, which decides how handshake packets are interpreted.
version_and_packet
Returns the version and packet id encoded in a packet’s first byte.