summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/onion_client.c4
-rw-r--r--toxcore/onion_client.h2
2 files changed, 5 insertions, 1 deletions
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
44 if (pathnum >= NUMBER_ONION_PATHS) 44 if (pathnum >= NUMBER_ONION_PATHS)
45 pathnum = rand() % NUMBER_ONION_PATHS; 45 pathnum = rand() % NUMBER_ONION_PATHS;
46 46
47 if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT)) { 47 if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT)
48 || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) {
48 Node_format nodes[3]; 49 Node_format nodes[3];
49 50
50 if (random_nodes_path(dht, nodes, 3) != 3) 51 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
54 return -1; 55 return -1;
55 56
56 onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; 57 onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT;
58 onion_paths->path_creation_time[pathnum] = unix_time();
57 } 59 }
58 60
59 memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); 61 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 @@
39 then for all the next consecutive times */ 39 then for all the next consecutive times */
40#define ONION_PATH_FIRST_TIMEOUT 5 40#define ONION_PATH_FIRST_TIMEOUT 5
41#define ONION_PATH_TIMEOUT 30 41#define ONION_PATH_TIMEOUT 30
42#define ONION_PATH_MAX_LIFETIME 600
42 43
43/* A cheap way of making it take less bandwidth at startup: 44/* A cheap way of making it take less bandwidth at startup:
44 by limiting the number of ping packets we can send per 45 by limiting the number of ping packets we can send per
@@ -62,6 +63,7 @@ typedef struct {
62typedef struct { 63typedef struct {
63 Onion_Path paths[NUMBER_ONION_PATHS]; 64 Onion_Path paths[NUMBER_ONION_PATHS];
64 uint64_t last_path_success[NUMBER_ONION_PATHS]; 65 uint64_t last_path_success[NUMBER_ONION_PATHS];
66 uint64_t path_creation_time[NUMBER_ONION_PATHS];
65} Onion_Client_Paths; 67} Onion_Client_Paths;
66 68
67typedef struct { 69typedef struct {