summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2018-07-01 23:26:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-19 19:24:00 +0000
commite7a5f52c14c3603f883b5dbdcc9ab589b50a3ed0 (patch)
tree332dc17d7b7042612a652d83da0c47e330fb1d53 /toxcore/net_crypto.h
parent3f6b6842f33f6ac74bdaa61cfa47565d509fa453 (diff)
Collect `PACKET_ID*` constants in `net_crypto.h`, cleanup their uses
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h70
1 files changed, 56 insertions, 14 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 2ed35883..e40b7bfd 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -31,6 +31,57 @@
31 31
32#include <pthread.h> 32#include <pthread.h>
33 33
34/*** Crypto payloads. ***/
35
36/** Ranges. **/
37
38/* Packets in this range are reserved for net_crypto internal use. */
39#define PACKET_ID_RANGE_RESERVED_START 0
40#define PACKET_ID_RANGE_RESERVED_END 15
41/* Packets in this range are reserved for Messenger use. */
42#define PACKET_ID_RANGE_LOSSLESS_START 16
43#define PACKET_ID_RANGE_LOSSLESS_NORMAL_START 16
44#define PACKET_ID_RANGE_LOSSLESS_NORMAL_END 159
45/* Packets in this range can be used for anything. */
46#define PACKET_ID_RANGE_LOSSLESS_CUSTOM_START 160
47#define PACKET_ID_RANGE_LOSSLESS_CUSTOM_END 191
48#define PACKET_ID_RANGE_LOSSLESS_END 191
49/* Packets in this range are reserved for AV use. */
50#define PACKET_ID_RANGE_LOSSY_START 192
51#define PACKET_ID_RANGE_LOSSY_AV_START 192
52#define PACKET_ID_RANGE_LOSSY_AV_SIZE 8
53#define PACKET_ID_RANGE_LOSSY_AV_END 199
54/* Packets in this range can be used for anything. */
55#define PACKET_ID_RANGE_LOSSY_CUSTOM_START 200
56#define PACKET_ID_RANGE_LOSSY_CUSTOM_END 254
57#define PACKET_ID_RANGE_LOSSY_END 254
58
59/** Messages. **/
60
61#define PACKET_ID_PADDING 0 /* Denotes padding */
62#define PACKET_ID_REQUEST 1 /* Used to request unreceived packets */
63#define PACKET_ID_KILL 2 /* Used to kill connection */
64
65#define PACKET_ID_ONLINE 24
66#define PACKET_ID_OFFLINE 25
67#define PACKET_ID_NICKNAME 48
68#define PACKET_ID_STATUSMESSAGE 49
69#define PACKET_ID_USERSTATUS 50
70#define PACKET_ID_TYPING 51
71#define PACKET_ID_MESSAGE 64
72#define PACKET_ID_ACTION 65 /* PACKET_ID_MESSAGE + MESSAGE_ACTION */
73#define PACKET_ID_MSI 69 /* Used by AV to setup calls and etc */
74#define PACKET_ID_FILE_SENDREQUEST 80
75#define PACKET_ID_FILE_CONTROL 81
76#define PACKET_ID_FILE_DATA 82
77#define PACKET_ID_INVITE_CONFERENCE 96
78#define PACKET_ID_ONLINE_PACKET 97
79#define PACKET_ID_DIRECT_CONFERENCE 98
80#define PACKET_ID_MESSAGE_CONFERENCE 99
81#define PACKET_ID_LOSSY_CONFERENCE 199
82
83/*** Crypto connections. ***/
84
34typedef enum Crypto_Conn_State { 85typedef enum Crypto_Conn_State {
35 CRYPTO_CONN_NO_CONNECTION = 0, 86 CRYPTO_CONN_NO_CONNECTION = 0,
36 CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets 87 CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets
@@ -66,20 +117,9 @@ typedef enum Crypto_Conn_State {
66/* The timeout of no received UDP packets before the direct UDP connection is considered dead. */ 117/* The timeout of no received UDP packets before the direct UDP connection is considered dead. */
67#define UDP_DIRECT_TIMEOUT 8 118#define UDP_DIRECT_TIMEOUT 8
68 119
69#define PACKET_ID_PADDING 0 /* Denotes padding */
70#define PACKET_ID_REQUEST 1 /* Used to request unreceived packets */
71#define PACKET_ID_KILL 2 /* Used to kill connection */
72
73/* Packet ids 0 to CRYPTO_RESERVED_PACKETS - 1 are reserved for use by net_crypto. */
74#define CRYPTO_RESERVED_PACKETS 16
75
76#define MAX_TCP_CONNECTIONS 64 120#define MAX_TCP_CONNECTIONS 64
77#define MAX_TCP_RELAYS_PEER 4 121#define MAX_TCP_RELAYS_PEER 4
78 122
79/* All packets starting with a byte in this range are considered lossy packets. */
80#define PACKET_ID_LOSSY_RANGE_START 192
81#define PACKET_ID_LOSSY_RANGE_SIZE 63
82
83#define CRYPTO_MAX_PADDING 8 /* All packets will be padded a number of bytes based on this number. */ 123#define CRYPTO_MAX_PADDING 8 /* All packets will be padded a number of bytes based on this number. */
84 124
85/* Base current transfer speed on last CONGESTION_QUEUE_ARRAY_SIZE number of points taken 125/* Base current transfer speed on last CONGESTION_QUEUE_ARRAY_SIZE number of points taken
@@ -209,7 +249,7 @@ bool max_speed_reached(Net_Crypto *c, int crypt_connection_id);
209 * return -1 if data could not be put in packet queue. 249 * return -1 if data could not be put in packet queue.
210 * return positive packet number if data was put into the queue. 250 * return positive packet number if data was put into the queue.
211 * 251 *
212 * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range. 252 * The first byte of data must be in the PACKET_ID_RANGE_LOSSLESS.
213 * 253 *
214 * congestion_control: should congestion control apply to this packet? 254 * congestion_control: should congestion control apply to this packet?
215 */ 255 */
@@ -225,10 +265,12 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
225 */ 265 */
226int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number); 266int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number);
227 267
228/* return -1 on failure. 268/* Sends a lossy cryptopacket.
269 *
270 * return -1 on failure.
229 * return 0 on success. 271 * return 0 on success.
230 * 272 *
231 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*) 273 * The first byte of data must be in the PACKET_ID_RANGE_LOSSY.
232 */ 274 */
233int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length); 275int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length);
234 276