]> Sergey Matveev's repositories - vors.git/blob - doc/proto.texi
Seems DTX won't harm
[vors.git] / doc / proto.texi
1 @node Protocol
2 @unnumbered Protocol
3
4 VoRS uses Opus codec with 20ms frames with 48kHz 1ch 16-bit S-LE sound.
5 It uses native @code{libopus}'es Packet Loss Concealment (PLC) feature
6 if number of lost frame does not exceed 32 count. DTX (discontinuous
7 transmission) is also on.
8
9 Each frame has 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-Poly1305. Key is generated during
14 handshake procedure with the server and is shared among other participants.
15 Stream identifier with packet counter are used as a nonce. Only 64-bits
16 of Poly1305 are used.
17
18 It is tuned for 32Kbps bandwidth. 24Kbps should be enough, but 40B of
19 IPv6 header, +8B of Poly1305 authentication tag, +4B of stream
20 identifier with the counter, +8B of UDP header for 50pps means also
21 24Kbps of bandwidth only for overhead transmission.
22
23 Each client handshakes with the server over TCP connection using
24 @url{http://noiseprotocol.org/, Noise}-NK protocol pattern with
25 curve25519, ChaCha20-Poly1305 and BLAKE2s algorithms.
26
27 @itemize
28
29 @item Client sends @code{VoRS v1} to the socket. Just a magic number.
30
31 @item All next messages are prepended with 16-bit big-endian length.
32
33 @item Client sends initial Noise handshake message with his username as
34 a payload.
35
36 @item Server answers with final Noise handshake message with the payload
37 of @code{OK HEX(COOKIE)}, or any other failure message. It may reject
38 client if there are too many peers or its name is already taken.
39
40 @item That 128-bit cookie is sent by client over UDP to the server every
41 second. If UDP packets are lost, then no connection is possible and
42 after timeout server drop TCP connection.
43
44 @item Otherwise it replies with @code{SID XXX}, where XXX is ASCII
45 decimal stream number client must use.
46
47 @item @code{PING} and @code{PONG} messages are then sent every ten
48 seconds as a heartbeat.
49
50 @end itemize
51
52 @example
53 S <- C : e, es, "username"
54 S -> C : e, ee, "OK COOKIE"
55 S <- C : UDP(COOKIE)
56 S -> C : "SID XXX"
57
58 S <- C : "PING"
59 S -> C : "PONG"
60 S <> C : ...
61
62 S -> C : "ADD SID USERNAME HEX(KEY)"
63 S -> C : ...
64
65 S -> C : "DEL SID"
66 S -> C : ...
67 @end example
68
69 Every second client sends UDP packet with his single-byte stream
70 identifier, even if it is muted. That may help punching holes in
71 stateful firewalls.
72
73 Clients are notified about new peers appearance with @code{ADD}
74 commands, telling their SIDs, usernames and keys. @code{DEL} notifies
75 about leaving peers.