diff options
author | irungentoo <irungentoo@gmail.com> | 2015-06-11 19:40:37 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-06-11 19:40:37 -0400 |
commit | bc5d5905d78ca3cf68b320417903194187dc81b6 (patch) | |
tree | 69b7183af41e6426df6919e1b51ec73c3dbe4b93 /toxcore | |
parent | ae2caad98245bdac24ea05685a730022d611576e (diff) |
Reannounce if path is considered dead.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/onion_client.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 524792ef..90eea451 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -198,6 +198,16 @@ static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format | |||
198 | return -1; | 198 | return -1; |
199 | } | 199 | } |
200 | 200 | ||
201 | /* is path timed out */ | ||
202 | static _Bool path_timed_out(Onion_Client_Paths *onion_paths, uint32_t pathnum) | ||
203 | { | ||
204 | pathnum = pathnum % NUMBER_ONION_PATHS; | ||
205 | |||
206 | return ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] | ||
207 | && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) | ||
208 | || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)); | ||
209 | } | ||
210 | |||
201 | /* Create a new path or use an old suitable one (if pathnum is valid) | 211 | /* Create a new path or use an old suitable one (if pathnum is valid) |
202 | * or a random one from onion_paths. | 212 | * or a random one from onion_paths. |
203 | * | 213 | * |
@@ -215,9 +225,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa | |||
215 | pathnum = pathnum % NUMBER_ONION_PATHS; | 225 | pathnum = pathnum % NUMBER_ONION_PATHS; |
216 | } | 226 | } |
217 | 227 | ||
218 | if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] | 228 | if (path_timed_out(onion_paths, pathnum)) { |
219 | && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) | ||
220 | || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { | ||
221 | Node_format nodes[ONION_PATH_LENGTH]; | 229 | Node_format nodes[ONION_PATH_LENGTH]; |
222 | 230 | ||
223 | if (random_nodes_path_onion(onion_c, nodes, ONION_PATH_LENGTH) != ONION_PATH_LENGTH) | 231 | if (random_nodes_path_onion(onion_c, nodes, ONION_PATH_LENGTH) != ONION_PATH_LENGTH) |
@@ -250,6 +258,15 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa | |||
250 | return 0; | 258 | return 0; |
251 | } | 259 | } |
252 | 260 | ||
261 | /* Does path with path_num exist. */ | ||
262 | static _Bool path_exists(Onion_Client_Paths *onion_paths, uint32_t path_num) | ||
263 | { | ||
264 | if (path_timed_out(onion_paths, path_num)) | ||
265 | return 0; | ||
266 | |||
267 | return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num; | ||
268 | } | ||
269 | |||
253 | /* Set path timeouts, return the path number. | 270 | /* Set path timeouts, return the path number. |
254 | * | 271 | * |
255 | */ | 272 | */ |
@@ -1318,7 +1335,7 @@ static void do_announce(Onion_Client *onion_c) | |||
1318 | 1335 | ||
1319 | unsigned int interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; | 1336 | unsigned int interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; |
1320 | 1337 | ||
1321 | if (list_nodes[i].is_stored) { | 1338 | if (list_nodes[i].is_stored && path_exists(&onion_c->onion_paths_self, list_nodes[i].path_used)) { |
1322 | interval = ANNOUNCE_INTERVAL_ANNOUNCED; | 1339 | interval = ANNOUNCE_INTERVAL_ANNOUNCED; |
1323 | } | 1340 | } |
1324 | 1341 | ||