diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-25 12:36:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-25 12:36:52 +0000 |
commit | a199124d5ffcea0dc0e99b550311d74c46b7f2b8 (patch) | |
tree | 80793a8342ff09333f1b22651fc6c273eefeb947 /src/dht | |
parent | 94ddc3ef166eebaaeda0799dcc7d6e813d8ce271 (diff) | |
download | gnunet-a199124d5ffcea0dc0e99b550311d74c46b7f2b8.tar.gz gnunet-a199124d5ffcea0dc0e99b550311d74c46b7f2b8.zip |
fixing 1829
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/dht_api.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index e0b97b457..ee91c6f06 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -195,6 +195,10 @@ struct GNUNET_DHT_Handle | |||
195 | */ | 195 | */ |
196 | uint64_t uid_gen; | 196 | uint64_t uid_gen; |
197 | 197 | ||
198 | /** | ||
199 | * Did we start our receive loop yet? | ||
200 | */ | ||
201 | int in_receive; | ||
198 | }; | 202 | }; |
199 | 203 | ||
200 | 204 | ||
@@ -217,6 +221,7 @@ try_connect (struct GNUNET_DHT_Handle *handle) | |||
217 | { | 221 | { |
218 | if (handle->client != NULL) | 222 | if (handle->client != NULL) |
219 | return GNUNET_OK; | 223 | return GNUNET_OK; |
224 | handle->in_receive = GNUNET_NO; | ||
220 | handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); | 225 | handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); |
221 | if (handle->client == NULL) | 226 | if (handle->client == NULL) |
222 | { | 227 | { |
@@ -224,11 +229,6 @@ try_connect (struct GNUNET_DHT_Handle *handle) | |||
224 | _("Failed to connect to the DHT service!\n")); | 229 | _("Failed to connect to the DHT service!\n")); |
225 | return GNUNET_NO; | 230 | return GNUNET_NO; |
226 | } | 231 | } |
227 | #if DEBUG_DHT | ||
228 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting to process replies from DHT\n"); | ||
229 | #endif | ||
230 | GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, | ||
231 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
232 | return GNUNET_YES; | 232 | return GNUNET_YES; |
233 | } | 233 | } |
234 | 234 | ||
@@ -249,7 +249,11 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) | |||
249 | struct GNUNET_DHT_GetHandle *rh = value; | 249 | struct GNUNET_DHT_GetHandle *rh = value; |
250 | 250 | ||
251 | if (GNUNET_NO == rh->message->in_pending_queue) | 251 | if (GNUNET_NO == rh->message->in_pending_queue) |
252 | { | 252 | { |
253 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
254 | "Retransmitting request related to %s to DHT %p\n", | ||
255 | GNUNET_h2s (key), | ||
256 | handle); | ||
253 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, | 257 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, |
254 | rh->message); | 258 | rh->message); |
255 | rh->message->in_pending_queue = GNUNET_YES; | 259 | rh->message->in_pending_queue = GNUNET_YES; |
@@ -278,7 +282,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
278 | struct GNUNET_DHT_Handle *handle = cls; | 282 | struct GNUNET_DHT_Handle *handle = cls; |
279 | 283 | ||
280 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 284 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
281 | "Reconnedting with DHT %p\n", | 285 | "Reconnecting with DHT %p\n", |
282 | handle); | 286 | handle); |
283 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 287 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
284 | if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) | 288 | if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) |
@@ -288,8 +292,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
288 | if (handle->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value) | 292 | if (handle->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value) |
289 | handle->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT; | 293 | handle->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT; |
290 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 294 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
291 | handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); | 295 | if (GNUNET_YES != try_connect (handle)) |
292 | if (handle->client == NULL) | ||
293 | { | 296 | { |
294 | LOG (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n"); | 297 | LOG (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n"); |
295 | return; | 298 | return; |
@@ -394,6 +397,7 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
394 | memcpy (buf, head->msg, tsize); | 397 | memcpy (buf, head->msg, tsize); |
395 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, | 398 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, |
396 | head); | 399 | head); |
400 | head->in_pending_queue = GNUNET_NO; | ||
397 | if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 401 | if (head->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
398 | { | 402 | { |
399 | GNUNET_SCHEDULER_cancel (head->timeout_task); | 403 | GNUNET_SCHEDULER_cancel (head->timeout_task); |
@@ -406,7 +410,6 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
406 | head->cont = NULL; | 410 | head->cont = NULL; |
407 | head->cont_cls = NULL; | 411 | head->cont_cls = NULL; |
408 | } | 412 | } |
409 | head->in_pending_queue = GNUNET_NO; | ||
410 | if (GNUNET_YES == head->free_on_send) | 413 | if (GNUNET_YES == head->free_on_send) |
411 | GNUNET_free (head); | 414 | GNUNET_free (head); |
412 | process_pending_messages (handle); | 415 | process_pending_messages (handle); |
@@ -414,6 +417,15 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
414 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 417 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
415 | "Forwarded request of %u bytes to DHT service\n", (unsigned int) tsize); | 418 | "Forwarded request of %u bytes to DHT service\n", (unsigned int) tsize); |
416 | #endif | 419 | #endif |
420 | if (GNUNET_NO == handle->in_receive) | ||
421 | { | ||
422 | #if DEBUG_DHT | ||
423 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting to process replies from DHT\n"); | ||
424 | #endif | ||
425 | handle->in_receive = GNUNET_YES; | ||
426 | GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, | ||
427 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
428 | } | ||
417 | return tsize; | 429 | return tsize; |
418 | } | 430 | } |
419 | 431 | ||
@@ -576,15 +588,16 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) | |||
576 | } | 588 | } |
577 | while (NULL != (pm = handle->pending_head)) | 589 | while (NULL != (pm = handle->pending_head)) |
578 | { | 590 | { |
591 | GNUNET_assert (GNUNET_YES == pm->in_pending_queue); | ||
579 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, | 592 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, |
580 | pm); | 593 | pm); |
594 | pm->in_pending_queue = GNUNET_NO; | ||
581 | GNUNET_assert (GNUNET_YES == pm->free_on_send); | 595 | GNUNET_assert (GNUNET_YES == pm->free_on_send); |
582 | if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task) | 596 | if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task) |
583 | GNUNET_SCHEDULER_cancel (pm->timeout_task); | 597 | GNUNET_SCHEDULER_cancel (pm->timeout_task); |
584 | if (NULL != pm->cont) | 598 | if (NULL != pm->cont) |
585 | GNUNET_SCHEDULER_add_continuation (pm->cont, pm->cont_cls, | 599 | GNUNET_SCHEDULER_add_continuation (pm->cont, pm->cont_cls, |
586 | GNUNET_SCHEDULER_REASON_TIMEOUT); | 600 | GNUNET_SCHEDULER_REASON_TIMEOUT); |
587 | pm->in_pending_queue = GNUNET_NO; | ||
588 | GNUNET_free (pm); | 601 | GNUNET_free (pm); |
589 | } | 602 | } |
590 | if (handle->client != NULL) | 603 | if (handle->client != NULL) |
@@ -612,8 +625,10 @@ timeout_put_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
612 | struct GNUNET_DHT_Handle *handle; | 625 | struct GNUNET_DHT_Handle *handle; |
613 | 626 | ||
614 | handle = pending->handle; | 627 | handle = pending->handle; |
628 | GNUNET_assert (GNUNET_YES == pending->in_pending_queue); | ||
615 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, | 629 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail, |
616 | pending); | 630 | pending); |
631 | pending->in_pending_queue = GNUNET_NO; | ||
617 | if (pending->cont != NULL) | 632 | if (pending->cont != NULL) |
618 | pending->cont (pending->cont_cls, tc); | 633 | pending->cont (pending->cont_cls, tc); |
619 | GNUNET_free (pending); | 634 | GNUNET_free (pending); |