From bc5d5905d78ca3cf68b320417903194187dc81b6 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 11 Jun 2015 19:40:37 -0400 Subject: Reannounce if path is considered dead. --- toxcore/onion_client.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'toxcore') diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 524792ef..90eea451 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -198,6 +198,16 @@ static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format return -1; } +/* is path timed out */ +static _Bool path_timed_out(Onion_Client_Paths *onion_paths, uint32_t pathnum) +{ + pathnum = pathnum % NUMBER_ONION_PATHS; + + return ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] + && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) + || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)); +} + /* Create a new path or use an old suitable one (if pathnum is valid) * or a random one from onion_paths. * @@ -215,9 +225,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa pathnum = pathnum % NUMBER_ONION_PATHS; } - if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] - && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) - || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { + if (path_timed_out(onion_paths, pathnum)) { Node_format nodes[ONION_PATH_LENGTH]; if (random_nodes_path_onion(onion_c, nodes, ONION_PATH_LENGTH) != ONION_PATH_LENGTH) @@ -250,6 +258,15 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa return 0; } +/* Does path with path_num exist. */ +static _Bool path_exists(Onion_Client_Paths *onion_paths, uint32_t path_num) +{ + if (path_timed_out(onion_paths, path_num)) + return 0; + + return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num; +} + /* Set path timeouts, return the path number. * */ @@ -1318,7 +1335,7 @@ static void do_announce(Onion_Client *onion_c) unsigned int interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; - if (list_nodes[i].is_stored) { + if (list_nodes[i].is_stored && path_exists(&onion_c->onion_paths_self, list_nodes[i].path_used)) { interval = ANNOUNCE_INTERVAL_ANNOUNCED; } -- cgit v1.2.3