summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Tox/libtox/docs/CHANGELOG.md80
-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
10 files changed, 234 insertions, 127 deletions
diff --git a/protocols/Tox/libtox/docs/CHANGELOG.md b/protocols/Tox/libtox/docs/CHANGELOG.md
index f0a24be0d8..e80f359878 100644
--- a/protocols/Tox/libtox/docs/CHANGELOG.md
+++ b/protocols/Tox/libtox/docs/CHANGELOG.md
@@ -1,9 +1,80 @@
+## v0.2.4
+
+### Merged PRs:
+
+- [#1014](https://github.com/TokTok/c-toxcore/pull/1014) Use string comparison operator in configure.ac.
+- [#1013](https://github.com/TokTok/c-toxcore/pull/1013) Link -lsocket and -lnsl for socket functions on Solaris.
+- [#1012](https://github.com/TokTok/c-toxcore/pull/1012) Correct the max hostname length constant.
+- [#1009](https://github.com/TokTok/c-toxcore/pull/1009) Using stdint instead of int/long
+- [#1008](https://github.com/TokTok/c-toxcore/pull/1008) Set `_XOPEN_SOURCE` to 700 for FreeBSD.
+- [#1007](https://github.com/TokTok/c-toxcore/pull/1007) Use enums for group packet types.
+- [#1006](https://github.com/TokTok/c-toxcore/pull/1006) Set C++11/C99 flag manually in older cmake on not-msvc.
+- [#1005](https://github.com/TokTok/c-toxcore/pull/1005) Use the correct repository name in the coverage badge.
+- [#1003](https://github.com/TokTok/c-toxcore/pull/1003) Remove LOGGER_ERROR for harmless send failure.
+- [#1001](https://github.com/TokTok/c-toxcore/pull/1001) Add conference_by_uid and conference_get_uid functions.
+- [#1000](https://github.com/TokTok/c-toxcore/pull/1000) Limit number of group chats to 65536.
+- [#998](https://github.com/TokTok/c-toxcore/pull/998) Use named function types for group callbacks.
+- [#997](https://github.com/TokTok/c-toxcore/pull/997) Style fixes in TCP code; remove MIN and PAIR from util.h.
+- [#996](https://github.com/TokTok/c-toxcore/pull/996) Add the bazel build as one of the PR blocking builds.
+- [#995](https://github.com/TokTok/c-toxcore/pull/995) Fix style in some header files.
+- [#994](https://github.com/TokTok/c-toxcore/pull/994) Fix style in DHT.c.
+- [#993](https://github.com/TokTok/c-toxcore/pull/993) Move `load_state` and its helper functions to their own module.
+- [#991](https://github.com/TokTok/c-toxcore/pull/991) Use named function types for friend_connection callbacks.
+- [#990](https://github.com/TokTok/c-toxcore/pull/990) Use named function types for friend_requests callbacks.
+- [#989](https://github.com/TokTok/c-toxcore/pull/989) Use named function types for callbacks in net_crypto.
+- [#987](https://github.com/TokTok/c-toxcore/pull/987) Use named types for onion callbacks.
+- [#986](https://github.com/TokTok/c-toxcore/pull/986) Simplify Travis-CI FreeBSD build
+- [#985](https://github.com/TokTok/c-toxcore/pull/985) Clarify the intent of "file kinds" in the API.
+- [#984](https://github.com/TokTok/c-toxcore/pull/984) Avoid side-effectful assignments in conditionals.
+- [#981](https://github.com/TokTok/c-toxcore/pull/981) Factor out time keeping code into its own module: mono_time.c.
+- [#979](https://github.com/TokTok/c-toxcore/pull/979) Add a thread-safe version of unix_time and friends.
+- [#978](https://github.com/TokTok/c-toxcore/pull/978) Rename `BS_LIST` to `BS_List` to follow the naming conventions.
+- [#977](https://github.com/TokTok/c-toxcore/pull/977) Remove VLA usage from `send_audio_packet`.
+- [#976](https://github.com/TokTok/c-toxcore/pull/976) Call the "peer leaves" callback only once on group delete.
+- [#975](https://github.com/TokTok/c-toxcore/pull/975) Factor out the actual test code from conference_test.
+- [#972](https://github.com/TokTok/c-toxcore/pull/972) Add a test that reproduces the NULL peer nick bug.
+- [#968](https://github.com/TokTok/c-toxcore/pull/968) Make tox.c unambiguously parseable.
+- [#967](https://github.com/TokTok/c-toxcore/pull/967) lan_discovery_test and version_test cleanup
+- [#966](https://github.com/TokTok/c-toxcore/pull/966) Use run_auto_test.h test fixture for some auto-tests.
+- [#965](https://github.com/TokTok/c-toxcore/pull/965) Add `#include <cstdio>` for `std::printf`.
+- [#964](https://github.com/TokTok/c-toxcore/pull/964) Add some tests for our ring_buffer implementation.
+- [#962](https://github.com/TokTok/c-toxcore/pull/962) Collect `PACKET_ID*` constants in `net_crypto.h`, cleanup their uses
+- [#958](https://github.com/TokTok/c-toxcore/pull/958) Fix leak of Logger instances in dht_test.
+- [#957](https://github.com/TokTok/c-toxcore/pull/957) Remove broken conference tests.
+- [#955](https://github.com/TokTok/c-toxcore/pull/955) Another TCP_test upgrade
+- [#954](https://github.com/TokTok/c-toxcore/pull/954) Proposal: Make arg `host` understand clearly.
+- [#953](https://github.com/TokTok/c-toxcore/pull/953) Add missing MAX_HOSTNAME_LENGTH doc.
+- [#945](https://github.com/TokTok/c-toxcore/pull/945) Add a test to try and overflow the send queue in net_crypto.
+- [#943](https://github.com/TokTok/c-toxcore/pull/943) Correct check for net_crypto packet index.
+- [#942](https://github.com/TokTok/c-toxcore/pull/942) Simplify Travis CI builds.
+- [#932](https://github.com/TokTok/c-toxcore/pull/932) Various minor cleanups in `net_crypto`.
+
+### Closed issues:
+
+- [#1015](https://github.com/TokTok/c-toxcore/issues/1015) Improve Solaris support
+- [#1004](https://github.com/TokTok/c-toxcore/issues/1004) qTox: "Program received signal SIGPIPE, Broken pipe." with TokTok-c-toxcore-v0.2.3_GH0 on FreeBSD 11.x.
+- [#988](https://github.com/TokTok/c-toxcore/issues/988) Registration on https://nodes.tox.chat (question)
+- [#982](https://github.com/TokTok/c-toxcore/issues/982) Merge the two travis stages for freebsd back into one
+- [#970](https://github.com/TokTok/c-toxcore/issues/970) Crash with persistent groups
+- [#963](https://github.com/TokTok/c-toxcore/issues/963) ToxAV's `rb_write` function is written in a strange way
+- [#946](https://github.com/TokTok/c-toxcore/issues/946) [API] for max proxy address length
+- [#944](https://github.com/TokTok/c-toxcore/issues/944) How detect that friend is busy
+- [#936](https://github.com/TokTok/c-toxcore/issues/936) Help needed in testing a tox client,I need some dummy toxids to test .
+- [#923](https://github.com/TokTok/c-toxcore/issues/923) Crash on malloc in ping_array_add
+- [#911](https://github.com/TokTok/c-toxcore/issues/911) Weekly Tox Dev Meeting
+- [#910](https://github.com/TokTok/c-toxcore/issues/910) Crash in clear_entry in ping_array.c
+- [#903](https://github.com/TokTok/c-toxcore/issues/903) c-toxcore and LGPL (question)
+- [#528](https://github.com/TokTok/c-toxcore/issues/528) c-toxcore on Windows can be compiled using MSYS2 (with modern MinGW-w64)
+- [#450](https://github.com/TokTok/c-toxcore/issues/450) Run format-test earlier in the build
+- [#429](https://github.com/TokTok/c-toxcore/issues/429) Cannot build on Windows using MinGW
+
## v0.2.3
### Merged PRs:
+- [#952](https://github.com/TokTok/c-toxcore/pull/952) Release v0.2.3
- [#951](https://github.com/TokTok/c-toxcore/pull/951) Only run astyle if the astyle binary exists.
- [#950](https://github.com/TokTok/c-toxcore/pull/950) Remove utils.c and utils.h from toxencryptsave build.
- [#949](https://github.com/TokTok/c-toxcore/pull/949) Fixes to the imported sodium sources to compile without warnings.
@@ -110,6 +181,7 @@
- [#789](https://github.com/TokTok/c-toxcore/pull/789) Remove tox_test from autotools build.
- [#788](https://github.com/TokTok/c-toxcore/pull/788) Don't print trace level logging in tests.
- [#787](https://github.com/TokTok/c-toxcore/pull/787) Split up tox_test into multiple smaller tests
+- [#784](https://github.com/TokTok/c-toxcore/pull/784) Use Wine Devel instead of Wine Staging
- [#783](https://github.com/TokTok/c-toxcore/pull/783) Send 0 as peer number in CHANGE_OCCURRED group event.
- [#782](https://github.com/TokTok/c-toxcore/pull/782) Use `const` more in C code.
- [#781](https://github.com/TokTok/c-toxcore/pull/781) Don't build all the small sub-libraries.
@@ -117,6 +189,7 @@
- [#779](https://github.com/TokTok/c-toxcore/pull/779) Remove leftover symmetric key from DHT struct.
- [#778](https://github.com/TokTok/c-toxcore/pull/778) Add static asserts for all the struct sizes in toxcore.
- [#776](https://github.com/TokTok/c-toxcore/pull/776) Optionally use newer cmake features.
+- [#775](https://github.com/TokTok/c-toxcore/pull/775) Look for dependencies in third_party/
- [#774](https://github.com/TokTok/c-toxcore/pull/774) Improve gtest finding, support local checkout.
- [#773](https://github.com/TokTok/c-toxcore/pull/773) Add gtest include directory to -I flags if found.
- [#772](https://github.com/TokTok/c-toxcore/pull/772) Reject discovery packets coming from outside the "LAN".
@@ -124,7 +197,9 @@
- [#770](https://github.com/TokTok/c-toxcore/pull/770) Add MSVC compilation instructions
- [#767](https://github.com/TokTok/c-toxcore/pull/767) Build toxcore with libsodium.dll instead of libsodium.lib.
- [#766](https://github.com/TokTok/c-toxcore/pull/766) Remove libcheck from the dependencies.
+- [#765](https://github.com/TokTok/c-toxcore/pull/765) Make outgoing Filetransfers round-robin.
- [#764](https://github.com/TokTok/c-toxcore/pull/764) Fix LAN discovery on FreeBSD.
+- [#761](https://github.com/TokTok/c-toxcore/pull/761) use official debian domain
- [#760](https://github.com/TokTok/c-toxcore/pull/760) Make cmake script more forgiving.
- [#759](https://github.com/TokTok/c-toxcore/pull/759) Use more ubuntu packages; remove hstox for now.
- [#757](https://github.com/TokTok/c-toxcore/pull/757) Improve stability of crypto_memcmp test.
@@ -156,12 +231,15 @@
- [#716](https://github.com/TokTok/c-toxcore/pull/716) Add comment from #629 in ring_buffer.c.
- [#714](https://github.com/TokTok/c-toxcore/pull/714) Make BUILD files more finely-grained.
- [#713](https://github.com/TokTok/c-toxcore/pull/713) Add BUILD files for all the little tools in the repo.
+- [#712](https://github.com/TokTok/c-toxcore/pull/712) Fix high quality video sending (backport to 0.1.x).
- [#711](https://github.com/TokTok/c-toxcore/pull/711) Make the monolith test a C++ binary.
- [#710](https://github.com/TokTok/c-toxcore/pull/710) Don't allocate or dereference Tox_Options in tests.
- [#709](https://github.com/TokTok/c-toxcore/pull/709) Remove nTox from the repo.
- [#708](https://github.com/TokTok/c-toxcore/pull/708) Add testing/*.c (except av_test) to bazel build.
- [#707](https://github.com/TokTok/c-toxcore/pull/707) Fix log message in simple_conference_test: invite -> message.
+- [#705](https://github.com/TokTok/c-toxcore/pull/705) Add correction support for conference
- [#703](https://github.com/TokTok/c-toxcore/pull/703) Add a simple conference test with 3 friends.
+- [#702](https://github.com/TokTok/c-toxcore/pull/702) Update to astyle 2.04 on CircleCI to get the correct result
- [#701](https://github.com/TokTok/c-toxcore/pull/701) Add astyle to Circle CI build.
- [#700](https://github.com/TokTok/c-toxcore/pull/700) Use more descriptive names in bwcontroller.
- [#699](https://github.com/TokTok/c-toxcore/pull/699) Add some explanatory comments to the toxav audio code.
@@ -191,6 +269,7 @@
- [#669](https://github.com/TokTok/c-toxcore/pull/669) Make Onion_Client a module-private type.
- [#668](https://github.com/TokTok/c-toxcore/pull/668) Make Ping_Array a module-private type.
- [#667](https://github.com/TokTok/c-toxcore/pull/667) pkg-config .pc files: added .private versions of Libs and Required
+- [#666](https://github.com/TokTok/c-toxcore/pull/666) Fix some typos in code and cmake comments
- [#665](https://github.com/TokTok/c-toxcore/pull/665) Remove useless if statement
- [#662](https://github.com/TokTok/c-toxcore/pull/662) Move Networking_Core struct into the .c file.
- [#661](https://github.com/TokTok/c-toxcore/pull/661) Disable asan, since it seems to break on travis.
@@ -199,6 +278,7 @@
- [#658](https://github.com/TokTok/c-toxcore/pull/658) Call freeaddrinfo on error paths in net_getipport.
- [#657](https://github.com/TokTok/c-toxcore/pull/657) Zero-initialise stack-allocated objects in hstox driver.
- [#656](https://github.com/TokTok/c-toxcore/pull/656) Fix file descriptor leak in hstox test.
+- [#654](https://github.com/TokTok/c-toxcore/pull/654) Bump toxcore version to 0.2.0.
- [#652](https://github.com/TokTok/c-toxcore/pull/652) Add support for building the monolith test on android.
- [#650](https://github.com/TokTok/c-toxcore/pull/650) Remove deprecated ToxDNS
- [#648](https://github.com/TokTok/c-toxcore/pull/648) Make hstox compile on FreeBSD
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);