diff options
-rw-r--r-- | toxcore/DHT.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 08faa635..3c265be3 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1176,9 +1176,9 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port, | |||
1176 | Client_data *data = &array[index]; | 1176 | Client_data *data = &array[index]; |
1177 | IPPTsPng *assoc; | 1177 | IPPTsPng *assoc; |
1178 | 1178 | ||
1179 | if (ip_port.ip.family == TOX_AF_INET) { | 1179 | if (ip_port.ip.family == AF_INET) { |
1180 | assoc = &data->assoc4; | 1180 | assoc = &data->assoc4; |
1181 | } else if (ip_port.ip.family == TOX_AF_INET6) { | 1181 | } else if (ip_port.ip.family == AF_INET6) { |
1182 | assoc = &data->assoc6; | 1182 | assoc = &data->assoc6; |
1183 | } else { | 1183 | } else { |
1184 | return true; | 1184 | return true; |
@@ -1298,7 +1298,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
1298 | plain[0] = num_nodes; | 1298 | plain[0] = num_nodes; |
1299 | memcpy(plain + 1 + nodes_length, sendback_data, length); | 1299 | memcpy(plain + 1 + nodes_length, sendback_data, length); |
1300 | 1300 | ||
1301 | const int crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; | 1301 | const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; |
1302 | VLA(uint8_t, data, 1 + nodes_length + length + crypto_size); | 1302 | VLA(uint8_t, data, 1 + nodes_length + length + crypto_size); |
1303 | 1303 | ||
1304 | int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, | 1304 | int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, |
@@ -1311,13 +1311,11 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
1311 | return sendpacket(dht->net, ip_port, data, len); | 1311 | return sendpacket(dht->net, ip_port, data, len); |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | #define CRYPTO_NODE_SIZE CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t) | 1314 | #define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)) |
1315 | 1315 | ||
1316 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 1316 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
1317 | { | 1317 | { |
1318 | const int crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; | 1318 | if (length != (CRYPTO_SIZE + CRYPTO_MAC_SIZE + sizeof(uint64_t))) { |
1319 | |||
1320 | if (length != (crypto_size + CRYPTO_NODE_SIZE)) { | ||
1321 | return 1; | 1319 | return 1; |
1322 | } | 1320 | } |
1323 | 1321 | ||
@@ -1580,21 +1578,21 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) | |||
1580 | ip_reset(&ip_port->ip); | 1578 | ip_reset(&ip_port->ip); |
1581 | ip_port->port = 0; | 1579 | ip_port->port = 0; |
1582 | 1580 | ||
1583 | int index = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key); | 1581 | uint32_t friend_index = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key); |
1584 | 1582 | ||
1585 | if (index == UINT32_MAX) { | 1583 | if (friend_index == UINT32_MAX) { |
1586 | return -1; | 1584 | return -1; |
1587 | } | 1585 | } |
1588 | 1586 | ||
1589 | DHT_Friend *frnd = &dht->friends_list[index]; | 1587 | DHT_Friend *frnd = &dht->friends_list[friend_index]; |
1590 | index = index_of_client_pk(frnd->client_list, MAX_FRIEND_CLIENTS, public_key); | 1588 | uint32_t client_index = index_of_client_pk(frnd->client_list, MAX_FRIEND_CLIENTS, public_key); |
1591 | 1589 | ||
1592 | if (index == UINT32_MAX) { | 1590 | if (client_index == -1) { |
1593 | return -1; | 1591 | return 0; |
1594 | } | 1592 | } |
1595 | 1593 | ||
1596 | Client_data *client = &frnd->client_list[index]; | 1594 | Client_data *client = &frnd->client_list[client_index]; |
1597 | IPPTsPng *assoc = NULL; | 1595 | IPPTsPng *assoc; |
1598 | uint32_t a; | 1596 | uint32_t a; |
1599 | 1597 | ||
1600 | for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) { | 1598 | for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) { |