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

Commit 2bc75fd

Browse files
committed
2 parents 9b624e6 + 316a47c commit 2bc75fd

File tree

4 files changed

+103
-34
lines changed

4 files changed

+103
-34
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"tag:yaml.org,2002:python/name:material.extensions.emoji.twemoji",
1111
"tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format"
1212
],
13-
"editor.formatOnSave": false,
1413
"cSpell.enabled": true,
1514
"cSpell.words": [
1615
"alice",

docs/Protocol Specifications/core.md

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,15 @@ The following opcodes are defined by the `core` namespace:
277277

278278
##### 3.2.1.3 Sequence numbers `s`
279279

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.
283-
284-
??? question "Doesn't TCP already cover this?"
285-
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.
294-
295280
Sequence numbers are unsigned integers with a 64 bit length. In the rare event that this integer should
296281
overflow, the server must close the connection to the client and prompt the client to initiate a new,
297282
non-resumed gateway connection.
298283

284+
The sequence number increases by one for every gateway message sent by the server. The client must
285+
keep track of received sequence numbers as part as the [guaranteed delivery mechanism](#326-guaranteed-delivery-of-gateway-messages-through-package-acknowledgement).
286+
Every gateway connection has its own sequence number counter, starting at 0 for the first event sent
287+
by the server.
288+
299289
#### 3.2.2 Heartbeats
300290

301291
Heartbeats are used to keep the WebSocket connection alive and, combined with [sequence numbers](#3213-sequence-numbers-s),
@@ -325,7 +315,12 @@ in milliseconds at which the client should send heartbeat events to the server.
325315

326316
```json
327317
{
328-
"heartbeat_interval": 45000
318+
"n": "core",
319+
"op": 1,
320+
"d": {
321+
"heartbeat_interval": 45000
322+
},
323+
"s": 0
329324
}
330325
```
331326

@@ -338,6 +333,8 @@ in milliseconds at which the client should send heartbeat events to the server.
338333
The "identify" event is sent by the client to the server to let the server know which actor the
339334
client is.
340335

336+
TODO
337+
341338
##### 3.2.3.3 Service channels
342339

343340
Service channels act like topics in a pub/sub system. They allow clients to subscribe to a specific
@@ -358,7 +355,8 @@ A service channel event payload has the following structure:
358355
"d": {
359356
"action": "subscribe",
360357
"service": "service_name"
361-
}
358+
},
359+
"s": 1
362360
}
363361
```
364362

@@ -381,7 +379,8 @@ was successful or not.
381379
"service": "service_name",
382380
"success": false,
383381
"errorMessage": "Service not found"
384-
}
382+
},
383+
"s": 1
385384
}
386385
```
387386

@@ -395,7 +394,8 @@ was successful or not.
395394
"action": "subscribe",
396395
"service": "service_name",
397396
"success": true,
398-
}
397+
},
398+
"s": 1
399399
}
400400
```
401401

@@ -423,7 +423,8 @@ about the new session mechanism in [section 4.3](#43-protection-against-misuse-b
423423
"op": 3,
424424
"d": {
425425
"cert": "-----BEGIN CERTIFICATE-----\nMIIBIjANB..."
426-
}
426+
},
427+
"s": 1
427428
}
428429
```
429430

@@ -448,14 +449,15 @@ occurs.
448449
"serial": "11704583652649",
449450
"invalidSince": "1737379403",
450451
"signature": "8eacd92192bacc57bb5df3c7922e93bbc8b3f683f5dec9224353b102fa2f2a75"
451-
}
452+
},
453+
"s": 1
452454
}
453455
```
454456

455-
| Field | Type | Description |
456-
| -------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
457-
| `serial` | uint64 | The serial number of the invalidated ID-Cert |
458-
| `invalidSince` | uint64 | UNIX timestamp of the point in time where this ID-Cert became invalid on |
457+
| Field | Type | Description |
458+
| -------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
459+
| `serial` | uint64 | The serial number of the invalidated ID-Cert |
460+
| `invalidSince` | uint64 | UNIX timestamp of the point in time where this ID-Cert became invalid on |
459461
| `signature` | string | Signature of a string concatenation of the `invalidSince` timestamp and the `serial` number, in that order. Clients must verify this signature, verifying that the signature was generated by the private key of the revoked certificate. |
460462

461463
##### 3.2.3.6 Resume event
@@ -479,7 +481,8 @@ of this event contains the ASCII-PEM encoded ID-Cert of the server.
479481
"d": {
480482
"cert": "-----BEGIN CERTIFICATE-----\nMIIBIjANB...",
481483
"oldInvalidSince": 1630012713
482-
}
484+
},
485+
"s": 1
483486
}
484487
```
485488

@@ -491,15 +494,41 @@ of this event contains the ASCII-PEM encoded ID-Cert of the server.
491494
##### 3.2.3.8 Heartbeat and heartbeat ACK events
492495

493496
The heartbeat event is sent by the client to the server to keep the WebSocket connection alive.
494-
The payload for both the heartbeat and heartbeat ACK events is an empty object `{}`.
497+
The payload for the heartbeat event is a "minified number list". Minified number lists are a JSON
498+
object with the fields `from`, `to`, and `except`. The `from` and `to` fields are strings representing
499+
a range of numbers. The `except` field is an array of strings representing numbers that are not
500+
included in the range.
501+
502+
The range described by the `from` and `to` fields is a mathematical, closed interval, where
503+
`from` is equal to $a$ and `to` is equal to $b$ :
504+
505+
$$
506+
[a,b]=\{x\in \mathbb {N} \mid a\leq x\leq b\}
507+
$$
508+
509+
!!! example "Minified number list"
510+
511+
```json
512+
{
513+
from: "1",
514+
to: "20",
515+
except: ["9", "12", "13"]
516+
}
517+
```
518+
519+
| Field | Type | Description |
520+
| ------ | ------ | ----------- |
521+
| `from` | string | |
522+
495523

496524
!!! example "Example heartbeat event payload"
497525

498526
```json
499527
{
500528
"n": "core",
501529
"op": 0,
502-
"d": {}
530+
"d": {},
531+
"s": 1
503532
}
504533
```
505534

@@ -509,7 +538,8 @@ The payload for both the heartbeat and heartbeat ACK events is an empty object `
509538
{
510539
"n": "core",
511540
"op": 7,
512-
"d": {}
541+
"d": {},
542+
"s": 1
513543
}
514544
```
515545

@@ -531,6 +561,24 @@ TODO
531561
come together to form an application-layer package acknowledgement mechanism, and how that
532562
mechanism works.
533563

564+
polyproto implements an application-level guaranteed delivery mechanism. This ensures that all gateway
565+
messages sent from a home server to a client are received by the client in the order they were sent
566+
in – especially when network conditions are suboptimal. This mechanism is based on the use of
567+
[sequence numbers](#3213-sequence-numbers-s) and [heartbeats](#322-heartbeats).
568+
569+
??? question "Doesn't TCP already cover this?"
570+
571+
While TCP ensures reliable delivery of data during an active connection, it does not retain
572+
knowledge of application-layer messages if a disconnect occurs. In such cases, the application
573+
must implement its own mechanisms to track which messages were successfully received.
574+
575+
Application-layer acknowledgements allow the protocol to recover from interruptions by
576+
identifying any messages that were lost during the disconnect and ensuring they are
577+
retransmitted, preserving the integrity and completeness of communication between the client
578+
and server.
579+
580+
581+
534582
#### 3.3 Events over REST
535583

536584
For some implementation contexts, a constant WebSocket connection might not be wanted. A client can

docs/javascripts/mathjax.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
window.MathJax = {
2+
tex: {
3+
inlineMath: [["\\(", "\\)"]],
4+
displayMath: [["\\[", "\\]"]],
5+
processEscapes: true,
6+
processEnvironments: true
7+
},
8+
options: {
9+
ignoreHtmlClass: ".*|",
10+
processHtmlClass: "arithmatex"
11+
}
12+
};
13+
14+
document$.subscribe(() => {
15+
MathJax.startup.output.clearCache()
16+
MathJax.typesetClear()
17+
MathJax.texReset()
18+
MathJax.typesetPromise()
19+
})

mkdocs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# yaml-language-server: $schema=https://squidfunk.github.io/mkdocs-material/schema.json
22
site_name: Polyphony
33
repo_url: https://github.com/polyphony-chat/docs
4+
site_url: https://docs.polyphony.chat/
45
edit_uri: edit/main/docs/
56
extra_css:
67
- stylesheets/extra.css
@@ -55,14 +56,11 @@ plugins:
5556
archive_date_format: MMMM yyyy
5657
- rss:
5758
match_path: blog/posts/.*
58-
59-
6059
date_from_meta:
6160
as_creation: date
6261
categories:
6362
- categories
6463
- tags
65-
6664
- privacy
6765
- search
6866
- mkdocs-nav-weight
@@ -97,4 +95,9 @@ markdown_extensions:
9795
toc_depth: 5
9896
- pymdownx.emoji:
9997
emoji_index: !!python/name:material.extensions.emoji.twemoji
100-
emoji_generator: !!python/name:material.extensions.emoji.to_svg
98+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
99+
- pymdownx.arithmatex:
100+
generic: true
101+
extra_javascript:
102+
- javascripts/mathjax.js
103+
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

0 commit comments

Comments
 (0)