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

Commit 565087b

Browse files
committed
describe heartbeat&ack, add close codes
1 parent a444e3b commit 565087b

File tree

1 file changed

+53
-4
lines changed
  • docs/Protocol Specifications

1 file changed

+53
-4
lines changed

docs/Protocol Specifications/core.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ of this event contains the ASCII-PEM encoded ID-Cert of the server.
495495
##### 3.2.3.8 Heartbeat and heartbeat ACK events
496496

497497
The heartbeat event is sent by the client to the server to keep the WebSocket connection alive.
498-
The payload for the heartbeat event is a "minified number list". Minified number lists are a JSON
498+
The payload for the heartbeat event is a minified number list. Minified number lists are a JSON
499499
object with the fields `from`, `to`, and `except`. The `from` and `to` fields are strings representing
500500
a range of numbers. The `except` field is an array of strings representing numbers that are not
501501
included in the range.
@@ -534,28 +534,75 @@ $$
534534
{
535535
"n": "core",
536536
"op": 0,
537-
"d": {},
537+
"d": {
538+
"from": "213",
539+
"to": "219"
540+
"except": ["214", "216"]
541+
},
538542
"s": 1
539543
}
540544
```
541545

546+
A heartbeat ACK contains events that the client has re-requested as part of their heartbeat message.
547+
542548
!!! example "Example heartbeat ACK event payload"
543549

544550
```json
545551
{
546552
"n": "core",
547553
"op": 7,
548-
"d": {},
554+
"d": {
555+
[
556+
{
557+
"n": "core",
558+
"op": 6,
559+
"d": {
560+
"payload data"
561+
}
562+
},
563+
{
564+
"n": "core",
565+
"op": 9,
566+
"d": {
567+
...
568+
}
569+
},
570+
...
571+
]
572+
},
549573
"s": 1
550574
}
551575
```
552576

577+
As such, the field `d` in a heartbeat ack is optional (`?`) and, if present, contains an array of
578+
other gateway events. Heartbeat ACK payloads must not be present in this array, making recursion
579+
impossible.
580+
553581
#### 3.2.4 Establishing a connection
554582

555583
TODO
556584

557585
#### 3.2.5 Closing a connection
558586

587+
At any time during the connection, the server or client may wish to terminate the session in an
588+
orderly fashion. This is being done by sending a [WebSocket close code](https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5)
589+
to the recipient. In addition to the pre-defined status codes in [IETF RFC #6455](https://www.rfc-editor.org/rfc/rfc6455.html),
590+
polyproto servers and clients must know of and use the following status codes in their appropriate
591+
situations:
592+
593+
| Code | Description | Explanation | Eligible for `RESUME`? | Sent by server? | Sent by client? |
594+
| ------ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | --------------- | --------------- |
595+
| `4000` | Unknown error | An unknown error has occurred and the connection was terminated. | x | x | x |
596+
| `4001` | Unknown opcode | The client has sent a message with an unknown [opcode](#3212-opcodes-op) to the server. | x | x | |
597+
| `4002` | Invalid payload | The client has sent a message with an invalid payload to the server. | x | x | |
598+
| `4003` | Not authenticated | The server has received a message from the client before the client identified itself, or the clients' session has been invalidated. | | x | |
599+
| `4004` | Invalid authentication | The authentication token received by the server as part of the identify payload is invalid. | | x | |
600+
| `4005` | Already authenticated | The client has sent an identify payload even though it has already identified successfully. | | x | |
601+
| `4006` | Reserved | 4006 is a reserved value and has no function in polyproto v1.0. The specific meaning may be defined in the future. | | | |
602+
| `4007` | Invalid sequence number(s) | The client has sent a heartbeat containing sequence numbers that were invalid. | x | x | |
603+
| `4008` | Rate limited | The client has sent payloads too quickly. | | x | |
604+
| `4009` | Timeout | The session has been deemed to be timed out. This can happen if a heartbeat or heartbeat ACK has not been sent in due time. | x (If sent by server) | X | x |
605+
559606
TODO
560607

561608
#### 3.2.6 Guaranteed delivery of gateway messages through package acknowledgement
@@ -584,7 +631,9 @@ in – especially when network conditions are suboptimal. This mechanism is base
584631
retransmitted, preserving the integrity and completeness of communication between the client
585632
and server.
586633

587-
634+
If `except` was present and contained entries in the heartbeat payload, the server must re-send these
635+
events in the `d` part of the heartbeat ACK response.
636+
TODO ^
588637

589638
#### 3.3 Events over REST
590639

0 commit comments

Comments
 (0)