aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-11-04 17:04:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-11-04 17:04:28 +0000
commit6c3bf6b3486fd31402ab991f5ddef76bf9cd93c4 (patch)
tree86ff97f084276e63ad6d58fd398b8dc1403199bb /src/gnsrecord
parenta5328c2a96b9582585511c1ce1aee08509eb0c0a (diff)
downloadgnunet-6c3bf6b3486fd31402ab991f5ddef76bf9cd93c4.tar.gz
gnunet-6c3bf6b3486fd31402ab991f5ddef76bf9cd93c4.zip
block expiration
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/Makefile.am12
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c11
-rw-r--r--src/gnsrecord/gnsrecord_misc.c23
-rw-r--r--src/gnsrecord/test_gnsrecord_block_expiration.c104
4 files changed, 144 insertions, 6 deletions
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 1f489c8d7..2c9d2f476 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -17,7 +17,8 @@ endif
17 17
18check_PROGRAMS = \ 18check_PROGRAMS = \
19 test_gnsrecord_crypto \ 19 test_gnsrecord_crypto \
20 test_gnsrecord_serialization 20 test_gnsrecord_serialization \
21 test_gnsrecord_block_expiration
21 22
22if ENABLE_TEST_RUN 23if ENABLE_TEST_RUN
23TESTS = \ 24TESTS = \
@@ -59,6 +60,7 @@ libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \
59EXTRA_DIST = \ 60EXTRA_DIST = \
60 $(check_SCRIPTS) 61 $(check_SCRIPTS)
61 62
63
62test_gnsrecord_serialization_SOURCES = \ 64test_gnsrecord_serialization_SOURCES = \
63 test_gnsrecord_serialization.c 65 test_gnsrecord_serialization.c
64test_gnsrecord_serialization_LDADD = \ 66test_gnsrecord_serialization_LDADD = \
@@ -66,6 +68,14 @@ test_gnsrecord_serialization_LDADD = \
66 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 68 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
67 $(top_builddir)/src/util/libgnunetutil.la 69 $(top_builddir)/src/util/libgnunetutil.la
68 70
71test_gnsrecord_block_expiration_SOURCES = \
72 test_gnsrecord_block_expiration.c
73test_gnsrecord_block_expiration_LDADD = \
74 $(top_builddir)/src/testing/libgnunettesting.la \
75 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
76 $(top_builddir)/src/util/libgnunetutil.la
77
78
69test_gnsrecord_crypto_SOURCES = \ 79test_gnsrecord_crypto_SOURCES = \
70 test_gnsrecord_crypto.c 80 test_gnsrecord_crypto.c
71test_gnsrecord_crypto_LDADD = \ 81test_gnsrecord_crypto_LDADD = \
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index a83a1c0cd..e11facf78 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -255,11 +255,12 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
255 { 255 {
256 if (k == i) 256 if (k == i)
257 continue; 257 continue;
258 if ((rd[k].record_type == rd[i].record_type) && 258 if (rd[i].expiration_time < now.abs_value_us)
259 (rd[k].expiration_time >= now.abs_value_us) && 259 include_record = GNUNET_NO; /* Shadow record is expired */
260 (rd[i].expiration_time >= now.abs_value_us) && 260 if ((rd[k].record_type == rd[i].record_type)
261 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))) 261 && (rd[k].expiration_time >= now.abs_value_us)
262 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */ 262 && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
263 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
263 } 264 }
264 if (GNUNET_YES == include_record) 265 if (GNUNET_YES == include_record)
265 { 266 {
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 91cbcf017..315835c04 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -153,9 +153,12 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
153 const struct GNUNET_GNSRECORD_Data *rd) 153 const struct GNUNET_GNSRECORD_Data *rd)
154{ 154{
155 unsigned int c; 155 unsigned int c;
156 unsigned int c2;
156 struct GNUNET_TIME_Absolute expire; 157 struct GNUNET_TIME_Absolute expire;
157 struct GNUNET_TIME_Absolute at; 158 struct GNUNET_TIME_Absolute at;
158 struct GNUNET_TIME_Relative rt; 159 struct GNUNET_TIME_Relative rt;
160 struct GNUNET_TIME_Absolute at_shadow;
161 struct GNUNET_TIME_Relative rt_shadow;
159 162
160 if (NULL == rd) 163 if (NULL == rd)
161 return GNUNET_TIME_UNIT_ZERO_ABS; 164 return GNUNET_TIME_UNIT_ZERO_ABS;
@@ -171,6 +174,26 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
171 { 174 {
172 at.abs_value_us = rd[c].expiration_time; 175 at.abs_value_us = rd[c].expiration_time;
173 } 176 }
177
178 for (c2 = 0; c2 < rd_count; c2++)
179 {
180 /* Check for shadow record */
181 if ((c == c2) ||
182 (rd[c].record_type != rd[c2].record_type) ||
183 (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
184 continue;
185 /* We have a shadow record */
186 if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
187 {
188 rt_shadow.rel_value_us = rd[2].expiration_time;
189 at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
190 }
191 else
192 {
193 at_shadow.abs_value_us = rd[c2].expiration_time;
194 }
195 at = GNUNET_TIME_absolute_max (at, at_shadow);
196 }
174 expire = GNUNET_TIME_absolute_min (at, expire); 197 expire = GNUNET_TIME_absolute_min (at, expire);
175 } 198 }
176 LOG (GNUNET_ERROR_TYPE_DEBUG, 199 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/gnsrecord/test_gnsrecord_block_expiration.c b/src/gnsrecord/test_gnsrecord_block_expiration.c
new file mode 100644
index 000000000..3f624e40a
--- /dev/null
+++ b/src/gnsrecord/test_gnsrecord_block_expiration.c
@@ -0,0 +1,104 @@
1/*
2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file gnsrecord/test_gnsrecord_crypto.c
22 * @brief testcase for block creation, verification and decryption
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h"
27
28#define RECORDS 5
29
30#define TEST_RECORD_TYPE 1234
31
32#define TEST_RECORD_DATALEN 123
33
34#define TEST_RECORD_DATA 'a'
35
36#define TEST_REMOVE_RECORD_TYPE 4321
37
38#define TEST_REMOVE_RECORD_DATALEN 255
39
40#define TEST_REMOVE_RECORD_DATA 'b'
41
42static int res;
43
44
45
46static void
47run (void *cls, char *const *args, const char *cfgfile,
48 const struct GNUNET_CONFIGURATION_Handle *cfg)
49{
50 struct GNUNET_GNSRECORD_Data rd[2];
51 struct GNUNET_TIME_Absolute expiration_abs;
52 struct GNUNET_TIME_Absolute expiration_abs_shadow;
53
54 expiration_abs.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
55 GNUNET_TIME_UNIT_SECONDS.rel_value_us;
56 expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
57 GNUNET_TIME_UNIT_MINUTES.rel_value_us;
58
59 /* create record */
60 rd[0].expiration_time = expiration_abs.abs_value_us;
61 rd[0].record_type = TEST_RECORD_TYPE;
62 rd[0].data_size = TEST_RECORD_DATALEN;
63 rd[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
64 rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
65 memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
66
67 rd[1].expiration_time = expiration_abs.abs_value_us;
68 rd[1].record_type = TEST_RECORD_TYPE;
69 rd[1].data_size = TEST_RECORD_DATALEN;
70 rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
71 rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
72 memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
73
74 GNUNET_assert (expiration_abs.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
75
76 rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
77 rd[1].record_type = TEST_RECORD_TYPE;
78 rd[1].data_size = TEST_RECORD_DATALEN;
79 rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
80 rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
81 memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
82
83 GNUNET_assert (expiration_abs_shadow.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
84 res = 0;
85}
86
87
88int
89main (int argc, char *argv[])
90{
91 static char *const argvx[] = { "test-gnsrecord-crypto",
92 NULL
93 };
94 static struct GNUNET_GETOPT_CommandLineOption options[] = {
95 GNUNET_GETOPT_OPTION_END
96 };
97
98 res = 1;
99 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
100 "nohelp", options, &run, &res);
101 return res;
102}
103
104/* end of test_gnsrecord_crypto.c */