- expiration update
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 5 Mar 2012 09:09:52 +0000 (09:09 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 5 Mar 2012 09:09:52 +0000 (09:09 +0000)
src/namestore/gnunet-service-namestore.c
src/namestore/test_namestore_api_create_update.c

index 8734ee34a64d57ba5b0a028b8c2b7040f6064904..b7bd129e59053adf09cf9bb5c545c7f829391743 100644 (file)
@@ -622,11 +622,9 @@ handle_create_record_it (void *cls,
         (crc->rd->data_size == rd[c].data_size) &&
         (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update!\n", crc->name);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update expiration date!\n", crc->name);
       exist = c;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "exp %llu %llu!\n", rd[c].expiration.abs_value, crc->rd->expiration.abs_value);
       if (crc->rd->expiration.abs_value != rd[c].expiration.abs_value)
-
         update = GNUNET_YES;
        break;
     }
@@ -664,6 +662,7 @@ handle_create_record_it (void *cls,
     rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData));
     memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
     rd_count_new = rd_count;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value);
     rd_new[exist].expiration = crc->rd->expiration;
     signature_new = GNUNET_NAMESTORE_create_signature (crc->pkey, crc->name, rd_new, rd_count_new);
     if (NULL == signature_new)
@@ -689,8 +688,30 @@ end:
   GNUNET_free_non_null (rd_new);
   GNUNET_free_non_null (signature_new);
 
+  switch (res) {
+    case GNUNET_SYSERR:
+       /* failed to create the record */
+       crc->res = GNUNET_SYSERR;
+      break;
+    case GNUNET_YES:
+      /* database operations OK */
+      if (GNUNET_YES == update)
+        /* we updated an existing record */
+        crc->res = GNUNET_NO;
+      else
+        /* we created a new record */
+        crc->res = GNUNET_YES;
+      break;
+    case GNUNET_NO:
+        /* identical entry existed, so we did nothing */
+        crc->res = GNUNET_NO;
+      break;
+    default:
+      break;
+  }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res);
-  crc->res = res;
+
 }
 
 static void handle_record_create (void *cls,
index 2c91a00f4014560d741ab853cea1edbefc666823..22313aca9d61df9777e1f012a40a0a6a2182f98c 100644 (file)
@@ -19,7 +19,7 @@
 */
 /**
  * @file namestore/test_namestore_api.c
- * @brief testcase for namestore_api.c
+ * @brief testcase for namestore_api.c for updating an existing record
  */
 #include "platform.h"
 #include "gnunet_common.h"
@@ -321,36 +321,40 @@ void
 create_updated_cont (void *cls, int32_t success, const char *emsg)
 {
   char *name = cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
-  if (success == GNUNET_OK)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration for record `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
+  if (success == GNUNET_NO)
   {
     res = 0;
-    GNUNET_SCHEDULER_add_now(&end, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updated record for name `%s'\n", name);
+  }
+  if (success == GNUNET_OK)
+  {
+    res = 1;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAIL, Create new record for name `%s'\n", name);
   }
   else
   {
     res = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
-    GNUNET_SCHEDULER_add_now(&end, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create records for name `%s'\n", name);
   }
-
+  GNUNET_SCHEDULER_add_now(&end, NULL);
 }
 
 void
 create_identical_cont (void *cls, int32_t success, const char *emsg)
 {
   char *name = cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create updated record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
-  if (success == GNUNET_OK)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
+  if (success == GNUNET_NO)
   {
     res = 0;
-    s_first_record->expiration = GNUNET_TIME_absolute_get_zero();
+    s_first_record->expiration = GNUNET_TIME_absolute_get ();
     GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_updated_cont, s_name);
   }
   else
   {
     res = 1;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg);
     GNUNET_SCHEDULER_add_now(&end, NULL);
   }
 
@@ -402,7 +406,7 @@ create_record (int count)
 
   for (c = 0; c < count; c++)
   {
-  rd[c].expiration = GNUNET_TIME_absolute_get();
+  rd[c].expiration = GNUNET_TIME_absolute_get_zero();
   rd[c].record_type = TEST_RECORD_TYPE;
   rd[c].data_size = TEST_RECORD_DATALEN;
   rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);