summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
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.c
parent3f6b6842f33f6ac74bdaa61cfa47565d509fa453 (diff)
Collect `PACKET_ID*` constants in `net_crypto.h`, cleanup their uses
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 6ca29ef3..8f5fd507 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1549,7 +1549,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1549 } 1549 }
1550 1550
1551 set_buffer_end(c->log, &conn->recv_array, num); 1551 set_buffer_end(c->log, &conn->recv_array, num);
1552 } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { 1552 } else if (real_data[0] >= PACKET_ID_RANGE_LOSSLESS_START && real_data[0] <= PACKET_ID_RANGE_LOSSLESS_END) {
1553 Packet_Data dt = {0}; 1553 Packet_Data dt = {0};
1554 dt.length = real_length; 1554 dt.length = real_length;
1555 memcpy(dt.data, real_data, real_length); 1555 memcpy(dt.data, real_data, real_length);
@@ -1582,8 +1582,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1582 1582
1583 /* Packet counter. */ 1583 /* Packet counter. */
1584 ++conn->packet_counter; 1584 ++conn->packet_counter;
1585 } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START && 1585 } else if (real_data[0] >= PACKET_ID_RANGE_LOSSY_START && real_data[0] <= PACKET_ID_RANGE_LOSSY_END) {
1586 real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) {
1587 1586
1588 set_buffer_end(c->log, &conn->recv_array, num); 1587 set_buffer_end(c->log, &conn->recv_array, num);
1589 1588
@@ -2702,6 +2701,8 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
2702 * return -1 if data could not be put in packet queue. 2701 * return -1 if data could not be put in packet queue.
2703 * return positive packet number if data was put into the queue. 2702 * return positive packet number if data was put into the queue.
2704 * 2703 *
2704 * The first byte of data must in the PACKET_ID_RANGE_LOSSLESS.
2705 *
2705 * congestion_control: should congestion control apply to this packet? 2706 * congestion_control: should congestion control apply to this packet?
2706 */ 2707 */
2707int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, 2708int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length,
@@ -2711,11 +2712,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
2711 return -1; 2712 return -1;
2712 } 2713 }
2713 2714
2714 if (data[0] < CRYPTO_RESERVED_PACKETS) { 2715 if (data[0] < PACKET_ID_RANGE_LOSSLESS_START || data[0] > PACKET_ID_RANGE_LOSSLESS_END) {
2715 return -1;
2716 }
2717
2718 if (data[0] >= PACKET_ID_LOSSY_RANGE_START) {
2719 return -1; 2716 return -1;
2720 } 2717 }
2721 2718
@@ -2780,10 +2777,12 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet
2780 return 0; 2777 return 0;
2781} 2778}
2782 2779
2783/* return -1 on failure. 2780/* Sends a lossy cryptopacket.
2781 *
2782 * return -1 on failure.
2784 * return 0 on success. 2783 * return 0 on success.
2785 * 2784 *
2786 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*) 2785 * The first byte of data must in the PACKET_ID_RANGE_LOSSY.
2787 */ 2786 */
2788int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) 2787int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
2789{ 2788{
@@ -2791,11 +2790,7 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
2791 return -1; 2790 return -1;
2792 } 2791 }
2793 2792
2794 if (data[0] < PACKET_ID_LOSSY_RANGE_START) { 2793 if (data[0] < PACKET_ID_RANGE_LOSSY_START || data[0] > PACKET_ID_RANGE_LOSSY_END) {
2795 return -1;
2796 }
2797
2798 if (data[0] >= PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE) {
2799 return -1; 2794 return -1;
2800 } 2795 }
2801 2796