fix indentation, typo, improve logging
[oweals/gnunet.git] / src / datastore / datastore_api.c
index 2856347595e3c9aa2442499478db4f302834f916..916e6acaef930121af9a4bfa04f0be4c72437d35 100644 (file)
@@ -267,6 +267,8 @@ free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe)
                                h->queue_tail,
                                qe);
   h->queue_size--;
+  if (NULL != qe->env)
+    GNUNET_MQ_discard (qe->env);
   GNUNET_free (qe);
 }
 
@@ -441,7 +443,7 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Re-connecting to issue DROP!\n");
     GNUNET_assert (NULL == h->mq);
-    h->mq = GNUNET_CLIENT_connecT (h->cfg,
+    h->mq = GNUNET_CLIENT_connect (h->cfg,
                                    "datastore",
                                    NULL,
                                    &disconnect_on_mq_error,
@@ -496,8 +498,17 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
   struct GNUNET_DATASTORE_QueueEntry *pos;
   unsigned int c;
 
-  c = 0;
-  pos = h->queue_head;
+  if ( (NULL != h->queue_tail) &&
+       (h->queue_tail->priority >= queue_priority) )
+  {
+    c = h->queue_size;
+    pos = NULL;
+  }
+  else
+  {
+    c = 0;
+    pos = h->queue_head;
+  }
   while ( (NULL != pos) &&
           (c < max_queue_size) &&
           (pos->priority >= queue_priority) )
@@ -846,27 +857,27 @@ handle_data_end (void *cls,
 static void
 try_reconnect (void *cls)
 {
-  GNUNET_MQ_hd_var_size (status,
-                         GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
-                         struct StatusMessage);
-  GNUNET_MQ_hd_var_size (data,
-                         GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
-                         struct DataMessage);
-  GNUNET_MQ_hd_fixed_size (data_end,
-                           GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END,
-                           struct GNUNET_MessageHeader);
   struct GNUNET_DATASTORE_Handle *h = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    make_status_handler (h),
-    make_data_handler (h),
-    make_data_end_handler (h),
+    GNUNET_MQ_hd_var_size (status,
+                           GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
+                           struct StatusMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (data,
+                           GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
+                           struct DataMessage,
+                           h),
+    GNUNET_MQ_hd_fixed_size (data_end,
+                             GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END,
+                             struct GNUNET_MessageHeader,
+                             h),
     GNUNET_MQ_handler_end ()
   };
 
   h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
   h->reconnect_task = NULL;
   GNUNET_assert (NULL == h->mq);
-  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+  h->mq = GNUNET_CLIENT_connect (h->cfg,
                                  "datastore",
                                  handlers,
                                  &mq_error_handler,
@@ -972,7 +983,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
   dm->uid = GNUNET_htonll (0);
   dm->expiration = GNUNET_TIME_absolute_hton (expiration);
   dm->key = *key;
-  memcpy (&dm[1],
+  GNUNET_memcpy (&dm[1],
           data,
           size);
   qc.sc.cont = cont;
@@ -1123,72 +1134,6 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
 }
 
 
-/**
- * Update a value in the datastore.
- *
- * @param h handle to the datastore
- * @param uid identifier for the value
- * @param priority how much to increase the priority of the value
- * @param expiration new expiration value should be MAX of existing and this argument
- * @param queue_priority ranking of this request in the priority queue
- * @param max_queue_size at what queue size should this request be dropped
- *        (if other requests of higher priority are in the queue)
- * @param cont continuation to call when done
- * @param cont_cls closure for @a cont
- * @return NULL if the entry was not queued, otherwise a handle that can be used to
- *         cancel; note that even if NULL is returned, the callback will be invoked
- *         (or rather, will already have been invoked)
- */
-struct GNUNET_DATASTORE_QueueEntry *
-GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
-                         uint64_t uid,
-                         uint32_t priority,
-                         struct GNUNET_TIME_Absolute expiration,
-                         unsigned int queue_priority,
-                         unsigned int max_queue_size,
-                         GNUNET_DATASTORE_ContinuationWithStatus cont,
-                         void *cont_cls)
-{
-  struct GNUNET_DATASTORE_QueueEntry *qe;
-  struct GNUNET_MQ_Envelope *env;
-  struct UpdateMessage *um;
-  union QueueContext qc;
-
-  if (NULL == cont)
-    cont = &drop_status_cont;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Asked to update entry %llu raising priority by %u and expiration to %s\n",
-       uid,
-       (unsigned int) priority,
-       GNUNET_STRINGS_absolute_time_to_string (expiration));
-  env = GNUNET_MQ_msg (um,
-                       GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
-  um->priority = htonl (priority);
-  um->expiration = GNUNET_TIME_absolute_hton (expiration);
-  um->uid = GNUNET_htonll (uid);
-
-  qc.sc.cont = cont;
-  qc.sc.cont_cls = cont_cls;
-  qe = make_queue_entry (h,
-                         env,
-                         queue_priority,
-                         max_queue_size,
-                         GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
-                         &qc);
-  if (NULL == qe)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Could not create queue entry for UPDATE\n");
-    return NULL;
-  }
-  GNUNET_STATISTICS_update (h->stats,
-                            gettext_noop ("# UPDATE requests executed"), 1,
-                            GNUNET_NO);
-  process_queue (h);
-  return qe;
-}
-
-
 /**
  * Explicitly remove some content from the database.
  * The @a cont continuation will be called with `status`
@@ -1246,7 +1191,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
   dm->uid = GNUNET_htonll (0);
   dm->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_ZERO_ABS);
   dm->key = *key;
-  memcpy (&dm[1],
+  GNUNET_memcpy (&dm[1],
           data,
           size);