summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/DHT.c21
-rw-r--r--toxcore/onion_client.c4
2 files changed, 18 insertions, 7 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index b4caa113..e748da7c 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1335,22 +1335,31 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1335 return -1; 1335 return -1;
1336} 1336}
1337 1337
1338static void divide_by_2(uint8_t *public_key) 1338static void abs_divide_by_2(uint8_t *public_key_dist)
1339{ 1339{
1340 unsigned int i; 1340 unsigned int i;
1341 _Bool one = 0; 1341 _Bool one = 0, abs = 0;
1342
1343 if (public_key_dist[0] & (1 << 7)) {
1344 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1345 public_key_dist[i] = ~public_key_dist[i];
1346 }
1347
1348 if (public_key_dist[crypto_box_PUBLICKEYBYTES - 1] != UINT8_MAX)
1349 ++public_key_dist[crypto_box_PUBLICKEYBYTES - 1];
1350 }
1342 1351
1343 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 1352 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1344 _Bool temp = 0; 1353 _Bool temp = 0;
1345 1354
1346 if (public_key[i] & (1)) { 1355 if (public_key_dist[i] & (1)) {
1347 temp = 1; 1356 temp = 1;
1348 } 1357 }
1349 1358
1350 public_key[i] >>= 1; 1359 public_key_dist[i] >>= 1;
1351 1360
1352 if (one) 1361 if (one)
1353 public_key[i] += (1 << 7); 1362 public_key_dist[i] += (1 << 7);
1354 1363
1355 one = temp; 1364 one = temp;
1356 } 1365 }
@@ -1364,7 +1373,7 @@ static void find_midpoint(uint8_t *out, const uint8_t *top, const uint8_t *bot)
1364 out[i] = top[i] ^ bot[i]; 1373 out[i] = top[i] ^ bot[i];
1365 } 1374 }
1366 1375
1367 divide_by_2(out); 1376 abs_divide_by_2(out);
1368 1377
1369 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 1378 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1370 out[i] ^= bot[i]; 1379 out[i] ^= bot[i];
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 2bbe420e..d6d078e1 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -597,7 +597,9 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
597 continue; 597 continue;
598 598
599 if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) 599 if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT)
600 || id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2) { 600 || id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2
601 || is_timeout(list_nodes[1].timestamp, ONION_NODE_TIMEOUT)
602 || id_closest(reference_id, list_nodes[1].public_key, nodes[i].public_key) == 2 ) {
601 /* check if node is already in list. */ 603 /* check if node is already in list. */
602 for (j = 0; j < list_length; ++j) { 604 for (j = 0; j < list_length; ++j) {
603 if (memcmp(list_nodes[j].public_key, nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) { 605 if (memcmp(list_nodes[j].public_key, nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) {