From dfc6be901cae5133286cbb16e6b651ff26bf2311 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 11 Jan 2015 19:11:33 -0500 Subject: [PATCH] Attempted fix of Tox killing routers. This commit makes tox use one Onion_Client_Paths struct for all friends instead of one per friend. This should lower the number of ips tox sends packets to which is what I think causes the router issues. --- toxcore/onion_client.c | 14 +++++++------- toxcore/onion_client.h | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index b02b7c240..f8d7630b8 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -249,9 +249,9 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t Onion_Client_Paths *onion_paths; if (num == 0) { - onion_paths = &onion_c->onion_paths; + onion_paths = &onion_c->onion_paths_self; } else { - onion_paths = &onion_c->friends_list[num - 1].onion_paths; + onion_paths = &onion_c->onion_paths_friends; } if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { @@ -377,10 +377,10 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_ Onion_Path path; if (num == 0) { - if (random_path(onion_c, &onion_c->onion_paths, pathnum, &path) == -1) + if (random_path(onion_c, &onion_c->onion_paths_self, pathnum, &path) == -1) return -1; } else { - if (random_path(onion_c, &onion_c->friends_list[num - 1].onion_paths, pathnum, &path) == -1) + if (random_path(onion_c, &onion_c->onion_paths_friends, pathnum, &path) == -1) return -1; } @@ -759,7 +759,7 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length) * return the number of packets sent on success * return -1 on failure. */ -int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) +int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length) { if ((uint32_t)friend_num >= onion_c->num_friends) return -1; @@ -792,7 +792,7 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t * ++num_nodes; if (list_nodes[i].is_stored) { - if (random_path(onion_c, &onion_c->friends_list[friend_num].onion_paths, ~0, &path[num_good]) == -1) + if (random_path(onion_c, &onion_c->onion_paths_friends, ~0, &path[num_good]) == -1) continue; good_nodes[num_good] = i; @@ -890,7 +890,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source * return the number of packets sent on success * return -1 on failure. */ -static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) +static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) { if (friend_num >= onion_c->num_friends) return -1; diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index fe586c5b7..3545b8597 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -102,8 +102,6 @@ typedef struct { uint64_t last_seen; - Onion_Client_Paths onion_paths; - Last_Pinged last_pinged[MAX_STORED_PINGED_NODES]; uint8_t last_pinged_index; @@ -130,7 +128,8 @@ typedef struct { Onion_Node clients_announce_list[MAX_ONION_CLIENTS]; - Onion_Client_Paths onion_paths; + Onion_Client_Paths onion_paths_self; + Onion_Client_Paths onion_paths_friends; uint8_t secret_symmetric_key[crypto_box_KEYBYTES]; uint64_t last_run; @@ -262,7 +261,7 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_ * return the number of packets sent on success * return -1 on failure. */ -int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length); +int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length); /* Function to call when onion data packet with contents beginning with byte is received. */ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object);