diff options
-rw-r--r-- | toxcore/onion_client.c | 8 | ||||
-rw-r--r-- | 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 | |||
162 | if (pathnum >= NUMBER_ONION_PATHS) | 162 | if (pathnum >= NUMBER_ONION_PATHS) |
163 | pathnum = rand() % NUMBER_ONION_PATHS; | 163 | pathnum = rand() % NUMBER_ONION_PATHS; |
164 | 164 | ||
165 | if (is_timeout(onion_paths->last_path_success[pathnum], ONION_PATH_TIMEOUT) | 165 | if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] |
166 | && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) | ||
166 | || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { | 167 | || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { |
167 | Node_format nodes[3]; | 168 | Node_format nodes[3]; |
168 | 169 | ||
@@ -177,6 +178,8 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa | |||
177 | 178 | ||
178 | onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; | 179 | onion_paths->last_path_success[pathnum] = unix_time() + ONION_PATH_FIRST_TIMEOUT - ONION_PATH_TIMEOUT; |
179 | onion_paths->path_creation_time[pathnum] = unix_time(); | 180 | onion_paths->path_creation_time[pathnum] = unix_time(); |
181 | onion_paths->last_path_used_times[pathnum] = ONION_PATH_MAX_NO_RESPONSE_USES / 2; | ||
182 | |||
180 | uint32_t path_num = rand(); | 183 | uint32_t path_num = rand(); |
181 | path_num /= NUMBER_ONION_PATHS; | 184 | path_num /= NUMBER_ONION_PATHS; |
182 | path_num *= NUMBER_ONION_PATHS; | 185 | path_num *= NUMBER_ONION_PATHS; |
@@ -188,6 +191,8 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa | |||
188 | } | 191 | } |
189 | } | 192 | } |
190 | 193 | ||
194 | ++onion_paths->last_path_used_times[pathnum]; | ||
195 | onion_paths->last_path_used[pathnum] = unix_time(); | ||
191 | memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); | 196 | memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path)); |
192 | return 0; | 197 | return 0; |
193 | } | 198 | } |
@@ -210,6 +215,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t | |||
210 | 215 | ||
211 | if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { | 216 | if (onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num) { |
212 | onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time(); | 217 | onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time(); |
218 | onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0; | ||
213 | return path_num % NUMBER_ONION_PATHS; | 219 | return path_num % NUMBER_ONION_PATHS; |
214 | } | 220 | } |
215 | 221 | ||
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 @@ | |||
41 | /* The timeout the first time the path is added and | 41 | /* The timeout the first time the path is added and |
42 | then for all the next consecutive times */ | 42 | then for all the next consecutive times */ |
43 | #define ONION_PATH_FIRST_TIMEOUT 5 | 43 | #define ONION_PATH_FIRST_TIMEOUT 5 |
44 | #define ONION_PATH_TIMEOUT 30 | 44 | #define ONION_PATH_TIMEOUT 10 |
45 | #define ONION_PATH_MAX_LIFETIME 600 | 45 | #define ONION_PATH_MAX_LIFETIME 1200 |
46 | #define ONION_PATH_MAX_NO_RESPONSE_USES 4 | ||
46 | 47 | ||
47 | #define MAX_STORED_PINGED_NODES 9 | 48 | #define MAX_STORED_PINGED_NODES 9 |
48 | #define MIN_NODE_PING_TIME 10 | 49 | #define MIN_NODE_PING_TIME 10 |
@@ -71,7 +72,10 @@ typedef struct { | |||
71 | typedef struct { | 72 | typedef struct { |
72 | Onion_Path paths[NUMBER_ONION_PATHS]; | 73 | Onion_Path paths[NUMBER_ONION_PATHS]; |
73 | uint64_t last_path_success[NUMBER_ONION_PATHS]; | 74 | uint64_t last_path_success[NUMBER_ONION_PATHS]; |
75 | uint64_t last_path_used[NUMBER_ONION_PATHS]; | ||
74 | uint64_t path_creation_time[NUMBER_ONION_PATHS]; | 76 | uint64_t path_creation_time[NUMBER_ONION_PATHS]; |
77 | /* number of times used without success. */ | ||
78 | unsigned int last_path_used_times[NUMBER_ONION_PATHS]; | ||
75 | } Onion_Client_Paths; | 79 | } Onion_Client_Paths; |
76 | 80 | ||
77 | typedef struct { | 81 | typedef struct { |