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 | 158 |
1 files changed, 47 insertions, 111 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 b21c860c8..b76acb4dd 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -23,68 +23,56 @@ | |||
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_testing_lib-new.h" | ||
26 | #include "gnunet_namestore_service.h" | 27 | #include "gnunet_namestore_service.h" |
27 | #include "namestore.h" | 28 | #include "namestore.h" |
28 | 29 | ||
29 | #define VERBOSE GNUNET_NO | ||
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
32 | 32 | ||
33 | |||
33 | static struct GNUNET_NAMESTORE_Handle * nsh; | 34 | static struct GNUNET_NAMESTORE_Handle * nsh; |
34 | 35 | ||
35 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 36 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
37 | |||
36 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; | 38 | static GNUNET_SCHEDULER_TaskIdentifier stopiteration_task; |
37 | static struct GNUNET_OS_Process *arm; | ||
38 | 39 | ||
39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 40 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
41 | |||
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 42 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
43 | |||
41 | static struct GNUNET_CRYPTO_ShortHashCode zone; | 44 | static struct GNUNET_CRYPTO_ShortHashCode zone; |
42 | 45 | ||
43 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; | 46 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; |
47 | |||
44 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; | 48 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; |
49 | |||
45 | static struct GNUNET_CRYPTO_ShortHashCode zone2; | 50 | static struct GNUNET_CRYPTO_ShortHashCode zone2; |
46 | 51 | ||
47 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 52 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
53 | |||
48 | static int res; | 54 | static int res; |
55 | |||
49 | static int returned_records; | 56 | static int returned_records; |
50 | 57 | ||
51 | struct GNUNET_CRYPTO_RsaSignature *sig_1; | 58 | static struct GNUNET_CRYPTO_RsaSignature *sig_1; |
52 | char * s_name_1; | ||
53 | struct GNUNET_NAMESTORE_RecordData *s_rd_1; | ||
54 | 59 | ||
55 | struct GNUNET_CRYPTO_RsaSignature *sig_2; | 60 | static char * s_name_1; |
56 | char * s_name_2; | ||
57 | struct GNUNET_NAMESTORE_RecordData *s_rd_2; | ||
58 | 61 | ||
59 | struct GNUNET_CRYPTO_RsaSignature *sig_3; | 62 | static struct GNUNET_NAMESTORE_RecordData *s_rd_1; |
60 | char * s_name_3; | ||
61 | struct GNUNET_NAMESTORE_RecordData *s_rd_3; | ||
62 | 63 | ||
63 | static void | 64 | static struct GNUNET_CRYPTO_RsaSignature *sig_2; |
64 | start_arm (const char *cfgname) | 65 | |
65 | { | 66 | static char * s_name_2; |
66 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | 67 | |
67 | "gnunet-service-arm", "-c", cfgname, | 68 | static struct GNUNET_NAMESTORE_RecordData *s_rd_2; |
68 | #if VERBOSE_PEERS | 69 | |
69 | "-L", "DEBUG", | 70 | static struct GNUNET_CRYPTO_RsaSignature *sig_3; |
70 | #else | 71 | |
71 | "-L", "ERROR", | 72 | static char * s_name_3; |
72 | #endif | 73 | |
73 | NULL); | 74 | static struct GNUNET_NAMESTORE_RecordData *s_rd_3; |
74 | } | ||
75 | 75 | ||
76 | static void | ||
77 | stop_arm () | ||
78 | { | ||
79 | if (NULL != arm) | ||
80 | { | ||
81 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
82 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
83 | GNUNET_OS_process_wait (arm); | ||
84 | GNUNET_OS_process_destroy (arm); | ||
85 | arm = NULL; | ||
86 | } | ||
87 | } | ||
88 | 76 | ||
89 | /** | 77 | /** |
90 | * Re-establish the connection to the service. | 78 | * Re-establish the connection to the service. |
@@ -104,14 +92,12 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
104 | if (nsh != NULL) | 92 | if (nsh != NULL) |
105 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 93 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
106 | nsh = NULL; | 94 | nsh = NULL; |
107 | |||
108 | GNUNET_free_non_null(sig_1); | 95 | GNUNET_free_non_null(sig_1); |
109 | GNUNET_free_non_null(sig_2); | 96 | GNUNET_free_non_null(sig_2); |
110 | GNUNET_free_non_null(sig_3); | 97 | GNUNET_free_non_null(sig_3); |
111 | GNUNET_free_non_null(s_name_1); | 98 | GNUNET_free_non_null(s_name_1); |
112 | GNUNET_free_non_null(s_name_2); | 99 | GNUNET_free_non_null(s_name_2); |
113 | GNUNET_free_non_null(s_name_3); | 100 | GNUNET_free_non_null(s_name_3); |
114 | |||
115 | if (s_rd_1 != NULL) | 101 | if (s_rd_1 != NULL) |
116 | { | 102 | { |
117 | GNUNET_free ((void *)s_rd_1->data); | 103 | GNUNET_free ((void *)s_rd_1->data); |
@@ -135,10 +121,6 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | if (privkey2 != NULL) | 121 | if (privkey2 != NULL) |
136 | GNUNET_CRYPTO_rsa_key_free (privkey2); | 122 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
137 | privkey2 = NULL; | 123 | privkey2 = NULL; |
138 | |||
139 | if (NULL != arm) | ||
140 | stop_arm(); | ||
141 | |||
142 | res = 1; | 124 | res = 1; |
143 | } | 125 | } |
144 | 126 | ||
@@ -151,17 +133,14 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
151 | GNUNET_SCHEDULER_cancel (stopiteration_task); | 133 | GNUNET_SCHEDULER_cancel (stopiteration_task); |
152 | stopiteration_task = GNUNET_SCHEDULER_NO_TASK; | 134 | stopiteration_task = GNUNET_SCHEDULER_NO_TASK; |
153 | } | 135 | } |
154 | |||
155 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 136 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
156 | { | 137 | { |
157 | GNUNET_SCHEDULER_cancel (endbadly_task); | 138 | GNUNET_SCHEDULER_cancel (endbadly_task); |
158 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 139 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
159 | } | 140 | } |
160 | |||
161 | if (privkey != NULL) | 141 | if (privkey != NULL) |
162 | GNUNET_CRYPTO_rsa_key_free (privkey); | 142 | GNUNET_CRYPTO_rsa_key_free (privkey); |
163 | privkey = NULL; | 143 | privkey = NULL; |
164 | |||
165 | if (privkey2 != NULL) | 144 | if (privkey2 != NULL) |
166 | GNUNET_CRYPTO_rsa_key_free (privkey2); | 145 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
167 | privkey2 = NULL; | 146 | privkey2 = NULL; |
@@ -187,23 +166,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
187 | GNUNET_free ((void *)s_rd_3->data); | 166 | GNUNET_free ((void *)s_rd_3->data); |
188 | GNUNET_free (s_rd_3); | 167 | GNUNET_free (s_rd_3); |
189 | } | 168 | } |
190 | |||
191 | if (nsh != NULL) | 169 | if (nsh != NULL) |
192 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 170 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
193 | nsh = NULL; | 171 | nsh = NULL; |
194 | |||
195 | |||
196 | if (NULL != arm) | ||
197 | stop_arm(); | ||
198 | } | 172 | } |
199 | 173 | ||
200 | void zone_proc (void *cls, | 174 | |
201 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 175 | static void |
202 | struct GNUNET_TIME_Absolute expire, | 176 | zone_proc (void *cls, |
203 | const char *name, | 177 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
204 | unsigned int rd_count, | 178 | struct GNUNET_TIME_Absolute expire, |
205 | const struct GNUNET_NAMESTORE_RecordData *rd, | 179 | const char *name, |
206 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 180 | unsigned int rd_count, |
181 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
182 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
207 | { | 183 | { |
208 | int failed = GNUNET_NO; | 184 | int failed = GNUNET_NO; |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_short_h2s (&zone)); | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_short_h2s (&zone)); |
@@ -285,25 +261,8 @@ void zone_proc (void *cls, | |||
285 | } | 261 | } |
286 | } | 262 | } |
287 | 263 | ||
288 | void | ||
289 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
290 | { | ||
291 | char *afsdir; | ||
292 | |||
293 | if (GNUNET_OK == | ||
294 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
295 | "FILENAME", &afsdir)) | ||
296 | { | ||
297 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
298 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
299 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
301 | GNUNET_free (afsdir); | ||
302 | } | ||
303 | |||
304 | } | ||
305 | 264 | ||
306 | void | 265 | static void |
307 | put_cont (void *cls, int32_t success, const char *emsg) | 266 | put_cont (void *cls, int32_t success, const char *emsg) |
308 | { | 267 | { |
309 | static int c = 0; | 268 | static int c = 0; |
@@ -343,6 +302,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
343 | } | 302 | } |
344 | } | 303 | } |
345 | 304 | ||
305 | |||
346 | static struct GNUNET_NAMESTORE_RecordData * | 306 | static struct GNUNET_NAMESTORE_RecordData * |
347 | create_record (int count) | 307 | create_record (int count) |
348 | { | 308 | { |
@@ -361,14 +321,14 @@ create_record (int count) | |||
361 | return rd; | 321 | return rd; |
362 | } | 322 | } |
363 | 323 | ||
324 | |||
364 | static void | 325 | static void |
365 | run (void *cls, char *const *args, const char *cfgfile, | 326 | run (void *cls, |
366 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 327 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
367 | { | 328 | { |
368 | delete_existing_db(cfg); | ||
369 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
370 | |||
371 | char *hostkey_file; | 329 | char *hostkey_file; |
330 | |||
331 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); | ||
372 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 332 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, |
373 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 333 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); |
@@ -386,26 +346,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
386 | GNUNET_assert (privkey2 != NULL); | 346 | GNUNET_assert (privkey2 != NULL); |
387 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); | 347 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); |
388 | GNUNET_CRYPTO_short_hash (&pubkey2, sizeof (pubkey), &zone2); | 348 | GNUNET_CRYPTO_short_hash (&pubkey2, sizeof (pubkey), &zone2); |
389 | |||
390 | |||
391 | start_arm (cfgfile); | ||
392 | GNUNET_assert (arm != NULL); | ||
393 | |||
394 | nsh = GNUNET_NAMESTORE_connect (cfg); | 349 | nsh = GNUNET_NAMESTORE_connect (cfg); |
395 | GNUNET_break (NULL != nsh); | 350 | GNUNET_break (NULL != nsh); |
396 | 351 | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
398 | |||
399 | GNUNET_asprintf(&s_name_1, "dummy1"); | 353 | GNUNET_asprintf(&s_name_1, "dummy1"); |
400 | s_rd_1 = create_record(1); | 354 | s_rd_1 = create_record(1); |
401 | sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_1[0].expiration ,s_name_1, s_rd_1, 1); | 355 | sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_1[0].expiration ,s_name_1, s_rd_1, 1); |
402 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL); | 356 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL); |
403 | 357 | ||
404 | |||
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); | 358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); |
406 | GNUNET_asprintf(&s_name_2, "dummy2"); | 359 | GNUNET_asprintf(&s_name_2, "dummy2"); |
407 | s_rd_2 = create_record(1); | 360 | s_rd_2 = create_record(1); |
408 | |||
409 | sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_2[0].expiration, s_name_2, s_rd_2, 1); | 361 | sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_rd_2[0].expiration, s_name_2, s_rd_2, 1); |
410 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); | 362 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); |
411 | 363 | ||
@@ -417,35 +369,19 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
417 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); | 369 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); |
418 | } | 370 | } |
419 | 371 | ||
420 | static int | ||
421 | check () | ||
422 | { | ||
423 | static char *const argv[] = { "test_namestore_api_zone_iteration", | ||
424 | "-c", | ||
425 | "test_namestore_api.conf", | ||
426 | #if VERBOSE | ||
427 | "-L", "DEBUG", | ||
428 | #endif | ||
429 | NULL | ||
430 | }; | ||
431 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
432 | GNUNET_GETOPT_OPTION_END | ||
433 | }; | ||
434 | |||
435 | res = 1; | ||
436 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test_namestore_api_zone_iteration", | ||
437 | "nohelp", options, &run, &res); | ||
438 | return res; | ||
439 | } | ||
440 | 372 | ||
441 | int | 373 | int |
442 | main (int argc, char *argv[]) | 374 | main (int argc, char *argv[]) |
443 | { | 375 | { |
444 | int ret; | 376 | res = 1; |
445 | 377 | if (0 != | |
446 | ret = check (); | 378 | GNUNET_TESTING_service_run ("test-namestore-api-zone-iteration-specific-zone", |
447 | 379 | "namestore", | |
448 | return ret; | 380 | "test_namestore_api.conf", |
381 | &run, | ||
382 | NULL)) | ||
383 | return 1; | ||
384 | return res; | ||
449 | } | 385 | } |
450 | 386 | ||
451 | /* end of test_namestore_api_zone_iteration_specific_zone.c */ | 387 | /* end of test_namestore_api_zone_iteration_specific_zone.c */ |