diff options
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 8 |
1 files changed, 7 insertions, 1 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 | ||