diff options
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r-- | toxcore/net_crypto.h | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 25f8c2f7..938046f1 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -69,6 +69,10 @@ | |||
69 | #define STATUS_TCP_INVISIBLE 2 /* we know the other peer is connected to this relay but he isn't appearing online */ | 69 | #define STATUS_TCP_INVISIBLE 2 /* we know the other peer is connected to this relay but he isn't appearing online */ |
70 | #define STATUS_TCP_ONLINE 3 | 70 | #define STATUS_TCP_ONLINE 3 |
71 | 71 | ||
72 | /* All packets starting with a byte in this range are considered lossy packets. */ | ||
73 | #define PACKET_ID_LOSSY_RANGE_START 192 | ||
74 | #define PACKET_ID_LOSSY_RANGE_SIZE 63 | ||
75 | |||
72 | typedef struct { | 76 | typedef struct { |
73 | uint64_t time; | 77 | uint64_t time; |
74 | uint16_t length; | 78 | uint16_t length; |
@@ -119,6 +123,10 @@ typedef struct { | |||
119 | void *connection_data_callback_object; | 123 | void *connection_data_callback_object; |
120 | int connection_data_callback_id; | 124 | int connection_data_callback_id; |
121 | 125 | ||
126 | int (*connection_lossy_data_callback)(void *object, int id, uint8_t *data, uint16_t length); | ||
127 | void *connection_lossy_data_callback_object; | ||
128 | int connection_lossy_data_callback_id; | ||
129 | |||
122 | uint64_t last_request_packet_sent; | 130 | uint64_t last_request_packet_sent; |
123 | 131 | ||
124 | uint32_t packet_counter; | 132 | uint32_t packet_counter; |
@@ -231,7 +239,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port); | |||
231 | int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object, | 239 | int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object, |
232 | int id, uint8_t status), void *object, int id); | 240 | int id, uint8_t status), void *object, int id); |
233 | 241 | ||
234 | /* Set function to be called when connection with crypt_connection_id receives a data packet of length. | 242 | /* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. |
235 | * | 243 | * |
236 | * The set function should return -1 on failure and 0 on success. | 244 | * The set function should return -1 on failure and 0 on success. |
237 | * Object and id will be passed to this function untouched. | 245 | * Object and id will be passed to this function untouched. |
@@ -243,16 +251,38 @@ int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connec | |||
243 | int id, uint8_t *data, uint16_t length), void *object, int id); | 251 | int id, uint8_t *data, uint16_t length), void *object, int id); |
244 | 252 | ||
245 | 253 | ||
254 | /* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. | ||
255 | * | ||
256 | * The set function should return -1 on failure and 0 on success. | ||
257 | * Object and id will be passed to this function untouched. | ||
258 | * | ||
259 | * return -1 on failure. | ||
260 | * return 0 on success. | ||
261 | */ | ||
262 | int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | ||
263 | int (*connection_lossy_data_callback)(void *object, int id, uint8_t *data, uint16_t length), void *object, int id); | ||
264 | |||
246 | /* returns the number of packet slots left in the sendbuffer. | 265 | /* returns the number of packet slots left in the sendbuffer. |
247 | * return 0 if failure. | 266 | * return 0 if failure. |
248 | */ | 267 | */ |
249 | uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id); | 268 | uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id); |
250 | 269 | ||
251 | /* return -1 if data could not be put in packet queue. | 270 | /* Sends a lossless cryptopacket. |
252 | * return positive packet number if data was put into the queue. | 271 | * |
272 | * return -1 if data could not be put in packet queue. | ||
273 | * return positive packet number if data was put into the queue. | ||
274 | * | ||
275 | * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range. | ||
253 | */ | 276 | */ |
254 | int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); | 277 | int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); |
255 | 278 | ||
279 | /* return -1 on failure. | ||
280 | * return 0 on success. | ||
281 | * | ||
282 | * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*) | ||
283 | */ | ||
284 | int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); | ||
285 | |||
256 | /* Add a tcp relay, associating it to a crypt_connection_id. | 286 | /* Add a tcp relay, associating it to a crypt_connection_id. |
257 | * | 287 | * |
258 | * return 0 if it was added. | 288 | * return 0 if it was added. |