-LRN: Correct time == 0 handling:
authorChristian Grothoff <christian@grothoff.org>
Thu, 5 Jul 2012 07:58:57 +0000 (07:58 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 5 Jul 2012 07:58:57 +0000 (07:58 +0000)
  With logging in namespace comparison it is now clear to me that
deletion fails due to expiration times not being equal. And sure
enough, gnunet-namespace sets expiration to 0 when submitting a
template for seek-and-destroy. This patch:
  1) Changes gnunet-namespace to fail if the time is not absolute or
unspecified. If it's absolute, it's used as-is (hoping that the user
got the exact expiration time somewhere - probably from -D). If it's
unspecified, it is set to zero (as it was before).
  2) Comparison ignores expiration time if either of the arguments has
expiration time set to zero (i'm assuming that real records will never
have expiration time of zero. If it's absolute, zero is in the past.
If it's relative, zero makes no sense). Also, i'm not sure it makes
sense to have two records that have different expiration times, but
are otherwise identical (i.e. both are public or private, same data,
size etc). Lookups will find (and will be satisfied) by either, so
there's no sense in keeping both (unless you're doing some wizardry
with expirations, but i'm not sure it's worth the compexity).

src/namestore/gnunet-namestore.c
src/namestore/namestore_common.c

index 5cac2e1336ab27e92a3b8213c183c829c43c2366..ad263e7d0973b6eb444a50f28ca2f8dd49ef5bee 100644 (file)
@@ -457,6 +457,15 @@ run (void *cls, char *const *args, const char *cfgfile,
       ret = 1;
       return;     
     }
+    if (etime_is_rel && del)
+    {
+      fprintf (stderr,
+              _("Deletion requires either absolute time, or no time at all. Got relative time `%s' instead.\n"),
+              expirationstring);
+      GNUNET_SCHEDULER_shutdown ();
+      ret = 1;
+      return;
+    }
   } 
   else if (add)
   {
@@ -524,6 +533,8 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.data_size = data_size;
     rd.record_type = type;
     rd.expiration_time = 0;
+    if (!etime_is_rel)
+      rd.expiration_time = etime_abs.abs_value;
     rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
     del_qe = GNUNET_NAMESTORE_record_remove (ns,
                                             zone_pkey,
index d676287671edf9d90b30164bc1a43f9b9a6abace..8b095eb26d140e31a5ae039b42ab5b6b5481a808 100644 (file)
@@ -178,7 +178,8 @@ GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a,
         "Record type %lu != %lu\n", a->record_type, b->record_type);
     return GNUNET_NO;
   }
-  if (a->expiration_time != b->expiration_time)
+  if ((a->expiration_time != b->expiration_time) &&
+      ((a->expiration_time != 0) && (b->expiration_time != 0)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
         "Expiration time %llu != %llu\n", a->expiration_time, b->expiration_time);