summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 6dd945b0..b3a54879 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -465,7 +465,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t
465 return path_num; 465 return path_num;
466 } 466 }
467 467
468 return ~0; 468 return -1;
469} 469}
470 470
471/* Function to send onion packet via TCP and UDP. 471/* Function to send onion packet via TCP and UDP.
@@ -544,7 +544,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *publ
544 * ret_pubkey must be at least CRYPTO_PUBLIC_KEY_SIZE big 544 * ret_pubkey must be at least CRYPTO_PUBLIC_KEY_SIZE big
545 * ret_ip_port must be at least 1 big 545 * ret_ip_port must be at least 1 big
546 * 546 *
547 * return ~0 on failure 547 * return -1 on failure
548 * return num (see new_sendback(...)) on success 548 * return num (see new_sendback(...)) on success
549 */ 549 */
550static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey, 550static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey,
@@ -555,7 +555,7 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
555 uint8_t data[sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port) + sizeof(uint32_t)]; 555 uint8_t data[sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port) + sizeof(uint32_t)];
556 556
557 if (ping_array_check(onion_c->announce_ping_array, onion_c->mono_time, data, sizeof(data), sback) != sizeof(data)) { 557 if (ping_array_check(onion_c->announce_ping_array, onion_c->mono_time, data, sizeof(data), sback) != sizeof(data)) {
558 return ~0; 558 return -1;
559 } 559 }
560 560
561 memcpy(ret_pubkey, data + sizeof(uint32_t), CRYPTO_PUBLIC_KEY_SIZE); 561 memcpy(ret_pubkey, data + sizeof(uint32_t), CRYPTO_PUBLIC_KEY_SIZE);
@@ -834,7 +834,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
834 } 834 }
835 835
836 if (j == list_length && good_to_ping(onion_c->mono_time, last_pinged, last_pinged_index, nodes[i].public_key)) { 836 if (j == list_length && good_to_ping(onion_c->mono_time, last_pinged, last_pinged_index, nodes[i].public_key)) {
837 client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, nullptr, ~0); 837 client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, nullptr, -1);
838 } 838 }
839 } 839 }
840 } 840 }
@@ -1098,7 +1098,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data,
1098 for (i = 0; i < num_good; ++i) { 1098 for (i = 0; i < num_good; ++i) {
1099 Onion_Path path; 1099 Onion_Path path;
1100 1100
1101 if (random_path(onion_c, &onion_c->onion_paths_friends, ~0, &path) == -1) { 1101 if (random_path(onion_c, &onion_c->onion_paths_friends, -1, &path) == -1) {
1102 continue; 1102 continue;
1103 } 1103 }
1104 1104
@@ -1303,7 +1303,7 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key)
1303 return num; 1303 return num;
1304 } 1304 }
1305 1305
1306 unsigned int i, index = ~0; 1306 unsigned int i, index = -1;
1307 1307
1308 for (i = 0; i < onion_c->num_friends; ++i) { 1308 for (i = 0; i < onion_c->num_friends; ++i) {
1309 if (onion_c->friends_list[i].status == 0) { 1309 if (onion_c->friends_list[i].status == 0) {
@@ -1312,7 +1312,7 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key)
1312 } 1312 }
1313 } 1313 }
1314 1314
1315 if (index == (uint32_t)~0) { 1315 if (index == (uint32_t) -1) {
1316 if (realloc_onion_friends(onion_c, onion_c->num_friends + 1) == -1) { 1316 if (realloc_onion_friends(onion_c, onion_c->num_friends + 1) == -1) {
1317 return -1; 1317 return -1;
1318 } 1318 }
@@ -1607,7 +1607,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
1607 if (mono_time_is_timeout(onion_c->mono_time, list_nodes[i].last_pinged, interval) 1607 if (mono_time_is_timeout(onion_c->mono_time, list_nodes[i].last_pinged, interval)
1608 || (ping_random && random_u32() % (MAX_ONION_CLIENTS - i) == 0)) { 1608 || (ping_random && random_u32() % (MAX_ONION_CLIENTS - i) == 0)) {
1609 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, 1609 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port,
1610 list_nodes[i].public_key, nullptr, ~0) == 0) { 1610 list_nodes[i].public_key, nullptr, -1) == 0) {
1611 list_nodes[i].last_pinged = mono_time_get(onion_c->mono_time); 1611 list_nodes[i].last_pinged = mono_time_get(onion_c->mono_time);
1612 ++list_nodes[i].unsuccessful_pings; 1612 ++list_nodes[i].unsuccessful_pings;
1613 ping_random = false; 1613 ping_random = false;
@@ -1630,7 +1630,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
1630 for (j = 0; j < n; ++j) { 1630 for (j = 0; j < n; ++j) {
1631 const uint32_t num = random_u32() % num_nodes; 1631 const uint32_t num = random_u32() % num_nodes;
1632 client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port, 1632 client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port,
1633 onion_c->path_nodes[num].public_key, nullptr, ~0); 1633 onion_c->path_nodes[num].public_key, nullptr, -1);
1634 } 1634 }
1635 1635
1636 ++onion_c->friends_list[friendnum].run_count; 1636 ++onion_c->friends_list[friendnum].run_count;
@@ -1723,7 +1723,7 @@ static void do_announce(Onion_Client *onion_c)
1723 if (list_nodes[i].unsuccessful_pings == ONION_NODE_MAX_PINGS - 1 1723 if (list_nodes[i].unsuccessful_pings == ONION_NODE_MAX_PINGS - 1
1724 && mono_time_is_timeout(onion_c->mono_time, list_nodes[i].added_time, TIME_TO_STABLE)) { 1724 && mono_time_is_timeout(onion_c->mono_time, list_nodes[i].added_time, TIME_TO_STABLE)) {
1725 /* Last chance for a long-lived node - try a random path */ 1725 /* Last chance for a long-lived node - try a random path */
1726 path_to_use = ~0; 1726 path_to_use = -1;
1727 } 1727 }
1728 1728
1729 if (client_send_announce_request(onion_c, 0, list_nodes[i].ip_port, list_nodes[i].public_key, 1729 if (client_send_announce_request(onion_c, 0, list_nodes[i].ip_port, list_nodes[i].public_key,
@@ -1751,7 +1751,7 @@ static void do_announce(Onion_Client *onion_c)
1751 if (num_nodes != 0) { 1751 if (num_nodes != 0) {
1752 for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) { 1752 for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
1753 const uint32_t num = random_u32() % num_nodes; 1753 const uint32_t num = random_u32() % num_nodes;
1754 client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, ~0); 1754 client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, -1);
1755 } 1755 }
1756 } 1756 }
1757 } 1757 }