From 15077f2981c7ca099ad0f71e264cc4de8906b895 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 22 Dec 2014 22:53:17 -0500 Subject: Improved detection of dead paths. --- toxcore/onion_client.c | 8 +++++++- toxcore/onion_client.h | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index a069de23..fcc43328 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -162,7 +162,8 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa if (pathnum >= NUMBER_ONION_PATHS) pathnum = rand() % NUMBER_ONION_PATHS; - if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT) + 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)) { Node_format nodes[3]; @@ -177,6 +178,8 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; onion_paths->path_creation_time[pathnum] = unix_time(); + onion_paths->last_path_used_times[pathnum] = ONION_PATH_MAX_NO_RESPONSE_USES / 2; + uint32_t path_num = rand(); path_num /= NUMBER_ONION_PATHS; path_num *= NUMBER_ONION_PATHS; @@ -188,6 +191,8 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa } } + ++onion_paths->last_path_used_times[pathnum]; + onion_paths->last_path_used[pathnum] = unix_time(); memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); return 0; } @@ -210,6 +215,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time(); + onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0; return path_num % NUMBER_ONION_PATHS; } diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index daf08a74..a99383c5 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -41,8 +41,9 @@ /* The timeout the first time the path is added and then for all the next consecutive times */ #define ONION_PATH_FIRST_TIMEOUT 5 -#define ONION_PATH_TIMEOUT 30 -#define ONION_PATH_MAX_LIFETIME 600 +#define ONION_PATH_TIMEOUT 10 +#define ONION_PATH_MAX_LIFETIME 1200 +#define ONION_PATH_MAX_NO_RESPONSE_USES 4 #define MAX_STORED_PINGED_NODES 9 #define MIN_NODE_PING_TIME 10 @@ -71,7 +72,10 @@ typedef struct { typedef struct { Onion_Path paths[NUMBER_ONION_PATHS]; uint64_t last_path_success[NUMBER_ONION_PATHS]; + uint64_t last_path_used[NUMBER_ONION_PATHS]; uint64_t path_creation_time[NUMBER_ONION_PATHS]; + /* number of times used without success. */ + unsigned int last_path_used_times[NUMBER_ONION_PATHS]; } Onion_Client_Paths; typedef struct { -- cgit v1.2.3