diff options
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_specific_type.c')
-rw-r--r-- | src/namestore/test_namestore_api_lookup_specific_type.c | 198 |
1 files changed, 65 insertions, 133 deletions
diff --git a/src/namestore/test_namestore_api_lookup_specific_type.c b/src/namestore/test_namestore_api_lookup_specific_type.c index 981e252de..e2ac2588d 100644 --- a/src/namestore/test_namestore_api_lookup_specific_type.c +++ b/src/namestore/test_namestore_api_lookup_specific_type.c | |||
@@ -24,62 +24,44 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
27 | #include "gnunet_testing_lib-new.h" | ||
27 | #include "namestore.h" | 28 | #include "namestore.h" |
28 | #include "gnunet_signatures.h" | 29 | #include "gnunet_signatures.h" |
29 | 30 | ||
30 | #define VERBOSE GNUNET_NO | ||
31 | 31 | ||
32 | #define RECORDS 5 | 32 | #define RECORDS 5 |
33 | |||
33 | #define TEST_RECORD_TYPE 1234 | 34 | #define TEST_RECORD_TYPE 1234 |
35 | |||
34 | #define TEST_RECORD_DATALEN 123 | 36 | #define TEST_RECORD_DATALEN 123 |
37 | |||
35 | #define TEST_RECORD_DATA 'a' | 38 | #define TEST_RECORD_DATA 'a' |
36 | 39 | ||
37 | #define TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING 11111 | 40 | #define TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING 11111 |
41 | |||
38 | #define TEST_RECORD_LOOKUP_TYPE_EXISTING 22222 | 42 | #define TEST_RECORD_LOOKUP_TYPE_EXISTING 22222 |
39 | 43 | ||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
41 | 45 | ||
46 | |||
42 | static struct GNUNET_NAMESTORE_Handle * nsh; | 47 | static struct GNUNET_NAMESTORE_Handle * nsh; |
43 | 48 | ||
44 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 49 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
45 | static struct GNUNET_OS_Process *arm; | ||
46 | 50 | ||
47 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 51 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
52 | |||
48 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 53 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
49 | struct GNUNET_CRYPTO_RsaSignature *s_signature; | 54 | |
55 | static struct GNUNET_CRYPTO_RsaSignature *s_signature; | ||
56 | |||
50 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; | 57 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; |
51 | struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
52 | static char *s_name; | ||
53 | 58 | ||
59 | static struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
54 | 60 | ||
61 | static char *s_name; | ||
55 | 62 | ||
56 | static int res; | 63 | static int res; |
57 | 64 | ||
58 | static void | ||
59 | start_arm (const char *cfgname) | ||
60 | { | ||
61 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
62 | "gnunet-service-arm", "-c", cfgname, | ||
63 | #if VERBOSE_PEERS | ||
64 | "-L", "DEBUG", | ||
65 | #else | ||
66 | "-L", "ERROR", | ||
67 | #endif | ||
68 | NULL); | ||
69 | } | ||
70 | |||
71 | static void | ||
72 | stop_arm () | ||
73 | { | ||
74 | if (NULL != arm) | ||
75 | { | ||
76 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
77 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
78 | GNUNET_OS_process_wait (arm); | ||
79 | GNUNET_OS_process_destroy (arm); | ||
80 | arm = NULL; | ||
81 | } | ||
82 | } | ||
83 | 65 | ||
84 | /** | 66 | /** |
85 | * Re-establish the connection to the service. | 67 | * Re-establish the connection to the service. |
@@ -93,14 +75,9 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
93 | if (nsh != NULL) | 75 | if (nsh != NULL) |
94 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 76 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
95 | nsh = NULL; | 77 | nsh = NULL; |
96 | |||
97 | if (privkey != NULL) | 78 | if (privkey != NULL) |
98 | GNUNET_CRYPTO_rsa_key_free (privkey); | 79 | GNUNET_CRYPTO_rsa_key_free (privkey); |
99 | privkey = NULL; | 80 | privkey = NULL; |
100 | |||
101 | if (NULL != arm) | ||
102 | stop_arm(); | ||
103 | |||
104 | res = 1; | 81 | res = 1; |
105 | } | 82 | } |
106 | 83 | ||
@@ -108,13 +85,13 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | static void | 85 | static void |
109 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 86 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | { | 87 | { |
88 | int c; | ||
89 | |||
111 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | 90 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) |
112 | { | 91 | { |
113 | GNUNET_SCHEDULER_cancel (endbadly_task); | 92 | GNUNET_SCHEDULER_cancel (endbadly_task); |
114 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 93 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 94 | } |
116 | |||
117 | int c; | ||
118 | for (c = 0; c < RECORDS; c++) | 95 | for (c = 0; c < RECORDS; c++) |
119 | { | 96 | { |
120 | GNUNET_free_non_null((void *) s_rd[c].data); | 97 | GNUNET_free_non_null((void *) s_rd[c].data); |
@@ -124,23 +101,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
124 | if (privkey != NULL) | 101 | if (privkey != NULL) |
125 | GNUNET_CRYPTO_rsa_key_free (privkey); | 102 | GNUNET_CRYPTO_rsa_key_free (privkey); |
126 | privkey = NULL; | 103 | privkey = NULL; |
127 | |||
128 | if (nsh != NULL) | 104 | if (nsh != NULL) |
129 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 105 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
130 | nsh = NULL; | 106 | nsh = NULL; |
131 | |||
132 | if (NULL != arm) | ||
133 | stop_arm(); | ||
134 | } | 107 | } |
135 | 108 | ||
136 | 109 | ||
137 | void name_lookup_existing_record_type (void *cls, | 110 | static void |
138 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 111 | name_lookup_existing_record_type (void *cls, |
139 | struct GNUNET_TIME_Absolute expire, | 112 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
140 | const char *n, | 113 | struct GNUNET_TIME_Absolute expire, |
141 | unsigned int rd_count, | 114 | const char *n, |
142 | const struct GNUNET_NAMESTORE_RecordData *rd, | 115 | unsigned int rd_count, |
143 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 116 | const struct GNUNET_NAMESTORE_RecordData *rd, |
117 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
144 | { | 118 | { |
145 | int failed = GNUNET_NO; | 119 | int failed = GNUNET_NO; |
146 | 120 | ||
@@ -171,7 +145,6 @@ void name_lookup_existing_record_type (void *cls, | |||
171 | GNUNET_break(0); | 145 | GNUNET_break(0); |
172 | failed = GNUNET_YES; | 146 | failed = GNUNET_YES; |
173 | } | 147 | } |
174 | |||
175 | if (failed == GNUNET_YES) | 148 | if (failed == GNUNET_YES) |
176 | { | 149 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore returned invalid response\n"); | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore returned invalid response\n"); |
@@ -181,18 +154,18 @@ void name_lookup_existing_record_type (void *cls, | |||
181 | { | 154 | { |
182 | res = 0; | 155 | res = 0; |
183 | } | 156 | } |
184 | |||
185 | GNUNET_SCHEDULER_add_now(&end, NULL); | 157 | GNUNET_SCHEDULER_add_now(&end, NULL); |
186 | } | 158 | } |
187 | 159 | ||
188 | 160 | ||
189 | void name_lookup_non_existing_record_type (void *cls, | 161 | static void |
190 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 162 | name_lookup_non_existing_record_type (void *cls, |
191 | struct GNUNET_TIME_Absolute expire, | 163 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
192 | const char *n, | 164 | struct GNUNET_TIME_Absolute expire, |
193 | unsigned int rd_count, | 165 | const char *n, |
194 | const struct GNUNET_NAMESTORE_RecordData *rd, | 166 | unsigned int rd_count, |
195 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 167 | const struct GNUNET_NAMESTORE_RecordData *rd, |
168 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
196 | { | 169 | { |
197 | int failed = GNUNET_NO; | 170 | int failed = GNUNET_NO; |
198 | /* We expect zone key != NULL, name != NULL, rd_count 0, rd NULL, signature NULL */ | 171 | /* We expect zone key != NULL, name != NULL, rd_count 0, rd NULL, signature NULL */ |
@@ -250,7 +223,8 @@ void name_lookup_non_existing_record_type (void *cls, | |||
250 | } | 223 | } |
251 | } | 224 | } |
252 | 225 | ||
253 | void | 226 | |
227 | static void | ||
254 | put_cont (void *cls, int32_t success, const char *emsg) | 228 | put_cont (void *cls, int32_t success, const char *emsg) |
255 | { | 229 | { |
256 | char * name = cls; | 230 | char * name = cls; |
@@ -270,13 +244,14 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
270 | } | 244 | } |
271 | } | 245 | } |
272 | 246 | ||
247 | |||
273 | static struct GNUNET_NAMESTORE_RecordData * | 248 | static struct GNUNET_NAMESTORE_RecordData * |
274 | create_record (int count) | 249 | create_record (int count) |
275 | { | 250 | { |
276 | int c; | 251 | int c; |
277 | struct GNUNET_NAMESTORE_RecordData * rd; | 252 | struct GNUNET_NAMESTORE_RecordData * rd; |
278 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
279 | 253 | ||
254 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
280 | for (c = 0; c < RECORDS-1; c++) | 255 | for (c = 0; c < RECORDS-1; c++) |
281 | { | 256 | { |
282 | rd[c].expiration = GNUNET_TIME_UNIT_ZERO_ABS; | 257 | rd[c].expiration = GNUNET_TIME_UNIT_ZERO_ABS; |
@@ -285,46 +260,25 @@ create_record (int count) | |||
285 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 260 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); |
286 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 261 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); |
287 | } | 262 | } |
288 | |||
289 | rd[c].expiration = GNUNET_TIME_absolute_get(); | 263 | rd[c].expiration = GNUNET_TIME_absolute_get(); |
290 | rd[c].record_type = TEST_RECORD_LOOKUP_TYPE_EXISTING; | 264 | rd[c].record_type = TEST_RECORD_LOOKUP_TYPE_EXISTING; |
291 | rd[c].data_size = TEST_RECORD_DATALEN; | 265 | rd[c].data_size = TEST_RECORD_DATALEN; |
292 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | 266 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); |
293 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | 267 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); |
294 | 268 | ||
295 | |||
296 | return rd; | 269 | return rd; |
297 | } | 270 | } |
298 | 271 | ||
299 | void | ||
300 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
301 | { | ||
302 | char *afsdir; | ||
303 | |||
304 | if (GNUNET_OK == | ||
305 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
306 | "FILENAME", &afsdir)) | ||
307 | { | ||
308 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
309 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
310 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
312 | GNUNET_free (afsdir); | ||
313 | } | ||
314 | |||
315 | } | ||
316 | 272 | ||
317 | static void | 273 | static void |
318 | run (void *cls, char *const *args, const char *cfgfile, | 274 | run (void *cls, |
319 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 275 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
320 | { | 276 | { |
321 | delete_existing_db(cfg); | ||
322 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | ||
323 | |||
324 | size_t rd_ser_len; | 277 | size_t rd_ser_len; |
278 | char *hostkey_file; | ||
325 | 279 | ||
280 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | ||
326 | /* load privat key */ | 281 | /* load privat key */ |
327 | char *hostkey_file; | ||
328 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 282 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, |
329 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 283 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); |
@@ -339,61 +293,39 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
339 | s_rd = create_record (RECORDS); | 293 | s_rd = create_record (RECORDS); |
340 | 294 | ||
341 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd); | 295 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd); |
342 | char rd_ser[rd_ser_len]; | 296 | { |
343 | GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser); | 297 | char rd_ser[rd_ser_len]; |
344 | 298 | GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser); | |
345 | /* sign */ | 299 | |
346 | s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_rd[RECORDS -1].expiration, s_name, s_rd, RECORDS); | 300 | /* sign */ |
347 | 301 | s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_rd[RECORDS -1].expiration, s_name, s_rd, RECORDS); | |
348 | /* create random zone hash */ | 302 | |
349 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | 303 | /* create random zone hash */ |
350 | 304 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | |
351 | start_arm (cfgfile); | 305 | nsh = GNUNET_NAMESTORE_connect (cfg); |
352 | GNUNET_assert (arm != NULL); | 306 | GNUNET_break (NULL != nsh); |
353 | 307 | GNUNET_break (s_rd != NULL); | |
354 | nsh = GNUNET_NAMESTORE_connect (cfg); | 308 | GNUNET_break (s_name != NULL); |
355 | GNUNET_break (NULL != nsh); | 309 | GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, |
356 | 310 | GNUNET_TIME_UNIT_FOREVER_ABS, | |
357 | GNUNET_break (s_rd != NULL); | 311 | RECORDS, s_rd, s_signature, put_cont, s_name); |
358 | GNUNET_break (s_name != NULL); | 312 | } |
359 | |||
360 | GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, | ||
361 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
362 | RECORDS, s_rd, s_signature, put_cont, s_name); | ||
363 | |||
364 | |||
365 | |||
366 | } | 313 | } |
367 | 314 | ||
368 | static int | ||
369 | check () | ||
370 | { | ||
371 | static char *const argv[] = { "test-namestore-api", | ||
372 | "-c", | ||
373 | "test_namestore_api.conf", | ||
374 | #if VERBOSE | ||
375 | "-L", "DEBUG", | ||
376 | #endif | ||
377 | NULL | ||
378 | }; | ||
379 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
380 | GNUNET_GETOPT_OPTION_END | ||
381 | }; | ||
382 | |||
383 | res = 1; | ||
384 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", | ||
385 | "nohelp", options, &run, &res); | ||
386 | return res; | ||
387 | } | ||
388 | 315 | ||
389 | int | 316 | int |
390 | main (int argc, char *argv[]) | 317 | main (int argc, char *argv[]) |
391 | { | 318 | { |
392 | int ret; | 319 | res = 1; |
393 | 320 | if (0 != | |
394 | ret = check (); | 321 | GNUNET_TESTING_service_run ("test-namestore-api-lookup-specific-type", |
395 | GNUNET_free (s_signature); | 322 | "namestore", |
396 | return ret; | 323 | "test_namestore_api.conf", |
324 | &run, | ||
325 | NULL)) | ||
326 | return 1; | ||
327 | GNUNET_free_non_null (s_signature); | ||
328 | return res; | ||
397 | } | 329 | } |
398 | 330 | ||
399 | /* end of test_namestore_api.c */ | 331 | /* end of test_namestore_api_lookup_specific_type.c */ |