fixes
[oweals/gnunet.git] / src / datastore / gnunet-service-datastore.c
index c3370e0a582179a53787ab580c36c599adb9efcb..a2e8aa8206adde0c8411de3a7cfcc66f1480d9d8 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_arm_service.h"
 #include "gnunet_protocols.h"
 #include "gnunet_statistics_service.h"
 #include "plugin_datastore.h"
@@ -242,7 +241,7 @@ static struct TransmitCallbackContext *tcc_head;
 static struct TransmitCallbackContext *tcc_tail;
 
 /**
- * Have we already clean ed up the TCCs and are hence no longer
+ * Have we already cleaned up the TCCs and are hence no longer
  * willing (or able) to transmit anything to anyone?
  */
 static int cleaning_done;
@@ -288,7 +287,7 @@ expired_processor (void *cls,
                   const GNUNET_HashCode * key,
                   uint32_t size,
                   const void *data,
-                  uint32_t type,
+                  enum GNUNET_BLOCK_Type type,
                   uint32_t priority,
                   uint32_t anonymity,
                   struct GNUNET_TIME_Absolute
@@ -297,7 +296,6 @@ expired_processor (void *cls,
 {
   struct GNUNET_TIME_Absolute now;
 
-  expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
   if (key == NULL) 
     {
       expired_kill_task 
@@ -323,7 +321,7 @@ expired_processor (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# bytes expired"),
                            size,
-                           GNUNET_NO);
+                           GNUNET_YES);
   GNUNET_CONTAINER_bloomfilter_remove (filter,
                                       key);
   return GNUNET_NO; /* delete */
@@ -343,6 +341,7 @@ static void
 delete_expired (void *cls,
                const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
   plugin->api->iter_ascending_expiration (plugin->api->cls, 
                                          0,
                                          &expired_processor,
@@ -375,7 +374,7 @@ manage (void *cls,
        const GNUNET_HashCode * key,
        uint32_t size,
        const void *data,
-       uint32_t type,
+       enum GNUNET_BLOCK_Type type,
        uint32_t priority,
        uint32_t anonymity,
        struct GNUNET_TIME_Absolute
@@ -404,7 +403,7 @@ manage (void *cls,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# bytes purged (low-priority)"),
                            size,
-                           GNUNET_NO);
+                           GNUNET_YES);
   GNUNET_CONTAINER_bloomfilter_remove (filter,
                                       key);
   return GNUNET_NO;
@@ -524,6 +523,11 @@ transmit (struct GNUNET_SERVER_Client *client,
 
   if (GNUNET_YES == cleaning_done)
     {
+#if DEBUG_DATASTORE
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 "Shutdown in progress, aborting transmission.\n");
+#endif
+      GNUNET_free (msg);
       if (NULL != tc)
        tc (tc_cls, GNUNET_SYSERR);
       return;
@@ -644,7 +648,7 @@ transmit_item (void *cls,
               const GNUNET_HashCode * key,
               uint32_t size,
               const void *data,
-              uint32_t type,
+              enum GNUNET_BLOCK_Type type,
               uint32_t priority,
               uint32_t anonymity,
               struct GNUNET_TIME_Absolute
@@ -870,22 +874,19 @@ handle_put (void *cls,
   struct ReservationList *pos;
   uint32_t size;
 
-#if DEBUG_DATASTORE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Processing `%s' request\n",
-             "PUT");
-#endif
-  if (ntohl(dm->type) == 0) 
-    {
-      GNUNET_break (0);
-      dm = NULL;
-    }
-  if (dm == NULL)
+  if ( (dm == NULL) ||
+       (ntohl(dm->type) == 0) ) 
     {
       GNUNET_break (0);
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
+#if DEBUG_DATASTORE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Processing `%s' request for `%s'\n",
+             "PUT",
+             GNUNET_h2s (&dm->key));
+#endif
   rid = ntohl(dm->rid);
   size = ntohl(dm->size);
   if (rid > 0)
@@ -919,7 +920,7 @@ handle_put (void *cls,
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# bytes stored"),
                                size,
-                               GNUNET_NO);
+                               GNUNET_YES);
       GNUNET_CONTAINER_bloomfilter_add (filter,
                                        &dm->key);
 #if DEBUG_DATASTORE
@@ -947,17 +948,12 @@ handle_put (void *cls,
  */
 static void
 handle_get (void *cls,
-            struct GNUNET_SERVER_Client *client,
-            const struct GNUNET_MessageHeader *message)
+           struct GNUNET_SERVER_Client *client,
+           const struct GNUNET_MessageHeader *message)
 {
   const struct GetMessage *msg;
   uint16_t size;
 
-#if DEBUG_DATASTORE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Processing `%s' request\n",
-             "GET");
-#endif
   size = ntohs(message->size);
   if ( (size != sizeof(struct GetMessage)) &&
        (size != sizeof(struct GetMessage) - sizeof(GNUNET_HashCode)) )
@@ -966,12 +962,19 @@ handle_get (void *cls,
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
+  msg = (const struct GetMessage*) message;
+#if DEBUG_DATASTORE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Processing `%s' request for `%s' of type %u\n",
+             "GET",
+             GNUNET_h2s (&msg->key),
+             ntohl (msg->type));
+#endif
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# GET requests received"),
                            1,
                            GNUNET_NO);
   GNUNET_SERVER_client_keep (client);
-  msg = (const struct GetMessage*) message;
   if ( (size == sizeof(struct GetMessage)) &&
        (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter,
                                                         &msg->key)) )
@@ -1017,17 +1020,18 @@ handle_update (void *cls,
   int ret;
   char *emsg;
 
-#if DEBUG_DATASTORE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Processing `%s' request\n",
-             "UPDATE");
-#endif
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# UPDATE requests received"),
                            1,
                            GNUNET_NO);
   msg = (const struct UpdateMessage*) message;
   emsg = NULL;
+#if DEBUG_DATASTORE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Processing `%s' request for %llu\n",
+             "UPDATE",
+             (unsigned long long) GNUNET_ntohll (msg->uid));
+#endif
   ret = plugin->api->update (plugin->api->cls,
                             GNUNET_ntohll(msg->uid),
                             (int32_t) ntohl(msg->priority),
@@ -1094,7 +1098,7 @@ remove_callback (void *cls,
                 const GNUNET_HashCode * key,
                 uint32_t size,
                 const void *data,
-                uint32_t type,
+                enum GNUNET_BLOCK_Type type,
                 uint32_t priority,
                 uint32_t anonymity,
                 struct GNUNET_TIME_Absolute
@@ -1120,14 +1124,15 @@ remove_callback (void *cls,
   rc->found = GNUNET_YES;
 #if DEBUG_DATASTORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Item %llu matches `%s' request.\n",
+             "Item %llu matches `%s' request for key `%s'.\n",
              (unsigned long long) uid,
-             "REMOVE");
+             "REMOVE",
+             GNUNET_h2s (key));
 #endif 
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# bytes removed (explicit request)"),
                            size,
-                           GNUNET_NO);
+                           GNUNET_YES);
   GNUNET_CONTAINER_bloomfilter_remove (filter,
                                       key);
   plugin->api->next_request (next_cls, GNUNET_YES);
@@ -1151,17 +1156,18 @@ handle_remove (void *cls,
   GNUNET_HashCode vhash;
   struct RemoveContext *rc;
 
-#if DEBUG_DATASTORE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Processing `%s' request\n",
-             "REMOVE");
-#endif
   if (dm == NULL)
     {
       GNUNET_break (0);
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
+#if DEBUG_DATASTORE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Processing `%s' request for `%s'\n",
+             "REMOVE",
+             GNUNET_h2s (&dm->key));
+#endif
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# REMOVE requests received"),
                            1,
@@ -1302,7 +1308,6 @@ unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_CONTAINER_bloomfilter_free (filter);
       filter = NULL;
     }
-  GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL);
   if (stats != NULL)
     {
       GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
@@ -1331,7 +1336,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
          GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
          GNUNET_SERVER_client_drop (tcc->client);
        }
-   if (NULL != tcc->tc)
+      if (NULL != tcc->tc)
        tcc->tc (tcc->tc_cls, GNUNET_SYSERR);
       GNUNET_free (tcc->msg);
       GNUNET_free (tcc);
@@ -1451,13 +1456,11 @@ run (void *cls,
        }
       return;
     }
-  GNUNET_ARM_start_services (cfg, sched, "statistics", NULL);
   plugin = load_plugin ();
   if (NULL == plugin)
     {
       GNUNET_CONTAINER_bloomfilter_free (filter);
       filter = NULL;
-      GNUNET_ARM_stop_services (cfg, sched, "statistics", NULL);
       if (stats != NULL)
        {
          GNUNET_STATISTICS_destroy (stats, GNUNET_YES);