summaryrefslogtreecommitdiff
path: root/protocols/Tox/libtox/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/libtox/src')
-rw-r--r--protocols/Tox/libtox/src/toxcore/Messenger.c59
-rw-r--r--protocols/Tox/libtox/src/toxcore/Messenger.h27
-rw-r--r--protocols/Tox/libtox/src/toxcore/group.c67
-rw-r--r--protocols/Tox/libtox/src/toxcore/net_crypto.c27
-rw-r--r--protocols/Tox/libtox/src/toxcore/net_crypto.h70
-rw-r--r--protocols/Tox/libtox/src/toxcore/network.c11
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.api.h8
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.c4
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.h8
9 files changed, 154 insertions, 127 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.c b/protocols/Tox/libtox/src/toxcore/Messenger.c
index 416b937c91..c45debed47 100644
--- a/protocols/Tox/libtox/src/toxcore/Messenger.c
+++ b/protocols/Tox/libtox/src/toxcore/Messenger.c
@@ -172,8 +172,8 @@ static int send_offline_packet(Messenger *m, int friendcon_id)
static int m_handle_status(void *object, int i, uint8_t status, void *userdata);
static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata);
-static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
- void *userdata);
+static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
+ void *userdata);
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
{
@@ -203,7 +203,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
m->friendlist[i].is_typing = 0;
m->friendlist[i].message_id = 0;
friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &m_handle_status, &m_handle_packet,
- &m_handle_custom_lossy_packet, m, i);
+ &m_handle_lossy_packet, m, i);
if (m->numfriends == i) {
++m->numfriends;
@@ -515,7 +515,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
}
VLA(uint8_t, packet, length + 1);
- packet[0] = type + PACKET_ID_MESSAGE;
+ packet[0] = PACKET_ID_MESSAGE + type;
if (length != 0) {
memcpy(packet + 1, message, length);
@@ -1807,8 +1807,8 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0);
}
-static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
- void *userdata)
+static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
+ void *userdata)
{
Messenger *m = (Messenger *)object;
@@ -1816,11 +1816,12 @@ static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint
return 1;
}
- if (packet[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) {
- if (m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % PACKET_LOSSY_AV_RESERVED].function) {
- return m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % PACKET_LOSSY_AV_RESERVED].function(
- m, friend_num, packet, length, m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] %
- PACKET_LOSSY_AV_RESERVED].object);
+ if (packet[0] <= PACKET_ID_RANGE_LOSSY_AV_END) {
+ const RTP_Packet_Handler *const ph =
+ &m->friendlist[friend_num].lossy_rtp_packethandlers[packet[0] % PACKET_ID_RANGE_LOSSY_AV_SIZE];
+
+ if (ph->function) {
+ return ph->function(m, friend_num, packet, length, ph->object);
}
return 1;
@@ -1845,20 +1846,23 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lo
return -1;
}
- if (byte < PACKET_ID_LOSSY_RANGE_START) {
- return -1;
- }
-
- if (byte >= (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) {
+ if (byte < PACKET_ID_RANGE_LOSSY_AV_START || byte > PACKET_ID_RANGE_LOSSY_AV_END) {
return -1;
}
- m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = function;
- m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].object = object;
+ m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_ID_RANGE_LOSSY_AV_SIZE].function = function;
+ m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_ID_RANGE_LOSSY_AV_SIZE].object = object;
return 0;
}
+/* TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets.
+ * Meanwhile, m_handle_lossy_packet routes custom packets to custom_lossy_packet_registerhandler
+ * as you would expect from its name.
+ *
+ * I.e. custom_lossy_packet_registerhandler's "custom lossy packet" and this "custom lossy packet"
+ * are not the same set of packets.
+ */
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
if (friend_not_valid(m, friendnumber)) {
@@ -1869,11 +1873,8 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
return -2;
}
- if (data[0] < PACKET_ID_LOSSY_RANGE_START) {
- return -3;
- }
-
- if (data[0] >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) {
+ // TODO(oxij): send_lossy_cryptpacket makes this check already, similarly for other similar places
+ if (data[0] < PACKET_ID_RANGE_LOSSY_START || data[0] > PACKET_ID_RANGE_LOSSY_END) {
return -3;
}
@@ -1898,11 +1899,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
return -1;
}
- if (packet[0] < PACKET_ID_LOSSLESS_RANGE_START) {
- return -1;
- }
-
- if (packet[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) {
+ if (packet[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || packet[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) {
return -1;
}
@@ -1928,11 +1925,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
return -2;
}
- if (data[0] < PACKET_ID_LOSSLESS_RANGE_START) {
- return -3;
- }
-
- if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) {
+ if (data[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || data[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) {
return -3;
}
diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.h b/protocols/Tox/libtox/src/toxcore/Messenger.h
index 833e6b2bfb..8a4686f12e 100644
--- a/protocols/Tox/libtox/src/toxcore/Messenger.h
+++ b/protocols/Tox/libtox/src/toxcore/Messenger.h
@@ -28,6 +28,7 @@
#include "friend_connection.h"
#include "friend_requests.h"
#include "logger.h"
+#include "net_crypto.h"
#define MAX_NAME_LENGTH 128
/* TODO(irungentoo): this must depend on other variable. */
@@ -49,30 +50,6 @@ typedef enum Message_Type {
MESSAGE_ACTION
} Message_Type;
-/* NOTE: Packet ids below 24 must never be used. */
-#define PACKET_ID_ONLINE 24
-#define PACKET_ID_OFFLINE 25
-#define PACKET_ID_NICKNAME 48
-#define PACKET_ID_STATUSMESSAGE 49
-#define PACKET_ID_USERSTATUS 50
-#define PACKET_ID_TYPING 51
-#define PACKET_ID_MESSAGE 64
-#define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) // 65
-#define PACKET_ID_MSI 69
-#define PACKET_ID_FILE_SENDREQUEST 80
-#define PACKET_ID_FILE_CONTROL 81
-#define PACKET_ID_FILE_DATA 82
-#define PACKET_ID_INVITE_CONFERENCE 96
-#define PACKET_ID_ONLINE_PACKET 97
-#define PACKET_ID_DIRECT_CONFERENCE 98
-#define PACKET_ID_MESSAGE_CONFERENCE 99
-#define PACKET_ID_LOSSY_CONFERENCE 199
-
-/* All packets starting with a byte in this range can be used for anything. */
-#define PACKET_ID_LOSSLESS_RANGE_START 160
-#define PACKET_ID_LOSSLESS_RANGE_SIZE 32
-#define PACKET_LOSSY_AV_RESERVED 8 // Number of lossy packet types at start of range reserved for A/V.
-
typedef struct Messenger_Options {
bool ipv6enabled;
bool udp_disabled;
@@ -247,7 +224,7 @@ typedef struct Friend {
uint32_t num_sending_files;
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
- RTP_Packet_Handler lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
+ RTP_Packet_Handler lossy_rtp_packethandlers[PACKET_ID_RANGE_LOSSY_AV_SIZE];
struct Receipts *receipts_start;
struct Receipts *receipts_end;
diff --git a/protocols/Tox/libtox/src/toxcore/group.c b/protocols/Tox/libtox/src/toxcore/group.c
index 2ee81de820..95de1afbaf 100644
--- a/protocols/Tox/libtox/src/toxcore/group.c
+++ b/protocols/Tox/libtox/src/toxcore/group.c
@@ -33,6 +33,41 @@
#include "mono_time.h"
#include "util.h"
+/**
+ * Packet type IDs as per the protocol specification.
+ */
+typedef enum Group_Message_Id {
+ GROUP_MESSAGE_PING_ID = 0,
+ GROUP_MESSAGE_NEW_PEER_ID = 16,
+ GROUP_MESSAGE_KILL_PEER_ID = 17,
+ GROUP_MESSAGE_NAME_ID = 48,
+ GROUP_MESSAGE_TITLE_ID = 49,
+} Group_Message_Id;
+
+#define GROUP_MESSAGE_NEW_PEER_LENGTH (sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2)
+#define GROUP_MESSAGE_KILL_PEER_LENGTH (sizeof(uint16_t))
+
+#define MAX_GROUP_MESSAGE_DATA_LEN (MAX_CRYPTO_DATA_SIZE - (1 + MIN_MESSAGE_PACKET_LEN))
+
+typedef enum Invite_Id {
+ INVITE_ID = 0,
+ INVITE_RESPONSE_ID = 1,
+} Invite_Id;
+
+#define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
+#define INVITE_RESPONSE_PACKET_SIZE (1 + sizeof(uint16_t) * 2 + GROUP_IDENTIFIER_LENGTH)
+
+#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
+
+typedef enum Peer_Id {
+ PEER_KILL_ID = 1,
+ PEER_QUERY_ID = 8,
+ PEER_RESPONSE_ID = 9,
+ PEER_TITLE_ID = 10,
+} Peer_Id;
+
+#define MIN_MESSAGE_PACKET_LEN (sizeof(uint16_t) * 2 + sizeof(uint32_t) + 1)
+
/* return false if the groupnumber is not valid.
* return true if the groupnumber is valid.
*/
@@ -218,14 +253,12 @@ static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2)
{
uint64_t cmp1 = 0, cmp2 = 0;
- unsigned int i;
-
- for (i = 0; i < sizeof(uint64_t); ++i) {
+ for (size_t i = 0; i < sizeof(uint64_t); ++i) {
cmp1 = (cmp1 << 8) + (uint64_t)pk1[i];
cmp2 = (cmp2 << 8) + (uint64_t)pk2[i];
}
- return (cmp1 - cmp2);
+ return cmp1 - cmp2;
}
typedef enum Groupchat_Closest {
@@ -1024,12 +1057,6 @@ static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendco
packet, SIZEOF_VLA(packet)) != -1;
}
-#define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
-#define INVITE_ID 0
-
-#define INVITE_RESPONSE_PACKET_SIZE (1 + sizeof(uint16_t) * 2 + GROUP_IDENTIFIER_LENGTH)
-#define INVITE_RESPONSE_ID 1
-
/* invite friendnumber to groupnumber.
*
* return 0 on success.
@@ -1254,7 +1281,6 @@ int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_d
static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data,
uint16_t len);
-#define GROUP_MESSAGE_PING_ID 0
static int group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
{
if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) {
@@ -1264,8 +1290,6 @@ static int group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
return -1;
}
-#define GROUP_MESSAGE_NEW_PEER_ID 16
-#define GROUP_MESSAGE_NEW_PEER_LENGTH (sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2)
/* send a new_peer message
* return 0 on success
* return -1 on failure
@@ -1287,9 +1311,6 @@ static int group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uin
return -1;
}
-#define GROUP_MESSAGE_KILL_PEER_ID 17
-#define GROUP_MESSAGE_KILL_PEER_LENGTH (sizeof(uint16_t))
-
/* send a kill_peer message
* return 0 on success
* return -1 on failure
@@ -1308,8 +1329,6 @@ static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, ui
return -1;
}
-#define GROUP_MESSAGE_NAME_ID 48
-
/* send a name message
* return 0 on success
* return -1 on failure
@@ -1327,8 +1346,6 @@ static int group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const u
return -1;
}
-#define GROUP_MESSAGE_TITLE_ID 49
-
/* set the group's title, limited to MAX_NAME_LENGTH
* return 0 on success
* return -1 if groupnumber is invalid.
@@ -1536,8 +1553,6 @@ static unsigned int count_close_connected(Group_c *g)
return count;
}
-#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
-
static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier)
{
uint8_t packet[1 + ONLINE_PACKET_DATA_SIZE];
@@ -1609,10 +1624,6 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_
return 0;
}
-#define PEER_KILL_ID 1
-#define PEER_QUERY_ID 8
-#define PEER_RESPONSE_ID 9
-#define PEER_TITLE_ID 10
// we could send title with invite, but then if it changes between sending and accepting inv, joinee won't see it
/* return 1 on success.
@@ -1795,8 +1806,6 @@ static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const u
}
}
-#define MIN_MESSAGE_PACKET_LEN (sizeof(uint16_t) * 2 + sizeof(uint32_t) + 1)
-
/* Send message to all close except receiver (if receiver isn't -1)
* NOTE: this function appends the group chat number to the data passed to it.
*
@@ -1920,8 +1929,6 @@ static unsigned int send_lossy_all_close(const Group_Chats *g_c, uint32_t groupn
return sent;
}
-#define MAX_GROUP_MESSAGE_DATA_LEN (MAX_CRYPTO_DATA_SIZE - (1 + MIN_MESSAGE_PACKET_LEN))
-
/* Send data of len with message_id to groupnumber.
*
* return number of peers it was sent to on success.
diff --git a/protocols/Tox/libtox/src/toxcore/net_crypto.c b/protocols/Tox/libtox/src/toxcore/net_crypto.c
index b9ffaf2149..8f5fd5071b 100644
--- a/protocols/Tox/libtox/src/toxcore/net_crypto.c
+++ b/protocols/Tox/libtox/src/toxcore/net_crypto.c
@@ -1174,7 +1174,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
}
} else {
conn->maximum_speed_reached = 1;
- LOGGER_ERROR(c->log, "send_data_packet failed");
+ LOGGER_DEBUG(c->log, "send_data_packet failed");
}
return packet_num;
@@ -1549,7 +1549,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
}
set_buffer_end(c->log, &conn->recv_array, num);
- } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) {
+ } else if (real_data[0] >= PACKET_ID_RANGE_LOSSLESS_START && real_data[0] <= PACKET_ID_RANGE_LOSSLESS_END) {
Packet_Data dt = {0};
dt.length = real_length;
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
/* Packet counter. */
++conn->packet_counter;
- } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START &&
- real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) {
+ } else if (real_data[0] >= PACKET_ID_RANGE_LOSSY_START && real_data[0] <= PACKET_ID_RANGE_LOSSY_END) {
set_buffer_end(c->log, &conn->recv_array, num);
@@ -2702,6 +2701,8 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
* return -1 if data could not be put in packet queue.
* return positive packet number if data was put into the queue.
*
+ * The first byte of data must in the PACKET_ID_RANGE_LOSSLESS.
+ *
* congestion_control: should congestion control apply to this packet?
*/
int64_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
return -1;
}
- if (data[0] < CRYPTO_RESERVED_PACKETS) {
- return -1;
- }
-
- if (data[0] >= PACKET_ID_LOSSY_RANGE_START) {
+ if (data[0] < PACKET_ID_RANGE_LOSSLESS_START || data[0] > PACKET_ID_RANGE_LOSSLESS_END) {
return -1;
}
@@ -2780,10 +2777,12 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet
return 0;
}
-/* return -1 on failure.
+/* Sends a lossy cryptopacket.
+ *
+ * return -1 on failure.
* return 0 on success.
*
- * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
+ * The first byte of data must in the PACKET_ID_RANGE_LOSSY.
*/
int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
{
@@ -2791,11 +2790,7 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
return -1;
}
- if (data[0] < PACKET_ID_LOSSY_RANGE_START) {
- return -1;
- }
-
- if (data[0] >= PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE) {
+ if (data[0] < PACKET_ID_RANGE_LOSSY_START || data[0] > PACKET_ID_RANGE_LOSSY_END) {
return -1;
}
diff --git a/protocols/Tox/libtox/src/toxcore/net_crypto.h b/protocols/Tox/libtox/src/toxcore/net_crypto.h
index 2ed35883d3..e40b7bfd95 100644
--- a/protocols/Tox/libtox/src/toxcore/net_crypto.h
+++ b/protocols/Tox/libtox/src/toxcore/net_crypto.h
@@ -31,6 +31,57 @@
#include <pthread.h>
+/*** Crypto payloads. ***/
+
+/** Ranges. **/
+
+/* Packets in this range are reserved for net_crypto internal use. */
+#define PACKET_ID_RANGE_RESERVED_START 0
+#define PACKET_ID_RANGE_RESERVED_END 15
+/* Packets in this range are reserved for Messenger use. */
+#define PACKET_ID_RANGE_LOSSLESS_START 16
+#define PACKET_ID_RANGE_LOSSLESS_NORMAL_START 16
+#define PACKET_ID_RANGE_LOSSLESS_NORMAL_END 159
+/* Packets in this range can be used for anything. */
+#define PACKET_ID_RANGE_LOSSLESS_CUSTOM_START 160
+#define PACKET_ID_RANGE_LOSSLESS_CUSTOM_END 191
+#define PACKET_ID_RANGE_LOSSLESS_END 191
+/* Packets in this range are reserved for AV use. */
+#define PACKET_ID_RANGE_LOSSY_START 192
+#define PACKET_ID_RANGE_LOSSY_AV_START 192
+#define PACKET_ID_RANGE_LOSSY_AV_SIZE 8
+#define PACKET_ID_RANGE_LOSSY_AV_END 199
+/* Packets in this range can be used for anything. */
+#define PACKET_ID_RANGE_LOSSY_CUSTOM_START 200
+#define PACKET_ID_RANGE_LOSSY_CUSTOM_END 254
+#define PACKET_ID_RANGE_LOSSY_END 254
+
+/** Messages. **/
+
+#define PACKET_ID_PADDING 0 /* Denotes padding */
+#define PACKET_ID_REQUEST 1 /* Used to request unreceived packets */
+#define PACKET_ID_KILL 2 /* Used to kill connection */
+
+#define PACKET_ID_ONLINE 24
+#define PACKET_ID_OFFLINE 25
+#define PACKET_ID_NICKNAME 48
+#define PACKET_ID_STATUSMESSAGE 49
+#define PACKET_ID_USERSTATUS 50
+#define PACKET_ID_TYPING 51
+#define PACKET_ID_MESSAGE 64
+#define PACKET_ID_ACTION 65 /* PACKET_ID_MESSAGE + MESSAGE_ACTION */
+#define PACKET_ID_MSI 69 /* Used by AV to setup calls and etc */
+#define PACKET_ID_FILE_SENDREQUEST 80
+#define PACKET_ID_FILE_CONTROL 81
+#define PACKET_ID_FILE_DATA 82
+#define PACKET_ID_INVITE_CONFERENCE 96
+#define PACKET_ID_ONLINE_PACKET 97
+#define PACKET_ID_DIRECT_CONFERENCE 98
+#define PACKET_ID_MESSAGE_CONFERENCE 99
+#define PACKET_ID_LOSSY_CONFERENCE 199
+
+/*** Crypto connections. ***/
+
typedef enum Crypto_Conn_State {
CRYPTO_CONN_NO_CONNECTION = 0,
CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets
@@ -66,20 +117,9 @@ typedef enum Crypto_Conn_State {
/* The timeout of no received UDP packets before the direct UDP connection is considered dead. */
#define UDP_DIRECT_TIMEOUT 8
-#define PACKET_ID_PADDING 0 /* Denotes padding */
-#define PACKET_ID_REQUEST 1 /* Used to request unreceived packets */
-#define PACKET_ID_KILL 2 /* Used to kill connection */
-
-/* Packet ids 0 to CRYPTO_RESERVED_PACKETS - 1 are reserved for use by net_crypto. */
-#define CRYPTO_RESERVED_PACKETS 16
-
#define MAX_TCP_CONNECTIONS 64
#define MAX_TCP_RELAYS_PEER 4
-/* All packets starting with a byte in this range are considered lossy packets. */
-#define PACKET_ID_LOSSY_RANGE_START 192
-#define PACKET_ID_LOSSY_RANGE_SIZE 63
-
#define CRYPTO_MAX_PADDING 8 /* All packets will be padded a number of bytes based on this number. */
/* 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);
* return -1 if data could not be put in packet queue.
* return positive packet number if data was put into the queue.
*
- * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range.
+ * The first byte of data must be in the PACKET_ID_RANGE_LOSSLESS.
*
* congestion_control: should congestion control apply to this packet?
*/
@@ -225,10 +265,12 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
*/
int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number);
-/* return -1 on failure.
+/* Sends a lossy cryptopacket.
+ *
+ * return -1 on failure.
* return 0 on success.
*
- * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
+ * The first byte of data must be in the PACKET_ID_RANGE_LOSSY.
*/
int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length);
diff --git a/protocols/Tox/libtox/src/toxcore/network.c b/protocols/Tox/libtox/src/toxcore/network.c
index 3c262bab89..1c1459db32 100644
--- a/protocols/Tox/libtox/src/toxcore/network.c
+++ b/protocols/Tox/libtox/src/toxcore/network.c
@@ -29,6 +29,12 @@
#define _DARWIN_C_SOURCE
#endif
+// For Solaris.
+#ifdef __sun
+#define __EXTENSIONS__ 1
+#endif
+
+// For Linux (and some BSDs).
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
@@ -85,6 +91,11 @@
#include <sys/types.h>
#include <unistd.h>
+#ifdef __sun
+#include <stropts.h>
+#include <sys/filio.h>
+#endif
+
#define TOX_EWOULDBLOCK EWOULDBLOCK
#else
diff --git a/protocols/Tox/libtox/src/toxcore/tox.api.h b/protocols/Tox/libtox/src/toxcore/tox.api.h
index 632d79c530..97a85312b4 100644
--- a/protocols/Tox/libtox/src/toxcore/tox.api.h
+++ b/protocols/Tox/libtox/src/toxcore/tox.api.h
@@ -182,7 +182,7 @@ const VERSION_MINOR = 2;
* The patch or revision number. Incremented when bugfixes are applied without
* changing any functionality or API or ABI.
*/
-const VERSION_PATCH = 3;
+const VERSION_PATCH = 4;
/**
* A macro to check at preprocessing time whether the client code is compatible
@@ -318,12 +318,12 @@ const MAX_FILENAME_LENGTH = 255;
/**
* Maximum length of a hostname, e.g. proxy or bootstrap node names.
*
- * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so
- * they are 255 characters plus one NUL byte.
+ * This length does not include the NUL byte. Hostnames are NUL-terminated C
+ * strings, so they are 255 characters plus one NUL byte.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
-const MAX_HOSTNAME_LENGTH = 256;
+const MAX_HOSTNAME_LENGTH = 255;
/*******************************************************************************
diff --git a/protocols/Tox/libtox/src/toxcore/tox.c b/protocols/Tox/libtox/src/toxcore/tox.c
index cae2dcb36b..80ff42c343 100644
--- a/protocols/Tox/libtox/src/toxcore/tox.c
+++ b/protocols/Tox/libtox/src/toxcore/tox.c
@@ -1522,7 +1522,9 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
return 0;
}
- if (data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) {
+ // TODO(oxij): this feels ugly, this is needed only because m_send_custom_lossy_packet in Messenger.c
+ // sends both AV and custom packets despite its name and this API hides those AV packets
+ if (data[0] <= PACKET_ID_RANGE_LOSSY_AV_END) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID);
return 0;
}
diff --git a/protocols/Tox/libtox/src/toxcore/tox.h b/protocols/Tox/libtox/src/toxcore/tox.h
index 6a4df16dce..f8279afeee 100644
--- a/protocols/Tox/libtox/src/toxcore/tox.h
+++ b/protocols/Tox/libtox/src/toxcore/tox.h
@@ -183,7 +183,7 @@ uint32_t tox_version_minor(void);
* The patch or revision number. Incremented when bugfixes are applied without
* changing any functionality or API or ABI.
*/
-#define TOX_VERSION_PATCH 3
+#define TOX_VERSION_PATCH 4
uint32_t tox_version_patch(void);
@@ -345,12 +345,12 @@ uint32_t tox_max_filename_length(void);
/**
* Maximum length of a hostname, e.g. proxy or bootstrap node names.
*
- * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so
- * they are 255 characters plus one NUL byte.
+ * This length does not include the NUL byte. Hostnames are NUL-terminated C
+ * strings, so they are 255 characters plus one NUL byte.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
-#define TOX_MAX_HOSTNAME_LENGTH 256
+#define TOX_MAX_HOSTNAME_LENGTH 255
uint32_t tox_max_hostname_length(void);