From c4202563fb4210adf3eb94fbdb6f40e059b63e37 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 10 May 2018 21:08:23 +0200 Subject: watch for namestore not completing store operations, add auto-abort with warning plus statistics to detect --- src/namestore/gnunet-service-namestore.c | 8 ++++++ src/namestore/namestore_api.c | 49 +++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index ffc76a911..6dedcd754 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -681,6 +681,10 @@ send_store_response (struct NamestoreClient *nc, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RECORD_STORE_RESPONSE message\n"); + GNUNET_STATISTICS_update (statistics, + "Store requests completed", + 1, + GNUNET_NO); env = GNUNET_MQ_msg (rcr_msg, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); rcr_msg->gns_header.r_id = htonl (rid); @@ -1308,6 +1312,10 @@ handle_record_store (void *cls, GNUNET_SERVICE_client_drop (nc->client); return; } + GNUNET_STATISTICS_update (statistics, + "Well-formed store requests received", + 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u records for name `%s'\n", (unsigned int) rd_count, diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index ab356838b..57bf8f81b 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -40,6 +40,11 @@ #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) +/** + * We grant the namestore up to 1 minute of latency, if it is slower than + * that, store queries will fail. + */ +#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES /** * An QueueEntry used to store information for a pending @@ -99,6 +104,11 @@ struct GNUNET_NAMESTORE_QueueEntry */ struct GNUNET_MQ_Envelope *env; + /** + * Task scheduled to warn us if the namestore is way too slow. + */ + struct GNUNET_SCHEDULER_Task *timeout_task; + /** * The operation id this zone iteration operation has */ @@ -300,6 +310,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) qe); if (NULL != qe->env) GNUNET_MQ_discard (qe->env); + if (NULL != qe->timeout_task) + GNUNET_SCHEDULER_cancel (qe->timeout_task); GNUNET_free (qe); } @@ -967,6 +979,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) } +/** + * Task launched to warn the user that the namestore is + * excessively slow and that a query was thus dropped. + * + * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` + */ +static void +warn_delay (void *cls) +{ + struct GNUNET_NAMESTORE_QueueEntry *qe = cls; + + qe->timeout_task = NULL; + LOG (GNUNET_ERROR_TYPE_WARNING, + "Did not receive response from namestore after %s!\n", + GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, + GNUNET_YES)); + if (NULL != qe->cont) + { + qe->cont (qe->cont_cls, + GNUNET_SYSERR, + "timeout"); + qe->cont = NULL; + } + GNUNET_NAMESTORE_cancel (qe); +} + + /** * Store an item in the namestore. If the item is already present, * it is replaced with the new record. Use an empty array to @@ -1048,12 +1087,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", label, rd_count); - + qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, + &warn_delay, + qe); if (NULL == h->mq) + { qe->env = env; + LOG (GNUNET_ERROR_TYPE_WARNING, + "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); + } else + { GNUNET_MQ_send (h->mq, env); + } return qe; } -- cgit v1.2.3