diff options
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration_specific_zone.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration_specific_zone.c | 184 |
1 files changed, 64 insertions, 120 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index a4fb320e9..303a7648a 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file namestore/test_namestore_api_zone_iteration_specific_zone.c | 19 | * @file namestore/test_namestore_api_zone_iteration_specific_zone.c |
@@ -26,6 +24,9 @@ | |||
26 | #include "gnunet_namestore_service.h" | 24 | #include "gnunet_namestore_service.h" |
27 | #include "gnunet_testing_lib.h" | 25 | #include "gnunet_testing_lib.h" |
28 | #include "namestore.h" | 26 | #include "namestore.h" |
27 | #include "gnunet_dnsparser_lib.h" | ||
28 | |||
29 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | ||
29 | 30 | ||
30 | 31 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
@@ -57,53 +58,17 @@ static char * s_name_3; | |||
57 | 58 | ||
58 | static struct GNUNET_GNSRECORD_Data *s_rd_3; | 59 | static struct GNUNET_GNSRECORD_Data *s_rd_3; |
59 | 60 | ||
60 | static char *directory; | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Re-establish the connection to the service. | 63 | * Handle timeout. |
64 | * | 64 | * |
65 | * @param cls handle to use to re-connect. | 65 | * @param cls handle to use to re-connect. |
66 | * @param tc scheduler context | ||
67 | */ | 66 | */ |
68 | static void | 67 | static void |
69 | endbadly (void *cls) | 68 | endbadly (void *cls) |
70 | { | 69 | { |
71 | if (NULL != zi) | 70 | endbadly_task = NULL; |
72 | { | 71 | GNUNET_SCHEDULER_shutdown (); |
73 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | ||
74 | zi = NULL; | ||
75 | } | ||
76 | if (nsh != NULL) | ||
77 | GNUNET_NAMESTORE_disconnect (nsh); | ||
78 | nsh = NULL; | ||
79 | |||
80 | GNUNET_free_non_null(s_name_1); | ||
81 | GNUNET_free_non_null(s_name_2); | ||
82 | GNUNET_free_non_null(s_name_3); | ||
83 | |||
84 | if (s_rd_1 != NULL) | ||
85 | { | ||
86 | GNUNET_free ((void *)s_rd_1->data); | ||
87 | GNUNET_free (s_rd_1); | ||
88 | } | ||
89 | if (s_rd_2 != NULL) | ||
90 | { | ||
91 | GNUNET_free ((void *)s_rd_2->data); | ||
92 | GNUNET_free (s_rd_2); | ||
93 | } | ||
94 | if (s_rd_3 != NULL) | ||
95 | { | ||
96 | GNUNET_free ((void *)s_rd_3->data); | ||
97 | GNUNET_free (s_rd_3); | ||
98 | } | ||
99 | |||
100 | if (privkey != NULL) | ||
101 | GNUNET_free (privkey); | ||
102 | privkey = NULL; | ||
103 | |||
104 | if (privkey2 != NULL) | ||
105 | GNUNET_free (privkey2); | ||
106 | privkey2 = NULL; | ||
107 | res = 1; | 72 | res = 1; |
108 | } | 73 | } |
109 | 74 | ||
@@ -116,21 +81,21 @@ end (void *cls) | |||
116 | GNUNET_NAMESTORE_zone_iteration_stop (zi); | 81 | GNUNET_NAMESTORE_zone_iteration_stop (zi); |
117 | zi = NULL; | 82 | zi = NULL; |
118 | } | 83 | } |
119 | 84 | if (NULL != endbadly_task) | |
120 | if (endbadly_task != NULL) | ||
121 | { | 85 | { |
122 | GNUNET_SCHEDULER_cancel (endbadly_task); | 86 | GNUNET_SCHEDULER_cancel (endbadly_task); |
123 | endbadly_task = NULL; | 87 | endbadly_task = NULL; |
124 | } | 88 | } |
125 | 89 | if (NULL != privkey) | |
126 | if (privkey != NULL) | 90 | { |
127 | GNUNET_free (privkey); | 91 | GNUNET_free (privkey); |
128 | privkey = NULL; | 92 | privkey = NULL; |
129 | 93 | } | |
130 | if (privkey2 != NULL) | 94 | if (NULL != privkey2) |
95 | { | ||
131 | GNUNET_free (privkey2); | 96 | GNUNET_free (privkey2); |
132 | privkey2 = NULL; | 97 | privkey2 = NULL; |
133 | 98 | } | |
134 | GNUNET_free (s_name_1); | 99 | GNUNET_free (s_name_1); |
135 | GNUNET_free (s_name_2); | 100 | GNUNET_free (s_name_2); |
136 | GNUNET_free (s_name_3); | 101 | GNUNET_free (s_name_3); |
@@ -150,8 +115,10 @@ end (void *cls) | |||
150 | GNUNET_free (s_rd_3); | 115 | GNUNET_free (s_rd_3); |
151 | } | 116 | } |
152 | if (nsh != NULL) | 117 | if (nsh != NULL) |
118 | { | ||
153 | GNUNET_NAMESTORE_disconnect (nsh); | 119 | GNUNET_NAMESTORE_disconnect (nsh); |
154 | nsh = NULL; | 120 | nsh = NULL; |
121 | } | ||
155 | } | 122 | } |
156 | 123 | ||
157 | 124 | ||
@@ -159,6 +126,7 @@ static void | |||
159 | fail_cb (void *cls) | 126 | fail_cb (void *cls) |
160 | { | 127 | { |
161 | GNUNET_assert (0); | 128 | GNUNET_assert (0); |
129 | zi = NULL; | ||
162 | } | 130 | } |
163 | 131 | ||
164 | 132 | ||
@@ -244,7 +212,8 @@ zone_proc (void *cls, | |||
244 | else | 212 | else |
245 | { | 213 | { |
246 | GNUNET_break (0); | 214 | GNUNET_break (0); |
247 | GNUNET_SCHEDULER_add_now (&end, NULL); | 215 | res = 2; |
216 | GNUNET_SCHEDULER_shutdown (); | ||
248 | } | 217 | } |
249 | } | 218 | } |
250 | 219 | ||
@@ -252,24 +221,28 @@ zone_proc (void *cls, | |||
252 | static void | 221 | static void |
253 | zone_proc_end (void *cls) | 222 | zone_proc_end (void *cls) |
254 | { | 223 | { |
224 | zi = NULL; | ||
255 | GNUNET_break (2 == returned_records); | 225 | GNUNET_break (2 == returned_records); |
256 | if (2 == returned_records) | 226 | if (2 == returned_records) |
257 | { | 227 | { |
258 | res = 0; /* Last iteraterator callback, we are done */ | 228 | res = 0; /* Last iteraterator callback, we are done */ |
259 | zi = NULL; | ||
260 | } | 229 | } |
261 | else | 230 | else |
231 | { | ||
262 | res = 1; | 232 | res = 1; |
233 | } | ||
263 | 234 | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
265 | "Received last result, iteration done after receing %u results\n", | 236 | "Received last result, iteration done after receing %u results\n", |
266 | returned_records); | 237 | returned_records); |
267 | GNUNET_SCHEDULER_add_now (&end, NULL); | 238 | GNUNET_SCHEDULER_shutdown (); |
268 | } | 239 | } |
269 | 240 | ||
270 | 241 | ||
271 | static void | 242 | static void |
272 | put_cont (void *cls, int32_t success, const char *emsg) | 243 | put_cont (void *cls, |
244 | int32_t success, | ||
245 | const char *emsg) | ||
273 | { | 246 | { |
274 | static int c = 0; | 247 | static int c = 0; |
275 | 248 | ||
@@ -285,9 +258,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
285 | "Failed to created records: `%s'\n", | 258 | "Failed to created records: `%s'\n", |
286 | emsg); | 259 | emsg); |
287 | GNUNET_break (0); | 260 | GNUNET_break (0); |
288 | if (NULL != endbadly_task) | 261 | res = 2; |
289 | GNUNET_SCHEDULER_cancel (endbadly_task); | 262 | GNUNET_SCHEDULER_shutdown (); |
290 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
291 | return; | 263 | return; |
292 | } | 264 | } |
293 | 265 | ||
@@ -310,9 +282,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
310 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 282 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
311 | "Failed to create zone iterator\n"); | 283 | "Failed to create zone iterator\n"); |
312 | GNUNET_break (0); | 284 | GNUNET_break (0); |
313 | if (NULL != endbadly_task) | 285 | res = 2; |
314 | GNUNET_SCHEDULER_cancel (endbadly_task); | 286 | GNUNET_SCHEDULER_shutdown (); |
315 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
316 | return; | 287 | return; |
317 | } | 288 | } |
318 | } | 289 | } |
@@ -322,14 +293,14 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
322 | static struct GNUNET_GNSRECORD_Data * | 293 | static struct GNUNET_GNSRECORD_Data * |
323 | create_record (unsigned int count) | 294 | create_record (unsigned int count) |
324 | { | 295 | { |
325 | unsigned int c; | 296 | struct GNUNET_GNSRECORD_Data *rd; |
326 | struct GNUNET_GNSRECORD_Data * rd; | ||
327 | 297 | ||
328 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 298 | rd = GNUNET_new_array (count, |
329 | for (c = 0; c < count; c++) | 299 | struct GNUNET_GNSRECORD_Data); |
300 | for (unsigned int c = 0; c < count; c++) | ||
330 | { | 301 | { |
331 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; | 302 | rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; |
332 | rd[c].record_type = 1111; | 303 | rd[c].record_type = TEST_RECORD_TYPE; |
333 | rd[c].data_size = 50; | 304 | rd[c].data_size = 50; |
334 | rd[c].data = GNUNET_malloc(50); | 305 | rd[c].data = GNUNET_malloc(50); |
335 | rd[c].flags = 0; | 306 | rd[c].flags = 0; |
@@ -357,9 +328,8 @@ empty_zone_proc (void *cls, | |||
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
358 | _("Expected empty zone but received zone private key\n")); | 329 | _("Expected empty zone but received zone private key\n")); |
359 | GNUNET_break (0); | 330 | GNUNET_break (0); |
360 | if (endbadly_task != NULL) | 331 | res = 2; |
361 | GNUNET_SCHEDULER_cancel (endbadly_task); | 332 | GNUNET_SCHEDULER_shutdown (); |
362 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
363 | return; | 333 | return; |
364 | } | 334 | } |
365 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) | 335 | if ((NULL != label) || (NULL != rd) || (0 != rd_count)) |
@@ -367,9 +337,8 @@ empty_zone_proc (void *cls, | |||
367 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 337 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
368 | _("Expected no zone content but received data\n")); | 338 | _("Expected no zone content but received data\n")); |
369 | GNUNET_break (0); | 339 | GNUNET_break (0); |
370 | if (endbadly_task != NULL) | 340 | res = 2; |
371 | GNUNET_SCHEDULER_cancel (endbadly_task); | 341 | GNUNET_SCHEDULER_shutdown (); |
372 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
373 | return; | 342 | return; |
374 | } | 343 | } |
375 | GNUNET_assert (0); | 344 | GNUNET_assert (0); |
@@ -379,35 +348,16 @@ empty_zone_proc (void *cls, | |||
379 | static void | 348 | static void |
380 | empty_zone_proc_end (void *cls) | 349 | empty_zone_proc_end (void *cls) |
381 | { | 350 | { |
382 | char *hostkey_file; | ||
383 | |||
384 | zi = NULL; | 351 | zi = NULL; |
385 | GNUNET_asprintf (&hostkey_file, | 352 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
386 | "zonefiles%s%s", | ||
387 | DIR_SEPARATOR_STR, | ||
388 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
390 | "Using zonekey file `%s'\n", | ||
391 | hostkey_file); | ||
392 | privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file); | ||
393 | GNUNET_free (hostkey_file); | ||
394 | GNUNET_assert (privkey != NULL); | 353 | GNUNET_assert (privkey != NULL); |
395 | 354 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); | |
396 | GNUNET_asprintf(&hostkey_file, | ||
397 | "zonefiles%s%s", | ||
398 | DIR_SEPARATOR_STR, | ||
399 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
401 | "Using zonekey file `%s' \n", | ||
402 | hostkey_file); | ||
403 | privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); | ||
404 | GNUNET_free (hostkey_file); | ||
405 | GNUNET_assert (privkey2 != NULL); | 355 | GNUNET_assert (privkey2 != NULL); |
406 | 356 | ||
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
408 | "Created record 1\n"); | 358 | "Created record 1\n"); |
409 | 359 | GNUNET_asprintf (&s_name_1, | |
410 | GNUNET_asprintf(&s_name_1, "dummy1"); | 360 | "dummy1"); |
411 | s_rd_1 = create_record (1); | 361 | s_rd_1 = create_record (1); |
412 | GNUNET_NAMESTORE_records_store (nsh, | 362 | GNUNET_NAMESTORE_records_store (nsh, |
413 | privkey, | 363 | privkey, |
@@ -419,7 +369,8 @@ empty_zone_proc_end (void *cls) | |||
419 | 369 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
421 | "Created record 2 \n"); | 371 | "Created record 2 \n"); |
422 | GNUNET_asprintf(&s_name_2, "dummy2"); | 372 | GNUNET_asprintf (&s_name_2, |
373 | "dummy2"); | ||
423 | s_rd_2 = create_record (1); | 374 | s_rd_2 = create_record (1); |
424 | GNUNET_NAMESTORE_records_store (nsh, | 375 | GNUNET_NAMESTORE_records_store (nsh, |
425 | privkey, | 376 | privkey, |
@@ -433,7 +384,8 @@ empty_zone_proc_end (void *cls) | |||
433 | "Created record 3\n"); | 384 | "Created record 3\n"); |
434 | 385 | ||
435 | /* name in different zone */ | 386 | /* name in different zone */ |
436 | GNUNET_asprintf(&s_name_3, "dummy3"); | 387 | GNUNET_asprintf (&s_name_3, |
388 | "dummy3"); | ||
437 | s_rd_3 = create_record (1); | 389 | s_rd_3 = create_record (1); |
438 | GNUNET_NAMESTORE_records_store (nsh, | 390 | GNUNET_NAMESTORE_records_store (nsh, |
439 | privkey2, | 391 | privkey2, |
@@ -449,14 +401,8 @@ run (void *cls, | |||
449 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 401 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
450 | struct GNUNET_TESTING_Peer *peer) | 402 | struct GNUNET_TESTING_Peer *peer) |
451 | { | 403 | { |
452 | directory = NULL; | 404 | GNUNET_SCHEDULER_add_shutdown (&end, |
453 | GNUNET_assert (GNUNET_OK == | 405 | NULL); |
454 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
455 | "PATHS", | ||
456 | "GNUNET_TEST_HOME", | ||
457 | &directory)); | ||
458 | GNUNET_DISK_directory_remove (directory); | ||
459 | |||
460 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 406 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
461 | &endbadly, | 407 | &endbadly, |
462 | NULL); | 408 | NULL); |
@@ -476,8 +422,7 @@ run (void *cls, | |||
476 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
477 | "Failed to create zone iterator\n"); | 423 | "Failed to create zone iterator\n"); |
478 | GNUNET_break (0); | 424 | GNUNET_break (0); |
479 | GNUNET_SCHEDULER_cancel (endbadly_task); | 425 | GNUNET_SCHEDULER_shutdown (); |
480 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
481 | } | 426 | } |
482 | } | 427 | } |
483 | 428 | ||
@@ -493,6 +438,8 @@ main (int argc, char *argv[]) | |||
493 | "test_namestore_api_%s.conf", | 438 | "test_namestore_api_%s.conf", |
494 | plugin_name); | 439 | plugin_name); |
495 | res = 1; | 440 | res = 1; |
441 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
442 | "GNUNET_TEST_HOME"); | ||
496 | if (0 != | 443 | if (0 != |
497 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", | 444 | GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", |
498 | cfg_name, | 445 | cfg_name, |
@@ -501,12 +448,9 @@ main (int argc, char *argv[]) | |||
501 | { | 448 | { |
502 | res = 1; | 449 | res = 1; |
503 | } | 450 | } |
451 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
452 | "GNUNET_TEST_HOME"); | ||
504 | GNUNET_free (cfg_name); | 453 | GNUNET_free (cfg_name); |
505 | if (NULL != directory) | ||
506 | { | ||
507 | GNUNET_DISK_directory_remove (directory); | ||
508 | GNUNET_free (directory); | ||
509 | } | ||
510 | return res; | 454 | return res; |
511 | } | 455 | } |
512 | 456 | ||