From 0d8e5fb7ae0282a1e4779c86e8cc30b803299e3e Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Fri, 10 Nov 2017 17:45:13 -0600 Subject: [PATCH] Fix skip_next_messages counting, combine logic This fixes messages like these: Nov 10 08:57:34-927033 fs-22733 ERROR Request 0x6080017479a0 of type 100 at head of datastore queue for more than 1 m And might fix issue #3903 --- src/datastore/datastore_api.c | 115 ++++++++++++++-------------------- 1 file changed, 47 insertions(+), 68 deletions(-) diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 31f7a997f..2ad864987 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -651,6 +651,46 @@ process_queue (struct GNUNET_DATASTORE_Handle *h) } +/** + * Get the entry at the head of the message queue. + * + * @param h handle to the datastore + * @param response_type the expected response type + * @return the queue entry + */ +static struct GNUNET_DATASTORE_QueueEntry * +get_queue_head (struct GNUNET_DATASTORE_Handle *h, + uint16_t response_type) +{ + struct GNUNET_DATASTORE_QueueEntry *qe; + + if (h->skip_next_messages > 0) + { + h->skip_next_messages--; + process_queue (h); + return NULL; + } + qe = h->queue_head; + if (NULL == qe) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (NULL != qe->env) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + if (response_type != qe->response_type) + { + GNUNET_break (0); + do_disconnect (h); + return NULL; + } + return qe; +} /** @@ -702,30 +742,10 @@ handle_status (void *cls, const char *emsg; int32_t status = ntohl (sm->status); - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - if (NULL == (qe = h->queue_head)) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); + if (NULL == qe) return; - } rc = qe->qc.sc; free_queue_entry (qe); if (ntohs (sm->header.size) > sizeof (struct StatusMessage)) @@ -785,30 +805,10 @@ handle_data (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); return; - } #if INSANE_STATISTICS GNUNET_STATISTICS_update (h->stats, gettext_noop ("# Results received"), @@ -854,31 +854,10 @@ handle_data_end (void *cls, struct GNUNET_DATASTORE_QueueEntry *qe; struct ResultContext rc; - if (h->skip_next_messages > 0) - { - h->skip_next_messages--; - process_queue (h); - return; - } - qe = h->queue_head; + qe = get_queue_head (h, + GNUNET_MESSAGE_TYPE_DATASTORE_DATA); if (NULL == qe) - { - GNUNET_break (0); - do_disconnect (h); return; - } - if (NULL != qe->env) - { - GNUNET_break (0); - do_disconnect (h); - return; - } - if (GNUNET_MESSAGE_TYPE_DATASTORE_DATA != qe->response_type) - { - GNUNET_break (0); - do_disconnect (h); - return; - } rc = qe->qc.rc; free_queue_entry (qe); LOG (GNUNET_ERROR_TYPE_DEBUG, -- 2.25.1