gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8753 - gnunet/src/datastore


From: gnunet
Subject: [GNUnet-SVN] r8753 - gnunet/src/datastore
Date: Sun, 19 Jul 2009 06:22:39 -0600

Author: grothoff
Date: 2009-07-19 06:22:39 -0600 (Sun, 19 Jul 2009)
New Revision: 8753

Modified:
   gnunet/src/datastore/gnunet-service-datastore.c
   gnunet/src/datastore/perf_datastore_api.c
   gnunet/src/datastore/test_datastore_api.c
Log:
bugfixes

Modified: gnunet/src/datastore/gnunet-service-datastore.c
===================================================================
--- gnunet/src/datastore/gnunet-service-datastore.c     2009-07-19 12:22:30 UTC 
(rev 8752)
+++ gnunet/src/datastore/gnunet-service-datastore.c     2009-07-19 12:22:39 UTC 
(rev 8753)
@@ -516,11 +516,6 @@
       GNUNET_break (0);
       return NULL;
     }
-  if (ntohl(dm->type) == 0) 
-    {
-      GNUNET_break (0);
-      return NULL;
-    }
   return dm;
 }
 
@@ -547,6 +542,11 @@
              "Processing `%s' request\n",
              "PUT");
 #endif
+  if (ntohl(dm->type) == 0) 
+    {
+      GNUNET_break (0);
+      dm = NULL;
+    }
   if (dm == NULL)
     {
       GNUNET_break (0);

Modified: gnunet/src/datastore/perf_datastore_api.c
===================================================================
--- gnunet/src/datastore/perf_datastore_api.c   2009-07-19 12:22:30 UTC (rev 
8752)
+++ gnunet/src/datastore/perf_datastore_api.c   2009-07-19 12:22:39 UTC (rev 
8753)
@@ -37,13 +37,16 @@
 #include "gnunet_protocols.h"
 #include "gnunet_datastore_service.h"
 
-static struct GNUNET_DATASTORE_Handle *datastore;
+#define VERBOSE GNUNET_YES
 
 /**
  * How long until we give up on transmitting the message?
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
+
+static struct GNUNET_DATASTORE_Handle *datastore;
+
 /**
  * Target datastore size (in bytes).
  * <p>
@@ -193,6 +196,8 @@
            int success,
            const char *msg)
 {
+  struct CpsRunContext *crc = cls;
+
   static int dc;
   dc++;
 #if REPORT_ID
@@ -200,6 +205,11 @@
     fprintf (stderr, "D");
 #endif
   GNUNET_assert (GNUNET_OK == success);
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    GNUNET_NO,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
 }
 
 
@@ -210,6 +220,8 @@
 {
   struct CpsRunContext *crc = cls;
 
+  stored_bytes -= crc->esize;
+  stored_entries--;
   GNUNET_DATASTORE_remove (datastore,
                           &crc->key,
                           crc->esize,
@@ -234,29 +246,31 @@
 {
   struct CpsRunContext *crc = cls;
 
-  if (stored_bytes < MAX_SIZE)
-    return;     
   if (key == NULL)
     {
       crc->phase = RP_REPORT;
-      GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                        GNUNET_NO,
-                                        &run_continuation,
-                                        crc,
-                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      if (stored_bytes < MAX_SIZE)
+       {
+         GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                            GNUNET_NO,
+                                            &run_continuation,
+                                            crc,
+                                            
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+         return;     
+       }
+      GNUNET_SCHEDULER_add_after (crc->sched,
+                                 GNUNET_NO,
+                                 GNUNET_SCHEDULER_PRIORITY_HIGH,
+                                 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
+                                 &do_delete,
+                                 crc);
       return;
     }
-  stored_bytes -= size;
-  stored_entries--;
+  if (stored_bytes < MAX_SIZE)
+    return;     
   crc->key = *key;
   crc->esize = size;
   memcpy (crc->data, data, size);
-  GNUNET_SCHEDULER_add_after (crc->sched,
-                             GNUNET_NO,
-                             GNUNET_SCHEDULER_PRIORITY_HIGH,
-                             GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
-                             &do_delete,
-                             crc);
 }
 
 
@@ -293,7 +307,7 @@
                            &key,
                            size,
                            data,
-                           i,
+                           i+1,
                            GNUNET_CRYPTO_random_u32 
(GNUNET_CRYPTO_QUALITY_WEAK, 100),
                            i,
                            GNUNET_TIME_relative_to_absolute 
@@ -398,6 +412,7 @@
 {
   int ret;
 
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
   GNUNET_log_setup ("perf-datastore-api",
 #if VERBOSE
                     "DEBUG",

Modified: gnunet/src/datastore/test_datastore_api.c
===================================================================
--- gnunet/src/datastore/test_datastore_api.c   2009-07-19 12:22:30 UTC (rev 
8752)
+++ gnunet/src/datastore/test_datastore_api.c   2009-07-19 12:22:39 UTC (rev 
8753)
@@ -33,7 +33,7 @@
 #include "gnunet_protocols.h"
 #include "gnunet_datastore_service.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 /**
  * How long until we give up on transmitting the message?
@@ -101,6 +101,7 @@
     RP_PUT,
     RP_GET,
     RP_DEL,
+    RP_DO_DEL,
     RP_DELVALIDATE
   };
 
@@ -112,6 +113,8 @@
   int *iptr;
   struct GNUNET_SCHEDULER_Handle *sched;
   struct GNUNET_CONFIGURATION_Handle *cfg;
+  void *data;
+  size_t size;
   enum RunPhase phase;
 };
 
@@ -131,6 +134,8 @@
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "%s\n", msg);
   GNUNET_assert (GNUNET_OK == success);
+  GNUNET_free_non_null (crc->data);
+  crc->data = NULL;
   GNUNET_SCHEDULER_add_continuation (crc->sched,
                                     GNUNET_NO,
                                     &run_continuation,
@@ -139,22 +144,6 @@
 }
 
 
-static void
-check_failure (void *cls,
-              int success,
-              const char *msg)
-{
-  struct CpsRunContext *crc = cls;
-  GNUNET_assert (GNUNET_OK != success);
-  GNUNET_assert (NULL != msg);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    GNUNET_NO,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-}
-
-
 static void 
 check_value (void *cls,
             const GNUNET_HashCode * key,
@@ -170,7 +159,19 @@
   int i;
 
   if (key == NULL)
-    return;
+    {
+      if (crc->i == 0)
+       {
+         crc->phase = RP_DEL;
+         crc->i = ITERATIONS;
+       }
+      GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                        GNUNET_NO,
+                                        &run_continuation,
+                                        crc,
+                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      return;
+    }
   i = crc->i;
   GNUNET_assert (size == get_size (i));
   GNUNET_assert (0 == memcmp (data, get_data(i), size));
@@ -178,11 +179,6 @@
   GNUNET_assert (priority == get_priority (i));
   GNUNET_assert (anonymity == get_anonymity(i));
   GNUNET_assert (expiration.value == get_expiration(i).value);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    GNUNET_NO,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
 }
 
 
@@ -199,31 +195,23 @@
 {
   struct CpsRunContext *crc = cls;
   if (key == NULL)
-    return;
-  GNUNET_DATASTORE_remove (datastore,
-                          key,
-                          size,
-                          data,
-                          &check_success,
-                          NULL,
-                          TIMEOUT);
-  ((int*)key)[0]++;
-  GNUNET_DATASTORE_remove (datastore,
-                          key,
-                          size,
-                          data,
-                          &check_failure,
-                          NULL,
-                          TIMEOUT);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    GNUNET_NO,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    {
+      crc->phase = RP_DO_DEL;
+      GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                        GNUNET_NO,
+                                        &run_continuation,
+                                        crc,
+                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      return;
+    }
+  GNUNET_assert (crc->data == NULL);
+  crc->size = size;
+  crc->key = *key;
+  crc->data = GNUNET_malloc (size);
+  memcpy (crc->data, data, size);
 }
 
 
-
 static void 
 check_nothing (void *cls,
             const GNUNET_HashCode * key,
@@ -237,6 +225,10 @@
 {
   struct CpsRunContext *crc = cls;
   GNUNET_assert (key == NULL);
+  if (crc->i == 0)
+    {
+      crc->phase = RP_DONE;      
+    }
   GNUNET_SCHEDULER_add_continuation (crc->sched,
                                     GNUNET_NO,
                                     &run_continuation,
@@ -260,7 +252,7 @@
                  "PUT",
                  crc->i);
 #endif
-      memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+      GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
       GNUNET_DATASTORE_put (datastore,
                            0,
                            &crc->key,
@@ -285,18 +277,13 @@
                  "GET",
                  crc->i);
 #endif
-      memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+      GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
       GNUNET_DATASTORE_get (datastore, 
                            &crc->key,
                            get_type (crc->i),
                            &check_value,
                            crc,
                            TIMEOUT);
-      if (crc->i == 0)
-       {
-         crc->phase = RP_DEL;
-         crc->i = ITERATIONS;
-       }
       break;
     case RP_DEL:
       crc->i--;
@@ -306,19 +293,38 @@
                  "DEL",
                  crc->i);
 #endif
-      memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+      GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
       GNUNET_DATASTORE_get (datastore, 
                            &crc->key,
                            get_type (crc->i),
                            &delete_value,
                            crc,
                            TIMEOUT);
+      break;
+    case RP_DO_DEL:
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Executing `%s' number %u\n",
+                 "DO_DEL",
+                 crc->i);
+#endif
       if (crc->i == 0)
        {
+         crc->i = ITERATIONS;   
          crc->phase = RP_DELVALIDATE;
-         crc->i = ITERATIONS;   
+       }      
+      else
+       {
+         crc->phase = RP_DEL;
        }
-      break;
+      GNUNET_DATASTORE_remove (datastore,
+                              &crc->key,
+                              crc->size,
+                              crc->data,
+                              &check_success,
+                              crc,
+                              TIMEOUT);
+      break;   
     case RP_DELVALIDATE:
       crc->i--;
 #if VERBOSE
@@ -327,17 +333,13 @@
                  "DEL-VALIDATE",
                  crc->i);
 #endif
-      memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode));
+      GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
       GNUNET_DATASTORE_get (datastore, 
                            &crc->key,
                            get_type (crc->i),
                            &check_nothing,
                            crc,
                            TIMEOUT);
-      if (crc->i == 0)
-       {
-         crc->phase = RP_DONE;   
-       }
       break;
   /* check reservations */
   /* check update */
@@ -417,7 +419,8 @@
 main (int argc, char *argv[])
 {
   int ret;
-
+  
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
   GNUNET_log_setup ("test-datastore-api",
 #if VERBOSE
                     "DEBUG",





reply via email to

[Prev in Thread] Current Thread [Next in Thread]