Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 62e9d42

Browse files
committed
extend websocket sections
1 parent f9b4998 commit 62e9d42

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

docs/Protocol Specifications/core.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ of the specification document: **v0.1.0-alpha.1**
2222
- [2. Trust model](#2-trust-model)
2323
- [3. APIs and underlying communication protocols](#3-apis-and-underlying-communication-protocols)
2424
- [3.1 `.well-known`](#31-well-known)
25-
- [3.2 WebSockets](#32-websockets)
26-
- [3.2.1 Events over REST](#321-events-over-rest)
25+
- [3.2 WebSocket Protocol](#32-websocket-protocol)
26+
- [3.2.1 Gateway Event Payloads](#321-gateway-event-payloads)
27+
- [3.2.1.1 Namespaces `n`](#3211-namespaces-n)
28+
- [3.2.1.2 Opcodes `op`](#3212-opcodes-op)
29+
- [3.2.1.3 Event names `t`](#3213-event-names-t)
30+
- [3.2.2 Events over REST](#322-events-over-rest)
2731
- [3.3 HTTP](#33-http)
2832
- [3.4 Internet Protocol (IP)](#34-internet-protocol-ip)
2933
- [4. Federated identity](#4-federated-identity)
@@ -173,11 +177,15 @@ the client can treat the server located at the *actual domain name* as a polypro
173177
*visible domain name*. Clients must not treat the server located at the *actual domain name* as a
174178
polyproto server serving the *actual domain name*.
175179

176-
### 3.2 WebSockets
180+
### 3.2 WebSocket Protocol
177181

178-
WebSockets enable real-time communication between actor clients and servers.
182+
WebSockets enable real-time, bidirectional communication between actor clients and home servers.
179183

180-
WebSocket connections to polyproto servers consist of the following cycle:
184+
!!! info
185+
186+
A polyproto WebSocket server is also called "Gateway" or "Gateway Server" for short.
187+
188+
WebSocket connections to polyproto servers consist of the following, general cycle:
181189

182190
```mermaid
183191
sequenceDiagram
@@ -214,11 +222,50 @@ end
214222

215223
*Fig. 1: Sequence diagram of a WebSocket connection to a polyproto server.*
216224

217-
!!! info
225+
#### 3.2.1 Gateway Event Payloads
226+
227+
Gateway event payloads share a general structure, though the content of the `d` field varies depending
228+
on the specific event.
229+
230+
| Field | Type | Description |
231+
| ----- | ---------- | ------------------------------------------------------------------------------------------ |
232+
| `n` | string | [Namespace](#82-namespaces) context for this payload. |
233+
| `op` | integer | Gateway Opcode indicating the type of payload. |
234+
| `d` | JSON value | The event data associated with this payload. |
235+
| `s`¹ | ?integer | Sequence number for the event, used for session resumption and heartbeats. |
236+
| `t`¹ | ?string | Event name for this payload (only applicable for and present in DISPATCH opcode payloads). |
237+
238+
¹ These fields are only included for payloads received from a server and are `null` when `op`
239+
is not equal to DISPATCH.
240+
241+
##### 3.2.1.1 Namespaces `n`
218242

219-
To learn more about polyproto WebSockets and WebSocket Events, consult the [WebSockets documentation](/docs/APIs/Core/WebSockets/index.md).
243+
The `n` field in a gateway event payload indicates the namespace context for the payload. You can
244+
read more about namespaces in [section 8.2](#82-namespaces).
220245

221-
#### 3.2.1 Events over REST
246+
Every namespace may define its own set of opcodes and event names.
247+
248+
The namespace context must be known to the entity receiving the payload, as it is crucial for
249+
correctly interpreting the payload.
250+
251+
##### 3.2.1.2 Opcodes `op`
252+
253+
The following opcodes are defined by the `core` namespace, which is the namespace managed by this
254+
specification:
255+
256+
| Opcode | Name | Action | Description |
257+
| ------ | ------------------------------ | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
258+
| `0` | Dispatch | Actor Receive | Delivery of a message payload to a client. |
259+
| `1` | Heartbeat | Actor Send/Receive | Keep alive for the WebSocket session. |
260+
| `2` | Hello | Actor Receive | Received upon establishing a connection. |
261+
| `3` | Identify | Actor Send | Identify to the server. |
262+
| `4` | Server Certificate Change | Actor Receive | Received when the server's certificate changed. |
263+
| `5` | New Session | Actor Receive | Received by all sessions except the new one. |
264+
| `6` | Actor Certificate Invalidation | Actor Send/Receive | Received by server when an actor certificate has been invalidated. Sent to server when an actor invalidates one of their certificates. |
265+
266+
##### 3.2.1.3 Event names `t`
267+
268+
#### 3.2.2 Events over REST
222269

223270
For some implementation contexts, a constant WebSocket connection might not be wanted. A client can
224271
instead opt to query an API endpoint to receive events, which would normally be sent through the WebSocket
@@ -487,7 +534,7 @@ and [Section #6.2.2](#621-message-verification) for more information.
487534

488535
### 6.1 Home server signed certificates for public client identity keys (ID-Cert)
489536

490-
The ID-Cert, a [X.509](https://en.wikipedia.org/wiki/X.509) certificate, validates a public actor
537+
The ID-Cert, an [X.509](https://en.wikipedia.org/wiki/X.509) certificate, validates a public actor
491538
identity key. It is an actor-generated CSR ([Certificate Signing Request](https://en.wikipedia.org/wiki/Certificate_signing_request)),
492539
signed by a home server, encompassing actor identity information and the client's public identity key.
493540
Clients can get an ID-Cert in return for a valid and well-formed CSR. Generating a new ID-Cert is
@@ -724,6 +771,10 @@ When an ID-Cert is revoked, the server must revoke the session associated with t
724771
Revoking an ID-Cert is considered a [sensitive action](#412-sensitive-actions) and therefore should
725772
require a second factor of authentication.
726773

774+
<!-->
775+
TODO: Note that servers can send revocation notices to connected clients
776+
<!-->
777+
727778
!!! info
728779

729780
The above paragraph is true for both foreign and home servers. The API routes associated with

snippets/glossary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- **Federation ID** - A unique identifier; In public contexts, usually **actor@**subdomain.**example**.com,
1111
where bold parts are required and non-bold parts are optional.
1212
- **Foreign server** - An instance that an actor is not registered on; essentially a third party.
13+
- **Gateway, Gateway Server** - A polyproto compliant WebSocket server.
1314
- **Home server** - The instance that an actor is registered on. Any polyproto-core compliant server
1415
hosted on the same domain is also considered a home server. A home server is the instance that
1516
publicly attests to the validity of all legitimate ID-Certs issued under its [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name).

0 commit comments

Comments
 (0)