Squashed 'external/toxcore/c-toxcore/' changes from 03e9fbf3703..55752a2e2ef
55752a2e2ef fix(toxav): pass video bit rate as kbit Previously we unintentionally made it Mbit. 7e573280a75 docs(toxav): fix docs of toxav.h - fix units to be more readable - use width before height consistently - video -> audio typo 5f88a084e8c fix: friend_connections leak on allocation failure clean up when it only contains connections in the NONE state 6d27a1ae178 fix: wrong comment for closelist ce4f29e8036 cleanup: Fix all `-Wsign-compare` warnings. 4d4251c397f chore: lower cirrus ci timeout drastically 40676284507 fix: events leak that can occur if allocation fails rare in practice, found by fuzzing 9610ac31c5f fix: Return an error instead of crashing on nullptr args in NGC. a57c2c8f956 refactor: Make ToxAV independent of toxcore internals. 5752fc29f86 refactor: Make tox-bootstrapd use bool instead of int df675786eb2 chore: Add release-drafter github action. 03fd7a69dcf chore: Use toktok's cmp instead of upstream. 350c0ba1205 cleanup: Sort apk/apt install commands in Dockerfiles. 8c1bda502cb chore(deps): bump golang.org/x/net ddb9d3210da chore: Upgrade to FreeBSD 14.1 in cirrus build. e9076f45bd3 chore(cmake): set options changes as cache and with force git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 55752a2e2ef894bfa6d7a2a21a0278e3f2bede7d
This commit is contained in:
@ -6,7 +6,7 @@ exports_files(
|
||||
"tox.h",
|
||||
"tox_private.h",
|
||||
],
|
||||
visibility = ["//c-toxcore:__pkg__"],
|
||||
visibility = ["//c-toxcore:__subpackages__"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@ -661,7 +661,10 @@ cc_library(
|
||||
name = "net_crypto",
|
||||
srcs = ["net_crypto.c"],
|
||||
hdrs = ["net_crypto.h"],
|
||||
visibility = ["//c-toxcore/auto_tests:__pkg__"],
|
||||
visibility = [
|
||||
"//c-toxcore/auto_tests:__pkg__",
|
||||
"//c-toxcore/toxav:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
":DHT",
|
||||
":LAN_discovery",
|
||||
|
@ -380,12 +380,12 @@ int dht_create_packet(const Memory *mem, const Random *rng,
|
||||
|
||||
const int encrypted_length = encrypt_data_symmetric(shared_key, nonce, plain, plain_length, encrypted);
|
||||
|
||||
if (encrypted_length == -1) {
|
||||
if (encrypted_length < 0) {
|
||||
mem_delete(mem, encrypted);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (length < 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + encrypted_length) {
|
||||
if (length < 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + (size_t)encrypted_length) {
|
||||
mem_delete(mem, encrypted);
|
||||
return -1;
|
||||
}
|
||||
@ -1347,15 +1347,15 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
|
||||
plain[0] = num_nodes;
|
||||
memcpy(plain + 1 + nodes_length, sendback_data, length);
|
||||
|
||||
const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE;
|
||||
const uint32_t data_size = 1 + nodes_length + length + crypto_size;
|
||||
const uint16_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE;
|
||||
const uint16_t data_size = 1 + nodes_length + length + crypto_size;
|
||||
VLA(uint8_t, data, data_size);
|
||||
|
||||
const int len = dht_create_packet(dht->mem, dht->rng,
|
||||
dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6,
|
||||
plain, 1 + nodes_length + length, data, data_size);
|
||||
|
||||
if (len != data_size) {
|
||||
if (len < 0 || (uint32_t)len != data_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -472,10 +472,6 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (m->friend_connectionstatuschange_internal != nullptr) {
|
||||
m->friend_connectionstatuschange_internal(m, friendnumber, false, m->friend_connectionstatuschange_internal_userdata);
|
||||
}
|
||||
|
||||
clear_receipts(m, friendnumber);
|
||||
remove_request_received(m->fr, m->friendlist[friendnumber].real_pk);
|
||||
friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, nullptr,
|
||||
@ -1027,13 +1023,6 @@ void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *funct
|
||||
m->core_connection_change = function;
|
||||
}
|
||||
|
||||
void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function,
|
||||
void *userdata)
|
||||
{
|
||||
m->friend_connectionstatuschange_internal = function;
|
||||
m->friend_connectionstatuschange_internal_userdata = userdata;
|
||||
}
|
||||
|
||||
non_null(1) nullable(3)
|
||||
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
|
||||
{
|
||||
@ -1081,11 +1070,6 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
|
||||
m->friendlist[friendnumber].status = status;
|
||||
|
||||
check_friend_tcp_udp(m, friendnumber, userdata);
|
||||
|
||||
if (m->friend_connectionstatuschange_internal != nullptr) {
|
||||
m->friend_connectionstatuschange_internal(m, friendnumber, is_online,
|
||||
m->friend_connectionstatuschange_internal_userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1855,23 +1839,6 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Set the callback for msi packets. */
|
||||
void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata)
|
||||
{
|
||||
m->msi_packet = function;
|
||||
m->msi_packet_userdata = userdata;
|
||||
}
|
||||
|
||||
/** @brief Send an msi packet.
|
||||
*
|
||||
* @retval true on success
|
||||
* @retval false on failure
|
||||
*/
|
||||
bool m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, false);
|
||||
}
|
||||
|
||||
static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length,
|
||||
void *userdata)
|
||||
{
|
||||
@ -1881,17 +1848,6 @@ static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t *
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (data[0] <= PACKET_ID_RANGE_LOSSY_AV_END) {
|
||||
const RTP_Packet_Handler *const ph =
|
||||
&m->friendlist[friendcon_id].lossy_rtp_packethandlers[data[0] % PACKET_ID_RANGE_LOSSY_AV_SIZE];
|
||||
|
||||
if (ph->function != nullptr) {
|
||||
return ph->function(m, friendcon_id, data, length, ph->object);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (m->lossy_packethandler != nullptr) {
|
||||
m->lossy_packethandler(m, friendcon_id, data[0], data, length, userdata);
|
||||
}
|
||||
@ -1904,38 +1860,6 @@ void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb
|
||||
m->lossy_packethandler = lossy_packethandler;
|
||||
}
|
||||
|
||||
int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function,
|
||||
void *object)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
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_ID_RANGE_LOSSY_AV_SIZE].function = function;
|
||||
m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_ID_RANGE_LOSSY_AV_SIZE].object = object;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief High level function to send custom lossy packets.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @retval -1 if friend invalid.
|
||||
* @retval -2 if length wrong.
|
||||
* @retval -3 if first byte invalid.
|
||||
* @retval -4 if friend offline.
|
||||
* @retval -5 if packet failed to send because of other error.
|
||||
* @retval 0 on success.
|
||||
*/
|
||||
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
@ -1946,7 +1870,6 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
|
||||
return -2;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@ -1974,7 +1897,10 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
|
||||
}
|
||||
|
||||
if (packet[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || packet[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) {
|
||||
return -1;
|
||||
// allow PACKET_ID_MSI packets to be handled by custom packet handler
|
||||
if (packet[0] != PACKET_ID_MSI) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (m->lossless_packethandler != nullptr) {
|
||||
@ -2356,20 +2282,6 @@ static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_msi(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
{
|
||||
if (data_length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m->msi_packet != nullptr) {
|
||||
m->msi_packet(m, friendcon_id, data, data_length, m->msi_packet_userdata);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
{
|
||||
@ -2443,7 +2355,7 @@ static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data,
|
||||
case PACKET_ID_FILE_DATA:
|
||||
return m_handle_packet_file_data(m, friendcon_id, payload, payload_length, userdata);
|
||||
case PACKET_ID_MSI:
|
||||
return m_handle_packet_msi(m, friendcon_id, payload, payload_length, userdata);
|
||||
return handle_custom_lossless_packet(object, friendcon_id, data, length, userdata);
|
||||
case PACKET_ID_INVITE_GROUPCHAT:
|
||||
return m_handle_packet_invite_groupchat(m, friendcon_id, payload, payload_length, userdata);
|
||||
}
|
||||
|
@ -200,20 +200,10 @@ typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint
|
||||
size_t length, void *user_data);
|
||||
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
|
||||
size_t length, void *user_data);
|
||||
typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number,
|
||||
bool is_online, void *user_data);
|
||||
typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
|
||||
void *user_data);
|
||||
typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length,
|
||||
const uint8_t *group_name, size_t group_name_length, void *user_data);
|
||||
typedef void m_msi_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length,
|
||||
void *user_data);
|
||||
typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object);
|
||||
|
||||
typedef struct RTP_Packet_Handler {
|
||||
m_lossy_rtp_packet_cb *function;
|
||||
void *object;
|
||||
} RTP_Packet_Handler;
|
||||
|
||||
typedef struct Friend {
|
||||
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@ -243,8 +233,6 @@ typedef struct Friend {
|
||||
uint32_t num_sending_files;
|
||||
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
||||
|
||||
RTP_Packet_Handler lossy_rtp_packethandlers[PACKET_ID_RANGE_LOSSY_AV_SIZE];
|
||||
|
||||
struct Receipts *receipts_start;
|
||||
struct Receipts *receipts_end;
|
||||
} Friend;
|
||||
@ -301,8 +289,6 @@ struct Messenger {
|
||||
m_friend_typing_cb *friend_typingchange;
|
||||
m_friend_read_receipt_cb *read_receipt;
|
||||
m_friend_connection_status_cb *friend_connectionstatuschange;
|
||||
m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
|
||||
void *friend_connectionstatuschange_internal_userdata;
|
||||
|
||||
struct Group_Chats *conferences_object;
|
||||
m_conference_invite_cb *conference_invite;
|
||||
@ -314,9 +300,6 @@ struct Messenger {
|
||||
m_file_recv_chunk_cb *file_filedata;
|
||||
m_file_chunk_request_cb *file_reqchunk;
|
||||
|
||||
m_msi_packet_cb *msi_packet;
|
||||
void *msi_packet_userdata;
|
||||
|
||||
m_friend_lossy_packet_cb *lossy_packethandler;
|
||||
m_friend_lossless_packet_cb *lossless_packethandler;
|
||||
|
||||
@ -614,10 +597,6 @@ non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *
|
||||
*/
|
||||
non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function);
|
||||
|
||||
/** Same as previous but for internal A/V core usage only */
|
||||
non_null() void m_callback_connectionstatus_internal_av(
|
||||
Messenger *m, m_friend_connectionstatuschange_internal_cb *function, void *userdata);
|
||||
|
||||
/** @brief Set the callback for typing changes. */
|
||||
non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);
|
||||
|
||||
@ -731,42 +710,12 @@ non_null(1) nullable(5)
|
||||
int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
|
||||
const uint8_t *data, uint16_t length);
|
||||
|
||||
/*** A/V related */
|
||||
|
||||
/** @brief Set the callback for msi packets. */
|
||||
non_null(1) nullable(2, 3)
|
||||
void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata);
|
||||
|
||||
/** @brief Send an msi packet.
|
||||
*
|
||||
* @retval true on success
|
||||
* @retval false on failure
|
||||
*/
|
||||
non_null()
|
||||
bool m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
||||
|
||||
/** @brief Set handlers for lossy rtp packets.
|
||||
*
|
||||
* @retval -1 on failure.
|
||||
* @retval 0 on success.
|
||||
*/
|
||||
non_null(1) nullable(4, 5)
|
||||
int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte,
|
||||
m_lossy_rtp_packet_cb *function, void *object);
|
||||
|
||||
/*** CUSTOM PACKETS */
|
||||
|
||||
/** @brief Set handlers for custom lossy packets. */
|
||||
non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler);
|
||||
|
||||
/** @brief High level function to send custom lossy packets.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @retval -1 if friend invalid.
|
||||
* @retval -2 if length wrong.
|
||||
|
@ -579,7 +579,7 @@ static int create_reply(Announcements *announce, const IP_Port *source,
|
||||
const int plain_reply_max_len = (int)reply_max_length -
|
||||
(1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
|
||||
|
||||
if (plain_reply_max_len < sizeof(uint64_t)) {
|
||||
if (plain_reply_max_len < (int)sizeof(uint64_t)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,10 @@ static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_E
|
||||
event.type = TOX_EVENT_CONFERENCE_CONNECTED;
|
||||
event.data.conference_connected = conference_connected;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_connected_free(conference_connected, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_connected;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,10 @@ static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events
|
||||
event.type = TOX_EVENT_CONFERENCE_INVITE;
|
||||
event.data.conference_invite = conference_invite;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_invite_free(conference_invite, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_invite;
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,10 @@ static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Event
|
||||
event.type = TOX_EVENT_CONFERENCE_MESSAGE;
|
||||
event.data.conference_message = conference_message;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_message_free(conference_message, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_message;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,10 @@ static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_li
|
||||
event.type = TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED;
|
||||
event.data.conference_peer_list_changed = conference_peer_list_changed;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_peer_list_changed_free(conference_peer_list_changed, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_peer_list_changed;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_E
|
||||
event.type = TOX_EVENT_CONFERENCE_PEER_NAME;
|
||||
event.data.conference_peer_name = conference_peer_name;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_peer_name_free(conference_peer_name, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_peer_name;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *e
|
||||
event.type = TOX_EVENT_CONFERENCE_TITLE;
|
||||
event.data.conference_title = conference_title;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_conference_title_free(conference_title, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return conference_title;
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,10 @@ static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Event
|
||||
event.type = TOX_EVENT_FILE_CHUNK_REQUEST;
|
||||
event.data.file_chunk_request = file_chunk_request;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_file_chunk_request_free(file_chunk_request, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return file_chunk_request;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,10 @@ static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const M
|
||||
event.type = TOX_EVENT_FILE_RECV;
|
||||
event.data.file_recv = file_recv;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_file_recv_free(file_recv, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return file_recv;
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,10 @@ static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *eve
|
||||
event.type = TOX_EVENT_FILE_RECV_CHUNK;
|
||||
event.data.file_recv_chunk = file_recv_chunk;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_file_recv_chunk_free(file_recv_chunk, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return file_recv_chunk;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,10 @@ static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events
|
||||
event.type = TOX_EVENT_FILE_RECV_CONTROL;
|
||||
event.data.file_recv_control = file_recv_control;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_file_recv_control_free(file_recv_control, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return file_recv_control;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_stat
|
||||
event.type = TOX_EVENT_FRIEND_CONNECTION_STATUS;
|
||||
event.data.friend_connection_status = friend_connection_status;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_connection_status_free(friend_connection_status, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_connection_status;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,10 @@ static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(T
|
||||
event.type = TOX_EVENT_FRIEND_LOSSLESS_PACKET;
|
||||
event.data.friend_lossless_packet = friend_lossless_packet;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_lossless_packet_free(friend_lossless_packet, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_lossless_packet;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,10 @@ static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Eve
|
||||
event.type = TOX_EVENT_FRIEND_LOSSY_PACKET;
|
||||
event.data.friend_lossy_packet = friend_lossy_packet;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_lossy_packet_free(friend_lossy_packet, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_lossy_packet;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,10 @@ static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *event
|
||||
event.type = TOX_EVENT_FRIEND_MESSAGE;
|
||||
event.data.friend_message = friend_message;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_message_free(friend_message, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_message;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,10 @@ static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *events, con
|
||||
event.type = TOX_EVENT_FRIEND_NAME;
|
||||
event.data.friend_name = friend_name;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_name_free(friend_name, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_name;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,10 @@ static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Eve
|
||||
event.type = TOX_EVENT_FRIEND_READ_RECEIPT;
|
||||
event.data.friend_read_receipt = friend_read_receipt;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_read_receipt_free(friend_read_receipt, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_read_receipt;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,10 @@ static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *event
|
||||
event.type = TOX_EVENT_FRIEND_REQUEST;
|
||||
event.data.friend_request = friend_request;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_request_free(friend_request, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_request;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *events,
|
||||
event.type = TOX_EVENT_FRIEND_STATUS;
|
||||
event.data.friend_status = friend_status;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_status_free(friend_status, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_status;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,10 @@ static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox
|
||||
event.type = TOX_EVENT_FRIEND_STATUS_MESSAGE;
|
||||
event.data.friend_status_message = friend_status_message;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_status_message_free(friend_status_message, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_status_message;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,10 @@ static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *events,
|
||||
event.type = TOX_EVENT_FRIEND_TYPING;
|
||||
event.data.friend_typing = friend_typing;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_friend_typing_free(friend_typing, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return friend_typing;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Group_Custom_Packet *tox_events_add_group_custom_packet(Tox_Eve
|
||||
event.type = TOX_EVENT_GROUP_CUSTOM_PACKET;
|
||||
event.data.group_custom_packet = group_custom_packet;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_custom_packet_free(group_custom_packet, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_custom_packet;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Group_Custom_Private_Packet *tox_events_add_group_custom_privat
|
||||
event.type = TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET;
|
||||
event.data.group_custom_private_packet = group_custom_private_packet;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_custom_private_packet_free(group_custom_private_packet, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_custom_private_packet;
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,10 @@ static Tox_Event_Group_Invite *tox_events_add_group_invite(Tox_Events *events, c
|
||||
event.type = TOX_EVENT_GROUP_INVITE;
|
||||
event.data.group_invite = group_invite;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_invite_free(group_invite, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_invite;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Group_Join_Fail *tox_events_add_group_join_fail(Tox_Events *eve
|
||||
event.type = TOX_EVENT_GROUP_JOIN_FAIL;
|
||||
event.data.group_join_fail = group_join_fail;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_join_fail_free(group_join_fail, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_join_fail;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,10 @@ static Tox_Event_Group_Message *tox_events_add_group_message(Tox_Events *events,
|
||||
event.type = TOX_EVENT_GROUP_MESSAGE;
|
||||
event.data.group_message = group_message;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_message_free(group_message, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_message;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,10 @@ static Tox_Event_Group_Moderation *tox_events_add_group_moderation(Tox_Events *e
|
||||
event.type = TOX_EVENT_GROUP_MODERATION;
|
||||
event.data.group_moderation = group_moderation;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_moderation_free(group_moderation, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_moderation;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,10 @@ static Tox_Event_Group_Password *tox_events_add_group_password(Tox_Events *event
|
||||
event.type = TOX_EVENT_GROUP_PASSWORD;
|
||||
event.data.group_password = group_password;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_password_free(group_password, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_password;
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,10 @@ static Tox_Event_Group_Peer_Exit *tox_events_add_group_peer_exit(Tox_Events *eve
|
||||
event.type = TOX_EVENT_GROUP_PEER_EXIT;
|
||||
event.data.group_peer_exit = group_peer_exit;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_peer_exit_free(group_peer_exit, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_peer_exit;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,10 @@ static Tox_Event_Group_Peer_Join *tox_events_add_group_peer_join(Tox_Events *eve
|
||||
event.type = TOX_EVENT_GROUP_PEER_JOIN;
|
||||
event.data.group_peer_join = group_peer_join;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_peer_join_free(group_peer_join, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_peer_join;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,10 @@ static Tox_Event_Group_Peer_Limit *tox_events_add_group_peer_limit(Tox_Events *e
|
||||
event.type = TOX_EVENT_GROUP_PEER_LIMIT;
|
||||
event.data.group_peer_limit = group_peer_limit;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_peer_limit_free(group_peer_limit, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_peer_limit;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Group_Peer_Name *tox_events_add_group_peer_name(Tox_Events *eve
|
||||
event.type = TOX_EVENT_GROUP_PEER_NAME;
|
||||
event.data.group_peer_name = group_peer_name;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_peer_name_free(group_peer_name, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_peer_name;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,10 @@ static Tox_Event_Group_Peer_Status *tox_events_add_group_peer_status(Tox_Events
|
||||
event.type = TOX_EVENT_GROUP_PEER_STATUS;
|
||||
event.data.group_peer_status = group_peer_status;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_peer_status_free(group_peer_status, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_peer_status;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Group_Privacy_State *tox_events_add_group_privacy_state(Tox_Eve
|
||||
event.type = TOX_EVENT_GROUP_PRIVACY_STATE;
|
||||
event.data.group_privacy_state = group_privacy_state;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_privacy_state_free(group_privacy_state, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_privacy_state;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,10 @@ static Tox_Event_Group_Private_Message *tox_events_add_group_private_message(Tox
|
||||
event.type = TOX_EVENT_GROUP_PRIVATE_MESSAGE;
|
||||
event.data.group_private_message = group_private_message;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_private_message_free(group_private_message, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_private_message;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,10 @@ static Tox_Event_Group_Self_Join *tox_events_add_group_self_join(Tox_Events *eve
|
||||
event.type = TOX_EVENT_GROUP_SELF_JOIN;
|
||||
event.data.group_self_join = group_self_join;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_self_join_free(group_self_join, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_self_join;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,10 @@ static Tox_Event_Group_Topic *tox_events_add_group_topic(Tox_Events *events, con
|
||||
event.type = TOX_EVENT_GROUP_TOPIC;
|
||||
event.data.group_topic = group_topic;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_topic_free(group_topic, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_topic;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Group_Topic_Lock *tox_events_add_group_topic_lock(Tox_Events *e
|
||||
event.type = TOX_EVENT_GROUP_TOPIC_LOCK;
|
||||
event.data.group_topic_lock = group_topic_lock;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_topic_lock_free(group_topic_lock, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_topic_lock;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,10 @@ static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events
|
||||
event.type = TOX_EVENT_GROUP_VOICE_STATE;
|
||||
event.data.group_voice_state = group_voice_state;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_group_voice_state_free(group_voice_state, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return group_voice_state;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,10 @@ static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(T
|
||||
event.type = TOX_EVENT_SELF_CONNECTION_STATUS;
|
||||
event.data.self_connection_status = self_connection_status;
|
||||
|
||||
tox_events_add(events, &event);
|
||||
if (!tox_events_add(events, &event)) {
|
||||
tox_event_self_connection_status_free(self_connection_status, mem);
|
||||
return nullptr;
|
||||
}
|
||||
return self_connection_status;
|
||||
}
|
||||
|
||||
|
@ -1032,6 +1032,11 @@ void kill_friend_connections(Friend_Connections *fr_c)
|
||||
kill_friend_connection(fr_c, i);
|
||||
}
|
||||
|
||||
// there might be allocated NONE connections
|
||||
if (fr_c->conns != nullptr) {
|
||||
free(fr_c->conns);
|
||||
}
|
||||
|
||||
lan_discovery_kill(fr_c->broadcast);
|
||||
free(fr_c);
|
||||
}
|
||||
|
@ -2520,7 +2520,7 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8
|
||||
|
||||
non_null(1, 3) nullable(6)
|
||||
static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
|
||||
int connection_index, void *userdata)
|
||||
uint32_t connection_index, void *userdata)
|
||||
{
|
||||
if (length == 0) {
|
||||
return;
|
||||
@ -2832,7 +2832,7 @@ static bool check_message_info(uint32_t message_number, uint8_t message_id, Grou
|
||||
|
||||
non_null(1, 3) nullable(6)
|
||||
static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
|
||||
int connection_index, void *userdata)
|
||||
uint32_t connection_index, void *userdata)
|
||||
{
|
||||
if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) {
|
||||
return;
|
||||
|
@ -8353,7 +8353,7 @@ bool gc_group_is_valid(const GC_Chat *chat)
|
||||
/** Return true if `group_number` designates an active group in session `c`. */
|
||||
static bool group_number_valid(const GC_Session *c, int group_number)
|
||||
{
|
||||
if (group_number < 0 || group_number >= c->chats_index) {
|
||||
if (group_number < 0 || (uint32_t)group_number >= c->chats_index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -122,9 +122,6 @@ typedef struct Crypto_Connection {
|
||||
|
||||
bool maximum_speed_reached;
|
||||
|
||||
/* Must be a pointer, because the struct is moved in memory */
|
||||
pthread_mutex_t *mutex;
|
||||
|
||||
dht_pk_cb *dht_pk_callback;
|
||||
void *dht_pk_callback_object;
|
||||
uint32_t dht_pk_callback_number;
|
||||
@ -143,10 +140,6 @@ struct Net_Crypto {
|
||||
TCP_Connections *tcp_c;
|
||||
|
||||
Crypto_Connection *crypto_connections;
|
||||
pthread_mutex_t tcp_mutex;
|
||||
|
||||
pthread_mutex_t connections_mutex;
|
||||
unsigned int connection_use_counter;
|
||||
|
||||
uint32_t crypto_connections_length; /* Length of connections array. */
|
||||
|
||||
@ -691,7 +684,6 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
|
||||
bool direct_send_attempt = false;
|
||||
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
const IP_Port ip_port = return_ip_port_connection(c, crypt_connection_id);
|
||||
|
||||
// TODO(irungentoo): on bad networks, direct connections might not last indefinitely.
|
||||
@ -703,11 +695,9 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
|
||||
if (direct_connected) {
|
||||
if ((uint32_t)sendpacket(dht_get_net(c->dht), &ip_port, data, length) == length) {
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
LOGGER_WARNING(c->log, "sending packet of length %d failed", length);
|
||||
return -1;
|
||||
}
|
||||
@ -724,19 +714,12 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = send_packet_tcp_connection(c->tcp_c, conn->connection_number_tcp, data, length);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
|
||||
if (ret == 0) {
|
||||
conn->last_tcp_sent = current_time_monotonic(c->mono_time);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
|
||||
if (direct_send_attempt) {
|
||||
return 0;
|
||||
}
|
||||
@ -1097,7 +1080,6 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
const uint16_t packet_size = 1 + sizeof(uint16_t) + length + CRYPTO_MAC_SIZE;
|
||||
VLA(uint8_t, packet, packet_size);
|
||||
packet[0] = NET_PACKET_CRYPTO_DATA;
|
||||
@ -1106,12 +1088,10 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_
|
||||
|
||||
if (len + 1 + sizeof(uint16_t) != packet_size) {
|
||||
LOGGER_ERROR(c->log, "encryption failed: %d", len);
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
increment_nonce(conn->sent_nonce);
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
|
||||
return send_packet_to(c, crypt_connection_id, packet, packet_size);
|
||||
}
|
||||
@ -1207,9 +1187,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
|
||||
dt.sent_time = 0;
|
||||
dt.length = length;
|
||||
memcpy(dt.data, data, length);
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
const int64_t packet_num = add_data_end_of_buffer(c->log, c->mem, &conn->send_array, &dt);
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
|
||||
if (packet_num == -1) {
|
||||
return -1;
|
||||
@ -1521,18 +1499,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
|
||||
false, userdata);
|
||||
}
|
||||
|
||||
while (true) { /* TODO(irungentoo): is this really the best way to do this? */
|
||||
pthread_mutex_lock(&c->connections_mutex);
|
||||
|
||||
if (c->connection_use_counter == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
}
|
||||
|
||||
crypto_kill(c, crypt_connection_id);
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
}
|
||||
|
||||
/** @brief Handle a received data packet.
|
||||
@ -1635,9 +1602,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
|
||||
}
|
||||
|
||||
while (true) {
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
const int ret = read_data_beg_buffer(c->mem, &conn->recv_array, &dt);
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
|
||||
if (ret == -1) {
|
||||
break;
|
||||
@ -1835,16 +1800,6 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
|
||||
non_null()
|
||||
static int create_crypto_connection(Net_Crypto *c)
|
||||
{
|
||||
while (true) { /* TODO(irungentoo): is this really the best way to do this? */
|
||||
pthread_mutex_lock(&c->connections_mutex);
|
||||
|
||||
if (c->connection_use_counter == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
}
|
||||
|
||||
int id = -1;
|
||||
|
||||
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
|
||||
@ -1863,30 +1818,17 @@ static int create_crypto_connection(Net_Crypto *c)
|
||||
}
|
||||
|
||||
if (id != -1) {
|
||||
pthread_mutex_t *mutex = (pthread_mutex_t *)mem_alloc(c->mem, sizeof(pthread_mutex_t));
|
||||
|
||||
if (mutex == nullptr) {
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(mutex, nullptr) != 0) {
|
||||
mem_delete(c->mem, mutex);
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Memsetting float/double to 0 is non-portable, so we explicitly set them to 0
|
||||
c->crypto_connections[id].packet_recv_rate = 0.0;
|
||||
c->crypto_connections[id].packet_send_rate = 0.0;
|
||||
c->crypto_connections[id].last_packets_left_rem = 0.0;
|
||||
c->crypto_connections[id].packet_send_rate_requested = 0.0;
|
||||
c->crypto_connections[id].last_packets_left_requested_rem = 0.0;
|
||||
c->crypto_connections[id].mutex = mutex;
|
||||
|
||||
// TODO(Green-Sky): This enum is likely unneeded and the same as FREE.
|
||||
c->crypto_connections[id].status = CRYPTO_CONN_NO_CONNECTION;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -1914,8 +1856,6 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
|
||||
|
||||
uint32_t i;
|
||||
|
||||
pthread_mutex_destroy(c->crypto_connections[crypt_connection_id].mutex);
|
||||
mem_delete(c->mem, c->crypto_connections[crypt_connection_id].mutex);
|
||||
crypto_memzero(&c->crypto_connections[crypt_connection_id], sizeof(Crypto_Connection));
|
||||
|
||||
/* check if we can resize the connections array */
|
||||
@ -2098,9 +2038,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c)
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int connection_number_tcp = new_tcp_connection_to(c->tcp_c, n_c->dht_public_key, crypt_connection_id);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
if (connection_number_tcp == -1) {
|
||||
wipe_crypto_connection(c, crypt_connection_id);
|
||||
@ -2117,9 +2055,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c)
|
||||
conn->status = CRYPTO_CONN_NOT_CONFIRMED;
|
||||
|
||||
if (create_send_handshake(c, crypt_connection_id, n_c->cookie, n_c->dht_public_key) != 0) {
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
wipe_crypto_connection(c, crypt_connection_id);
|
||||
return -1;
|
||||
}
|
||||
@ -2155,9 +2091,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
|
||||
|
||||
Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id];
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int connection_number_tcp = new_tcp_connection_to(c->tcp_c, dht_public_key, crypt_connection_id);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
if (connection_number_tcp == -1) {
|
||||
wipe_crypto_connection(c, crypt_connection_id);
|
||||
@ -2181,9 +2115,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
|
||||
if (create_cookie_request(c, cookie_request, conn->dht_public_key, conn->cookie_request_number,
|
||||
conn->shared_key) != sizeof(cookie_request)
|
||||
|| new_temp_packet(c, crypt_connection_id, cookie_request, sizeof(cookie_request)) != 0) {
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
wipe_crypto_connection(c, crypt_connection_id);
|
||||
return -1;
|
||||
}
|
||||
@ -2241,11 +2173,7 @@ static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_
|
||||
return tcp_handle_cookie_request(c, conn->connection_number_tcp, packet, length);
|
||||
}
|
||||
|
||||
// This unlocks the mutex that at this point is locked by do_tcp before
|
||||
// calling do_tcp_connections.
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
const int ret = handle_packet_connection(c, crypt_connection_id, packet, length, false, userdata);
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
@ -2295,10 +2223,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
return ret;
|
||||
return add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key);
|
||||
}
|
||||
|
||||
/** @brief Add a tcp relay to the array.
|
||||
@ -2308,10 +2233,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
|
||||
*/
|
||||
int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_key)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = add_tcp_relay_global(c->tcp_c, ip_port, public_key);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
return ret;
|
||||
return add_tcp_relay_global(c->tcp_c, ip_port, public_key);
|
||||
}
|
||||
|
||||
/** @brief Return a random TCP connection number for use in send_tcp_onion_request.
|
||||
@ -2322,13 +2244,9 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k
|
||||
* return TCP connection number on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int get_random_tcp_con_number(Net_Crypto *c)
|
||||
int get_random_tcp_con_number(const Net_Crypto *c)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = get_random_tcp_onion_conn_number(c->tcp_c);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return get_random_tcp_onion_conn_number(c->tcp_c);
|
||||
}
|
||||
|
||||
/** @brief Put IP_Port of a random onion TCP connection in ip_port.
|
||||
@ -2336,13 +2254,9 @@ int get_random_tcp_con_number(Net_Crypto *c)
|
||||
* return true on success.
|
||||
* return false on failure.
|
||||
*/
|
||||
bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port)
|
||||
bool get_random_tcp_conn_ip_port(const Net_Crypto *c, IP_Port *ip_port)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const bool ret = tcp_get_random_conn_ip_port(c->tcp_c, ip_port);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return tcp_get_random_conn_ip_port(c->tcp_c, ip_port);
|
||||
}
|
||||
|
||||
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
|
||||
@ -2352,11 +2266,7 @@ bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port)
|
||||
*/
|
||||
int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2371,12 +2281,8 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port
|
||||
const uint8_t *chain_keys, uint16_t chain_length,
|
||||
const uint8_t *data, uint16_t data_length)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const int ret = tcp_send_forward_request(logger, c->tcp_c, tcp_forwarder, dht_node,
|
||||
chain_keys, chain_length, data, data_length);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return tcp_send_forward_request(logger, c->tcp_c, tcp_forwarder, dht_node,
|
||||
chain_keys, chain_length, data, data_length);
|
||||
}
|
||||
|
||||
/** @brief Copy a maximum of num random TCP relays we are connected to to tcp_relays.
|
||||
@ -2386,38 +2292,28 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port
|
||||
* return number of relays copied to tcp_relays on success.
|
||||
* return 0 on failure.
|
||||
*/
|
||||
unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
|
||||
unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const unsigned int ret = tcp_copy_connected_relays(c->tcp_c, tcp_relays, num);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return tcp_copy_connected_relays(c->tcp_c, tcp_relays, num);
|
||||
}
|
||||
|
||||
uint32_t copy_connected_tcp_relays_index(Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx)
|
||||
uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx)
|
||||
{
|
||||
if (num == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
const uint32_t ret = tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
return ret;
|
||||
return tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_tcp(Net_Crypto *c, void *userdata)
|
||||
{
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
do_tcp_connections(c->log, c->tcp_c, userdata);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
|
||||
const Crypto_Connection *conn = get_crypto_connection(c, i);
|
||||
@ -2436,9 +2332,7 @@ static void do_tcp(Net_Crypto *c, void *userdata)
|
||||
continue;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
set_tcp_connection_to_status(c->tcp_c, conn->connection_number_tcp, !direct_connected);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2593,15 +2487,12 @@ static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
|
||||
if (net_family_is_ipv4(source->ip.family)) {
|
||||
conn->direct_lastrecv_timev4 = mono_time_get(c->mono_time);
|
||||
} else {
|
||||
conn->direct_lastrecv_timev6 = mono_time_get(c->mono_time);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2997,26 +2888,16 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->connections_mutex);
|
||||
++c->connection_use_counter;
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
|
||||
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
|
||||
|
||||
int ret = -1;
|
||||
|
||||
if (conn != nullptr) {
|
||||
pthread_mutex_lock(conn->mutex);
|
||||
const uint32_t buffer_start = conn->recv_array.buffer_start;
|
||||
const uint32_t buffer_end = conn->send_array.buffer_end;
|
||||
pthread_mutex_unlock(conn->mutex);
|
||||
ret = send_data_packet_helper(c, crypt_connection_id, buffer_start, buffer_end, data, length);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->connections_mutex);
|
||||
--c->connection_use_counter;
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -3036,9 +2917,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
|
||||
send_kill_packet(c, crypt_connection_id);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&c->tcp_mutex);
|
||||
kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp);
|
||||
pthread_mutex_unlock(&c->tcp_mutex);
|
||||
|
||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_portv4, crypt_connection_id);
|
||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_portv6, crypt_connection_id);
|
||||
@ -3135,13 +3014,6 @@ Net_Crypto *new_net_crypto(const Logger *log, const Memory *mem, const Random *r
|
||||
set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp);
|
||||
set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp);
|
||||
|
||||
if (create_recursive_mutex(&temp->tcp_mutex) != 0 ||
|
||||
pthread_mutex_init(&temp->connections_mutex, nullptr) != 0) {
|
||||
kill_tcp_connections(temp->tcp_c);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->dht = dht;
|
||||
|
||||
new_keys(temp);
|
||||
@ -3215,9 +3087,6 @@ void kill_net_crypto(Net_Crypto *c)
|
||||
crypto_kill(c, i);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&c->tcp_mutex);
|
||||
pthread_mutex_destroy(&c->connections_mutex);
|
||||
|
||||
kill_tcp_connections(c->tcp_c);
|
||||
bs_list_free(&c->ip_port_list);
|
||||
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, nullptr, nullptr);
|
||||
|
@ -40,7 +40,6 @@
|
||||
/** 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
|
||||
@ -311,7 +310,7 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k
|
||||
* return -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int get_random_tcp_con_number(Net_Crypto *c);
|
||||
int get_random_tcp_con_number(const Net_Crypto *c);
|
||||
|
||||
/** @brief Put IP_Port of a random onion TCP connection in ip_port.
|
||||
*
|
||||
@ -319,7 +318,7 @@ int get_random_tcp_con_number(Net_Crypto *c);
|
||||
* return false on failure.
|
||||
*/
|
||||
non_null()
|
||||
bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port);
|
||||
bool get_random_tcp_conn_ip_port(const Net_Crypto *c, IP_Port *ip_port);
|
||||
|
||||
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
|
||||
*
|
||||
@ -351,7 +350,7 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port
|
||||
* return 0 on failure.
|
||||
*/
|
||||
non_null()
|
||||
unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
|
||||
unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
|
||||
|
||||
/**
|
||||
* Copy a maximum of `max_num` TCP relays we are connected to starting at the index in the TCP relay array
|
||||
@ -360,7 +359,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u
|
||||
* Returns the number of relays successfully copied.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t copy_connected_tcp_relays_index(Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx);
|
||||
uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx);
|
||||
|
||||
/** @brief Kill a crypto connection.
|
||||
*
|
||||
|
@ -955,7 +955,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
|
||||
}
|
||||
|
||||
uint8_t plain[1 + ONION_PING_ID_SIZE + ONION_ANNOUNCE_RESPONSE_MAX_SIZE - ONION_ANNOUNCE_RESPONSE_MIN_SIZE];
|
||||
const int plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE;
|
||||
const uint32_t plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE;
|
||||
int len;
|
||||
const uint16_t nonce_start = 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH;
|
||||
const uint16_t ciphertext_start = nonce_start + CRYPTO_NONCE_SIZE;
|
||||
|
@ -1058,7 +1058,7 @@ void tox_kill(Tox *tox)
|
||||
}
|
||||
|
||||
tox_lock(tox);
|
||||
LOGGER_ASSERT(tox->m->log, tox->m->msi_packet == nullptr, "Attempted to kill tox while toxav is still alive");
|
||||
LOGGER_ASSERT(tox->m->log, tox->toxav_object == nullptr, "Attempted to kill tox while toxav is still alive");
|
||||
kill_groupchats(tox->m->conferences_object);
|
||||
kill_messenger(tox->m);
|
||||
mono_time_free(tox->sys.mem, tox->mono_time);
|
||||
@ -2551,6 +2551,12 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
|
||||
Tox_Err_Conference_Join *error)
|
||||
{
|
||||
assert(tox != nullptr);
|
||||
|
||||
if (cookie == nullptr) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_JOIN_NULL);
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
tox_lock(tox);
|
||||
const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
|
||||
tox_unlock(tox);
|
||||
@ -4263,6 +4269,11 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t
|
||||
{
|
||||
assert(tox != nullptr);
|
||||
|
||||
if (invite_data == nullptr || name == nullptr) {
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_NULL);
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
tox_lock(tox);
|
||||
const int ret = gc_accept_invite(tox->m->group_handler, friend_number, invite_data, length, name, name_length, password,
|
||||
password_length);
|
||||
|
@ -2891,6 +2891,11 @@ typedef enum Tox_Err_Conference_Join {
|
||||
*/
|
||||
TOX_ERR_CONFERENCE_JOIN_FAIL_SEND,
|
||||
|
||||
/**
|
||||
* The cookie passed was NULL.
|
||||
*/
|
||||
TOX_ERR_CONFERENCE_JOIN_NULL,
|
||||
|
||||
} Tox_Err_Conference_Join;
|
||||
|
||||
const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value);
|
||||
@ -3216,9 +3221,9 @@ typedef enum Tox_Err_Friend_Custom_Packet {
|
||||
TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED,
|
||||
|
||||
/**
|
||||
* The first byte of data was not in the specified range for the packet
|
||||
* type. This range is 192-254 for lossy, and 69, 160-191 for lossless
|
||||
* packets.
|
||||
* The first byte of data was not one of the permitted values;
|
||||
* for lossy packets the first byte must be in the range 192-254,
|
||||
* and for lossless packets it must be either 69 or in the range 160-191.
|
||||
*/
|
||||
TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID,
|
||||
|
||||
@ -3269,7 +3274,7 @@ bool tox_friend_send_lossy_packet(
|
||||
/**
|
||||
* @brief Send a custom lossless packet to a friend.
|
||||
*
|
||||
* The first byte of data must be in the range 69, 160-191. Maximum length of a
|
||||
* The first byte of data must be either 69 or in the range 160-191. Maximum length of a
|
||||
* custom packet is TOX_MAX_CUSTOM_PACKET_SIZE.
|
||||
*
|
||||
* Lossless packet behaviour is comparable to TCP (reliability, arrive in order)
|
||||
@ -3288,6 +3293,9 @@ bool tox_friend_send_lossless_packet(
|
||||
Tox_Err_Friend_Custom_Packet *error);
|
||||
|
||||
/**
|
||||
* tox_callback_friend_lossy_packet is the compatibility function to
|
||||
* set the callback for all packet IDs except those reserved for ToxAV.
|
||||
*
|
||||
* @param friend_number The friend number of the friend who sent a lossy packet.
|
||||
* @param data A byte array containing the received packet data.
|
||||
* @param length The length of the packet data byte array.
|
||||
@ -4992,6 +5000,11 @@ typedef enum Tox_Err_Group_Invite_Accept {
|
||||
*/
|
||||
TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND,
|
||||
|
||||
/**
|
||||
* Invite data or name is NULL.
|
||||
*/
|
||||
TOX_ERR_GROUP_INVITE_ACCEPT_NULL,
|
||||
|
||||
} Tox_Err_Group_Invite_Accept;
|
||||
|
||||
const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value);
|
||||
|
@ -887,6 +887,9 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value)
|
||||
|
||||
case TOX_ERR_CONFERENCE_JOIN_FAIL_SEND:
|
||||
return "TOX_ERR_CONFERENCE_JOIN_FAIL_SEND";
|
||||
|
||||
case TOX_ERR_CONFERENCE_JOIN_NULL:
|
||||
return "TOX_ERR_CONFERENCE_JOIN_NULL";
|
||||
}
|
||||
|
||||
return "<invalid Tox_Err_Conference_Join>";
|
||||
@ -1448,6 +1451,9 @@ const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept va
|
||||
|
||||
case TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND:
|
||||
return "TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND";
|
||||
|
||||
case TOX_ERR_GROUP_INVITE_ACCEPT_NULL:
|
||||
return "TOX_ERR_GROUP_INVITE_ACCEPT_NULL";
|
||||
}
|
||||
|
||||
return "<invalid Tox_Err_Group_Invite_Accept>";
|
||||
|
@ -155,17 +155,15 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip
|
||||
const uint8_t *target_public_key, Tox_Err_Dht_Get_Nodes *error);
|
||||
|
||||
/**
|
||||
* This function returns the ratio of close dht nodes that are known to support
|
||||
* announce/store. This function returns the number of DHT nodes in the
|
||||
* closelist.
|
||||
* This function returns the number of DHT nodes in the closelist.
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
uint16_t tox_dht_get_num_closelist(const Tox *tox);
|
||||
|
||||
/**
|
||||
* This function returns the number of DHT nodes in the closelist,
|
||||
* that are capable to store announce data (introduced in version 0.2.18).
|
||||
* This function returns the number of DHT nodes in the closelist
|
||||
* that are capable of storing announce data (introduced in version 0.2.18).
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
|
Reference in New Issue
Block a user