summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/TASKS.txt78
-rw-r--r--doc/pica-client-tutorial/gettingstarted.html86
-rw-r--r--doc/proto-doc.txt119
-rwxr-xr-xdoc/proto.txt192
-rw-r--r--doc/protocol-specification.txt822
5 files changed, 868 insertions, 429 deletions
diff --git a/doc/TASKS.txt b/doc/TASKS.txt
deleted file mode 100755
index f92ca7e..0000000
--- a/doc/TASKS.txt
+++ /dev/null
@@ -1,78 +0,0 @@
-+ Написать отдельную функцию, которая добавляет сообщение в исходящий буфер для заданного клиента/узла
-
-+ Расширение сервера до распределенного взаимодействия. Открыть еще один порт для входящих соед. от других узлов. Разработать структуру, опис. соединение с др. узлами. Написать функцию, загружающую список адресов узлов,выполняющую подключение к узлам и обновляющую список. Написать функцию работы с соединениями с другими узлами.
-
-- Регрессионные тесты
-
-- Список узлов. Разработать структуру элемента списка, функции для работы со списком, которые будут применяться клиентом и узлом.
-
-- Реализовать поддержку туннелей, как в SSH
-
-- Возле каждой функции в коде сделать ее описание. Делать описание для будущих функций
-
-- Сделать обработку ошибок
-
--(+--) Упорядочить названия идентификаторов
-
-- Добавить поддержку IPv6
-
--(+--) Реализовать обработку тайм-аутов
-
-- Счетчики трафика входящего и исходящего, активных пользователей
-
-- Привести в соответствие требованиям GNU coding standards( к приемлемым требованиям)
-
-
-- Адресные пространства
-
-+ Удалить понятие "название сети" из протокола и кода.Инкрементировать версию протокола
-
-+ Добавить в клиентскую библиотеку еще одну callback-функцию, сообщающую о неуспешной попытке создания канала./Разобраться с неконсистентностью освобождения ресурсов в (close_channel,close_connection,establish_data_connection)/
-
-- Соединения между узлами шифруются при помощи ADH (не нужно?)
-
-+ Все входящие соединения узла через один TCP порт, а не 3
-
-- Очередь задач (соединиться с узлом и т.д)
-
-- Балансировка нагрузки между узлами (Узлы обмениваются количеством подключенных юзеров, потом самые нагруженные узлы посылают клиентам команду "сменить узел" с отсортированным списком N наименее нагруженных узлов)
-
-+ автоматическая регистрация аккаунтов
-
-+ сайт, багтрекер, VCS, форум, почтовая рассылка
-
-+ сохранение открытых ключей контактов и их сопоставление при каждом сеансе
-
-- список контактов, кому разрешено видеть, когда абонент в сети
-
-+ хранение списка узлов pica-node в базе sqlite
-
-+ autotools
-
-+ хранение недоставленных сообщений на стороне клиента, в базе sqlite, пока абонент не появится в сети
-
-+ история сообщений, с опциональным шифрованием
-
-+ проверка сертификата клиента узлом (узел должен иметь копию корневого сертификата)
-
-- переводы интерфейса
-
-- документация пользователя
-
-- текст лицензий (OpenSSL, iniparser, pica pica, Qt) в окошке about и файлах LICENSE
-
-+ собрать и протестировать под Windows (32 и 64 бита)
-
-- аудио-видео звонки (ffmpeg)
-
-+ передача файлов
-
-- возможность прямого P2P соединения между клиентами, клиент может выбирать предпочитаемый вариант (запретить P2P / использовать по возможности)
-
-(уже не нужно) периодическая смена CA ключей и уничтожение старого приватного ключа, публикация списков выданных сертификатов для каждого ключа (???)
-
-+ конфигурация узла (конфиг файл, опции командной строки, дефолтные значения)
-
-+- пакеты для разных дистрибутивов (ebuild +, deb +, mac os x dmg -, windows +, freebsd -)
-
-
diff --git a/doc/pica-client-tutorial/gettingstarted.html b/doc/pica-client-tutorial/gettingstarted.html
index 1148fbb..c658175 100644
--- a/doc/pica-client-tutorial/gettingstarted.html
+++ b/doc/pica-client-tutorial/gettingstarted.html
@@ -1,4 +1,4 @@
-
+
<html>
<head>
<title>Pica Pica Messenger. Getting Started.</title>
@@ -6,97 +6,103 @@
<body>
<h2>Pica Pica Messenger. Getting Started.</h2>
<p>
-This illustrated tutorial will introduce you to Pica Pica Messenger (or pica-client), client software for distributed decentralised instant messaging
-system. The main goal of Pica Pica project is to maintain privacy of your communications by using strong end-to-end encryption based
-on modern cryptographical standards and protocols.
+This illustrated tutorial will introduce you to Pica Pica Messenger (or pica-client), the client software for a distributed, decentralised instant messaging
+system. The main goal of the Pica Pica project is to maintain the privacy of your communications by using strong end-to-end encryption based
+on modern cryptographic standards and protocols.
</p>
-<h3>First start. Creating account.</h3>
+<h3>First start. Creating an account.</h3>
<p>
When you start pica-client for the first time, you'll have to create your new account.
</p>
<img src="pic1.png" align=center>
<p>
-Click "Create New Account..." button. Let's say you want to use <b>Anonymous</b> as your nickname. Type it in the "Name:" field.
-It is recommended to set checkbox "Set passphrase for the secret key", in this case private key associated with your account is
-encrypted by passphrase and you have to enter it on each login (term "passphrase" is often used in cryptographic applications instead
-of "password"). Click "Create" button and wait a little until public/private
- key pair and certificate that represents your account are generated.
+Click the "Create New Account..." button. Let's say you want to use <b>Anonymous</b> as your nickname. Type it in the "Name:" field.
+It is recommended to tick the "Set passphrase for the secret key" checkbox. In this case the private key associated with your account is
+encrypted with a passphrase, and you have to enter it on each login (the term "passphrase" is often used in cryptographic applications instead
+of "password"). Click the "Create" button and wait a little until the public/private
+ key pair and the certificate that represents your account are generated.
</p>
<img src="pic2.png" align=center>
<p>
-Pica Pica users are uniquely identified by their ID which is a SHA224 hash function of their certificate. Your ID will be displayed
-after certificate generation, and then you can copy it and send to friends, put on your website, print on business cards, etc. ID can
-be viewed any time later by clicking menu item "Account -> Show My Pica Pica ID". Pica Pica IDs need to have such cryptic looking like
-<b>wYI8zxNi4XEcMCwi7BRdgOpwgiX+5e1mj6Xr1A==</b> due to decentralised nature of the system.
+Pica Pica users are uniquely identified by their ID, which is the SHA224 hash of their certificate. Your ID will be displayed
+after the certificate is generated, and then you can copy it and send it to friends, put it on your website, print it on business cards, etc. The ID can
+be viewed at any time later by clicking the menu item "Account -> Show My Pica Pica ID". Pica Pica IDs have to look as cryptic as
+<b>wYI8zxNi4XEcMCwi7BRdgOpwgiX+5e1mj6Xr1A==</b> due to the decentralised nature of the system.
</p>
<img src="pic3.png" align=center>
<p>
So you have successfully created your Pica Pica account. It's time to start using it. Click "OK" in the dialog box above and you'll see
-initial window, but now drop-down list contains your newly created account and "Log In" button is enabled. Click this button.
+the initial window, but now the drop-down list contains your newly created account and the "Log In" button is enabled. Click this button.
</p>
<img src="pic4.png" align=center>
<p>
-If you have set passphrase for your account, prompt will appear. Enter the passphrase and click "OK".
+If you have set a passphrase for your account, a prompt will appear. Enter the passphrase and click "OK".
</p>
<img src="pic5.png" align=center>
<p>
Now pica-client will try
-to make connections to known Pica Pica nodes and update list of active nodes, i.e nodes that are online, up and running. If some alive
-node is found and connection is successful, pica-client will change its state to "Connected" and sitting bird icon (it is a common
-magpie, Latin name <i>"Pica pica"</i>) in system tray area will be changed to the flying bird icon. Now it's time to add some people to
+to make connections to known Pica Pica nodes and update the list of active nodes, i.e. nodes that are online, up and running. If a live
+node is found and the connection is successful, pica-client will change its state to "Connected" and the sitting bird icon (it is a common
+magpie, Latin name <i>"Pica pica"</i>) in the system tray area will be changed to the flying bird icon. Now it's time to add some people to
your contact list.
</p>
<h3>Contacts.</h3>
<p>
Let's suppose that your friend Jane Doe has sent her Pica Pica ID to you. Right-click on the empty area of the main window (or select
-menu item "Contacts") and click "Add Contact...". Paste received ID and click "OK".
+the menu item "Contacts") and click "Add Contact...". Paste the received ID and click "OK".
</p>
<img src="pic6.png" align=center>
<p>
-Newly added ID will appear in the contacts list, but without nickname yet. Double-click on this ID (or right-click and select
-"Start Chat"). Chat window will be opened. Say "hi" to Jane. If she is online at this moment, message will be delivered and "+"
-sign will appear to the left of the message. Also ID entry in the contacts list will be changed to nickname and ID in braces.
-Remember that date and time indicated in chat window is your local date and time when the message was received or sent by you,
-not the date and time when it was actually sent or received by your peer. Messages are sent by pressing "Enter", newline is added
-by combination "Shift"+"Enter". If your contact is not online, outgoing messages are stored in local history and marked as undelivered.
+The newly added ID will appear in the contact list, but without a nickname yet. Double-click on this ID (or right-click and select
+"Start Chat"). A chat window will be opened. Say "hi" to Jane. If she is online at this moment, the message will be delivered and a "+"
+sign will appear to the left of the message. Also the ID entry in the contact list will be changed to her nickname and the ID in parentheses.
+Remember that the date and time shown in the chat window are your local date and time when the message was received or sent by you,
+not the date and time when it was actually sent or received by your peer. Messages are sent by pressing "Enter"; a newline is added
+with the combination "Shift"+"Enter". If your contact is not online, outgoing messages are stored in the local history and marked as undelivered.
Pica-client periodically tries to deliver them.
</p>
<img src="pic7.png" align=center>
<p>
-Now let's suppose that your another friend John Smith has received your Pica Pica ID, created his account and wants to chat with you. You will
-see this question
+Now let's suppose that another friend of yours, John Smith, has received your Pica Pica ID, created his account and wants to chat with you. You will
+see this question:
</p>
<img src="pic8.png" align=center>
<p>
-You can click "Yes" to add him, "No" to ignore him or "Add to blacklist" to ban him forever. Because he is a friend, probably you
+You can click "Yes" to add him, "No" to ignore him or "Add to blacklist" to ban him forever. Because he is a friend, you probably
want to select "Yes". Then his name will appear in your contact list.
</p>
<p>
-It is strongly recommended to always verify Pica Pica ID of your new contacts in order to prevent "man-in-the-middle" attack.
-Key exchange and identity verification is a fundamental problem of encrypted communications, so you have to take it seriously.
+It is strongly recommended to always verify the Pica Pica IDs of your new contacts in order to prevent a "man-in-the-middle" attack.
+Key exchange and identity verification is a fundamental problem of encrypted communications, so you have to take it seriously.
It's better to exchange Pica Pica IDs in person, but obviously that's not always possible. You can make phone calls
-to your contacts and ask them to read their Pica Pica ID and check that it matches ID in your contact list (right-click on contact
+to your contacts and ask them to read their Pica Pica ID and check that it matches the ID in your contact list (right-click on the contact
and select "Show Pica Pica ID"), then read them your ID and make them verify it in their contact list. This procedure significantly
-reduces risk of silently replacing ID by some adversary. However, I don't think that government agencies are totally uncapable of
-imitating voice of selected person in real-time :)
+reduces the risk of an adversary silently replacing the ID. However, I don't think that government agencies are totally incapable of
+imitating the voice of a selected person in real time :)
+</p>
+<p>
+Upd (2026): real-time voice and face imitation is no longer limited to government agencies; it can now be done with AI models on consumer hardware.
+An adversary who controls the call could replace only the moments when the ID is read aloud, leaving the rest of the conversation genuine, so a voice call alone
+is no longer reliable verification. Prefer a video call where your contact also points the camera at the screen showing the ID, as this is harder (though not impossible) to fake.
+Also compare IDs over several independent channels, such as other messengers, email or a personal website, so that an adversary would have to compromise all of them.
</p>
<h3>Sending and receiving files.</h3>
<p>
-You can exchange files using Pica Pica. Needless to say, file transfers are encrypted too. To send file, right-click on contact and
-select "Send File". File selection dialog will ask you which file you want to send.
+You can exchange files using Pica Pica. Needless to say, file transfers are encrypted too. To send a file, right-click on a contact and
+select "Send File". A file selection dialog will ask you which file you want to send.
</p>
<img src="pic9.png" align=center>
<p>
-Then file transfer window will show up.
+Then the file transfer window will show up.
</p>
<img src="pic10.png" align=center>
<p>
-Receiver of file has to click "Accept" in order to start tranfer.
+The receiver of the file has to click "Accept" in order to start the transfer.
</p>
<img src="pic11.png" align=center>
<p>
-Then file transfer starts.
+Then the file transfer starts.
</p>
<img src="pic12.png" align=center>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/doc/proto-doc.txt b/doc/proto-doc.txt
deleted file mode 100644
index cdfaec2..0000000
--- a/doc/proto-doc.txt
+++ /dev/null
@@ -1,119 +0,0 @@
-Protocol Specification.
-
-Terminology.
-
-Client - software instance that interacts with human users and lets them send and
-receive encrypted messages over Pica Pica.
-
-Node - software instance that coordinates Pica Pica network, maintains list of
-all active nodes and provides connectivity to clients.
-
-Connections.
-There are 4 types of connections between Pica Pica nodes and clients.
-
--client to node (c2n) - control connection from client to node
-
--client to client (c2c) - data connection between clients through node acting
-as a proxy
-
--node to node (n2n) - control & data connection between nodes
-
--direct client to client (directc2c) - direct connection between clients,
-using IPv4/IPv6/DNS
-address of accepting client previously communicated through c2c connection.
-
-These connections use TCP transport. First 3 connection types start
-with TLS 1.2 handshake using anonymous Diffie-Hellman ciphersuite,
-connecting host acts as a TLS client, accepting host is TLS server.
-After connection type is identified by accepting node, anonymous TLS
-session is gracefully closed in case of c2n and c2c connections. Node starts
-new TLS session with client in case of c2n, where node acts as a TLS client and
-client acts as a TLS server, using client's RSA certificate. In case of
-c2c connection node acts as a transparent proxy, sending chunks of data
-received from the first client to the second one and vise versa. Clients
-establish mutually authenticated TLS session over proxied connection,
-initiator client is a TLS client, accepting client has TLS server role.
-n2n connection continues to operate in ADH TLS session, as by design nodes
-do not store state that identifies them except network address.
-
-
-Packet Format.
-
-Pica Pica protocol message packet contains header and tail.
-
-[Header][Tail]
-
-Header is a 2 octet sequence that identifies packet. First and second octets
-are always equal to each other.
-Tail is a remaining part of the packet. Can be empty. Tail can have fixed
-predefined length or in case of variable length packet it begins with 1 or 2
-octet sequence that contains unsigned integer number which defines length in
-octets of remaining part of the tail not including length octets. Length field
-is stored in little-endian format, least significant octet first.
-Whole packet length is limited to 65536 octets, so length field value is within
-0..65532 range.
-
-Example:
-
-0x55 0x55 0x03 0x00 0xAA 0xBB 0xCC
-[0x55 0x55] - header
-[0x03 0x00] - tail length, 2 octets
-[0xAA 0xBB 0xCC] payload, 3 octets
-
-
-C2N Messages.
-====================================================
-C2N Connection initialization request.
-Sent by client.
-ANON TLS
-
-[0xCA 0xCA][VER_MAJOR][VER_MINOR]
-
-4 octets
-
-====================================================
-C2N connection initialization success.
-Sent by node.
-ANON TLS
-
-[0x01 0x01]['O']['K']
-
-4 octets
-
-After this message client and node initiate ANON TLS session shutdown
-and after successful shutdown initiate new authenticated TLS session
-over the same TCP connection. Client acts as a TLS server and presents
-client sertificate, node acts as a TLS client and does not present
-certificate.
-====================================================
-Protocol versions mismatch.
-Sent by node.
-ANON TLS
-
-[0x02 0x02][VER_MAJOR][VER_MINOR]
-
-4 octets
-
-VER_MAJOR, VER_MINOR - Pica Pica protocol version supported by node
-
-This message is sent if node and client protocol versions are not equal.
-After sending and receiving this message TCP connection is closed by both
-hosts.
-====================================================
-Multilogin notification.
-Sent by client that logged in. Retranslated to other nodes.
-Delivered to existing connected client instance.
-
-[0x0E 0x0E][length 2 octets][timestamp][node address][signature from UH, timestamp, node
-address]
-
-timestamp - time when client logged in, 64-bit Unix timestamp in UTC timezone
-
-node address - one of 0xA0, 0xA1, 0xA2 message, announced address of the node
-which sending client is connected to.
-
-signature - digital signature using SHA224 hash and private RSA key of sending
-client. Signature is calculated from concatenated sender's UH, timestamp and
-node address = Sign(UH|timestamp|node address)
-
-
diff --git a/doc/proto.txt b/doc/proto.txt
deleted file mode 100755
index a7f16ec..0000000
--- a/doc/proto.txt
+++ /dev/null
@@ -1,192 +0,0 @@
-Формат пакета
-[Заголовок] - 2 байта с одинаковым значением, определяющим тип сообщения
-[Хвост] - остальная часть пакета. Может быть пустым. Имеет либо фиксированную длину, заданную для данного сообщения,
-либо содержит в начале 1 или 2 байта, содержащих размер (в виде целого беззнакового числа, порядок байт-младший байт по младшему адресу) остальной части, не включая байты размера
-
-UH - user hash - SHA224 хэш от сертификата пользователя в DER формате, 28 байт, является идентификатором пользователя
-
-Протокол авторизации и пересылки данных (между сервером и клиентом)
-
-+++[запрос на подключение] -клиент
-0xCA 0xCA (Ver_major Ver_minor - версия протокола клиента, 2 байта)
--4 байт
-
-===============новый вариант
-+++[ответ сервера] - сервер
-0x01 0x01 'O' 'K'
-===============новый вариант
-При удачном прохождении проверки клиент ожидает инициирования защищенного соединения по протоколу TLS, выступая в роли сервера. Сервер выступает в роли TLS-клиента.
-
-
-+++[различные версии протокола] -сервер
-0x02 0x02 Ver_major Ver_minor - версия протокола сервера
-
-после отправки данного пакета сервер разрывает соединение.
-
- Нижеследующие сообщения передаются через защищенное управляющее соединение клиента с сервером.
-|КЛИЕНТ-СЕРВЕР|
-
-+++[запрос на установление соединения с собеседником] - клиент, по установленному защищенному соединению
-0x03 0x03 (UH вызываемого пользователя)
-
-+++[запрос на разрешение соединения] - сервер, по установленному защищенному соединению
-0x04 0x04 (UH инициатора)
-
-+++[пользователь с данным UH не найден (в оффлайне, отказался от разговора)]
-- сервер, по установленному защищенному соединению
-0x05 0x05 (UH вызываемого пользователя)
-
-+++[разрешение соединения от вызываемого пользователя] -вызываемый клиент, по установленному защищенному соединению
-0x06 0x06 (UH вызывающего пользователя)
-после отправки данного сообщения вызваемый клиент осуществляет подключение к серверу на порт обмена данными (_DATA_PORT) и отправляет через это соединение сообщение 0x20 -идентификация нового соединения
-
-+++[пользователь с данным UH найден и готов общаться] - сервер вызывающему клиенту
-0x07 0x07 (UH вызываемого пользователя)
-
-+++[отказ от общения]-вызываемый клиент
-0x08 0x08 (UH вызывающего пользователя)
-
-+++[запрос списка узлов] - клиент
-0x09 0x09 (2 псевдослучайных байта)
-
-+++[список узлов] - сервер
-0x0A 0x0A -- см формат 0xA4
-
- Нижеследующие сообщения передаются через соединение сервера с клиентом для передачи данных
-
-+++[идентификация нового соединения] - клиент
-0x20 0x20 (UH вызывающего пользователя) (UH вызываемого пользователя)
-
-сервер при получении данного сообщения проверяет UH-ы. При несовпадении соединение разрывается. После проверки сервер переходит в режим пересылки данных между двумя клиентами. Вызывающий клиент инициирует установку соединения по протоколу TLS
-
-
-
-Протокол обмена сообщениями (между клиентами через сервер(ы) ) |КЛИЕНТ-КЛИЕНТ|
-
-+++[начало c2c соединения] - клиент клиенту
-0xCC 0xCC Ver_major Ver_minor - версия протокола клиента
-варианты ответа - 0x01,0x02
-
-+++[список прямых адресов клиента]
-0x0B 0x0B -- см формат A4
-0xA0, 0xA1, 0xA1 - аналогично сообщениям n2n
-Если клиент настроен для приёма входящих прямых соединений между клиентами (минуя ноду), он может послать список своих адресов.
-Первыми в списке должны идти адреса локальной сети (если они есть) из подсетей 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8,
-чтобы клиенты, находящиеся в одной локальной сети могли соединиться напрямую. Далее следуют публичные адреса интернета.
-Если клиент находится за NAT и пробрасывает открытый порт на свой локальный адрес, в адресе должен быть указан внешний порт.
- Получив анонс, другой клиент может создать соединение с этим адресом и закрыть соединение через ноду
-
-+++[попытки прямого соединения провалились]
-0x0C 0x0C (2 псевдослучайных байта)
-отправляется инициатором, если он получил от вызываемого клиента список прямых адресов и все попытки подключения к полученным адресам оказались неуспешны.
-После получения этого сообщения вызываемый клиент начинает попытки подключения к прямым адресам инициатора, если от инициатора был получен список прямых
-адресов и прямые подключения разрешены настройками вызываемого
-
-+++[переключение на прямое соединение]
-0x0D 0x0D (2 псевдослучайных байта)
-отправляется после успешного TLS хэндшейка на прямом соединении каждой из сторон по соединению через ноду, после отправки этого сообщения все следующие сообщения
-отправляются по прямому соединению, получатель сообщения соответственно ожидает следующие сообщения уже по прямому соединению.
-
-+++[сообщение - текст в кодировке UTF8]
-0x30 0x30 (длина сообщения в байтах- 2 байта в формате little-endian) сообщение в кодировке UTF8
-
-+++[отчет о доставке предыдущего сообщения]
-0x40 0x40 (2 псевдослучайных байта)
-
-+++ [запрос на отправку файла]
-0x50 0x50 (длина сообщения - 2 байта, 9..263) (размер файла - 8 байт) имя файла в UTF-8, 1 - 255 байт
-
-+++ [подтверждение принятия файла]
-0x51 0x51 (2 псевдослучайных байта)
-
-после получения этого сообщения отправитель начинает отправку файла
-
-+++ [отказ от приёма файла]
-0x52 0x52 (2 псевдослучайных байта)
-
-+++ [фрагмент файла]
-0x53 0x53 (длина фрагмента - 2 байта, 0 - 65532) фрагмент файла
-
-+++[управление передачей файла]
-0x54 0x54 (команда отправителя) (команда получателя)
-Команды: 00 - пустая команда (бездействие) 01 - приостановить 02 - возобновить 03 - отменить 04 - отменить из-за ошибки чтения/записи файла
-
-
-Пинг
-
-+++[пинг-запрос] - может быть отправлен любой стороной, как по управляющему соединению, так и по межклиентскому
-0x68 0x68 (2 псевдослучайных байта)
-
-+++[пинг-ответ]
-0x69 0x69 (2 псевдослучайных байта)
-
-
-
-Протокол межсерверного взаимодействия | СЕРВЕР-СЕРВЕР (УЗЕЛ-УЗЕЛ)
-
-+++[запрос на подключение сервера] -узел узлу
-0xCB 0xCB Ver_major Ver_minor - версия протокола узла
-
-(варианты ответа сервера - 0x01,0x02 - те же, что и для клиента)
-
-+++[анонс нового узла - IPv4 адрес]
-0xA0 0xA0 | IP -адрес нового узла - 4 байта, сетевой порядок байт| номер порта - 2 байта, сетевой порядок байт|
-
-+++[анонс нового узла - IPv6 адрес]
-0xA1 0xA1 | IPv6 -адрес нового узла - 16 байт, сетевой порядок байт| номер порта - 2 байта, сетевой порядок байт|
-
-+++[анонс нового узла - DNS адрес]
-0xA2 0xA2 | длина адреса - 1 байт | DNS адрес нового узла| номер порта - 2 байта, сетевой порядок байт|
-
-Заявленный в анонсе адрес должнен соответствовать адресу, с которого произошло подключение. Получивший анонс узел должен это проверить.
-
-+++[список узлов]
-0xA4 0xA4 | размер списка адресов в байтах, 2 байта - 0..65532| список адресов
-список адресов представляет собой последовательность из элементов 3 возможных типов
-|0xA0|IP -адрес - 4 байта | номер порта - 2 байта| - 7 байт
-|0xA1|IPv6 -адрес | номер порта - 2 байта|- 19 байт
-|0xA2|длина адреса - 1байт| DNS адрес| номер порта - 2 байта| 4 ... 259байт
-
-Первым в списке всегда идет собственный адрес узла-отправителя (в данном адресном пространстве).
-Сообщение может содержать не весь список узлов, а только часть. Весь список в таком случае будет пересылаться по частям. Адреса и номера портов имеют "сетевой" порядок байтов.
-Размер всего пакета не превышает 64кб
-
-+++[запрос списка узлов] @@@
-0x90 0x90 (2 псевдослучайных байта)
-
-
-+++[поиск клиента] - отправляется всем узлам. Узел-получатель отвечает на это сообщение, только если искомый UH найден среди локальных клиентов либо в кэше
-0xA5 0xA5 (UH вызываемого пользователя)
-
-+++[результат поиска клиента-клиент найден ] - отправляется узлом, получившим 0xA5, если искомый UH найден среди локальных подключенных клиентов
-0xA8 0xA8 (UH вызываемого пользователя)
-
-+++[результат поиска клиента-клиент найден в кэше ] - отправляется узлом, получившим 0xA5, если искомый UH найден в кэше (т.е есть информация о подключении искомого клиента к другому узлу)
-0xA9 0xA9 (размер - два байта, [32-287] )(UH вызываемого пользователя) (адрес узла, на котором может быть искомый UH, в формате A0|A1|A2 см. описание 0xA4)
-
-
-+++[запрос на разрешение соединения c клиентом узла-получателя]
-0xAA 0xAA (UH инициатора) (UH вызываемого пользователя)
-
-+++[разрешение соединения от вызываемого пользователя]-отправляется после того, как вызываемый локальный клиент ответил сообщением 0x06 и создал новое соединение для обмена сообщениями
-0xAB 0xAB (UH инициатора) (UH вызываемого пользователя)
-
-+++[клиент не найден (в оффлайне, отказался от разговора)]
-отправляется узлом в ответ на сообщение 0xD0, адресованное данному UH-у,
-если данный пользователь уже отключился или его нету в списке локальных клиентов,
-либо в ответ на 0xAA, если вызываемый клиент отказался от соединения.
-0xB8 0xB8 (UH инициатора)(UH вызываемого пользователя)
-
-+++[сообщение, передаваемое клиентами между узлами]
-0xD0 0xD0 (длина вложенного сообщения в байтах [56 - 65532] , - 2 байта в формате little-endian) (UH локального пользователя-отправителя) (UH пользователя на другом узле) вложенные данные
-
-вложенные данные - данные передаваемые через соединение КЛИЕНТ-КЛИЕНТ
-
-
-
-
-
-
-
-
-
diff --git a/doc/protocol-specification.txt b/doc/protocol-specification.txt
new file mode 100644
index 0000000..ed0380e
--- /dev/null
+++ b/doc/protocol-specification.txt
@@ -0,0 +1,822 @@
+Protocol Specification.
+
+Terminology.
+
+Client - a software instance that interacts with human users and lets them send
+and receive encrypted messages over Pica Pica.
+
+Node - a software instance that coordinates the Pica Pica network, maintains a
+list of all active nodes and provides connectivity to clients.
+
+UH - user hash - the SHA224 hash of a user certificate in DER format, 28
+octets. It is used as a user identifier.
+
+Connections.
+There are 5 types of connections between Pica Pica nodes and clients.
+Apart from them, a node accepts single UDP datagrams from clients, see the "Get
+my UDP address" messages.
+
+-client to node (c2n) - a control connection from a client to a node
+
+-client to client (c2c) - a data connection between clients through a node
+acting as a proxy
+
+-node to node (n2n) - a control & data connection between nodes
+
+-direct client to client (directc2c) - a direct connection between clients,
+using the IPv4/IPv6/DNS address of the accepting client previously
+communicated over a c2c connection.
+
+-media client to client (mediac2c) - a direct connection between clients
+carrying the real time media of an audio/video call. It uses UDP transport
+and DTLS 1.2 with mutual certificate authentication.
+
+A mediac2c connection is established only while a call is in progress. It is
+made in one of two ways, see "Establishing the media connection" in the Audio
+and Video Calls section:
+
+-over the address of an established directc2c connection, with UDP instead
+of TCP: the client that made the outgoing directc2c connection acts as the
+DTLS client and connects to the address and port number that connection was
+made to, the client that accepted it acts as the DTLS server and listens on
+the UDP port with the same number as its directc2c listening port;
+
+-by UDP hole punching, between the media sockets the two clients opened for
+the call, over the addresses exchanged in the 0x70 and 0x71 messages: the
+caller acts as the DTLS client, the callee as the DTLS server. No directc2c
+connection is needed for this.
+
+Either way, each side verifies that the certificate presented by the peer
+hashes to the UH of the peer of the c2c connection the call belongs to,
+exactly as it does on a directc2c connection.
+
+Media packets are carried over the mediac2c connection whenever it is
+established, and over the c2c or directc2c connection otherwise. There is
+no message announcing the change: the receiving side accepts media packets
+over either transport for the whole duration of a call.
+
+The first 4 connection types use TCP transport. The first 3 connection types start
+with a TLS 1.2 handshake using an anonymous Diffie-Hellman ciphersuite; the
+connecting host acts as the TLS client, the accepting host as the TLS server.
+After the connection type is identified by the accepting node, the anonymous
+TLS session is gracefully closed in the case of c2n and c2c connections. In the
+case of c2n the node starts a new TLS session with the client, where the node
+acts as the TLS client and the client acts as the TLS server, using the
+client's RSA certificate. In the case of a c2c connection the node acts as a
+transparent proxy, sending chunks of data received from the first client to the
+second one and vice versa. The clients establish a mutually authenticated TLS
+session over the proxied connection; the initiator client is the TLS client,
+the accepting client has the TLS server role.
+An n2n connection continues to operate in the ADH TLS session, as by design
+nodes do not store any state that identifies them other than their network
+address.
+
+
+Packet Format.
+
+A Pica Pica protocol message packet contains a header and a tail.
+
+[Header][Tail]
+
+The header is a 2-octet sequence that identifies the packet. The first and
+second octets are always equal to each other.
+The tail is the remaining part of the packet and can be empty. The tail can
+have a fixed predefined length or, in the case of a variable length packet, it
+begins with a 1- or 2-octet sequence containing an unsigned integer that
+defines the length in octets of the remaining part of the tail, not including
+the length octets. The length field is stored in little-endian format, least
+significant octet first.
+The whole packet length is limited to 65536 octets, so the length field value
+is within the 0..65532 range.
+
+Example:
+
+0x55 0x55 0x03 0x00 0xAA 0xBB 0xCC
+[0x55 0x55] - header
+[0x03 0x00] - tail length, 2 octets
+[0xAA 0xBB 0xCC] - payload, 3 octets
+
+
+C2N Messages.
+====================================================
+C2N connection initialization request.
+Sent by the client.
+ANON TLS
+
+[0xCA 0xCA][VER_MAJOR][VER_MINOR]
+
+4 octets
+
+VER_MAJOR, VER_MINOR - the Pica Pica protocol version supported by the client
+
+====================================================
+C2N connection initialization success.
+Sent by the node.
+ANON TLS
+
+[0x01 0x01]['O']['K']
+
+4 octets
+
+After this message the client and the node initiate an ANON TLS session
+shutdown, and after a successful shutdown they initiate a new authenticated TLS
+session over the same TCP connection. The client acts as the TLS server and
+presents the client certificate; the node acts as the TLS client and does not
+present a certificate.
+====================================================
+Protocol version mismatch.
+Sent by the node.
+ANON TLS
+
+[0x02 0x02][VER_MAJOR][VER_MINOR]
+
+4 octets
+
+VER_MAJOR, VER_MINOR - the Pica Pica protocol version supported by the node
+
+This message is sent if the node's and the client's protocol versions do not
+match. After this message is sent and received, the TCP connection is closed by
+both hosts.
+====================================================
+
+ The messages below are transmitted over the secure c2n control
+ connection between a client and a node.
+
+====================================================
+Request to establish a connection with a peer.
+Sent by the client.
+
+[0x03 0x03][UH of the called user]
+
+30 octets
+====================================================
+Incoming connection permission request.
+Sent by the node.
+
+[0x04 0x04][UH of the initiator]
+
+30 octets
+====================================================
+The user with the given UH was not found (offline, or refused to talk).
+Sent by the node.
+
+[0x05 0x05][UH of the called user]
+
+30 octets
+====================================================
+Connection allowed by the called user.
+Sent by the called client.
+
+[0x06 0x06][UH of the calling user]
+
+30 octets
+
+After sending this message, the called client connects to the node's data
+exchange port (_DATA_PORT) and sends message 0x20 - new connection
+identification - over that connection.
+====================================================
+The user with the given UH was found and is ready to talk.
+Sent by the node to the calling client.
+
+[0x07 0x07][UH of the called user]
+
+30 octets
+====================================================
+Connection denied.
+Sent by the called client.
+
+[0x08 0x08][UH of the calling user]
+
+30 octets
+====================================================
+Node list request.
+Sent by the client.
+
+[0x09 0x09][2 pseudo-random octets]
+
+4 octets
+====================================================
+Node list.
+Sent by the node.
+
+[0x0A 0x0A] - see the 0xA4 message format
+====================================================
+Multilogin notification.
+Sent by a client that has logged in. Relayed to other nodes.
+Delivered to the existing connected client instance.
+
+[0x0E 0x0E][length 2 octets][timestamp][node address][signature from UH, timestamp, node
+address]
+
+timestamp - the time when the client logged in, a 64-bit Unix timestamp in the
+UTC timezone
+
+node address - one of the 0xA0, 0xA1, 0xA2 messages; the announced address of
+the node the sending client is connected to.
+
+signature - a digital signature using the SHA224 hash and the private RSA key
+of the sending client. The signature is calculated from the sender's
+concatenated UH, timestamp and node address = Sign(UH|timestamp|node address)
+
+====================================================
+Get my TCP address.
+
+Sent by a client. Requests the node to respond with the client
+address and TCP port as seen by the node. The response should
+be one packet of the type A0 or A1 corresponding to the protocol used for this
+TCP connection - IPv4 or IPv6
+
+[0x0F 0x0F][2 pseudo-random octets]
+
+4 octets
+====================================================
+My TCP address.
+Sent by the node in reply to 0x0F.
+
+[0xA0 0xA0][IP address - 4 octets, network byte order][port number - 2 octets, network byte order]
+
+8 octets
+
+or
+
+[0xA1 0xA1][IPv6 address - 16 octets, network byte order][port number - 2 octets, network byte order]
+
+20 octets
+
+A client must ignore this message unless it is waiting for it.
+====================================================
+Get my UDP address.
+Sent by a client.
+
+[0x10 0x10][2 pseudo-random octets]
+
+4 octets
+
+Requests a token that lets the client learn the address and port its UDP
+datagrams arrive at the node from, i.e. what the NAT in front of the client
+maps one of its UDP sockets to. The exchange is:
+
+ c2n client -> node 0x10 request
+ c2n node -> client 0x11 token
+ UDP client -> node 0x10 the token, from the socket in question
+ c2n node -> client 0x12 source address and port of that datagram
+
+A node serves only a limited number of these requests in a row from one
+client, and may not serve them at all (e.g. it has no UDP port open); a request
+that is not served is not answered. The client gives up by timeout.
+====================================================
+UDP address token.
+Sent by the node in reply to 0x10.
+
+[0x11 0x11][token, 16 octets]
+
+18 octets
+
+token - random octets from a cryptographically secure generator, chosen by the
+node. It is valid for a short time (10 seconds) and for one datagram. A client
+has at most one valid token: a new 0x10 request invalidates the token issued
+for the previous one.
+====================================================
+UDP address probe.
+Sent by a client to the node as a UDP datagram, not over a connection.
+
+[0x10 0x10][token, 16 octets]
+
+18 octets, the whole datagram
+
+Sent to the UDP port with the same number as the TCP port the c2n connection
+was made to, from the socket whose external address the client wants to learn.
+Datagrams can be lost, so the client sends it a few times, about a second
+apart, until 0x12 arrives.
+
+The node never answers over UDP, whatever it receives. A datagram that is not
+exactly 18 octets long, or does not carry a currently valid token, is silently
+dropped. When a valid token arrives, the node invalidates it and sends 0x12
+over the c2n connection the token was issued on. Copies of the datagram that
+arrive afterwards are therefore dropped as well.
+====================================================
+My UDP address.
+Sent by the node over the c2n connection.
+
+[0x12 0x12][length, 1 octet][address]
+
+address - the source address and port of the datagram that carried the token,
+in network byte order:
+[0xA0][IP address - 4 octets][port number - 2 octets], length 7, or
+[0xA1][IPv6 address - 16 octets][port number - 2 octets], length 19.
+
+A client must ignore this message unless it is waiting for it.
+
+Security considerations.
+The token only ties a datagram to an authenticated c2n connection. The source
+address the node reports cannot be authenticated - it is not known to the
+client, and is rewritten on the way by design - so somebody able to observe the
+datagram can send a copy of it from another address, and have that address
+reported if the copy arrives first. The reported address must therefore be
+treated only as a place where the client might be reachable, never as proof of
+who is reachable there: a connection made to it has to authenticate the peer
+on its own, as directc2c and mediac2c connections do.
+====================================================
+
+ The message below is transmitted over the connection between a node
+ and a client which is used for data transfer.
+
+====================================================
+New connection identification.
+Sent by the client.
+
+[0x20 0x20][UH of the calling user][UH of the called user]
+
+58 octets
+
+Upon receiving this message the node checks the UHs. If they do not match, the
+connection is closed. After the check the node switches into data relaying mode
+between the two clients. The calling client initiates the TLS connection
+establishment.
+====================================================
+
+
+C2C Messages.
+The messaging protocol between clients through node(s).
+====================================================
+C2C connection initialization request.
+Sent by a client to another client.
+
+[0xCC 0xCC][VER_MAJOR][VER_MINOR]
+
+4 octets
+
+VER_MAJOR, VER_MINOR - the c2c protocol version supported by the client
+
+Possible responses - 0x01, 0x02
+====================================================
+Client direct address list.
+
+[0x0B 0x0B] - see the 0xA4 message format
+0xA0, 0xA1, 0xA2 - the same as in n2n messages
+
+If a client is configured to accept incoming direct client to client
+connections (bypassing the node), it can send a list of its own addresses.
+The list can contain any number of addresses, e.g. one for every network
+interface of the client and the external address of a port forwarded to it.
+Local network addresses (if there are any) from the 192.168.0.0/16,
+172.16.0.0/12 and 10.0.0.0/8 subnets must be placed first in the list, so that
+clients residing in the same local network are able to connect directly. Public
+internet addresses follow them.
+If the client is behind NAT and forwards an open port to its local address, the
+external port number must be specified in the address.
+The connecting client tries the addresses one at a time, in the order of the
+list. It skips the elements of a type it does not connect to (e.g. 0xA1 without
+IPv6 connectivity), stepping over them by their size as given in the 0xA4
+description; such elements are not an error.
+A private address (the subnets above, and 100.64.0.0/10) is only tried if it
+is on the network of a private address of one of the connecting client's own
+network interfaces, as given by that interface's netmask; any other private
+address belongs to some other network and is skipped without a connection
+attempt. Since such an address is on the local network, the TCP connection to
+it is given up after 200 milliseconds, while the TLS handshake that follows
+has as long as for any other address.
+Having received the announcement, the other client can create a connection to
+that address and close the connection through the node.
+The announced port numbers are used both for TCP directc2c connections and for
+UDP mediac2c connections, so a client behind NAT has to forward the port for
+both protocols.
+====================================================
+Direct connection attempts failed.
+
+[0x0C 0x0C][2 pseudo-random octets]
+
+4 octets
+
+Sent by the initiator if it has received a direct address list from the called
+client and all connection attempts to the received addresses were unsuccessful.
+After receiving this message, the called client starts connection attempts to
+the direct addresses of the initiator, if an address list was received from the
+initiator and direct connections are allowed by the called client's settings.
+====================================================
+Switch to direct connection.
+
+[0x0D 0x0D][2 pseudo-random octets]
+
+4 octets
+
+Sent by each side over the connection through the node after a successful TLS
+handshake on the direct connection. After sending this message, all subsequent
+messages are sent over the direct connection; the receiver of the message
+correspondingly expects subsequent messages over the direct connection.
+====================================================
+Message - UTF-8 encoded text.
+
+[0x30 0x30][length 2 octets][UTF-8 encoded message]
+====================================================
+Delivery report for the previous message.
+
+[0x40 0x40][2 pseudo-random octets]
+
+4 octets
+====================================================
+File sending request.
+
+[0x50 0x50][length 2 octets, 9..263][file size, 8 octets][file name in UTF-8, 1 - 255 octets]
+====================================================
+File accepted.
+
+[0x51 0x51][2 pseudo-random octets]
+
+4 octets
+
+After receiving this message, the sender starts sending the file.
+====================================================
+File rejected.
+
+[0x52 0x52][2 pseudo-random octets]
+
+4 octets
+====================================================
+File fragment.
+
+[0x53 0x53][fragment length, 2 octets, 0 - 65532][file fragment]
+====================================================
+File transfer control.
+
+[0x54 0x54][sender command][receiver command]
+
+4 octets
+
+Commands:
+00 - void command (no action)
+01 - pause
+02 - resume
+03 - cancel
+04 - cancel because of a file read/write error
+====================================================
+
+
+Audio and Video Calls.
+The call control messages (0x70 - 0x75) are sent between clients over a c2c or
+directc2c connection.
+The media packets (0x76, 0x77) are sent over a mediac2c connection when one is
+established, and over the c2c or directc2c connection otherwise. Over a
+mediac2c connection every datagram contains exactly one message, and messages
+can be lost, reordered or duplicated; the receiving side must be prepared for
+that and must not treat a malformed or unexpected packet as a protocol error
+breaking the connection. In particular, a media packet can arrive before the
+0x74 or 0x75 message describing the stream it belongs to, because those travel
+over a different connection; such a packet is discarded.
+The media connection probe is not a message of any connection: it is a UDP
+datagram sent while the media connection is being established, see below.
+====================================================
+Call request (ring)
+
+[0x70 0x70][length, 2 octets][probe token, 8 octets][address list]
+
+length - covers everything following it: 8 + the size of the address list.
+
+probe token - random octets from a cryptographically secure generator, chosen
+anew for every call. The peer puts it into the media connection probes it sends
+to the sender of this message.
+
+address list - the addresses where the sender's media socket for this call may
+be reachable, as elements of the 0xA4 format, of types 0xA0 and 0xA1 only:
+first the socket's port number with each of the sender's own interface
+addresses, then the address and port the node reported for that socket in a
+0x12 message, if the sender got one. The list is empty if the sender does not
+take part in hole punching, e.g. because direct connections are disabled in its
+settings.
+
+Before sending this message the caller opens its media socket and asks the node
+for the socket's address (0x10 - 0x12), waiting for the answer at most 2
+seconds; when it does not come in time, the message is sent without that
+address.
+
+The receiver skips elements of other types and uses at most the first 8
+addresses of the list.
+====================================================
+Call answer (pick up)
+
+[0x71 0x71][length, 2 octets][probe token, 8 octets][address list]
+
+The same format and meaning as in 0x70, for the callee's media socket.
+
+The callee opens its media socket and asks the node for its address when the
+0x70 message arrives, while the call is ringing, so that sending 0x71 is not
+delayed by it when the user answers; if the address has still not arrived by
+then, 0x71 waits for it at most 2 seconds. The callee's addresses are revealed
+only by this message, i.e. only if the call is answered. The list can be empty
+when the caller's list was.
+====================================================
+Call reject
+
+[0x72 0x72]
+[2 pseudo-random octets]
+
+4 octets
+====================================================
+Call hang up (finished)
+
+[0x73 0x73]
+[2 pseudo-random octets]
+
+4 octets
+====================================================
+Audio stream parameters
+
+[0x74 0x74]
+[codec - a 20 octet string, left-aligned, padded with zeroes;
+"opus", "adpcm_g722", "pcm_alaw", named as in ffmpeg]
+[sample rate, uint16_t, little-endian]
+
+24 octets
+====================================================
+Video stream parameters
+
+[0x75 0x75]
+[codec - a 20 octet string, left-aligned, padded with zeroes, e.g.
+"hevc", "h264", "mjpeg", "vp9", named as in ffmpeg]
+[width, uint16_t, little-endian]
+[height, uint16_t, little-endian]
+
+26 octets
+====================================================
+Voice (audio) packet
+
+[0x76 0x76][length 2 octets][sequence number, uint16_t, little-endian][timestamp, uint32_t, little-endian, milliseconds since the start of the call][data]
+
+length - covers everything following it: the 2-octet sequence number, the
+4-octet timestamp and the data, i.e. data length + 6.
+
+sequence number - incremented by one for every audio packet sent over this
+call, wraps around at 65536. It lets the receiving side detect encoder-side
+gaps (e.g. a dropped capture buffer) and, over a mediac2c connection, put
+the received packets back in order, detect losses and discard duplicates.
+
+timestamp - the capture timestamp of the packet's first sample, in
+milliseconds, relative to the moment the call became active (the 0x71
+message was processed). Used by the receiver for playout-buffer timing and
+audio/video synchronization.
+====================================================
+Video packet
+
+[0x77 0x77][length 2 octets][sequence number, uint16_t, little-endian][timestamp, uint32_t, little-endian, milliseconds since the start of the call][data]
+
+length - covers everything following it: the 2-octet sequence number, the
+4-octet timestamp and the data, i.e. data length + 6.
+
+sequence number - the most significant bit (0x8000) is the last fragment
+marker, see the fragmentation description below. The remaining 15 bits are a
+counter incremented by one for every video packet sent over this call,
+wrapping around at 32768. The counter serves the same purpose as in the 0x76
+message: gap detection and future unordered/lossy transport support.
+
+timestamp - the capture timestamp of the encoded video frame, in
+milliseconds, relative to the moment the call became active. Used by the
+receiver for playout timing and audio/video synchronization. All fragments
+of one encoded frame carry the same timestamp, see below.
+
+Fragmentation.
+
+The length field limits the data carried by a single 0x77 message to 65526
+octets, while an encoded video frame - an intra-coded (key) frame in
+particular - can be larger than that. Such a frame is split into several
+consecutive 0x77 messages.
+
+All fragments of one encoded frame carry the same timestamp; the 15-bit
+counter part of the sequence number is incremented for every fragment, as it
+is for every other video packet. The last fragment of a frame has the last
+fragment marker bit (0x8000) set in its sequence number; every preceding
+fragment of the same frame has that bit cleared. A frame that fits into a
+single message is sent as one message with the marker bit set.
+
+Over a c2c or directc2c connection a single 0x77 message can carry up to
+65526 octets of data. Over a mediac2c connection the whole message has to
+fit into one datagram, so the amount of data a fragment carries is limited
+by the path MTU instead, and an encoded frame is normally split into many
+more fragments.
+
+The receiving side concatenates the data of the received fragments and
+passes the result to the video decoder once a message with the marker bit
+set has been received.
+
+Since fragments can be lost over a mediac2c connection, the receiving side
+must also check that the fragments it concatenates are consecutive: a
+fragment may only start a new frame if the previously accepted message had
+the last fragment marker bit set and the counter part of the sequence
+number of the new one follows it without a gap. If a gap is detected, the
+partially assembled frame is discarded and the receiving side skips
+fragments until a message with the last fragment marker bit set is
+received, resuming assembly with the message following it. Without this
+rule, losing the first fragment of a frame would make the receiving side
+treat the second one as the beginning of a frame and pass a truncated frame
+to the decoder.
+====================================================
+Establishing the media connection.
+
+When a call becomes active - for the callee when it sends 0x71, for the
+caller when 0x71 arrives - each side makes up to two attempts to establish a
+mediac2c connection, one after another. Until one succeeds, and for the rest
+of the call if neither does, the media packets travel over the c2c or
+directc2c connection. Once established, the mediac2c connection carries the
+media until the call ends: lost datagrams, a time without any arriving, or
+errors the system reports for datagrams sent (e.g. ICMP port unreachable) do
+not end it. Only the DTLS session ending - a close_notify or a fatal alert
+from the peer - does.
+
+Attempt 1, over the directc2c address. Made only if the c2c connection the
+call belongs to has an established directc2c connection, as described in the
+Connections section. Given up when the DTLS handshake fails, or when the
+connection is not established 5 seconds after the call became active.
+
+Attempt 2, by UDP hole punching. Made when attempt 1 is not made or is given
+up, and only if both the 0x70 and the 0x71 message carried a non-empty address
+list. Each side uses its media socket for the call - the one its address list
+was made for - and the caller acts as the DTLS client.
+
+1. Each side sends a media connection probe to every address of the peer's
+list, repeating every 200 milliseconds. A private address in the list is
+handled as in the 0x0B message: it is skipped unless it is on the network of
+a private address of one of the side's own network interfaces. One that is
+not skipped is local, and is sent probes only during the first 200
+milliseconds, every 50 milliseconds. A probe that arrives before the
+receiving side has started sending its own waits on that side's media
+socket, so a side starting later than the other still selects the address in
+step 2 and answers from it.
+2. When a side receives a probe carrying its own probe token, it selects the
+address the probe came from. That address need not be in the peer's list: a
+NAT can map the peer's socket to another port for this destination than for
+the node. From then on the side sends probes to the selected address only and
+accepts datagrams only from it.
+3. The caller starts the DTLS handshake as soon as it has selected an address,
+and keeps sending probes to it until the first datagram of the handshake
+arrives from the callee. The callee keeps sending probes until the first
+datagram of the handshake arrives from the caller. DTLS datagrams that arrive
+before the receiving side has selected an address are discarded; the DTLS
+retransmission takes care of them.
+4. The attempt is given up if no address has been selected 10 seconds after
+the side started sending probes, or if the handshake fails or is not complete
+10 seconds after that.
+
+A side starting attempt 2 late - having given up attempt 1, or having become
+active later than the peer - is still within the 10 seconds the peer keeps
+sending probes for.
+
+Security considerations.
+The probe token, sent over the authenticated c2c connection, keeps a host
+that does not see the probes from steering the choice of the address. One that
+does see them can send copies from another address, the same as with the 0x10
+datagram; the DTLS handshake authenticates the peer regardless, and a failed
+handshake only leaves the media on the c2c connection.
+The addresses in a peer's list are not checked, so a peer can make a client
+send probes to any host. This is bounded by the limits above: 8 addresses,
+5 probes a second each, 10 seconds - at most 400 datagrams of 10 octets per
+call.
+====================================================
+Media connection probe.
+Sent as a UDP datagram from the media socket of a call, outside of DTLS.
+
+[0x78 0x78][probe token, 8 octets]
+
+10 octets, the whole datagram
+
+probe token - the token the receiver of the probe sent in its 0x70 or 0x71
+message.
+
+A probe carries nothing but the token and is discarded after it has been
+looked at. One that is exactly 10 octets long, carries the receiver's token
+and arrives before the receiver has selected an address makes the receiver
+select the address it came from, see step 2 above; all others have no effect.
+A DTLS record never starts with the octet 0x78, so probes are told apart from
+DTLS records by their first octet at any stage of the connection.
+====================================================
+
+
+Ping.
+Can be sent by either side, both over the c2n control connection and over a
+connection between clients.
+Over a mediac2c connection it is also used as a keepalive, to hold open the
+NAT and firewall state the connection depends on while neither side is
+sending media, and to detect that the connection has stopped working.
+====================================================
+Ping request.
+
+[0x68 0x68][2 pseudo-random octets]
+
+4 octets
+====================================================
+Ping reply.
+
+[0x69 0x69][2 pseudo-random octets]
+
+4 octets
+====================================================
+
+
+N2N Messages.
+The inter-node interaction protocol.
+====================================================
+Node connection request.
+Sent by one node to another.
+
+[0xCB 0xCB][VER_MAJOR][VER_MINOR]
+
+4 octets
+
+VER_MAJOR, VER_MINOR - the Pica Pica protocol version supported by the node
+
+Possible responses - 0x01, 0x02 - the same as for a client
+====================================================
+New node announcement - IPv4 address.
+
+[0xA0 0xA0][IP address of the new node - 4 octets, network byte order][port number - 2 octets, network byte order]
+
+8 octets
+====================================================
+New node announcement - IPv6 address.
+
+[0xA1 0xA1][IPv6 address of the new node - 16 octets, network byte order][port number - 2 octets, network byte order]
+
+20 octets
+====================================================
+New node announcement - DNS address.
+
+[0xA2 0xA2][address length - 1 octet][DNS address of the new node][port number - 2 octets, network byte order]
+====================================================
+
+The address declared in the announcement must match the address from which the
+connection was made. The node that receives the announcement must verify this.
+
+====================================================
+Node list.
+
+[0xA4 0xA4][address list size in octets, 2 octets - 0..65532][address list]
+
+The address list is a sequence of elements of 3 possible types
+[0xA0][IP address - 4 octets][port number - 2 octets] - 7 octets
+[0xA1][IPv6 address][port number - 2 octets] - 19 octets
+[0xA2][address length - 1 octet][DNS address][port number - 2 octets] - 4 ... 259 octets
+
+The sending node's own address (in the given address space) always goes first
+in the list.
+A message can contain only a part of the node list instead of the whole list;
+in that case the whole list is sent in parts. Addresses and port numbers are in
+"network" byte order.
+The whole packet size does not exceed 64 KB.
+====================================================
+Node list request.
+
+[0x90 0x90][2 pseudo-random octets]
+
+4 octets
+====================================================
+Client search.
+Sent to all nodes. The receiving node replies to this message only if the
+requested UH is found among its local clients or in its cache.
+
+[0xA5 0xA5][UH of the called user]
+
+30 octets
+====================================================
+Client search result - client found.
+Sent by a node that received 0xA5, if the requested UH is found among its local
+connected clients.
+
+[0xA8 0xA8][UH of the called user]
+
+30 octets
+====================================================
+Client search result - client found in cache.
+Sent by a node that received 0xA5, if the requested UH is found in its cache
+(i.e. there is information that the client being searched for is connected to
+another node).
+
+[0xA9 0xA9][size, 2 octets, 32..287][UH of the called user][address of the node where the requested UH may be located, in A0|A1|A2 format, see the 0xA4 description]
+====================================================
+Request to allow a connection with a client of the receiving node.
+
+[0xAA 0xAA][UH of the initiator][UH of the called user]
+
+58 octets
+====================================================
+Connection allowed by the called user.
+Sent after the called local client has replied with a 0x06 message and created
+a new connection for message exchange.
+
+[0xAB 0xAB][UH of the initiator][UH of the called user]
+
+58 octets
+====================================================
+Client not found (offline, or refused to talk).
+
+[0xB8 0xB8][UH of the initiator][UH of the called user]
+
+58 octets
+
+Sent by a node in reply to a 0xD0 message addressed to this UH, if that user
+has already disconnected or is not in the list of local clients, or in reply to
+0xAA, if the called client denied the connection.
+====================================================
+Message transmitted between nodes on behalf of clients.
+
+[0xD0 0xD0][embedded message length in octets, 56..65532, 2 octets little-endian][UH of the local sending user][UH of the user on another node][embedded data]
+
+embedded data - data transmitted over the CLIENT-CLIENT connection
+====================================================