]> Sergey Matveev's repositories - vors.git/blob - doc/proto.texi
Noising
[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.
7
8 Each frame has single byte stream identifier (unique identifier of the
9 participant) and 24-bit big-endian packet counter. Reordered packets are
10 dropped. 24-bit counter is long enough for very long talk sessions.
11
12 Each packet is encrypted with ChaCha20-Poly1305. Key is generated during
13 handshake procedure with the server and is shared among other participants.
14 Stream identifier with packet counter are used as a nonce. Only 64-bits
15 of Poly1305 are used.
16
17 It is tuned for 32Kbps bandwidth. 24Kbps should be enough, but 40B of
18 IPv6 header, +8B of Poly1305 authentication tag, +4B of stream
19 identifier with the counter, +8B of UDP header for 50pps means also
20 24Kbps of bandwidth only for overhead transmission.
21
22 Each client handshakes with the server over TCP connection using
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 v1} to the socket. Just a magic number.
29
30 @item All next messages are prepended with 16-bit big-endian length.
31
32 @item Client sends initial Noise handshake message with his username as
33 a payload.
34
35 @item Server answers with final Noise handshake message with the payload
36 of @code{OK HEX(COOKIE)}, or any other failure message. It may reject
37 client if there are too many peers or its name is already taken.
38
39 @item That 128-bit cookie is sent by client over UDP to the server every
40 second. If UDP packets are lost, then no connection is possible and
41 after timeout server drop TCP connection.
42
43 @item Otherwise it replies with @code{SID XXX}, where XXX is ASCII
44 decimal stream number client must use.
45
46 @item @code{PING} and @code{PONG} messages are then sent every ten
47 seconds as a heartbeat.
48
49 @end itemize
50
51 @example
52 S <- C : e, es, "username"
53 S -> C : e, ee, "OK COOKIE"
54 S <- C : UDP(COOKIE)
55 S -> C : "SID XXX"
56
57 S <- C : "PING"
58 S -> C : "PONG"
59 S <> C : ...
60
61 S -> C : "ADD SID USERNAME HEX(KEY)"
62 S -> C : ...
63
64 S -> C : "DEL SID"
65 S -> C : ...
66 @end example
67
68 Every second client sends UDP packet with his single-byte stream
69 identifier, even if it is muted. That may help punching holes in
70 stateful firewalls.
71
72 Clients are notified about new peers appearance with @code{ADD}
73 commands, telling their SIDs, usernames and keys. @code{DEL} notifies
74 about leaving peers.