diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 9b75a234..cc147828 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -44,7 +44,8 @@ static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathn if (pathnum >= NUMBER_ONION_PATHS) pathnum = rand() % NUMBER_ONION_PATHS; - if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT)) { + if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT) + || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { Node_format nodes[3]; if (random_nodes_path(dht, nodes, 3) != 3) @@ -54,6 +55,7 @@ static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathn return -1; onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; + onion_paths->path_creation_time[pathnum] = unix_time(); } memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 3235c3f4..ae3e7ea3 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -39,6 +39,7 @@ then for all the next consecutive times */ #define ONION_PATH_FIRST_TIMEOUT 5 #define ONION_PATH_TIMEOUT 30 +#define ONION_PATH_MAX_LIFETIME 600 /* A cheap way of making it take less bandwidth at startup: by limiting the number of ping packets we can send per @@ -62,6 +63,7 @@ typedef struct { typedef struct { Onion_Path paths[NUMBER_ONION_PATHS]; uint64_t last_path_success[NUMBER_ONION_PATHS]; + uint64_t path_creation_time[NUMBER_ONION_PATHS]; } Onion_Client_Paths; typedef struct {