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/libtox.def1
-rw-r--r--protocols/Tox/libtox/src/toxcore/DHT.c14
-rw-r--r--protocols/Tox/libtox/src/toxcore/Messenger.c2
-rw-r--r--protocols/Tox/libtox/src/toxcore/Messenger.h2
-rw-r--r--protocols/Tox/libtox/src/toxcore/TCP_connection.c13
-rw-r--r--protocols/Tox/libtox/src/toxcore/TCP_connection.h2
-rw-r--r--protocols/Tox/libtox/src/toxcore/group.c127
-rw-r--r--protocols/Tox/libtox/src/toxcore/group.h75
-rw-r--r--protocols/Tox/libtox/src/toxcore/mono_time.c23
-rw-r--r--protocols/Tox/libtox/src/toxcore/mono_time.h3
-rw-r--r--protocols/Tox/libtox/src/toxcore/network.c1
-rw-r--r--protocols/Tox/libtox/src/toxcore/onion_client.c26
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.api.h39
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.c80
-rw-r--r--protocols/Tox/libtox/src/toxcore/tox.h41
-rw-r--r--protocols/Tox/libtox/src/toxcore/util.c5
-rw-r--r--protocols/Tox/libtox/src/toxcore/util.h1
17 files changed, 266 insertions, 189 deletions
diff --git a/protocols/Tox/libtox/src/libtox.def b/protocols/Tox/libtox/src/libtox.def
index 9df7b08801..ecc1c989f6 100644
--- a/protocols/Tox/libtox/src/libtox.def
+++ b/protocols/Tox/libtox/src/libtox.def
@@ -74,6 +74,7 @@ tox_version_patch
tox_add_tcp_relay
tox_bootstrap
tox_callback_conference_invite
+tox_callback_conference_connected
tox_callback_conference_message
tox_callback_conference_peer_list_changed
tox_callback_conference_peer_name
diff --git a/protocols/Tox/libtox/src/toxcore/DHT.c b/protocols/Tox/libtox/src/toxcore/DHT.c
index 543ee19176..37dd9385a0 100644
--- a/protocols/Tox/libtox/src/toxcore/DHT.c
+++ b/protocols/Tox/libtox/src/toxcore/DHT.c
@@ -1740,10 +1740,10 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
}
if ((num_nodes != 0) && (is_timeout(*lastgetnode, GET_NODE_INTERVAL) || *bootstrap_times < MAX_BOOTSTRAP_TIMES)) {
- uint32_t rand_node = rand() % num_nodes;
+ uint32_t rand_node = random_u32() % num_nodes;
if ((num_nodes - 1) != rand_node) {
- rand_node += rand() % (num_nodes - (rand_node + 1));
+ rand_node += random_u32() % (num_nodes - (rand_node + 1));
}
getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key, nullptr);
@@ -2050,7 +2050,7 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *
return 0;
}
- const int retval = sendpacket(dht->net, ip_list[rand() % n], packet, length);
+ const int retval = sendpacket(dht->net, ip_list[random_u32() % n], packet, length);
if ((unsigned int)retval == length) {
return 1;
@@ -2492,7 +2492,7 @@ static Node_format random_node(DHT *dht, Family sa_family)
uint8_t id[CRYPTO_PUBLIC_KEY_SIZE];
for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE / 4; ++i) { /* populate the id with pseudorandom bytes.*/
- const uint32_t t = rand();
+ const uint32_t t = random_u32();
memcpy(id + i * sizeof(t), &t, sizeof(t));
}
@@ -2504,7 +2504,7 @@ static Node_format random_node(DHT *dht, Family sa_family)
return nodes_list[0];
}
- return nodes_list[rand() % num_nodes];
+ return nodes_list[random_u32() % num_nodes];
}
#endif
@@ -2530,7 +2530,7 @@ static uint16_t list_nodes(Client_data *list, size_t length, Node_format *nodes,
if (!is_timeout(list[i - 1].assoc6.timestamp, BAD_NODE_TIMEOUT)) {
if (assoc == nullptr) {
assoc = &list[i - 1].assoc6;
- } else if (rand() % 2) {
+ } else if (random_u08() % 2) {
assoc = &list[i - 1].assoc6;
}
}
@@ -2560,7 +2560,7 @@ uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
}
uint16_t count = 0;
- const unsigned int r = rand();
+ const uint32_t r = random_u32();
for (size_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
count += list_nodes(dht->friends_list[(i + r) % DHT_FAKE_FRIEND_NUMBER].client_list, MAX_FRIEND_CLIENTS, nodes + count,
diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.c b/protocols/Tox/libtox/src/toxcore/Messenger.c
index a52c07f0b7..acf9f806f7 100644
--- a/protocols/Tox/libtox/src/toxcore/Messenger.c
+++ b/protocols/Tox/libtox/src/toxcore/Messenger.c
@@ -2626,7 +2626,7 @@ void do_messenger(Messenger *m, void *userdata)
for (client = 0; client < LCLIENT_LIST; ++client) {
const Client_data *cptr = dht_get_close_client(m->dht, client);
- const IPPTsPng *const assocs[] = { &cptr->assoc4, &cptr->assoc4, nullptr };
+ const IPPTsPng *const assocs[] = { &cptr->assoc4, &cptr->assoc6, nullptr };
for (const IPPTsPng * const *it = assocs; *it; ++it) {
const IPPTsPng *const assoc = *it;
diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.h b/protocols/Tox/libtox/src/toxcore/Messenger.h
index 8cab9801a0..6fc4df024c 100644
--- a/protocols/Tox/libtox/src/toxcore/Messenger.h
+++ b/protocols/Tox/libtox/src/toxcore/Messenger.h
@@ -272,7 +272,7 @@ struct Messenger {
m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
void *friend_connectionstatuschange_internal_userdata;
- void *conferences_object; /* Set by new_groupchats()*/
+ struct Group_Chats *conferences_object; /* Set by new_groupchats()*/
m_conference_invite_cb *conference_invite;
m_file_recv_cb *file_sendrequest;
diff --git a/protocols/Tox/libtox/src/toxcore/TCP_connection.c b/protocols/Tox/libtox/src/toxcore/TCP_connection.c
index 2d2dd47028..6763328da4 100644
--- a/protocols/Tox/libtox/src/toxcore/TCP_connection.c
+++ b/protocols/Tox/libtox/src/toxcore/TCP_connection.c
@@ -371,10 +371,10 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
*/
int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c)
{
- unsigned int i, r = rand();
+ const uint32_t r = random_u32();
- for (i = 0; i < tcp_c->tcp_connections_length; ++i) {
- unsigned int index = ((i + r) % tcp_c->tcp_connections_length);
+ for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
+ uint32_t index = ((i + r) % tcp_c->tcp_connections_length);
if (tcp_c->tcp_connections[index].onion && tcp_c->tcp_connections[index].status == TCP_CONN_CONNECTED) {
return index;
@@ -1283,11 +1283,12 @@ unsigned int tcp_connection_to_online_tcp_relays(TCP_Connections *tcp_c, int con
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
-unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
+uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num)
{
- unsigned int i, copied = 0, r = rand();
+ const uint32_t r = random_u32();
+ uint32_t copied = 0;
- for (i = 0; (i < tcp_c->tcp_connections_length) && (copied < max_num); ++i) {
+ for (uint32_t i = 0; (i < tcp_c->tcp_connections_length) && (copied < max_num); ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, (i + r) % tcp_c->tcp_connections_length);
if (!tcp_con) {
diff --git a/protocols/Tox/libtox/src/toxcore/TCP_connection.h b/protocols/Tox/libtox/src/toxcore/TCP_connection.h
index 658ee1f46f..2d99e12288 100644
--- a/protocols/Tox/libtox/src/toxcore/TCP_connection.h
+++ b/protocols/Tox/libtox/src/toxcore/TCP_connection.h
@@ -210,7 +210,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
-unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
+uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
/* Returns a new TCP_Connections object associated with the secret_key.
*
diff --git a/protocols/Tox/libtox/src/toxcore/group.c b/protocols/Tox/libtox/src/toxcore/group.c
index 317b885f56..20075c8b92 100644
--- a/protocols/Tox/libtox/src/toxcore/group.c
+++ b/protocols/Tox/libtox/src/toxcore/group.c
@@ -54,10 +54,10 @@ typedef enum Invite_Id {
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 INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + 1 + GROUP_ID_LENGTH)
+#define INVITE_RESPONSE_PACKET_SIZE (1 + sizeof(uint16_t) * 2 + 1 + GROUP_ID_LENGTH)
-#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
+#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + 1 + GROUP_ID_LENGTH)
typedef enum Peer_Id {
PEER_KILL_ID = 1,
@@ -200,17 +200,17 @@ static int peer_in_chat(const Group_c *chat, const uint8_t *real_pk)
}
/*
- * check if group with identifier is in group array.
+ * check if group with the given type and id is in group array.
*
* return group number if peer is in list.
* return -1 if group is not in list.
*
* TODO(irungentoo): make this more efficient and maybe use constant time comparisons?
*/
-static int32_t get_group_num(const Group_Chats *g_c, const uint8_t *identifier)
+static int32_t get_group_num(const Group_Chats *g_c, const uint8_t type, const uint8_t *id)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
- if (crypto_memcmp(g_c->chats[i].identifier, identifier, GROUP_IDENTIFIER_LENGTH) == 0) {
+ if (g_c->chats[i].type == type && crypto_memcmp(g_c->chats[i].id, id, GROUP_ID_LENGTH) == 0) {
return i;
}
}
@@ -218,10 +218,10 @@ static int32_t get_group_num(const Group_Chats *g_c, const uint8_t *identifier)
return -1;
}
-int32_t conference_by_uid(const Group_Chats *g_c, const uint8_t *uid)
+int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
- if (crypto_memcmp(g_c->chats[i].identifier + 1, uid, GROUP_IDENTIFIER_LENGTH - 1) == 0) {
+ if (crypto_memcmp(g_c->chats[i].id, id, GROUP_ID_LENGTH) == 0) {
return i;
}
}
@@ -371,7 +371,8 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk)
return 0;
}
-static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier);
+static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t type,
+ uint8_t *id);
static int connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
{
@@ -437,7 +438,7 @@ static int connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *user
add_conn_to_groupchat(g_c, friendcon_id, groupnumber, 1, lock);
if (friend_con_connected(g_c->fr_c, friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
- send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->identifier);
+ send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->type, g->id);
}
}
@@ -692,7 +693,7 @@ static void set_conns_type_close(Group_Chats *g_c, uint32_t groupnumber, int fri
}
if (type == GROUPCHAT_CLOSE_ONLINE) {
- send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->identifier);
+ send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->type, g->id);
} else {
g->close[i].type = type;
}
@@ -790,8 +791,8 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
g->status = GROUPCHAT_STATUS_CONNECTED;
g->number_joined = -1;
- new_symmetric_key(g->identifier + 1);
- g->identifier[0] = type;
+ g->type = type;
+ new_symmetric_key(g->id);
g->peer_number = 0; /* Founder is peer 0. */
memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE);
int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, nullptr, false);
@@ -1000,15 +1001,15 @@ int group_get_type(const Group_Chats *g_c, uint32_t groupnumber)
return -1;
}
- return g->identifier[0];
+ return g->type;
}
-/* Copies the unique id of group_chat[groupnumber] into uid.
+/* Copies the unique id of group_chat[groupnumber] into id.
*
* return false on failure.
* return true on success.
*/
-bool conference_get_uid(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *uid)
+bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id)
{
const Group_c *g = get_group_c(g_c, groupnumber);
@@ -1016,8 +1017,8 @@ bool conference_get_uid(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *u
return false;
}
- if (uid != nullptr) {
- memcpy(uid, g->identifier + 1, sizeof(g->identifier) - 1);
+ if (id != nullptr) {
+ memcpy(id, g->id, sizeof(g->id));
}
return true;
@@ -1088,7 +1089,8 @@ int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber)
invite[0] = INVITE_ID;
uint16_t groupchat_num = net_htons((uint16_t)groupnumber);
memcpy(invite + 1, &groupchat_num, sizeof(groupchat_num));
- memcpy(invite + 1 + sizeof(groupchat_num), g->identifier, GROUP_IDENTIFIER_LENGTH);
+ invite[1 + sizeof(groupchat_num)] = g->type;
+ memcpy(invite + 1 + sizeof(groupchat_num) + 1, g->id, GROUP_ID_LENGTH);
if (send_conference_invite_packet(g_c->m, friendnumber, invite, sizeof(invite))) {
return 0;
@@ -1113,7 +1115,7 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t
*/
int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length)
{
- if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) {
+ if (length != sizeof(uint16_t) + 1 + GROUP_ID_LENGTH) {
return -1;
}
@@ -1127,7 +1129,7 @@ int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_typ
return -3;
}
- if (get_group_num(g_c, data + sizeof(uint16_t)) != -1) {
+ if (get_group_num(g_c, data[sizeof(uint16_t)], data + sizeof(uint16_t) + 1) != -1) {
return -4;
}
@@ -1147,13 +1149,14 @@ int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_typ
uint8_t response[INVITE_RESPONSE_PACKET_SIZE];
response[0] = INVITE_RESPONSE_ID;
memcpy(response + 1, &group_num, sizeof(uint16_t));
- memcpy(response + 1 + sizeof(uint16_t), data, sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH);
+ memcpy(response + 1 + sizeof(uint16_t), data, sizeof(uint16_t) + 1 + GROUP_ID_LENGTH);
if (send_conference_invite_packet(g_c->m, friendnumber, response, sizeof(response))) {
uint16_t other_groupnum;
memcpy(&other_groupnum, data, sizeof(other_groupnum));
other_groupnum = net_ntohs(other_groupnum);
- memcpy(g->identifier, data + sizeof(uint16_t), GROUP_IDENTIFIER_LENGTH);
+ g->type = data[sizeof(uint16_t)];
+ memcpy(g->id, data + sizeof(uint16_t) + 1, GROUP_ID_LENGTH);
int close_index = add_conn_to_groupchat(g_c, friendcon_id, groupnumber, 0, 1);
if (close_index != -1) {
@@ -1171,33 +1174,25 @@ int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_typ
return -6;
}
-/* Set handlers for custom lossy packets.
- *
- * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
- *
- * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length)
- */
+/* Set handlers for custom lossy packets. */
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function)
{
g_c->lossy_packethandlers[byte].function = function;
}
-/* Set the callback for group invites.
- *
- * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, size_t length, void *userdata)
- *
- * data of length is what needs to be passed to join_groupchat().
- */
+/* Set the callback for group invites. */
void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function)
{
g_c->invite_callback = function;
}
-// TODO(sudden6): function signatures in comments are incorrect
-/* Set the callback for group messages.
- *
- * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata)
- */
+/* Set the callback for group connection. */
+void g_callback_group_connected(Group_Chats *g_c, g_conference_connected_cb *function)
+{
+ g_c->connected_callback = function;
+}
+
+/* Set the callback for group messages. */
void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function)
{
g_c->message_callback = function;
@@ -1206,7 +1201,6 @@ void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *functio
/* Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
- * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata)
*/
void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function)
{
@@ -1216,19 +1210,13 @@ void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function)
/* Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
- * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
*/
void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function)
{
g_c->peer_list_changed_callback = function;
}
-// TODO(sudden6): function signatures are incorrect
-/* Set callback function for title changes.
- *
- * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata)
- * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group)
- */
+/* Set callback function for title changes. */
void g_callback_group_title(Group_Chats *g_c, title_cb *function)
{
g_c->title_callback = function;
@@ -1236,8 +1224,6 @@ void g_callback_group_title(Group_Chats *g_c, title_cb *function)
/* Set a function to be called when a new peer joins a group chat.
*
- * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber)
- *
* return 0 on success.
* return -1 on failure.
*/
@@ -1255,8 +1241,6 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, pe
/* Set a function to be called when a peer leaves a group chat.
*
- * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object))
- *
* return 0 on success.
* return -1 on failure.
*/
@@ -1274,8 +1258,6 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_
/* Set a function to be called when the group chat is deleted.
*
- * Function(void *group object (set with group_set_object), int groupnumber)
- *
* return 0 on success.
* return -1 on failure.
*/
@@ -1441,7 +1423,7 @@ int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title
static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length,
void *userdata)
{
- Group_Chats *g_c = (Group_Chats *)m->conferences_object;
+ Group_Chats *g_c = m->conferences_object;
if (length <= 1) {
return;
@@ -1456,7 +1438,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
return;
}
- int groupnumber = get_group_num(g_c, data + 1 + sizeof(uint16_t));
+ int groupnumber = get_group_num(g_c, data[1 + sizeof(uint16_t)], data + 1 + sizeof(uint16_t) + 1);
if (groupnumber == -1) {
if (g_c->invite_callback) {
@@ -1484,18 +1466,22 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
return;
}
- if (crypto_memcmp(data + 1 + sizeof(uint16_t) * 2, g->identifier, GROUP_IDENTIFIER_LENGTH) != 0) {
+ if (data[1 + sizeof(uint16_t) * 2] != g->type) {
+ return;
+ }
+
+ if (crypto_memcmp(data + 1 + sizeof(uint16_t) * 2 + 1, g->id, GROUP_ID_LENGTH) != 0) {
return;
}
/* TODO(irungentoo): what if two people enter the group at the same time and
are given the same peer_number by different nodes? */
- uint16_t peer_number = rand();
+ uint16_t peer_number = random_u16();
unsigned int tries = 0;
while (get_peer_index(g, peer_number) != -1) {
- peer_number = rand();
+ peer_number = random_u16();
++tries;
if (tries > 32) {
@@ -1506,7 +1492,13 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
memcpy(&other_groupnum, data + 1, sizeof(uint16_t));
other_groupnum = net_ntohs(other_groupnum);
- int friendcon_id = getfriendcon_id(m, friendnumber);
+ const int friendcon_id = getfriendcon_id(m, friendnumber);
+
+ if (friendcon_id == -1) {
+ // TODO(iphydf): Log something?
+ return;
+ }
+
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE], temp_pk[CRYPTO_PUBLIC_KEY_SIZE];
get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id);
@@ -1567,13 +1559,15 @@ static unsigned int count_close_connected(Group_c *g)
return count;
}
-static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier)
+static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t type,
+ uint8_t *id)
{
uint8_t packet[1 + ONLINE_PACKET_DATA_SIZE];
group_num = net_htons(group_num);
packet[0] = PACKET_ID_ONLINE_PACKET;
memcpy(packet + 1, &group_num, sizeof(uint16_t));
- memcpy(packet + 1 + sizeof(uint16_t), identifier, GROUP_IDENTIFIER_LENGTH);
+ packet[1 + sizeof(uint16_t)] = type;
+ memcpy(packet + 1 + sizeof(uint16_t) + 1, id, GROUP_ID_LENGTH);
return write_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id), packet,
sizeof(packet), 0) != -1;
}
@@ -1586,7 +1580,7 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_
return -1;
}
- int groupnumber = get_group_num(g_c, data + sizeof(uint16_t));
+ int groupnumber = get_group_num(g_c, data[sizeof(uint16_t)], data + sizeof(uint16_t) + 1);
if (groupnumber == -1) {
return -1;
@@ -1618,7 +1612,7 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_
g->close[index].group_number = other_groupnum;
g->close[index].type = GROUPCHAT_CLOSE_ONLINE;
- send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->identifier);
+ send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->type, g->id);
return 0;
}
@@ -1733,6 +1727,11 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8
&& public_key_cmp(d, nc_get_self_public_key(g_c->m->net_crypto)) == 0) {
g->peer_number = peer_num;
g->status = GROUPCHAT_STATUS_CONNECTED;
+
+ if (g_c->connected_callback) {
+ g_c->connected_callback(g_c->m, groupnumber, userdata);
+ }
+
group_name_send(g_c, groupnumber, g_c->m->name, g_c->m->name_length);
}
diff --git a/protocols/Tox/libtox/src/toxcore/group.h b/protocols/Tox/libtox/src/toxcore/group.h
index 970cf7fb04..175999ae78 100644
--- a/protocols/Tox/libtox/src/toxcore/group.h
+++ b/protocols/Tox/libtox/src/toxcore/group.h
@@ -71,7 +71,7 @@ typedef struct Group_Peer {
#define DESIRED_CLOSE_CONNECTIONS 4
#define MAX_GROUP_CONNECTIONS 16
-#define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) // type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it
+#define GROUP_ID_LENGTH CRYPTO_SYMMETRIC_KEY_SIZE
typedef enum Groupchat_Close_Type {
GROUPCHAT_CLOSE_NONE,
@@ -111,7 +111,8 @@ typedef struct Group_c {
Groupchat_Close_Connection closest_peers[DESIRED_CLOSE_CONNECTIONS];
uint8_t changed;
- uint8_t identifier[GROUP_IDENTIFIER_LENGTH];
+ uint8_t type;
+ uint8_t id[GROUP_ID_LENGTH];
uint8_t title[MAX_NAME_LENGTH];
uint8_t title_len;
@@ -131,15 +132,38 @@ typedef struct Group_c {
group_on_delete_cb *group_on_delete;
} Group_c;
+/* Callback for group invites.
+ *
+ * data of length is what needs to be passed to join_groupchat().
+ */
typedef void g_conference_invite_cb(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie,
size_t length, void *user_data);
+
+/* Callback for group connection. */
+typedef void g_conference_connected_cb(Messenger *m, uint32_t conference_number, void *user_data);
+
+/* Callback for group messages. */
typedef void g_conference_message_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type,
const uint8_t *message, size_t length, void *user_data);
+
+/* Callback for peer nickname changes. */
typedef void peer_name_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *name,
size_t length, void *user_data);
+
+/* Set callback function for peer list changes. */
typedef void peer_list_changed_cb(Messenger *m, uint32_t conference_number, void *user_data);
+
+/* Callback for title changes.
+ *
+ * If peer_number == -1, then author is unknown (e.g. initial joining the group).
+ */
typedef void title_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *title,
size_t length, void *user_data);
+
+/* Callback for lossy packets.
+ *
+ * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
+ */
typedef int lossy_packet_cb(void *object, uint32_t conference_number, uint32_t peer_number, void *peer_object,
const uint8_t *packet, uint16_t length);
@@ -155,6 +179,7 @@ typedef struct Group_Chats {
uint16_t num_chats;
g_conference_invite_cb *invite_callback;
+ g_conference_connected_cb *connected_callback;
g_conference_message_cb *message_callback;
peer_name_cb *peer_name_callback;
peer_list_changed_cb *peer_list_changed_callback;
@@ -163,39 +188,28 @@ typedef struct Group_Chats {
Group_Lossy_Handler lossy_packethandlers[256];
} Group_Chats;
-/* Set the callback for group invites.
- *
- * Function(Group_Chats *g_c, uint32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
- *
- * data of length is what needs to be passed to join_groupchat().
- */
+/* Set the callback for group invites. */
void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function);
-/* Set the callback for group messages.
- *
- * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
- */
+/* Set the callback for group connection. */
+void g_callback_group_connected(Group_Chats *g_c, g_conference_connected_cb *function);
+
+/* Set the callback for group messages. */
void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function);
-/* Set callback function for title changes.
- *
- * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata)
- * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group)
- */
+/* Set callback function for title changes. */
void g_callback_group_title(Group_Chats *g_c, title_cb *function);
/* Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
- * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata)
*/
void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function);
/* Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
- * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
*/
void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function);
@@ -326,12 +340,7 @@ int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int p
int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[],
uint16_t length);
-/* Set handlers for custom lossy packets.
- *
- * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
- *
- * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length)
- */
+/* Set handlers for custom lossy packets. */
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function);
/* High level function to send custom lossy packets.
@@ -361,14 +370,14 @@ uint32_t copy_chatlist(const Group_Chats *g_c, uint32_t *out_list, uint32_t list
*/
int group_get_type(const Group_Chats *g_c, uint32_t groupnumber);
-/* Copies the unique id of group_chat[groupnumber] into uid.
+/* Copies the unique id of group_chat[groupnumber] into id.
*
* return false on failure.
* return true on success.
*/
-bool conference_get_uid(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *uid);
+bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id);
-int32_t conference_by_uid(const Group_Chats *g_c, const uint8_t *uid);
+int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id);
/* Send current name (set in messenger) to all online groups.
*/
@@ -388,14 +397,14 @@ int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object)
*/
int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object);
-/* Return the object tide to the group chat previously set by group_set_object.
+/* Return the object tied to the group chat previously set by group_set_object.
*
* return NULL on failure.
* return object on success.
*/
void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber);
-/* Return the object tide to the group chat peer previously set by group_peer_set_object.
+/* Return the object tied to the group chat peer previously set by group_peer_set_object.
*
* return NULL on failure.
* return object on success.
@@ -404,8 +413,6 @@ void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int pe
/* Set a function to be called when a new peer joins a group chat.
*
- * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber)
- *
* return 0 on success.
* return -1 on failure.
*/
@@ -413,8 +420,6 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, pe
/* Set a function to be called when a peer leaves a group chat.
*
- * Function(void *group object (set with group_set_object), uint32_t groupnumber, void *group peer object (set with group_peer_set_object))
- *
* return 0 on success.
* return -1 on failure.
*/
@@ -422,8 +427,6 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_
/* Set a function to be called when the group chat is deleted.
*
- * Function(void *group object (set with group_set_object), uint32_t groupnumber)
- *
* return 0 on success.
* return -1 on failure.
*/
diff --git a/protocols/Tox/libtox/src/toxcore/mono_time.c b/protocols/Tox/libtox/src/toxcore/mono_time.c
index 415981d9eb..0beb72542b 100644
--- a/protocols/Tox/libtox/src/toxcore/mono_time.c
+++ b/protocols/Tox/libtox/src/toxcore/mono_time.c
@@ -90,29 +90,6 @@ int is_timeout(uint64_t timestamp, uint64_t timeout)
}
-
-/* return current UNIX time in microseconds (us). */
-uint64_t current_time_actual(void)
-{
- uint64_t time;
-#ifdef OS_WIN32
- /* This probably works fine */
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
- time = ft.dwHighDateTime;
- time <<= 32;
- time |= ft.dwLowDateTime;
- time -= 116444736000000000ULL;
- return time / 10;
-#else
- struct timeval a;
- gettimeofday(&a, nullptr);
- time = 1000000ULL * a.tv_sec + a.tv_usec;
- return time;
-#endif
-}
-
-
//!TOKSTYLE-
// No global mutable state in Tokstyle.
#ifdef OS_WIN32
diff --git a/protocols/Tox/libtox/src/toxcore/mono_time.h b/protocols/Tox/libtox/src/toxcore/mono_time.h
index 63e0f49df7..9775956085 100644
--- a/protocols/Tox/libtox/src/toxcore/mono_time.h
+++ b/protocols/Tox/libtox/src/toxcore/mono_time.h
@@ -22,9 +22,6 @@ void unix_time_update(void);
uint64_t unix_time(void);
int is_timeout(uint64_t timestamp, uint64_t timeout);
-/* return current UNIX time in microseconds (us). */
-uint64_t current_time_actual(void);
-
/* return current monotonic time in milliseconds (ms). */
uint64_t current_time_monotonic(void);
diff --git a/protocols/Tox/libtox/src/toxcore/network.c b/protocols/Tox/libtox/src/toxcore/network.c
index 1c1459db32..68ca43e5aa 100644
--- a/protocols/Tox/libtox/src/toxcore/network.c
+++ b/protocols/Tox/libtox/src/toxcore/network.c
@@ -698,7 +698,6 @@ int networking_at_startup(void)
}
#endif
- srand((uint32_t)current_time_actual());
at_startup_ran = 1;
return 0;
}
diff --git a/protocols/Tox/libtox/src/toxcore/onion_client.c b/protocols/Tox/libtox/src/toxcore/onion_client.c
index 9c59343dd7..819bd23fae 100644
--- a/protocols/Tox/libtox/src/toxcore/onion_client.c
+++ b/protocols/Tox/libtox/src/toxcore/onion_client.c
@@ -267,7 +267,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
return 0;
}
- unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES;
+ const uint32_t num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES;
// if (dht_non_lan_connected(onion_c->dht)) {
if (dht_isconnected(onion_c->dht)) {
@@ -276,7 +276,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
}
for (i = 0; i < max_num; ++i) {
- nodes[i] = onion_c->path_nodes[rand() % num_nodes];
+ nodes[i] = onion_c->path_nodes[random_u32() % num_nodes];
}
} else {
int random_tcp = get_random_tcp_con_number(onion_c->c);
@@ -290,7 +290,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp;
for (i = 1; i < max_num; ++i) {
- nodes[i] = onion_c->path_nodes[rand() % num_nodes];
+ nodes[i] = onion_c->path_nodes[random_u32() % num_nodes];
}
} else {
unsigned int num_nodes_bs = (onion_c->path_nodes_index_bs < MAX_PATH_NODES) ? onion_c->path_nodes_index_bs :
@@ -304,7 +304,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp;
for (i = 1; i < max_num; ++i) {
- nodes[i] = onion_c->path_nodes_bs[rand() % num_nodes_bs];
+ nodes[i] = onion_c->path_nodes_bs[random_u32() % num_nodes_bs];
}
}
}
@@ -371,7 +371,7 @@ static bool onion_node_timed_out(const Onion_Node *node)
static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path)
{
if (pathnum == UINT32_MAX) {
- pathnum = rand() % NUMBER_ONION_PATHS;
+ pathnum = random_u32() % NUMBER_ONION_PATHS;
} else {
pathnum = pathnum % NUMBER_ONION_PATHS;
}
@@ -394,7 +394,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
onion_paths->last_path_success[pathnum] = onion_paths->path_creation_time[pathnum];
onion_paths->last_path_used_times[pathnum] = ONION_PATH_MAX_NO_RESPONSE_USES / 2;
- uint32_t path_num = rand();
+ uint32_t path_num = random_u32();
path_num /= NUMBER_ONION_PATHS;
path_num *= NUMBER_ONION_PATHS;
path_num += pathnum;
@@ -1597,7 +1597,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
}
if (is_timeout(list_nodes[i].last_pinged, interval)
- || (ping_random && rand() % (MAX_ONION_CLIENTS - i) == 0)) {
+ || (ping_random && random_u32() % (MAX_ONION_CLIENTS - i) == 0)) {
if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port,
list_nodes[i].public_key, nullptr, ~0) == 0) {
list_nodes[i].last_pinged = unix_time();
@@ -1616,12 +1616,12 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
n = (MAX_ONION_CLIENTS / 2);
}
- if (count <= (uint32_t)rand() % MAX_ONION_CLIENTS) {
+ if (count <= random_u32() % MAX_ONION_CLIENTS) {
if (num_nodes != 0) {
unsigned int j;
for (j = 0; j < n; ++j) {
- unsigned int num = rand() % num_nodes;
+ const uint32_t num = random_u32() % num_nodes;
client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port,
onion_c->path_nodes[num].public_key, nullptr, ~0);
}
@@ -1708,7 +1708,7 @@ static void do_announce(Onion_Client *onion_c)
if (is_timeout(list_nodes[i].last_pinged, interval)
|| (is_timeout(onion_c->last_announce, ONION_NODE_PING_INTERVAL)
- && rand() % (MAX_ONION_CLIENTS_ANNOUNCE - i) == 0)) {
+ && random_u32() % (MAX_ONION_CLIENTS_ANNOUNCE - i) == 0)) {
uint32_t path_to_use = list_nodes[i].path_used;
if (list_nodes[i].unsuccessful_pings == ONION_NODE_MAX_PINGS - 1
@@ -1730,7 +1730,7 @@ static void do_announce(Onion_Client *onion_c)
unsigned int num_nodes;
Node_format *path_nodes;
- if (rand() % 2 == 0 || onion_c->path_nodes_index == 0) {
+ if (random_u08() % 2 == 0 || onion_c->path_nodes_index == 0) {
num_nodes = (onion_c->path_nodes_index_bs < MAX_PATH_NODES) ? onion_c->path_nodes_index_bs : MAX_PATH_NODES;
path_nodes = onion_c->path_nodes_bs;
} else {
@@ -1738,10 +1738,10 @@ static void do_announce(Onion_Client *onion_c)
path_nodes = onion_c->path_nodes;
}
- if (count <= (uint32_t)rand() % MAX_ONION_CLIENTS_ANNOUNCE) {
+ if (count <= random_u32() % MAX_ONION_CLIENTS_ANNOUNCE) {
if (num_nodes != 0) {
for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
- unsigned int num = rand() % num_nodes;
+ const uint32_t num = random_u32() % num_nodes;
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, ~0);
}
}
diff --git a/protocols/Tox/libtox/src/toxcore/tox.api.h b/protocols/Tox/libtox/src/toxcore/tox.api.h
index 243606410c..3629bed1b4 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 = 5;
+const VERSION_PATCH = 6;
/**
* A macro to check at preprocessing time whether the client code is compatible
@@ -342,6 +342,9 @@ const MAX_HOSTNAME_LENGTH = 255;
/**
* Represents the possible statuses a client can have.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class USER_STATUS {
/**
@@ -364,6 +367,9 @@ enum class USER_STATUS {
/**
* Represents message types for ${tox.friend.send.message} and conference
* messages.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class MESSAGE_TYPE {
/**
@@ -387,6 +393,9 @@ enum class MESSAGE_TYPE {
/**
* Type of proxy used to connect to TCP relays.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class PROXY_TYPE {
/**
@@ -405,6 +414,9 @@ enum class PROXY_TYPE {
/**
* Type of savedata to create the Tox instance from.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class SAVEDATA_TYPE {
/**
@@ -424,6 +436,9 @@ enum class SAVEDATA_TYPE {
/**
* Severity level of log messages.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class LOG_LEVEL {
/**
@@ -813,6 +828,9 @@ bool add_tcp_relay(string host, uint16_t port, const uint8_t[PUBLIC_KEY_SIZE] pu
/**
* Protocols that can be used to connect to the network or friends.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class CONNECTION {
/**
@@ -2104,6 +2122,9 @@ namespace conference {
/**
* Conference types for the ${event invite} event.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
enum class TYPE {
/**
@@ -2136,6 +2157,18 @@ namespace conference {
/**
+ * This event is triggered when the client successfully connects to a
+ * conference after joining it with the $join function.
+ */
+ event connected const {
+ /**
+ * @param conference_number The conference number of the conference to which we have connected.
+ */
+ typedef void(uint32_t conference_number);
+ }
+
+
+ /**
* This event is triggered when the client receives a conference message.
*/
event message const {
@@ -2292,6 +2325,10 @@ namespace conference {
/**
* Invites a friend to a conference.
*
+ * We must be connected to the conference, meaning that the conference has not
+ * been deleted, and either we created the conference with the $new function,
+ * or a `${event connected}` event has occurred for the conference.
+ *
* @param friend_number The friend number of the friend we want to invite.
* @param conference_number The conference number of the conference we want to invite the friend to.
*
diff --git a/protocols/Tox/libtox/src/toxcore/tox.c b/protocols/Tox/libtox/src/toxcore/tox.c
index bf84f022e7..cd1b71f095 100644
--- a/protocols/Tox/libtox/src/toxcore/tox.c
+++ b/protocols/Tox/libtox/src/toxcore/tox.c
@@ -91,6 +91,7 @@ struct Tox {
tox_file_recv_cb *file_recv_callback;
tox_file_recv_chunk_cb *file_recv_chunk_callback;
tox_conference_invite_cb *conference_invite_callback;
+ tox_conference_connected_cb *conference_connected_callback;
tox_conference_message_cb *conference_message_callback;
tox_conference_title_cb *conference_title_callback;
tox_conference_peer_name_cb *conference_peer_name_callback;
@@ -247,6 +248,15 @@ static void tox_conference_invite_handler(Messenger *m, uint32_t friend_number,
}
}
+static void tox_conference_connected_handler(Messenger *m, uint32_t conference_number, void *user_data)
+{
+ struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
+
+ if (tox_data->tox->conference_connected_callback != nullptr) {
+ tox_data->tox->conference_connected_callback(tox_data->tox, conference_number, tox_data->user_data);
+ }
+}
+
static void tox_conference_message_handler(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type,
const uint8_t *message, size_t length, void *user_data)
{
@@ -487,11 +497,12 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
callback_file_reqchunk(m, tox_file_chunk_request_handler);
callback_file_sendrequest(m, tox_file_recv_handler);
callback_file_data(m, tox_file_recv_chunk_handler);
- g_callback_group_invite((Group_Chats *)m->conferences_object, tox_conference_invite_handler);
- g_callback_group_message((Group_Chats *)m->conferences_object, tox_conference_message_handler);
- g_callback_group_title((Group_Chats *)m->conferences_object, tox_conference_title_handler);
- g_callback_peer_name((Group_Chats *)m->conferences_object, tox_conference_peer_name_handler);
- g_callback_peer_list_changed((Group_Chats *)m->conferences_object, tox_conference_peer_list_changed_handler);
+ g_callback_group_invite(m->conferences_object, tox_conference_invite_handler);
+ g_callback_group_connected(m->conferences_object, tox_conference_connected_handler);
+ g_callback_group_message(m->conferences_object, tox_conference_message_handler);
+ g_callback_group_title(m->conferences_object, tox_conference_title_handler);
+ g_callback_peer_name(m->conferences_object, tox_conference_peer_name_handler);
+ g_callback_peer_list_changed(m->conferences_object, tox_conference_peer_list_changed_handler);
custom_lossy_packet_registerhandler(m, tox_friend_lossy_packet_handler);
custom_lossless_packet_registerhandler(m, tox_friend_lossless_packet_handler);
@@ -506,7 +517,7 @@ void tox_kill(Tox *tox)
}
Messenger *m = tox->m;
- kill_groupchats((Group_Chats *)m->conferences_object);
+ kill_groupchats(m->conferences_object);
kill_messenger(m);
free(tox);
}
@@ -645,7 +656,7 @@ void tox_iterate(Tox *tox, void *user_data)
Messenger *m = tox->m;
struct Tox_Userdata tox_data = { tox, user_data };
do_messenger(m, &tox_data);
- do_groupchats((Group_Chats *)m->conferences_object, &tox_data);
+ do_groupchats(m->conferences_object, &tox_data);
}
void tox_self_get_address(const Tox *tox, uint8_t *address)
@@ -697,7 +708,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set
if (setname(m, name, length) == 0) {
// TODO(irungentoo): function to set different per group names?
- send_name_all_groups((Group_Chats *)m->conferences_object);
+ send_name_all_groups(m->conferences_object);
SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
return 1;
}
@@ -989,15 +1000,17 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8
return 0;
}
- const Messenger *m = tox->m;
- // TODO(irungentoo): size parameter?
- int ret = m_copy_statusmessage(m, friend_number, status_message, m_get_statusmessage_size(m, friend_number));
+ const Messenger *const m = tox->m;
+ const int size = m_get_statusmessage_size(m, friend_number);
- if (ret == -1) {
+ if (size == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
return 0;
}
+ const int ret = m_copy_statusmessage(m, friend_number, status_message, size);
+ assert(ret == size && "concurrency problem: friend status message changed");
+
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
return 1;
}
@@ -1386,6 +1399,11 @@ void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback
tox->conference_invite_callback = callback;
}
+void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback)
+{
+ tox->conference_connected_callback = callback;
+}
+
void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback)
{
tox->conference_message_callback = callback;
@@ -1409,7 +1427,7 @@ void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_lis
uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
{
Messenger *m = tox->m;
- int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT);
+ int ret = add_groupchat(m->conferences_object, GROUPCHAT_TYPE_TEXT);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_NEW_INIT);
@@ -1423,7 +1441,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
{
Messenger *m = tox->m;
- int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number);
+ int ret = del_groupchat(m->conferences_object, conference_number);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_DELETE_CONFERENCE_NOT_FOUND);
@@ -1437,7 +1455,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere
uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox->m;
- int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number);
+ int ret = group_number_peers(m->conferences_object, conference_number);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_PEER_QUERY_CONFERENCE_NOT_FOUND);
@@ -1452,7 +1470,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox->m;
- int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number);
+ int ret = group_peername_size(m->conferences_object, conference_number, peer_number);
switch (ret) {
case -1:
@@ -1472,7 +1490,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox->m;
- int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name);
+ int ret = group_peername(m->conferences_object, conference_number, peer_number, name);
switch (ret) {
case -1:
@@ -1492,7 +1510,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox->m;
- int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key);
+ int ret = group_peer_pubkey(m->conferences_object, conference_number, peer_number, public_key);
switch (ret) {
case -1:
@@ -1512,7 +1530,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox->m;
- int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number);
+ int ret = group_peernumber_is_ours(m->conferences_object, conference_number, peer_number);
switch (ret) {
case -1:
@@ -1536,7 +1554,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference
Tox_Err_Conference_Invite *error)
{
Messenger *m = tox->m;
- int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number);
+ int ret = invite_friend(m->conferences_object, friend_number, conference_number);
switch (ret) {
case -1:
@@ -1560,7 +1578,7 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
Tox_Err_Conference_Join *error)
{
Messenger *m = tox->m;
- int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
+ int ret = join_groupchat(m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
switch (ret) {
case -1:
@@ -1599,9 +1617,9 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa
int ret = 0;
if (type == TOX_MESSAGE_TYPE_NORMAL) {
- ret = group_message_send((Group_Chats *)m->conferences_object, conference_number, message, length);
+ ret = group_message_send(m->conferences_object, conference_number, message, length);
} else {
- ret = group_action_send((Group_Chats *)m->conferences_object, conference_number, message, length);
+ ret = group_action_send(m->conferences_object, conference_number, message, length);
}
switch (ret) {
@@ -1629,7 +1647,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa
size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error)
{
const Messenger *m = tox->m;
- int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number);
+ int ret = group_title_get_size(m->conferences_object, conference_number);
switch (ret) {
case -1:
@@ -1649,7 +1667,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_
Tox_Err_Conference_Title *error)
{
const Messenger *m = tox->m;
- int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title);
+ int ret = group_title_get(m->conferences_object, conference_number, title);
switch (ret) {
case -1:
@@ -1669,7 +1687,7 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_
Tox_Err_Conference_Title *error)
{
Messenger *m = tox->m;
- int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length);
+ int ret = group_title_send(m->conferences_object, conference_number, title, length);
switch (ret) {
case -1:
@@ -1692,21 +1710,21 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_
size_t tox_conference_get_chatlist_size(const Tox *tox)
{
const Messenger *m = tox->m;
- return count_chatlist((Group_Chats *)m->conferences_object);
+ return count_chatlist(m->conferences_object);
}
void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
{
const Messenger *m = tox->m;
size_t list_size = tox_conference_get_chatlist_size(tox);
- copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size);
+ copy_chatlist(m->conferences_object, chatlist, list_size);
}
Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number,
Tox_Err_Conference_Get_Type *error)
{
const Messenger *m = tox->m;
- int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number);
+ int ret = group_get_type(m->conferences_object, conference_number);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND);
@@ -1719,7 +1737,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_
bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id /* TOX_CONFERENCE_ID_SIZE bytes */)
{
- return conference_get_uid((Group_Chats *)tox->m->conferences_object, conference_number, id);
+ return conference_get_id(tox->m->conferences_object, conference_number, id);
}
// TODO(iphydf): Delete in 0.3.0.
@@ -1735,7 +1753,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere
return UINT32_MAX;
}
- int32_t ret = conference_by_uid((Group_Chats *)tox->m->conferences_object, id);
+ int32_t ret = conference_by_id(tox->m->conferences_object, id);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND);
diff --git a/protocols/Tox/libtox/src/toxcore/tox.h b/protocols/Tox/libtox/src/toxcore/tox.h
index 2c40389bf6..9f3072a7bf 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 5
+#define TOX_VERSION_PATCH 6
uint32_t tox_version_patch(void);
@@ -374,6 +374,9 @@ uint32_t tox_max_hostname_length(void);
/**
* Represents the possible statuses a client can have.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_USER_STATUS {
@@ -400,6 +403,9 @@ typedef enum TOX_USER_STATUS {
/**
* Represents message types for tox_friend_send_message and conference
* messages.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_MESSAGE_TYPE {
@@ -428,6 +434,9 @@ typedef enum TOX_MESSAGE_TYPE {
/**
* Type of proxy used to connect to TCP relays.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_PROXY_TYPE {
@@ -451,6 +460,9 @@ typedef enum TOX_PROXY_TYPE {
/**
* Type of savedata to create the Tox instance from.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_SAVEDATA_TYPE {
@@ -474,6 +486,9 @@ typedef enum TOX_SAVEDATA_TYPE {
/**
* Severity level of log messages.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_LOG_LEVEL {
@@ -972,6 +987,9 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
/**
* Protocols that can be used to connect to the network or friends.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_CONNECTION {
@@ -2379,6 +2397,9 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback);
/**
* Conference types for the conference_invite event.
+ *
+ * @deprecated All UPPER_CASE enum type names are deprecated. Use the
+ * Camel_Snake_Case versions, instead.
*/
typedef enum TOX_CONFERENCE_TYPE {
@@ -2417,6 +2438,20 @@ typedef void tox_conference_invite_cb(Tox *tox, uint32_t friend_number, TOX_CONF
void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback);
/**
+ * @param conference_number The conference number of the conference to which we have connected.
+ */
+typedef void tox_conference_connected_cb(Tox *tox, uint32_t conference_number, void *user_data);
+
+
+/**
+ * Set the callback for the `conference_connected` event. Pass NULL to unset.
+ *
+ * This event is triggered when the client successfully connects to a
+ * conference after joining it with the tox_conference_join function.
+ */
+void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback);
+
+/**
* @param conference_number The conference number of the conference the message is intended for.
* @param peer_number The ID of the peer who sent the message.
* @param type The type of message (normal, action, ...).
@@ -2624,6 +2659,10 @@ typedef enum TOX_ERR_CONFERENCE_INVITE {
/**
* Invites a friend to a conference.
*
+ * We must be connected to the conference, meaning that the conference has not
+ * been deleted, and either we created the conference with the tox_conference_new function,
+ * or a `conference_connected` event has occurred for the conference.
+ *
* @param friend_number The friend number of the friend we want to invite.
* @param conference_number The conference number of the conference we want to invite the friend to.
*
diff --git a/protocols/Tox/libtox/src/toxcore/util.c b/protocols/Tox/libtox/src/toxcore/util.c
index f349e8fe0e..de01625eae 100644
--- a/protocols/Tox/libtox/src/toxcore/util.c
+++ b/protocols/Tox/libtox/src/toxcore/util.c
@@ -100,6 +100,11 @@ int32_t max_s32(int32_t a, int32_t b)
return a > b ? a : b;
}
+int32_t min_s32(int32_t a, int32_t b)
+{
+ return a < b ? a : b;
+}
+
uint32_t min_u32(uint32_t a, uint32_t b)
{
return a < b ? a : b;
diff --git a/protocols/Tox/libtox/src/toxcore/util.h b/protocols/Tox/libtox/src/toxcore/util.h
index 76951fff31..842c97a444 100644
--- a/protocols/Tox/libtox/src/toxcore/util.h
+++ b/protocols/Tox/libtox/src/toxcore/util.h
@@ -47,6 +47,7 @@ void net_to_host(uint8_t *num, uint16_t numbytes);
int create_recursive_mutex(pthread_mutex_t *mutex);
int32_t max_s32(int32_t a, int32_t b);
+int32_t min_s32(int32_t a, int32_t b);
uint32_t min_u32(uint32_t a, uint32_t b);
uint64_t min_u64(uint64_t a, uint64_t b);