watch for namestore not completing store operations, add auto-abort with warning...
authorChristian Grothoff <christian@grothoff.org>
Thu, 10 May 2018 19:08:23 +0000 (21:08 +0200)
committerChristian Grothoff <christian@grothoff.org>
Thu, 10 May 2018 19:08:23 +0000 (21:08 +0200)
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c

index ffc76a9117ac8b0e01a2845efc64cbbf144b6c48..6dedcd754e49e89a67c0e602b1b3d79803993ad4 100644 (file)
@@ -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,
index ab356838b7e3bf364217c0f88d90784f3abc338d..57bf8f81be306f8ffc8e9c84e18a677a28736ecf 100644 (file)
 
 #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;
 }