aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_plugin_namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-22 22:34:13 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-22 22:34:13 +0000
commitf6884a301a25d5038b0eeebaa4678eb164dc395b (patch)
treec32b9669785d992cad4ddcf260305bd2f137b08c /src/namestore/test_plugin_namestore.c
parent280637c8e3e1712b495fb6a3184ed48e91110cf0 (diff)
downloadgnunet-f6884a301a25d5038b0eeebaa4678eb164dc395b.tar.gz
gnunet-f6884a301a25d5038b0eeebaa4678eb164dc395b.zip
-extended testcase plus misc fixes
Diffstat (limited to 'src/namestore/test_plugin_namestore.c')
-rw-r--r--src/namestore/test_plugin_namestore.c293
1 files changed, 291 insertions, 2 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index 01f73df8e..6b606e62b 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -80,12 +80,295 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
80} 80}
81 81
82 82
83/**
84 * Function called by for each matching record.
85 *
86 * @param cls closure
87 * @param zone hash of the public key of the zone
88 * @param loc location of the signature for this record
89 * @param name name that is being mapped (at most 255 characters long)
90 * @param record_type type of the record (A, AAAA, PKEY, etc.)
91 * @param expiration expiration time for the content
92 * @param flags flags for the content
93 * @param data_size number of bytes in data
94 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
95 * GNS specification for GNS extensions)
96 */
97static void
98test_record (void *cls,
99 const GNUNET_HashCode *zone,
100 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
101 const char *name,
102 uint32_t record_type,
103 struct GNUNET_TIME_Absolute expiration,
104 enum GNUNET_NAMESTORE_RecordFlags flags,
105 size_t data_size,
106 const void *data)
107{
108 int *idp = cls;
109 int id = *idp;
110 size_t tdata_size = id * 17;
111 char tdata[tdata_size];
112 GNUNET_HashCode tzone;
113 char tname[32];
114 uint32_t trecord_type;
115 struct GNUNET_NAMESTORE_SignatureLocation tloc;
116 enum GNUNET_NAMESTORE_RecordFlags tflags;
117
118 memset (&tzone, 42, sizeof (tzone));
119 memset (tdata, id % 255, sizeof (tdata));
120 GNUNET_snprintf (tname, sizeof (tname),
121 "aa%u", (unsigned int) id);
122 trecord_type = id % 4;
123 tloc.depth = (id % 10);
124 tloc.offset = (id % 3);
125 tloc.revision = id % 1024;
126 tflags = GNUNET_NAMESTORE_RF_AUTHORITY;
127
128 GNUNET_assert (0 == memcmp (&tzone, zone, sizeof (GNUNET_HashCode)));
129 GNUNET_assert (trecord_type == record_type);
130 GNUNET_assert (0 == strcmp (tname, name));
131 GNUNET_assert (tdata_size == data_size);
132 GNUNET_assert (0 == memcmp (data, tdata, data_size));
133 GNUNET_assert (flags == tflags);
134 GNUNET_assert (0 == memcmp (loc, &tloc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
135}
136
137
138static void
139get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
140{
141 GNUNET_HashCode zone;
142 GNUNET_HashCode nh;
143 char name[32];
144
145 memset (&zone, 42, sizeof (zone));
146 GNUNET_snprintf (name, sizeof (name),
147 "aa%u", (unsigned int) id);
148 GNUNET_CRYPTO_hash (name, strlen (name), &nh);
149 GNUNET_assert (1 == nsp->iterate_records (nsp->cls,
150 &zone,
151 &nh,
152 &test_record, &id));
153}
154
155
156/**
157 * Function called with the matching node.
158 *
159 * @param cls closure
160 * @param zone hash of public key of the zone
161 * @param loc location in the B-tree
162 * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
163 * @param num_entries number of entries at this node in the B-tree
164 * @param entries the 'num_entries' entries to store (hashes over the
165 * records)
166 */
167static void
168test_node (void *cls,
169 const GNUNET_HashCode *zone,
170 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
171 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
172 unsigned int num_entries,
173 const GNUNET_HashCode *entries)
174{
175 int *idp = cls;
176 int id = *idp;
177 struct GNUNET_NAMESTORE_SignatureLocation tloc;
178 struct GNUNET_NAMESTORE_SignatureLocation tploc;
179 unsigned int tnum_entries = 1 + (id % 15);
180 GNUNET_HashCode tentries[num_entries];
181 unsigned int i;
182
183 tloc.depth = (id % 10);
184 tloc.offset = (id % 3);
185 tloc.revision = id % 1024;
186 tploc.depth = tloc.depth + 1;
187 tploc.offset = (id % 5);
188 tploc.revision = tloc.revision;
189 for (i=0;i<tnum_entries;i++)
190 memset (&tentries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
191 GNUNET_assert (0 == memcmp (&tloc, loc,
192 sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
193 GNUNET_assert (0 == memcmp (&tploc, ploc,
194 sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
195 GNUNET_assert (num_entries == tnum_entries);
196 GNUNET_assert (0 == memcmp (entries, tentries, sizeof (tentries)));
197}
198
199
200static void
201get_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
202{
203 GNUNET_HashCode zone;
204 struct GNUNET_NAMESTORE_SignatureLocation loc;
205
206 memset (&zone, 42, sizeof (zone));
207 loc.depth = (id % 10);
208 loc.offset = (id % 3);
209 loc.revision = id % 1024;
210 GNUNET_assert (GNUNET_OK ==
211 nsp->get_node (nsp->cls,
212 &zone,
213 &loc,
214 &test_node,
215 &id));
216}
217
218
219/**
220 * Function called with the matching signature.
221 *
222 * @param cls closure
223 * @param zone public key of the zone
224 * @param loc location of the root in the B-tree (depth, revision)
225 * @param top_sig signature signing the zone
226 * @param zone_time time the signature was created
227 * @param root_hash top level hash that is being signed
228 */
229static void
230test_signature (void *cls,
231 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
232 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
233 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
234 struct GNUNET_TIME_Absolute zone_time,
235 const GNUNET_HashCode *root_hash)
236{
237 int *idp = cls;
238 int id = *idp;
239 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key;
240 struct GNUNET_NAMESTORE_SignatureLocation tloc;
241 struct GNUNET_CRYPTO_RsaSignature ttop_sig;
242 GNUNET_HashCode troot_hash;
243
244 memset (&tzone_key, 13, sizeof (tzone_key));
245 tloc.depth = (id % 10);
246 tloc.offset = (id % 3);
247 tloc.revision = id % 1024;
248 memset (&ttop_sig, 24, sizeof (ttop_sig));
249 memset (&troot_hash, 42, sizeof (troot_hash));
250
251 GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (GNUNET_HashCode)));
252 GNUNET_assert (0 == memcmp (&tloc, loc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
253 GNUNET_assert (0 == memcmp (&ttop_sig, top_sig, sizeof (struct GNUNET_CRYPTO_RsaSignature)));
254 GNUNET_assert (0 == memcmp (&troot_hash, root_hash, sizeof (GNUNET_HashCode)));
255}
256
257
258static void
259get_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
260{
261 GNUNET_HashCode root_hash;
262
263 memset (&root_hash, 42, sizeof (root_hash));
264 GNUNET_assert (GNUNET_OK ==
265 nsp->get_signature (nsp->cls,
266 &root_hash,
267 test_signature,
268 &id));
269}
270
271
272static void
273put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
274{
275 size_t data_size = id * 17;
276 char data[data_size];
277 GNUNET_HashCode zone;
278 char name[32];
279 uint32_t record_type;
280 struct GNUNET_NAMESTORE_SignatureLocation loc;
281 struct GNUNET_TIME_Absolute expiration;
282 enum GNUNET_NAMESTORE_RecordFlags flags;
283
284 memset (&zone, 42, sizeof (zone));
285 memset (data, id % 255, sizeof (data));
286 GNUNET_snprintf (name, sizeof (name),
287 "aa%u", (unsigned int) id);
288 record_type = id % 4;
289 loc.depth = (id % 10);
290 loc.offset = (id % 3);
291 loc.revision = id % 1024;
292 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
293 flags = GNUNET_NAMESTORE_RF_AUTHORITY;
294
295 GNUNET_assert (GNUNET_OK ==
296 nsp->put_record (nsp->cls,
297 &zone,
298 name,
299 record_type,
300 &loc,
301 expiration,
302 flags,
303 data_size,
304 data));
305}
306
307
308static void
309put_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
310 int id)
311{
312 GNUNET_HashCode zone;
313 struct GNUNET_NAMESTORE_SignatureLocation loc;
314 struct GNUNET_NAMESTORE_SignatureLocation ploc;
315 unsigned int num_entries = 1 + (id % 15);
316 GNUNET_HashCode entries[num_entries];
317 unsigned int i;
318
319 memset (&zone, 42, sizeof (zone));
320 loc.depth = (id % 10);
321 loc.offset = (id % 3);
322 loc.revision = id % 1024;
323 ploc.depth = loc.depth + 1;
324 ploc.offset = (id % 5);
325 ploc.revision = loc.revision;
326 for (i=0;i<num_entries;i++)
327 memset (&entries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
328 GNUNET_assert (GNUNET_OK ==
329 nsp->put_node (nsp->cls,
330 &zone,
331 &loc,
332 &ploc,
333 num_entries,
334 entries));
335}
336
337
338static void
339put_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
340 int id)
341{
342 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
343 struct GNUNET_NAMESTORE_SignatureLocation loc;
344 struct GNUNET_CRYPTO_RsaSignature top_sig;
345 GNUNET_HashCode root_hash;
346 struct GNUNET_TIME_Absolute zone_time;
347
348 memset (&zone_key, 13, sizeof (zone_key));
349 loc.depth = (id % 10);
350 loc.offset = (id % 3);
351 loc.revision = id % 1024;
352 memset (&top_sig, 24, sizeof (top_sig));
353 memset (&root_hash, 42, sizeof (root_hash));
354 zone_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
355
356 GNUNET_assert (GNUNET_OK ==
357 nsp->put_signature (nsp->cls,
358 &zone_key,
359 &loc,
360 &top_sig,
361 &root_hash,
362 zone_time));
363}
364
365
83static void 366static void
84run (void *cls, char *const *args, const char *cfgfile, 367run (void *cls, char *const *args, const char *cfgfile,
85 const struct GNUNET_CONFIGURATION_Handle *cfg) 368 const struct GNUNET_CONFIGURATION_Handle *cfg)
86{ 369{
87 struct GNUNET_NAMESTORE_PluginFunctions *nsp; 370 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
88 371
89 ok = 0; 372 ok = 0;
90 nsp = load_plugin (cfg); 373 nsp = load_plugin (cfg);
91 if (NULL == nsp) 374 if (NULL == nsp)
@@ -95,6 +378,12 @@ run (void *cls, char *const *args, const char *cfgfile,
95 "Failed to initialize namestore. Database likely not setup, skipping test.\n"); 378 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
96 return; 379 return;
97 } 380 }
381 put_record (nsp, 1);
382 get_record (nsp, 1);
383 put_node (nsp, 1);
384 get_node (nsp, 1);
385 put_signature (nsp, 1);
386 get_signature (nsp, 1);
98 387
99 unload_plugin (nsp); 388 unload_plugin (nsp);
100} 389}