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

Commit 8e402f7

Browse files
committed
explain messaging group federation
1 parent dbcc166 commit 8e402f7

File tree

1 file changed

+106
-13
lines changed
  • docs/Protocol Specifications/P2 Extensions

1 file changed

+106
-13
lines changed

docs/Protocol Specifications/P2 Extensions/chat.md

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,109 @@ title: polyproto-chat
1919

2020
[Semantic versioning v2.0.0](https://semver.org/spec/v2.0.0.html) is used to version this specification.
2121

22-
## 1. Federation
22+
- [p2-Extension: polyproto-chat](#p2-extension-polyproto-chat)
23+
- [1. Federation of Group Messages](#1-federation-of-group-messages)
24+
- [2. Encrypted channels and groups](#2-encrypted-channels-and-groups)
25+
- [2.1 Encrypted guild channels](#21-encrypted-guild-channels)
26+
- [2.2 Encrypted direct messages](#22-encrypted-direct-messages)
27+
- [2.3 Encrypted group messages](#23-encrypted-group-messages)
28+
- [2.4 Joining new devices from existing users](#24-joining-new-devices-from-existing-users)
29+
- [2.5 Best practices](#25-best-practices)
30+
- [polyproto-chat specific glossary](#polyproto-chat-specific-glossary)
31+
- [General glossary](#general-glossary)
2332

24-
This chapter covers the main federation mechanisms used to transfer messages between networks.
33+
## 1. Federation of Group Messages
2534

26-
<!-->tldr:
27-
- send message to own server
28-
- notify other members about update
29-
- other members pull message from server
35+
Every messaging group is also an MLS group. Messaging groups are always encrypted using the MLS
36+
protocol and shared cipher suites. A direct messaging group between two actors is also treated as
37+
a group message in this case.
3038

31-
either that or we directly take advantage of encryption and do something more efficient that way. idk im tired i need sleepies
32-
<-->
39+
Group messages are decentralized in nature. Each participant of a messaging group stores the messages
40+
they send on the server which acts as their primary service provider for the polyproto-chat service.
3341

34-
### 1.1 Direct messages
42+
!!! info
3543

36-
Federating direct messages is straightforward. When Alice sends a message to Bob, their client will
37-
send the message to Bob's home server via an API request. Bob's home server will then send the
38-
message to Bob's client via an established WebSocket connection, and vice versa.
44+
Read chapter #9 of the polyproto core specification document for more information on services and
45+
service providers.
3946

40-
### 1.2 Group messages
47+
With multiple servers participating in a conversation, a server outage only affects the messages
48+
stored on that server, not the entire messaging group.
49+
50+
The below sequence diagram showcases how a private messaging channel between two actors with different
51+
service providers works.
52+
53+
```mermaid
54+
sequenceDiagram
55+
autonumber
56+
57+
actor a as Alice
58+
participant s1 as Server A
59+
participant s2 as Server B
60+
actor b as Bob
61+
62+
a->>a: Encrypt message for MLS group
63+
a->>s1: Send encrypted message<br/>to own server
64+
s1->s1: Store encrypted message
65+
s1->>s2: Forward encrypted message<br/>to Bobs home server
66+
note over s2: Server B does not store<br/>the encrypted message.
67+
s2->>b: Forward message<br/>to Bob
68+
opt Bob sends a message
69+
b->>b: Encrypt message for MLS group
70+
b->>s2: Send encrypted message<br/>to own server
71+
s2->s2: Store encrypted message
72+
s2->>s1: Forward encrypted message<br/>to Alices home server
73+
note over s1: Server A does not store<br/>the encrypted message.
74+
s1->>a: Forward message<br/>to Alice
75+
end
76+
opt Bob wants to fetch the message at a later point
77+
note over b,s1: Bob must be authenticated on Server A and<br/>must present a valid session token to fetch messages.
78+
b->>s1: Request message with $id
79+
s1->s1: Load message
80+
s1->>b: Retrieved message
81+
end
82+
opt Alice wants to fetch her message at a later point
83+
note over a,s1: Of course, Alice must also present a<br/>valid session token to fetch messages.
84+
a->>s1: Request message with $id
85+
s1->s1: Load message
86+
s1->>a: Retrieved message
87+
end
88+
```
89+
90+
*Fig. 1: Message sending and message retrieval in a messaging group.*
91+
92+
Below, you can find a condensed sequence diagram showcasing how a messaging group with > 2 actors
93+
works:
94+
95+
```mermaid
96+
sequenceDiagram
97+
autonumber
98+
99+
actor a as Actor 1
100+
participant s1 as Server 1
101+
participant s2 as Server 2
102+
participant s3 as Server n
103+
actor b as Actor 2
104+
actor c as Actor m
105+
106+
a->>a: Encrypt message for MLS group
107+
a->>s1: Send encrypted message<br/>to own server
108+
s1->s1: Store encrypted message
109+
note over s1,s3: It is the senders' servers' duty to forward<br/>this message to all other involved servers.
110+
par
111+
s1->>s2: Forward message to Server 2
112+
and
113+
s1->>s3: Forward message to Server n
114+
end
115+
note over s2,s3: Neither of these servers store<br/>this message.
116+
par
117+
s2->>b: Forward message<br/>to Actor 2
118+
and
119+
s3->>c: Forward message<br/>to Actor m
120+
end
121+
note over a,c: Fetching messages works the same way as showcased in Fig. 1.
122+
```
123+
124+
vvv
41125

42126
Group messages work just like guilds, in the sense that data is stored by the home server of the
43127
group's creator, meaning that all group members will have to communicate with the group creator's
@@ -166,4 +250,13 @@ accepted by default.
166250

167251
---
168252

253+
## polyproto-chat specific glossary
254+
255+
- **Message group** - A "guildless" message channel with 2-15 individual actors.
256+
- **Guild** - Guilds are fundamental organizational units, representing a community or group of users
257+
who share a common interest, purpose or affiliation. Guilds are organized into channel categories,
258+
which contain channels. See also: `Channel`, `Channel Category`, `Role`, `Permission`
259+
260+
## General glossary
261+
169262
--8<-- "snippets/glossary.md"

0 commit comments

Comments
 (0)