]> Sergey Matveev's repositories - vors.git/blob - doc/proto.texi
0bb140474af3cc9371e9576f3ad03dcbe9f22253744eb7ac8d8b6919e539042f
[vors.git] / doc / proto.texi
1 @node Protocol
2 @unnumbered Protocol
3
4 VoRS uses the Opus codec with 20ms frames with 48kHz 1ch 16-bit S-LE
5 sound. It uses native @code{libopus}'es Packet Loss Concealment (PLC)
6 feature when the number of lost frame does not exceed 32 count. DTX
7 (discontinuous transmission) is also on.
8
9 Each frame has a single byte stream identifier (unique identifier of the
10 participant) and 24-bit big-endian packet counter. Reordered packets are
11 dropped. 24-bit counter is long enough for very long talk sessions.
12
13 Each packet is encrypted with ChaCha20 and authenticated with SipHash24.
14 Their keys are generated from BLAKE2s-XOF, which is fed with completed
15 handshake's binding value. Then they are shared among the other
16 participants. The stream identifier together with the packet counter is
17 used as a nonce.
18
19 It is tuned for 24Kbps bandwidth. But remember that it has additional 8B
20 of MAC tag, 4B VoRS, 8B UDP and 40B IPv6 headers.
21
22 Each client handshakes with the server over TCP connection using the
23 @url{http://noiseprotocol.org/, Noise}-NK protocol pattern with
24 curve25519, ChaCha20-Poly1305 and BLAKE2s algorithms.
25
26 @itemize
27
28 @item Client sends @code{VoRS v3} to the socket. Just a magic number.
29
30 @item All next messages are @url{http://cr.yp.to/proto/netstrings.txt,
31 Netstring} encoded strings. Most of them contain netstring encoded
32 sequence of netstrings if multiple values are expected:
33
34 @example
35 NS(NS(arg0) || NS(arg1) || ...)
36 @end example
37
38 @item Client sends initial Noise handshake message with his username,
39 room name and optional BLAKE2s-256 hash of the room's password (or an
40 empty string) as a payload: @code{"USERNAME", "ROOM", BLAKE2s(PASSWORD)}.
41
42 @item Server answers with final noise handshake message with the
43 @code{"COOKIE", COOKIE}, or @code{"ERR", MSG} failure message.
44 It may reject a client if there are too many peers, its name is
45 already taken or it provided an invalid room's password.
46
47 @item The 128-bit cookie is sent by client over UDP to the server every
48 second. If UDP packets are lost, then no connection is possible and
49 after a timeout the server drops the TCP connection. That cookie means:
50
51     @itemize
52     @item confirmation of successful handshake on client side;
53     @item UDP hole punching of stateful firewall or NAT;
54     @item fact of client's UDP traffic ability to reach the server;
55     @item client's UDP address knowledge (after passing NAT, its port
56         may differ from known to client one)
57     @end itemize
58
59 @item Server replies with @code{"SID", X}, where X is single byte
60 stream number client must use.
61
62 @item @code{"PING"} and @code{"PONG"} messages are then sent every ten
63 seconds as a heartbeat.
64
65 @end itemize
66
67 @example
68 S <- C : e, es, NS(NS("USERNAME") || NS("ROOM") || NS("PASSWORD"))
69 S -> C : e, ee, NS(NS("COOKIE") || NS(COOKIE))
70 S <- C : UDP(COOKIE)
71 S -> C : NS(NS("SID") || NS(X))
72
73 S <- C : NS(NS("PING"))
74 S -> C : NS(NS("PONG"))
75 S <> C : ...
76
77 S -> C : NS(NS("ADD") || NS(SID) || NS(USERNAME) || NS(KEY))
78 S -> C : ...
79
80 S -> C : NS(NS("DEL") || NS(SID))
81 S -> C : ...
82 @end example
83
84 Every second the client sends UDP packet with his single-byte stream
85 identifier, even if it's muted. That may help punching holes in stateful
86 firewalls.
87
88 Clients are notified about new peers appearance with @code{ADD}
89 commands, telling their SIDs, usernames and keys. @code{DEL} notifies
90 about leaving peers. @code{MUTED}, @code{UNMUTED} notifies peer's mute
91 toggling.