]> Sergey Matveev's repositories - vors.git/blob - doc/proto.texi
a1af4d43a52e65b4a9eb9b6e30a2a7e718c84f2164a7fe8e68bd90e003641b61
[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 The keys are generated during the handshake procedure with the server
15 and is shared among the other participants. The stream identifier
16 together with the packet counter is used as a nonce.
17
18 It is tuned for 24Kbps bandwidth. But remember that it has additional 8B
19 of MAC tag, 4B VoRS, 8B UDP and 40B IPv6 headers.
20
21 Each client handshakes with the server over TCP connection using the
22 @url{http://noiseprotocol.org/, Noise}-NK protocol pattern with
23 curve25519, ChaCha20-Poly1305 and BLAKE2s algorithms.
24
25 @itemize
26
27 @item Client sends @code{VoRS v1} to the socket. Just a magic number.
28
29 @item All next messages are prepended with 16-bit big-endian length.
30
31 @item Client sends initial Noise handshake message with his username as
32 a payload.
33
34 @item Server answers with final noise handshake message with the payload
35 of @code{OK HEX(COOKIE)}, or any other failure message. It may reject a
36 client if there are too many peers or its name is already taken.
37
38 @item The 128-bit cookie is sent by client over UDP to the server every
39 second. If UDP packets are lost, then no connection is possible and
40 after a timeout the server drops the TCP connection.
41
42 @item Otherwise it replies with @code{SID XXX}, where XXX is ASCII
43 decimal stream number client must use.
44
45 @item @code{PING} and @code{PONG} messages are then sent every ten
46 seconds as a heartbeat.
47
48 @end itemize
49
50 @example
51 S <- C : e, es, "username"
52 S -> C : e, ee, "OK COOKIE"
53 S <- C : UDP(COOKIE)
54 S -> C : "SID XXX"
55
56 S <- C : "PING"
57 S -> C : "PONG"
58 S <> C : ...
59
60 S -> C : "ADD SID USERNAME HEX(KEY)"
61 S -> C : ...
62
63 S -> C : "DEL SID"
64 S -> C : ...
65 @end example
66
67 Every second the client sends UDP packet with his single-byte stream
68 identifier, even if it's muted. That may help punching holes in stateful
69 firewalls.
70
71 Clients are notified about new peers appearance with @code{ADD}
72 commands, telling their SIDs, usernames and keys. @code{DEL} notifies
73 about leaving peers.