diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/ats_api_scheduling.c | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 1dd7ad36f..0bd7c4f94 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -138,6 +138,10 @@ struct GNUNET_ATS_SchedulingHandle | |||
138 | */ | 138 | */ |
139 | unsigned int session_array_size; | 139 | unsigned int session_array_size; |
140 | 140 | ||
141 | /** | ||
142 | * Should we reconnect to ATS due to some serious error? | ||
143 | */ | ||
144 | int reconnect; | ||
141 | }; | 145 | }; |
142 | 146 | ||
143 | 147 | ||
@@ -150,7 +154,6 @@ static void | |||
150 | reconnect (struct GNUNET_ATS_SchedulingHandle *sh); | 154 | reconnect (struct GNUNET_ATS_SchedulingHandle *sh); |
151 | 155 | ||
152 | 156 | ||
153 | |||
154 | /** | 157 | /** |
155 | * Re-establish the connection to the ATS service. | 158 | * Re-establish the connection to the ATS service. |
156 | * | 159 | * |
@@ -169,6 +172,22 @@ reconnect_task (void *cls, | |||
169 | 172 | ||
170 | 173 | ||
171 | /** | 174 | /** |
175 | * Disconnect from ATS and then reconnect. | ||
176 | * | ||
177 | * @param sh our handle | ||
178 | */ | ||
179 | static void | ||
180 | force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | ||
181 | { | ||
182 | sh->reconnect = GNUNET_NO; | ||
183 | GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); | ||
184 | sh->client = NULL; | ||
185 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
186 | &reconnect_task, sh); | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
172 | * Transmit messages from the message queue to the service | 191 | * Transmit messages from the message queue to the service |
173 | * (if there are any, and if we are not already trying). | 192 | * (if there are any, and if we are not already trying). |
174 | * | 193 | * |
@@ -211,10 +230,7 @@ transmit_message_to_ats (void *cls, | |||
211 | sh->th = NULL; | 230 | sh->th = NULL; |
212 | if ( (size == 0) || (buf == NULL)) | 231 | if ( (size == 0) || (buf == NULL)) |
213 | { | 232 | { |
214 | GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); | 233 | force_reconnect (sh); |
215 | sh->client = NULL; | ||
216 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
217 | &reconnect_task, sh); | ||
218 | return 0; | 234 | return 0; |
219 | } | 235 | } |
220 | ret = 0; | 236 | ret = 0; |
@@ -284,9 +300,14 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, | |||
284 | } | 300 | } |
285 | if (session_id == 0) | 301 | if (session_id == 0) |
286 | return NULL; | 302 | return NULL; |
287 | GNUNET_assert (0 == memcmp (peer, | 303 | if (0 != memcmp (peer, |
288 | &sh->session_array[session_id].peer, | 304 | &sh->session_array[session_id].peer, |
289 | sizeof (struct GNUNET_PeerIdentity))); | 305 | sizeof (struct GNUNET_PeerIdentity))) |
306 | { | ||
307 | GNUNET_break (0); | ||
308 | sh->reconnect = GNUNET_YES; | ||
309 | return NULL; | ||
310 | } | ||
290 | return sh->session_array[session_id].session; | 311 | return sh->session_array[session_id].session; |
291 | } | 312 | } |
292 | 313 | ||
@@ -376,10 +397,20 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh, | |||
376 | uint32_t session_id, | 397 | uint32_t session_id, |
377 | const struct GNUNET_PeerIdentity *peer) | 398 | const struct GNUNET_PeerIdentity *peer) |
378 | { | 399 | { |
379 | GNUNET_assert (session_id < sh->session_array_size); | 400 | if (session_id >= sh->session_array_size) |
380 | GNUNET_assert (0 == memcmp (peer, | 401 | { |
381 | &sh->session_array[session_id].peer, | 402 | GNUNET_break (0); |
382 | sizeof (struct GNUNET_PeerIdentity))); | 403 | sh->reconnect = GNUNET_YES; |
404 | return; | ||
405 | } | ||
406 | if (0 != memcmp (peer, | ||
407 | &sh->session_array[session_id].peer, | ||
408 | sizeof (struct GNUNET_PeerIdentity))) | ||
409 | { | ||
410 | GNUNET_break (0); | ||
411 | sh->reconnect = GNUNET_YES; | ||
412 | return; | ||
413 | } | ||
383 | sh->session_array[session_id].slot_used = GNUNET_NO; | 414 | sh->session_array[session_id].slot_used = GNUNET_NO; |
384 | memset (&sh->session_array[session_id].peer, | 415 | memset (&sh->session_array[session_id].peer, |
385 | 0, | 416 | 0, |
@@ -419,10 +450,7 @@ process_ats_message (void *cls, | |||
419 | 450 | ||
420 | if (NULL == msg) | 451 | if (NULL == msg) |
421 | { | 452 | { |
422 | GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); | 453 | force_reconnect (sh); |
423 | sh->client = NULL; | ||
424 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
425 | &reconnect_task, sh); | ||
426 | return; | 454 | return; |
427 | } | 455 | } |
428 | if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && | 456 | if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && |
@@ -433,16 +461,15 @@ process_ats_message (void *cls, | |||
433 | GNUNET_CLIENT_receive (sh->client, | 461 | GNUNET_CLIENT_receive (sh->client, |
434 | &process_ats_message, sh, | 462 | &process_ats_message, sh, |
435 | GNUNET_TIME_UNIT_FOREVER_REL); | 463 | GNUNET_TIME_UNIT_FOREVER_REL); |
464 | if (GNUNET_YES == sh->reconnect) | ||
465 | force_reconnect (sh); | ||
436 | return; | 466 | return; |
437 | } | 467 | } |
438 | if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || | 468 | if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || |
439 | (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) | 469 | (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) |
440 | { | 470 | { |
441 | GNUNET_break (0); | 471 | GNUNET_break (0); |
442 | GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); | 472 | force_reconnect (sh); |
443 | sh->client = NULL; | ||
444 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
445 | &reconnect_task, sh); | ||
446 | return; | 473 | return; |
447 | } | 474 | } |
448 | m = (const struct AddressSuggestionMessage*) msg; | 475 | m = (const struct AddressSuggestionMessage*) msg; |
@@ -460,10 +487,7 @@ process_ats_message (void *cls, | |||
460 | (plugin_name[plugin_name_length - 1] != '\0') ) | 487 | (plugin_name[plugin_name_length - 1] != '\0') ) |
461 | { | 488 | { |
462 | GNUNET_break (0); | 489 | GNUNET_break (0); |
463 | GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); | 490 | force_reconnect (sh); |
464 | sh->client = NULL; | ||
465 | sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
466 | &reconnect_task, sh); | ||
467 | return; | 491 | return; |
468 | } | 492 | } |
469 | sh->suggest_cb (sh->suggest_cb_cls, | 493 | sh->suggest_cb (sh->suggest_cb_cls, |
@@ -478,6 +502,8 @@ process_ats_message (void *cls, | |||
478 | GNUNET_CLIENT_receive (sh->client, | 502 | GNUNET_CLIENT_receive (sh->client, |
479 | &process_ats_message, sh, | 503 | &process_ats_message, sh, |
480 | GNUNET_TIME_UNIT_FOREVER_REL); | 504 | GNUNET_TIME_UNIT_FOREVER_REL); |
505 | if (GNUNET_YES == sh->reconnect) | ||
506 | force_reconnect (sh); | ||
481 | } | 507 | } |
482 | 508 | ||
483 | 509 | ||