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

Commit 1979cfe

Browse files
committed
add more sections, describe sequence numbers a little
1 parent 6247bdd commit 1979cfe

File tree

1 file changed

+54
-15
lines changed
  • docs/Protocol Specifications

1 file changed

+54
-15
lines changed

docs/Protocol Specifications/core.md

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ weight: 0
3838
- [3.2.3.7 Server certificate change event](#3237-server-certificate-change-event)
3939
- [3.2.3.8 Heartbeat and heartbeat ACK events](#3238-heartbeat-and-heartbeat-ack-events)
4040
- [3.2.4 Establishing a connection](#324-establishing-a-connection)
41+
- [3.2.5 Closing a connection](#325-closing-a-connection)
42+
- [3.2.6 Guaranteed delivery of gateway messages through package acknowledgement](#326-guaranteed-delivery-of-gateway-messages-through-package-acknowledgement)
4143
- [3.3 Events over REST](#33-events-over-rest)
4244
- [3.4 HTTP](#34-http)
4345
- [3.5 Internet Protocol (IP)](#35-internet-protocol-ip)
46+
- [3.6 Compression](#36-compression)
4447
- [4. Federated identity](#4-federated-identity)
4548
- [4.1 Authentication](#41-authentication)
4649
- [4.1.1 Authenticating on a foreign server](#411-authenticating-on-a-foreign-server)
@@ -243,7 +246,7 @@ on the specific event.
243246
| `n` | string | [Namespace](#82-namespaces) context for this payload. |
244247
| `op` | uint16 | Gateway Opcode indicating the type of payload. |
245248
| `d` | JSON value | The event data associated with this payload. |
246-
| `s` | uint32 | Sequence number of the event, used for guaranteed, ordered delivery |
249+
| `s` | uint64 | Sequence number of the event, used for guaranteed, ordered delivery |
247250

248251
##### 3.2.1.1 Namespaces `n`
249252

@@ -274,31 +277,42 @@ The following opcodes are defined by the `core` namespace:
274277

275278
##### 3.2.1.3 Sequence numbers `s`
276279

277-
<!-->
278-
TODO
279-
<-->
280+
Sequence numbers are used as an application-layer packet acknowledgement mechanism in conjunction with
281+
[heartbeats](#322-heartbeats). This *guarantees* the delivery of all gateway messages sent from a
282+
home server to a client, especially in suboptimal network conditions.
280283

281-
!!! bug TODO
284+
??? question "Doesn't TCP already cover this?"
282285

283-
How are we going to do sequence numbers? Requirements are:
286+
While TCP ensures reliable delivery of data during an active connection, it does not retain
287+
knowledge of application-layer messages if a disconnect occurs. In such cases, the application
288+
must implement its own mechanisms to track which messages were successfully received.
289+
290+
Application-layer acknowledgements allow the protocol to recover from interruptions by
291+
identifying any messages that were lost during the disconnect and ensuring they are
292+
retransmitted, preserving the integrity and completeness of communication between the client
293+
and server.
284294

285-
- Guaranteed, ordered delivery of payloads
286-
- Notice delivery gaps, especially when connection stability is flawed
287-
288-
See: https://chatgpt.com/share/678e89ba-aa20-8004-bde7-4a33bab804b9
295+
Sequence numbers are unsigned integers with a 64 bit length. In the rare event that this integer should
296+
overflow, the server must close the connection to the client and prompt the client to initiate a new,
297+
non-resumed gateway connection.
289298

290299
#### 3.2.2 Heartbeats
291300

292-
Heartbeats are used to keep the WebSocket connection alive. The client continuously sends a heartbeat
293-
event to the server with the interval specified in the "Hello" event payload.
301+
Heartbeats are used to keep the WebSocket connection alive and, combined with [sequence numbers](#3213-sequence-numbers-s),
302+
form an application-layer packet acknowledgement mechanism. The client continuously sends a heartbeat
303+
event to the server with the interval specified in the ["Hello" event payload](#3231-hello-event).
294304
The server must acknowledge the heartbeat event by sending a heartbeat ACK event back to the client.
295305

296306
Servers must account for the time it takes for the client to send the heartbeat event. Before closing
297307
a connection due to a missed heartbeat, the server should request a heartbeat event from the client
298-
by sending a heartbeat event to the client.
308+
by sending a heartbeat event to the client. If the client is not responding within a reasonable
309+
time frame, the server should close the gateway connection with an appropriate [close code](#325-closing-a-connection).
299310

300311
The structure of the heartbeat and heartbeat ACK events are described in [section 3.2.3.8](#3238-heartbeat-and-heartbeat-ack-events).
301312

313+
Recommended values for heartbeat intervals are 30 to 60 seconds. The heartbeat interval is chosen by
314+
the server.
315+
302316
#### 3.2.3 Gateway event payload definitions
303317

304318
##### 3.2.3.1 "Hello" event
@@ -392,8 +406,8 @@ was successful or not.
392406
| `success` | boolean | Whether the action was successful or not. |
393407
| `message` | string? | Only present if `success` is `false`. A message indicating why the action failed. |
394408

395-
If a successful subscription to a service channel is acknowledged, all further events and logic
396-
is defined by the service's specification.
409+
If a successful subscription to a service channel is acknowledged, all logic and further event on
410+
this channel are defined by the service's specification.
397411

398412
##### 3.2.3.4 New session event
399413

@@ -503,6 +517,20 @@ The payload for both the heartbeat and heartbeat ACK events is an empty object `
503517

504518
TODO
505519

520+
#### 3.2.5 Closing a connection
521+
522+
TODO
523+
524+
#### 3.2.6 Guaranteed delivery of gateway messages through package acknowledgement
525+
526+
TODO
527+
528+
!!! bug "TODO"
529+
530+
This section will explain how [heartbeats](#322-heartbeats) and [sequence numbers](#3213-sequence-numbers-s)
531+
come together to form an application-layer package acknowledgement mechanism, and how that
532+
mechanism works.
533+
506534
#### 3.3 Events over REST
507535

508536
For some implementation contexts, a constant WebSocket connection might not be wanted. A client can
@@ -560,6 +588,17 @@ Protocol in polyproto should happen on a best-effort basis.
560588
written to support polyproto must be capable of handling traffic over both IPv4 and IPv6, should
561589
both versions of the Internet Protocol be available to the software at runtime.
562590

591+
### 3.6 Compression
592+
593+
TODO
594+
595+
!!! bug "TODO; Here's a TL;DR:"
596+
597+
- zstd level 5-13 recommended
598+
- zstd must be offered on gateway server
599+
- zstd must be offered on http api
600+
- uncompressed available (but why would you do that)
601+
563602
## 4. Federated identity
564603

565604
The federation of actor identities allows users to engage with foreign servers as if they were their

0 commit comments

Comments
 (0)