From 06ff4d4f274ae5269c9b403e1bbd0b93a96ff6d8 Mon Sep 17 00:00:00 2001 From: Omar Tarabai Date: Fri, 19 Dec 2014 02:06:13 +0000 Subject: #3581 --- src/peerstore/peerstore_api.c | 67 ++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'src/peerstore/peerstore_api.c') diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 52b1b22ca..8ef04604f 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c @@ -437,6 +437,7 @@ static void reconnect (struct GNUNET_PEERSTORE_Handle *h) { struct GNUNET_PEERSTORE_IterateContext *ic; + struct GNUNET_PEERSTORE_IterateContext *ic_tmp; GNUNET_PEERSTORE_Processor icb; void *icb_cls; struct GNUNET_PEERSTORE_StoreContext *sc; @@ -450,32 +451,17 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) sc->ev = NULL; } } - if (NULL != h->mq) - { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } - if (NULL != h->client) - { - GNUNET_CLIENT_disconnect (h->client); - h->client = NULL; - } - h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); - GNUNET_assert (NULL != h->client); - h->mq = - GNUNET_MQ_queue_for_connection_client (h->client, mq_handlers, - &handle_client_error, h); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Resending pending requests after reconnect.\n"); - if (NULL != h->watches) - GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); - for (ic = h->iterate_head; NULL != ic; ic = ic->next) + ic = h->iterate_head; + while (NULL != ic) { if (GNUNET_YES == ic->iterating) { icb = ic->callback; icb_cls = ic->callback_cls; - GNUNET_PEERSTORE_iterate_cancel (ic); + ic->iterating = GNUNET_NO; + ic_tmp = ic; + ic = ic->next; + GNUNET_PEERSTORE_iterate_cancel (ic_tmp); if (NULL != icb) icb (icb_cls, NULL, _("Iteration canceled due to reconnection.")); } @@ -491,16 +477,39 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) GNUNET_MQ_send_cancel (ic->ev); ic->ev = NULL; } - ic->ev = - PEERSTORE_create_record_mq_envelope (ic->sub_system, &ic->peer, - ic->key, NULL, 0, NULL, 0, - GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); - GNUNET_MQ_notify_sent (ic->ev, &iterate_request_sent, ic); - GNUNET_MQ_send (h->mq, ic->ev); - ic->timeout_task = - GNUNET_SCHEDULER_add_delayed (ic->timeout, &iterate_timeout, ic); + ic = ic->next; } } + if (NULL != h->mq) + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + if (NULL != h->client) + { + GNUNET_CLIENT_disconnect (h->client); + h->client = NULL; + } + h->client = GNUNET_CLIENT_connect ("peerstore", h->cfg); + GNUNET_assert (NULL != h->client); + h->mq = + GNUNET_MQ_queue_for_connection_client (h->client, mq_handlers, + &handle_client_error, h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Resending pending requests after reconnect.\n"); + if (NULL != h->watches) + GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); + for (ic = h->iterate_head; NULL != ic; ic = ic->next) + { + ic->ev = + PEERSTORE_create_record_mq_envelope (ic->sub_system, &ic->peer, ic->key, + NULL, 0, NULL, 0, + GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); + GNUNET_MQ_notify_sent (ic->ev, &iterate_request_sent, ic); + GNUNET_MQ_send (h->mq, ic->ev); + ic->timeout_task = + GNUNET_SCHEDULER_add_delayed (ic->timeout, &iterate_timeout, ic); + } for (sc = h->store_head; NULL != sc; sc = sc->next) { sc->ev = -- cgit v1.2.3