mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Made onion paths expire eventually client side.
This commit is contained in:
parent
325395820d
commit
602c71bc17
|
@ -44,7 +44,8 @@ static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathn
|
||||||
if (pathnum >= NUMBER_ONION_PATHS)
|
if (pathnum >= NUMBER_ONION_PATHS)
|
||||||
pathnum = rand() % 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];
|
Node_format nodes[3];
|
||||||
|
|
||||||
if (random_nodes_path(dht, nodes, 3) != 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;
|
return -1;
|
||||||
|
|
||||||
onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT;
|
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));
|
memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path));
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
then for all the next consecutive times */
|
then for all the next consecutive times */
|
||||||
#define ONION_PATH_FIRST_TIMEOUT 5
|
#define ONION_PATH_FIRST_TIMEOUT 5
|
||||||
#define ONION_PATH_TIMEOUT 30
|
#define ONION_PATH_TIMEOUT 30
|
||||||
|
#define ONION_PATH_MAX_LIFETIME 600
|
||||||
|
|
||||||
/* A cheap way of making it take less bandwidth at startup:
|
/* A cheap way of making it take less bandwidth at startup:
|
||||||
by limiting the number of ping packets we can send per
|
by limiting the number of ping packets we can send per
|
||||||
|
@ -62,6 +63,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Onion_Path paths[NUMBER_ONION_PATHS];
|
Onion_Path paths[NUMBER_ONION_PATHS];
|
||||||
uint64_t last_path_success[NUMBER_ONION_PATHS];
|
uint64_t last_path_success[NUMBER_ONION_PATHS];
|
||||||
|
uint64_t path_creation_time[NUMBER_ONION_PATHS];
|
||||||
} Onion_Client_Paths;
|
} Onion_Client_Paths;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user