-fix gns record deletion
authorChristian Grothoff <christian@grothoff.org>
Tue, 3 Jul 2012 19:15:15 +0000 (19:15 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 3 Jul 2012 19:15:15 +0000 (19:15 +0000)
src/include/gnunet_namestore_service.h
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_common.c

index b00967c00a695dd51a7526305b15ae4430562336..ee8654948394ae5bd0c8f4f5ab168a3f1133ca73 100644 (file)
@@ -170,6 +170,18 @@ enum GNUNET_NAMESTORE_RecordFlags
    */
   GNUNET_NAMESTORE_RF_SHADOW_RECORD = 16
 
+  /**
+   * When comparing flags for record equality for removal,
+   * which flags should must match (in addition to the type,
+   * name, expiration value and data of the record)?  All flags
+   * that are not listed here will be ignored for this purpose.
+   * (for example, we don't expect that users will remember to
+   * pass the '--private' option when removing a record from
+   * the namestore, hence we don't require this particular option
+   * to match upon removal).  See also
+   * 'GNUNET_NAMESTORE_records_cmp'.
+   */
+#define GNUNET_NAMESTORE_RF_RCMP_FLAGS (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)
 };
 
 
index 95ee989d1987fa0326ced8b34596996455883d21..7609c73a3600fea91b976ca2b896ae7d879fb3a1 100644 (file)
@@ -1280,15 +1280,13 @@ handle_record_remove_it (void *cls,
     rrc->op_res = RECORD_REMOVE_RESULT_NO_RECORDS;
     return;
   }
-
   /* Find record to remove */
   found = -1;
   for (c = 0; c < rd_count; c++)
   {
-    if ( (rd[c].flags != rrc->rd->flags) ||
-        (rd[c].record_type != rrc->rd->record_type) ||
-        (rd[c].data_size != rrc->rd->data_size) ||
-        (0 != memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size)) )
+    if (GNUNET_YES !=
+       GNUNET_NAMESTORE_records_cmp (&rd[c],
+                                     rrc->rd))
       continue;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count);
     found = c;
@@ -1379,6 +1377,7 @@ handle_record_remove (void *cls,
   uint32_t rid;
   struct RemoveRecordContext rrc;
   int res;
+  uint64_t off;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
              "Received `%s' message\n", 
@@ -1465,18 +1464,28 @@ handle_record_remove (void *cls,
                "Removing record for name `%s' in zone `%s'\n", name_tmp, 
                GNUNET_short_h2s (&pubkey_hash));
     rrc.rd = &rd;
-    res = GSN_database->iterate_records (GSN_database->cls,
-                                         &pubkey_hash,
-                                         name_tmp,
-                                         0,
-                                         handle_record_remove_it, &rrc);
+    rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
+    off = 0;
+    res = GNUNET_OK;
+    while ( (RECORD_REMOVE_RESULT_RECORD_NOT_FOUND == rrc.op_res) &&
+           (GNUNET_OK == res) )
+    {
+      res = GSN_database->iterate_records (GSN_database->cls,
+                                          &pubkey_hash,
+                                          name_tmp,
+                                          off++,
+                                          &handle_record_remove_it, &rrc);
+    } 
     switch (res)
     {
     case GNUNET_OK:
       res = rrc.op_res;
       break;
     case GNUNET_NO:
+      GNUNET_break (RECORD_REMOVE_RESULT_NO_RECORDS == rrc.op_res);
       res = RECORD_REMOVE_RESULT_NO_RECORDS;
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 _("Failed to find record to remove\n"));
       break;
     case GNUNET_SYSERR:
       res = RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE;
index 8a2e15e2ab8f4b0384a38c33c6e8eb2edb1c2199..eead6e492d8136b274ccef5c797f7da8569520da 100644 (file)
@@ -172,8 +172,8 @@ GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
 {
   if ((a->record_type == b->record_type) &&
       (a->expiration_time == b->expiration_time) &&
-      ((a->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION
-       == (b->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) ) &&
+      ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS
+       == (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS) ) &&
       (a->data_size == b->data_size) &&
       (0 == memcmp (a->data, b->data, a->data_size)))
     return GNUNET_YES;