Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Apr 1, 2022
1 parent d8608d4 commit 4d73af5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,7 @@ uint32_t messenger_run_interval(const Messenger *m)
non_null()
static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend)
{
GC_Public_Announce announce = {{{0}}};
GC_Public_Announce announce = {{0}};

const bool ip_port_is_set = chat->self_udp_status != SELF_UDP_STATUS_NONE;
const int tcp_num = tcp_copy_connected_relays(chat->tcp_conn, announce.base_announce.tcp_relays,
Expand Down
6 changes: 3 additions & 3 deletions toxcore/group_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t
}

if (announce->ip_port_is_set) {
const int ip_port_length = unpack_ip_port(&announce->ip_port, data + offset, length - offset, 0);
const int ip_port_length = unpack_ip_port(&announce->ip_port, data + offset, length - offset, false);

if (ip_port_length == -1) {
LOGGER_ERROR(log, "Failed to unpack ip_port");
Expand All @@ -203,7 +203,7 @@ static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t

uint16_t nodes_length;
const int nodes_count = unpack_nodes(announce->tcp_relays, announce->tcp_relays_count, &nodes_length,
data + offset, length - offset, 1);
data + offset, length - offset, true);

if (nodes_count != announce->tcp_relays_count) {
LOGGER_ERROR(log, "Failed to unpack TCP nodes");
Expand Down Expand Up @@ -396,7 +396,7 @@ void kill_gca(GC_Announces_List *announces_list)

GC_Announces *root = announces_list->root_announces;

while (root) {
while (root != nullptr) {
GC_Announces *next = root->next_announce;
free(root);
root = next;
Expand Down
34 changes: 21 additions & 13 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ static int handle_gc_tcp_relays(GC_Chat *chat, GC_Connection *gconn, const uint8
}

Node_format tcp_relays[GCC_MAX_TCP_SHARED_RELAYS];
const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS, nullptr, data, length, 1);
const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS, nullptr, data, length, true);

if (num_nodes <= 0) {
return -2;
Expand Down Expand Up @@ -5605,7 +5605,7 @@ static int handle_gc_handshake_request(GC_Chat *chat, const IP_Port *ipp, const
const int processed = ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE + 1;

const int nodes_count = unpack_nodes(node, GCA_MAX_ANNOUNCED_TCP_RELAYS, nullptr,
data + processed, length - processed, 1);
data + processed, length - processed, true);

if (nodes_count <= 0 && ipp == nullptr) {
if (is_new_peer) {
Expand Down Expand Up @@ -6131,11 +6131,19 @@ static int handle_gc_tcp_packet(void *object, int id, const uint8_t *packet, uin

switch (packet_type) {
case NET_PACKET_GC_LOSSLESS: {
return handle_gc_lossless_packet(c, chat, sender_pk, payload, payload_len, false, userdata);
if (!handle_gc_lossless_packet(c, chat, sender_pk, payload, payload_len, false, userdata)) {
return -1;
}

return 0;
}

case NET_PACKET_GC_LOSSY: {
return handle_gc_lossy_packet(c, chat, sender_pk, payload, payload_len, false, userdata);
if (!handle_gc_lossy_packet(c, chat, sender_pk, payload, payload_len, false, userdata)) {
return -1;
}

return 0;
}

case NET_PACKET_GC_HANDSHAKE: {
Expand Down Expand Up @@ -6287,7 +6295,7 @@ static int handle_gc_udp_packet(void *object, const IP_Port *ipp, const uint8_t
}
}

return ret;
return ret ? 0 : -1;
}

void gc_callback_message(const Messenger *m, gc_message_cb *function)
Expand Down Expand Up @@ -6948,7 +6956,7 @@ static void do_timed_out_reconn(GC_Chat *chat)
if (mono_time_is_timeout(chat->mono_time, timeout->last_seen, GC_TIMED_OUT_STALE_TIMEOUT)
|| get_peer_number_of_enc_pk(chat, timeout->addr.public_key, true) != -1) {
*timeout = (GC_TimedOutPeer) {
0
{{0}}
};
continue;
}
Expand Down Expand Up @@ -7729,7 +7737,7 @@ int handle_gc_invite_confirmed_packet(const GC_Session *c, int friend_number, co
Node_format tcp_relays[GCC_MAX_TCP_SHARED_RELAYS];
const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS,
nullptr, data + ENC_PUBLIC_KEY_SIZE + CHAT_ID_SIZE,
length - GC_JOIN_DATA_LENGTH, 1);
length - GC_JOIN_DATA_LENGTH, true);

const bool copy_ip_port_result = copy_friend_ip_port_to_gconn(c->messenger, friend_number, gconn);

Expand Down Expand Up @@ -7808,10 +7816,10 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con
}

uint16_t len = GC_JOIN_DATA_LENGTH;
uint8_t send_data[GC_JOIN_DATA_LENGTH + (GCC_MAX_TCP_SHARED_RELAYS * PACKED_NODE_SIZE_IP6)];
uint8_t out_data[GC_JOIN_DATA_LENGTH + (GCC_MAX_TCP_SHARED_RELAYS * PACKED_NODE_SIZE_IP6)];

memcpy(send_data, chat_id, CHAT_ID_SIZE);
memcpy(send_data + CHAT_ID_SIZE, chat->self_public_key, ENC_PUBLIC_KEY_SIZE);
memcpy(out_data, chat_id, CHAT_ID_SIZE);
memcpy(out_data + CHAT_ID_SIZE, chat->self_public_key, ENC_PUBLIC_KEY_SIZE);

if (num_tcp_relays > 0) {
const uint32_t tcp_relays_added = add_gc_tcp_relays(chat, gconn, tcp_relays, num_tcp_relays);
Expand All @@ -7821,7 +7829,7 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con
return -1;
}

const int nodes_len = pack_nodes(chat->log, send_data + len, sizeof(send_data) - len, tcp_relays,
const int nodes_len = pack_nodes(chat->log, out_data + len, sizeof(out_data) - len, tcp_relays,
(uint16_t)num_tcp_relays);

if (nodes_len <= 0 && !copy_ip_port_result) {
Expand All @@ -7831,7 +7839,7 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con
len += nodes_len;
}

if (send_gc_invite_confirmed_packet(m, chat, friend_number, send_data, len)) {
if (send_gc_invite_confirmed_packet(m, chat, friend_number, out_data, len)) {
return 0;
}

Expand Down Expand Up @@ -7890,7 +7898,7 @@ int gc_accept_invite(GC_Session *c, int32_t friend_number, const uint8_t *data,
return -2;
}

if (send_gc_invite_accepted_packet(c->messenger, chat, friend_number)) {
if (send_gc_invite_accepted_packet(c->messenger, chat, friend_number) != 0) {
return -7;
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/group_chats.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int get_peer_number_of_enc_pk(const GC_Chat *chat, const uint8_t *public_enc_key
* Return -2 if malloc fails.
* Return -3 if encryption fails.
*/
non_null(1, 2, 3, 4) nullable(6)
non_null(1, 2, 3, 4, 5) nullable(7)
int group_packet_wrap(
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
Expand Down
2 changes: 1 addition & 1 deletion toxcore/group_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
return false;
}

bool manually_disconnected = 0;
bool manually_disconnected = false;
uint8_t privacy_state = 0;
uint8_t voice_state = 0;

Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u

Node_format nodes[MAX_SENT_NODES];
const int num_nodes = unpack_nodes(nodes, nodes_count, &len_nodes, plain + 2 + ONION_PING_ID_SIZE,
plain_size - 2 - ONION_PING_ID_SIZE, 0);
plain_size - 2 - ONION_PING_ID_SIZE, false);

if (num_nodes < 0) {
return 1;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ Tox_Group_Role tox_group_self_get_role(const Tox *tox, uint32_t group_number, To

SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SELF_QUERY_OK);

const uint8_t role = gc_get_self_role(chat);
const Group_Role role = gc_get_self_role(chat);
tox_unlock(tox);

return (Tox_Group_Role)role;
Expand Down

0 comments on commit 4d73af5

Please sign in to comment.