gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30510 - gnunet/src/gnsrecord


From: gnunet
Subject: [GNUnet-SVN] r30510 - gnunet/src/gnsrecord
Date: Mon, 4 Nov 2013 18:04:28 +0100

Author: wachs
Date: 2013-11-04 18:04:28 +0100 (Mon, 04 Nov 2013)
New Revision: 30510

Added:
   gnunet/src/gnsrecord/test_gnsrecord_block_expiration.c
Modified:
   gnunet/src/gnsrecord/Makefile.am
   gnunet/src/gnsrecord/gnsrecord_crypto.c
   gnunet/src/gnsrecord/gnsrecord_misc.c
Log:
block expiration


Modified: gnunet/src/gnsrecord/Makefile.am
===================================================================
--- gnunet/src/gnsrecord/Makefile.am    2013-11-04 16:27:48 UTC (rev 30509)
+++ gnunet/src/gnsrecord/Makefile.am    2013-11-04 17:04:28 UTC (rev 30510)
@@ -17,7 +17,8 @@
 
 check_PROGRAMS = \
  test_gnsrecord_crypto \
- test_gnsrecord_serialization
+ test_gnsrecord_serialization \
+ test_gnsrecord_block_expiration
 
 if ENABLE_TEST_RUN
 TESTS = \
@@ -59,6 +60,7 @@
 EXTRA_DIST = \
   $(check_SCRIPTS)
 
+
 test_gnsrecord_serialization_SOURCES = \
  test_gnsrecord_serialization.c
 test_gnsrecord_serialization_LDADD = \
@@ -66,6 +68,14 @@
   $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
+test_gnsrecord_block_expiration_SOURCES = \
+ test_gnsrecord_block_expiration.c
+test_gnsrecord_block_expiration_LDADD = \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+  $(top_builddir)/src/util/libgnunetutil.la
+
+
 test_gnsrecord_crypto_SOURCES = \
  test_gnsrecord_crypto.c
 test_gnsrecord_crypto_LDADD = \

Modified: gnunet/src/gnsrecord/gnsrecord_crypto.c
===================================================================
--- gnunet/src/gnsrecord/gnsrecord_crypto.c     2013-11-04 16:27:48 UTC (rev 
30509)
+++ gnunet/src/gnsrecord/gnsrecord_crypto.c     2013-11-04 17:04:28 UTC (rev 
30510)
@@ -255,11 +255,12 @@
           {
             if (k == i)
               continue;
-            if ((rd[k].record_type == rd[i].record_type) &&
-                (rd[k].expiration_time >= now.abs_value_us) &&
-                (rd[i].expiration_time >= now.abs_value_us) &&
-                (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
-                include_record = GNUNET_NO; /* We have a non-expired, 
non-shadow record of the same type */
+            if (rd[i].expiration_time < now.abs_value_us)
+              include_record = GNUNET_NO; /* Shadow record is expired */
+            if ((rd[k].record_type == rd[i].record_type)
+                && (rd[k].expiration_time >= now.abs_value_us)
+                && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+              include_record = GNUNET_NO; /* We have a non-expired, non-shadow 
record of the same type */
           }
           if (GNUNET_YES == include_record)
           {

Modified: gnunet/src/gnsrecord/gnsrecord_misc.c
===================================================================
--- gnunet/src/gnsrecord/gnsrecord_misc.c       2013-11-04 16:27:48 UTC (rev 
30509)
+++ gnunet/src/gnsrecord/gnsrecord_misc.c       2013-11-04 17:04:28 UTC (rev 
30510)
@@ -153,9 +153,12 @@
                                             const struct GNUNET_GNSRECORD_Data 
*rd)
 {
   unsigned int c;
+  unsigned int c2;
   struct GNUNET_TIME_Absolute expire;
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Relative rt;
+  struct GNUNET_TIME_Absolute at_shadow;
+  struct GNUNET_TIME_Relative rt_shadow;
 
   if (NULL == rd)
     return GNUNET_TIME_UNIT_ZERO_ABS;
@@ -171,6 +174,26 @@
     {
       at.abs_value_us = rd[c].expiration_time;
     }
+
+    for (c2 = 0; c2 < rd_count; c2++)
+    {
+      /* Check for shadow record */
+      if ((c == c2) ||
+          (rd[c].record_type != rd[c2].record_type) ||
+          (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+          continue;
+      /* We have a shadow record */
+      if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
+      {
+        rt_shadow.rel_value_us = rd[2].expiration_time;
+        at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
+      }
+      else
+      {
+        at_shadow.abs_value_us = rd[c2].expiration_time;
+      }
+      at = GNUNET_TIME_absolute_max (at, at_shadow);
+    }
     expire = GNUNET_TIME_absolute_min (at, expire);
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,

Added: gnunet/src/gnsrecord/test_gnsrecord_block_expiration.c
===================================================================
--- gnunet/src/gnsrecord/test_gnsrecord_block_expiration.c                      
        (rev 0)
+++ gnunet/src/gnsrecord/test_gnsrecord_block_expiration.c      2013-11-04 
17:04:28 UTC (rev 30510)
@@ -0,0 +1,104 @@
+/*
+     This file is part of GNUnet.
+     (C) 2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gnsrecord/test_gnsrecord_crypto.c
+ * @brief testcase for block creation, verification and decryption
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_gnsrecord_lib.h"
+
+#define RECORDS 5
+
+#define TEST_RECORD_TYPE 1234
+
+#define TEST_RECORD_DATALEN 123
+
+#define TEST_RECORD_DATA 'a'
+
+#define TEST_REMOVE_RECORD_TYPE 4321
+
+#define TEST_REMOVE_RECORD_DATALEN 255
+
+#define TEST_REMOVE_RECORD_DATA 'b'
+
+static int res;
+
+
+
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_GNSRECORD_Data rd[2];
+  struct GNUNET_TIME_Absolute expiration_abs;
+  struct GNUNET_TIME_Absolute expiration_abs_shadow;
+
+  expiration_abs.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
+      GNUNET_TIME_UNIT_SECONDS.rel_value_us;
+  expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us 
+
+      GNUNET_TIME_UNIT_MINUTES.rel_value_us;
+
+  /* create record */
+  rd[0].expiration_time = expiration_abs.abs_value_us;
+  rd[0].record_type = TEST_RECORD_TYPE;
+  rd[0].data_size = TEST_RECORD_DATALEN;
+  rd[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
+  rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
+  memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+
+  rd[1].expiration_time = expiration_abs.abs_value_us;
+  rd[1].record_type = TEST_RECORD_TYPE;
+  rd[1].data_size = TEST_RECORD_DATALEN;
+  rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
+  rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
+  memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+
+  GNUNET_assert (expiration_abs.abs_value_us == 
GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
+
+  rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
+  rd[1].record_type = TEST_RECORD_TYPE;
+  rd[1].data_size = TEST_RECORD_DATALEN;
+  rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
+  rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
+  memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+
+  GNUNET_assert (expiration_abs_shadow.abs_value_us == 
GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
+  res = 0;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  static char *const argvx[] = { "test-gnsrecord-crypto",
+    NULL
+  };
+  static struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  res = 1;
+  GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, 
"test-namestore-api",
+                      "nohelp", options, &run, &res);
+  return res;
+}
+
+/* end of test_gnsrecord_crypto.c */




reply via email to

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