Improved detection of dead paths.

This commit is contained in:
irungentoo 2014-12-22 22:53:17 -05:00
parent dd59d99a7a
commit 15077f2981
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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 {