diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-27 21:00:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-27 21:00:50 +0000 |
commit | 74e3276f887c7852a1359d39c9c7c57b856ee23e (patch) | |
tree | c185bfb54fa7e2603d2c2400806b84b4c5237d18 /src/gns | |
parent | d5770b6e1636cd96a3e5ded9af68e6e953a83c2c (diff) | |
download | gnunet-74e3276f887c7852a1359d39c9c7c57b856ee23e.tar.gz gnunet-74e3276f887c7852a1359d39c9c7c57b856ee23e.zip |
-test case cleanup
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/test_gns_cname_lookup.c | 166 | ||||
-rw-r--r-- | src/gns/test_gns_pseu_shorten.c | 6 | ||||
-rw-r--r-- | src/gns/test_gns_simple_lookup.c | 178 |
3 files changed, 197 insertions, 153 deletions
diff --git a/src/gns/test_gns_cname_lookup.c b/src/gns/test_gns_cname_lookup.c index 36cdcde05..5a864b556 100644 --- a/src/gns/test_gns_cname_lookup.c +++ b/src/gns/test_gns_cname_lookup.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2012 Christian Grothoff (and other contributing authors) |
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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -20,7 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file gns/test_gns_cname_lookup.c | 21 | * @file gns/test_gns_cname_lookup.c |
22 | * @brief base testcase for testing a local GNS record lookup | 22 | * @brief base testcase for testing a local GNS record lookup |
23 | * | 23 | * @author Martin Schanzenbach |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib-new.h" | 26 | #include "gnunet_testing_lib-new.h" |
@@ -31,15 +31,12 @@ | |||
31 | #include "gnunet_dnsparser_lib.h" | 31 | #include "gnunet_dnsparser_lib.h" |
32 | #include "gnunet_gns_service.h" | 32 | #include "gnunet_gns_service.h" |
33 | 33 | ||
34 | /* DEFINES */ | ||
35 | #define VERBOSE GNUNET_YES | ||
36 | 34 | ||
37 | /* Timeout for entire testcase */ | 35 | /** |
36 | * Timeout for entire testcase | ||
37 | */ | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) |
39 | 39 | ||
40 | /* If number of peers not in config file, use this number */ | ||
41 | #define DEFAULT_NUM_PEERS 2 | ||
42 | |||
43 | /* test records to resolve */ | 40 | /* test records to resolve */ |
44 | #define TEST_DOMAIN_PLUS "www.gads" | 41 | #define TEST_DOMAIN_PLUS "www.gads" |
45 | #define TEST_DOMAIN_ZKEY "www2.gads" | 42 | #define TEST_DOMAIN_ZKEY "www2.gads" |
@@ -58,10 +55,9 @@ | |||
58 | 55 | ||
59 | #define KEYFILE_BOB "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey" | 56 | #define KEYFILE_BOB "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey" |
60 | 57 | ||
61 | /* Globals */ | ||
62 | 58 | ||
63 | /* Task handle to use to schedule test failure */ | 59 | /* Task handle to use to schedule test failure */ |
64 | GNUNET_SCHEDULER_TaskIdentifier die_task; | 60 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
65 | 61 | ||
66 | /* Global return value (0 for success, anything else for failure) */ | 62 | /* Global return value (0 for success, anything else for failure) */ |
67 | static int ok; | 63 | static int ok; |
@@ -70,7 +66,8 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; | |||
70 | 66 | ||
71 | static struct GNUNET_GNS_Handle *gns_handle; | 67 | static struct GNUNET_GNS_Handle *gns_handle; |
72 | 68 | ||
73 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 69 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
70 | |||
74 | 71 | ||
75 | /** | 72 | /** |
76 | * Check if the get_handle is being used, if so stop the request. Either | 73 | * Check if the get_handle is being used, if so stop the request. Either |
@@ -83,10 +80,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
83 | die_task = GNUNET_SCHEDULER_NO_TASK; | 80 | die_task = GNUNET_SCHEDULER_NO_TASK; |
84 | if (NULL != gns_handle) | 81 | if (NULL != gns_handle) |
85 | { | 82 | { |
86 | GNUNET_GNS_disconnect(gns_handle); | 83 | GNUNET_GNS_disconnect (gns_handle); |
87 | gns_handle = NULL; | 84 | gns_handle = NULL; |
88 | } | 85 | } |
89 | |||
90 | if (NULL != namestore_handle) | 86 | if (NULL != namestore_handle) |
91 | { | 87 | { |
92 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 88 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
@@ -97,6 +93,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
97 | ok = 1; | 93 | ok = 1; |
98 | } | 94 | } |
99 | 95 | ||
96 | |||
100 | static void | 97 | static void |
101 | end_badly_now () | 98 | end_badly_now () |
102 | { | 99 | { |
@@ -104,26 +101,30 @@ end_badly_now () | |||
104 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 101 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
105 | } | 102 | } |
106 | 103 | ||
107 | static void shutdown_task (void *cls, | 104 | |
108 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 105 | static void |
106 | shutdown_task (void *cls, | ||
107 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
109 | { | 108 | { |
110 | GNUNET_GNS_disconnect(gns_handle); | 109 | GNUNET_GNS_disconnect (gns_handle); |
110 | gns_handle = NULL; | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); | 111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); |
112 | GNUNET_SCHEDULER_shutdown (); | 112 | GNUNET_SCHEDULER_shutdown (); |
113 | } | 113 | } |
114 | 114 | ||
115 | |||
115 | static void | 116 | static void |
116 | on_lookup_result_cname (void *cls, uint32_t rd_count, | 117 | on_lookup_result_cname (void *cls, |
117 | const struct GNUNET_NAMESTORE_RecordData *rd) | 118 | uint32_t rd_count, |
119 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
118 | { | 120 | { |
119 | int i; | 121 | uint32_t i; |
120 | 122 | ||
121 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 123 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
122 | { | 124 | { |
123 | GNUNET_SCHEDULER_cancel (die_task); | 125 | GNUNET_SCHEDULER_cancel (die_task); |
124 | die_task = GNUNET_SCHEDULER_NO_TASK; | 126 | die_task = GNUNET_SCHEDULER_NO_TASK; |
125 | } | 127 | } |
126 | |||
127 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 128 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
128 | namestore_handle = NULL; | 129 | namestore_handle = NULL; |
129 | if (rd_count == 0) | 130 | if (rd_count == 0) |
@@ -158,12 +159,14 @@ on_lookup_result_cname (void *cls, uint32_t rd_count, | |||
158 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 159 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
159 | } | 160 | } |
160 | 161 | ||
162 | |||
161 | static void | 163 | static void |
162 | on_lookup_result_dns (void *cls, uint32_t rd_count, | 164 | on_lookup_result_dns (void *cls, |
163 | const struct GNUNET_NAMESTORE_RecordData *rd) | 165 | uint32_t rd_count, |
166 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
164 | { | 167 | { |
165 | struct in_addr a; | 168 | struct in_addr a; |
166 | int i; | 169 | uint32_t i; |
167 | char* addr; | 170 | char* addr; |
168 | 171 | ||
169 | if (rd_count == 0) | 172 | if (rd_count == 0) |
@@ -197,19 +200,19 @@ on_lookup_result_dns (void *cls, uint32_t rd_count, | |||
197 | } | 200 | } |
198 | } | 201 | } |
199 | } | 202 | } |
200 | |||
201 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME, | 203 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME, |
202 | GNUNET_YES, | 204 | GNUNET_YES, |
203 | NULL, | 205 | NULL, |
204 | &on_lookup_result_cname, TEST_DOMAIN_PLUS); | 206 | &on_lookup_result_cname, TEST_DOMAIN_PLUS); |
205 | } | 207 | } |
206 | 208 | ||
209 | |||
207 | static void | 210 | static void |
208 | on_lookup_result_zkey (void *cls, uint32_t rd_count, | 211 | on_lookup_result_zkey (void *cls, uint32_t rd_count, |
209 | const struct GNUNET_NAMESTORE_RecordData *rd) | 212 | const struct GNUNET_NAMESTORE_RecordData *rd) |
210 | { | 213 | { |
211 | struct in_addr a; | 214 | struct in_addr a; |
212 | int i; | 215 | uint32_t i; |
213 | char* addr; | 216 | char* addr; |
214 | 217 | ||
215 | if (rd_count == 0) | 218 | if (rd_count == 0) |
@@ -221,41 +224,46 @@ on_lookup_result_zkey (void *cls, uint32_t rd_count, | |||
221 | else | 224 | else |
222 | { | 225 | { |
223 | ok = 1; | 226 | ok = 1; |
224 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | 227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
228 | "name: %s\n", (char*)cls); | ||
225 | for (i=0; i<rd_count; i++) | 229 | for (i=0; i<rd_count; i++) |
226 | { | 230 | { |
227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | 231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
232 | "type: %d\n", rd[i].record_type); | ||
228 | if (rd[i].record_type == GNUNET_GNS_RECORD_A) | 233 | if (rd[i].record_type == GNUNET_GNS_RECORD_A) |
229 | { | 234 | { |
230 | memcpy(&a, rd[i].data, sizeof(a)); | 235 | memcpy (&a, rd[i].data, sizeof(a)); |
231 | addr = inet_ntoa(a); | 236 | addr = inet_ntoa(a); |
232 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | 237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
233 | if (0 == strcmp(addr, TEST_IP_ZKEY)) | 238 | "address: %s\n", addr); |
239 | if (0 == strcmp (addr, TEST_IP_ZKEY)) | ||
234 | { | 240 | { |
235 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 241 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
236 | "%s correctly resolved to %s!\n", TEST_DOMAIN_ZKEY, addr); | 242 | "%s correctly resolved to %s!\n", |
243 | TEST_DOMAIN_ZKEY, addr); | ||
237 | ok = 0; | 244 | ok = 0; |
238 | } | 245 | } |
239 | } | 246 | } |
240 | else | 247 | else |
241 | { | 248 | { |
242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | 249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
250 | "No resolution!\n"); | ||
243 | } | 251 | } |
244 | } | 252 | } |
245 | } | 253 | |
246 | 254 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_DNS, GNUNET_GNS_RECORD_A, | |
247 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_DNS, GNUNET_GNS_RECORD_A, | 255 | GNUNET_YES, |
248 | GNUNET_YES, | 256 | NULL, |
249 | NULL, | 257 | &on_lookup_result_dns, TEST_DOMAIN_DNS); |
250 | &on_lookup_result_dns, TEST_DOMAIN_DNS); | ||
251 | } | 258 | } |
252 | 259 | ||
260 | |||
253 | static void | 261 | static void |
254 | on_lookup_result_plus (void *cls, uint32_t rd_count, | 262 | on_lookup_result_plus (void *cls, uint32_t rd_count, |
255 | const struct GNUNET_NAMESTORE_RecordData *rd) | 263 | const struct GNUNET_NAMESTORE_RecordData *rd) |
256 | { | 264 | { |
257 | struct in_addr a; | 265 | struct in_addr a; |
258 | int i; | 266 | uint32_t i; |
259 | char* addr; | 267 | char* addr; |
260 | 268 | ||
261 | if (rd_count == 0) | 269 | if (rd_count == 0) |
@@ -289,20 +297,34 @@ on_lookup_result_plus (void *cls, uint32_t rd_count, | |||
289 | } | 297 | } |
290 | } | 298 | } |
291 | } | 299 | } |
292 | 300 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ZKEY, GNUNET_GNS_RECORD_A, | |
293 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ZKEY, GNUNET_GNS_RECORD_A, | 301 | GNUNET_YES, |
294 | GNUNET_YES, | 302 | NULL, |
295 | NULL, | 303 | &on_lookup_result_zkey, TEST_DOMAIN_ZKEY); |
296 | &on_lookup_result_zkey, TEST_DOMAIN_ZKEY); | ||
297 | } | 304 | } |
298 | 305 | ||
306 | |||
299 | /** | 307 | /** |
300 | * Function scheduled to be run on the successful start of services | 308 | * Function scheduled to be run on the successful start of services |
301 | * tries to look up the dns record for TEST_DOMAIN | 309 | * tries to look up the dns record for TEST_DOMAIN |
310 | * | ||
311 | * @param cls closure | ||
312 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
313 | * GNUNET_NO if content was already there or not found | ||
314 | * GNUNET_YES (or other positive value) on success | ||
315 | * @param emsg NULL on success, otherwise an error message | ||
302 | */ | 316 | */ |
303 | static void | 317 | static void |
304 | commence_testing (void *cls, int32_t success, const char *emsg) | 318 | commence_testing (void *cls, int32_t success, const char *emsg) |
305 | { | 319 | { |
320 | if (NULL != emsg) | ||
321 | { | ||
322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
323 | "Failed to store record in namestore: %s\n", | ||
324 | emsg); | ||
325 | end_badly_now (); | ||
326 | return; | ||
327 | } | ||
306 | gns_handle = GNUNET_GNS_connect(cfg); | 328 | gns_handle = GNUNET_GNS_connect(cfg); |
307 | if (NULL == gns_handle) | 329 | if (NULL == gns_handle) |
308 | { | 330 | { |
@@ -311,11 +333,10 @@ commence_testing (void *cls, int32_t success, const char *emsg) | |||
311 | end_badly_now (); | 333 | end_badly_now (); |
312 | return; | 334 | return; |
313 | } | 335 | } |
314 | 336 | GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_A, | |
315 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_A, | 337 | GNUNET_YES, |
316 | GNUNET_YES, | 338 | NULL, |
317 | NULL, | 339 | &on_lookup_result_plus, TEST_DOMAIN_PLUS); |
318 | &on_lookup_result_plus, TEST_DOMAIN_PLUS); | ||
319 | } | 340 | } |
320 | 341 | ||
321 | 342 | ||
@@ -328,16 +349,19 @@ do_check (void *cls, | |||
328 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; | 349 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; |
329 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; | 350 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; |
330 | char* alice_keyfile; | 351 | char* alice_keyfile; |
352 | struct GNUNET_NAMESTORE_RecordData rd; | ||
353 | const char* ip = TEST_IP_PLUS; | ||
354 | struct in_addr web; | ||
331 | 355 | ||
332 | cfg = ccfg; | 356 | cfg = ccfg; |
333 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 357 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
334 | 358 | ||
335 | |||
336 | /* put records into namestore */ | 359 | /* put records into namestore */ |
337 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | 360 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); |
338 | if (NULL == namestore_handle) | 361 | if (NULL == namestore_handle) |
339 | { | 362 | { |
340 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | 363 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
364 | "Failed to connect to namestore\n"); | ||
341 | end_badly_now (); | 365 | end_badly_now (); |
342 | return; | 366 | return; |
343 | } | 367 | } |
@@ -346,26 +370,22 @@ do_check (void *cls, | |||
346 | "ZONEKEY", | 370 | "ZONEKEY", |
347 | &alice_keyfile)) | 371 | &alice_keyfile)) |
348 | { | 372 | { |
349 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | 373 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
374 | "Failed to get key from cfg\n"); | ||
350 | end_badly_now (); | 375 | end_badly_now (); |
351 | return; | 376 | return; |
352 | } | 377 | } |
353 | 378 | ||
354 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); | 379 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); |
355 | |||
356 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); | 380 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); |
357 | |||
358 | GNUNET_free(alice_keyfile); | 381 | GNUNET_free(alice_keyfile); |
359 | 382 | ||
360 | bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); | 383 | bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); |
361 | 384 | ||
362 | struct GNUNET_NAMESTORE_RecordData rd; | ||
363 | char* ip = TEST_IP_PLUS; | ||
364 | struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); | ||
365 | rd.expiration_time = UINT64_MAX; | 385 | rd.expiration_time = UINT64_MAX; |
366 | GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); | 386 | GNUNET_assert(1 == inet_pton (AF_INET, ip, &web)); |
367 | rd.data_size = sizeof(struct in_addr); | 387 | rd.data_size = sizeof(struct in_addr); |
368 | rd.data = web; | 388 | rd.data = &web; |
369 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 389 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
370 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; | 390 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; |
371 | 391 | ||
@@ -409,38 +429,32 @@ do_check (void *cls, | |||
409 | NULL, | 429 | NULL, |
410 | NULL); | 430 | NULL); |
411 | 431 | ||
412 | GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP_ZKEY, web)); | 432 | GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP_ZKEY, &web)); |
413 | rd.data_size = sizeof(struct in_addr); | 433 | rd.data_size = sizeof(struct in_addr); |
414 | rd.data = web; | 434 | rd.data = &web; |
415 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 435 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
416 | 436 | ||
417 | GNUNET_NAMESTORE_record_create (namestore_handle, | 437 | GNUNET_NAMESTORE_record_create (namestore_handle, |
418 | bob_key, | 438 | bob_key, |
419 | TEST_RECORD_NAME_PLUS, | 439 | TEST_RECORD_NAME_PLUS, |
420 | &rd, | 440 | &rd, |
421 | &commence_testing, | 441 | &commence_testing, |
422 | NULL); | 442 | NULL); |
423 | |||
424 | GNUNET_CRYPTO_rsa_key_free(alice_key); | 443 | GNUNET_CRYPTO_rsa_key_free(alice_key); |
425 | GNUNET_CRYPTO_rsa_key_free(bob_key); | 444 | GNUNET_CRYPTO_rsa_key_free(bob_key); |
426 | GNUNET_free(web); | ||
427 | |||
428 | } | 445 | } |
429 | 446 | ||
447 | |||
430 | int | 448 | int |
431 | main (int argc, char *argv[]) | 449 | main (int argc, char *argv[]) |
432 | { | 450 | { |
433 | ok = 1; | 451 | ok = 1; |
434 | 452 | ||
435 | GNUNET_log_setup ("test-gns-simple-cname-lookup", | 453 | GNUNET_log_setup ("test-gns-simple-cname-lookup", |
436 | #if VERBOSE | ||
437 | "DEBUG", | ||
438 | #else | ||
439 | "WARNING", | 454 | "WARNING", |
440 | #endif | ||
441 | NULL); | 455 | NULL); |
442 | GNUNET_TESTING_peer_run ("test-gns-simple-cname-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); | 456 | GNUNET_TESTING_peer_run ("test-gns-simple-cname-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); |
443 | return ok; | 457 | return ok; |
444 | } | 458 | } |
445 | 459 | ||
446 | /* end of test_gns_simple_cname_lookup.c */ | 460 | /* end of test_gns_cname_lookup.c */ |
diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index c5ff6435e..8f279bb55 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c | |||
@@ -239,21 +239,17 @@ on_lookup_result(void *cls, uint32_t rd_count, | |||
239 | static void | 239 | static void |
240 | commence_testing (void *cls, int success) | 240 | commence_testing (void *cls, int success) |
241 | { | 241 | { |
242 | |||
243 | GNUNET_CRYPTO_rsa_key_free(our_key); | 242 | GNUNET_CRYPTO_rsa_key_free(our_key); |
244 | GNUNET_CRYPTO_rsa_key_free(bob_key); | 243 | GNUNET_CRYPTO_rsa_key_free(bob_key); |
245 | GNUNET_CRYPTO_rsa_key_free(alice_key); | 244 | GNUNET_CRYPTO_rsa_key_free(alice_key); |
246 | |||
247 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 245 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
248 | namestore_handle = NULL; | 246 | namestore_handle = NULL; |
249 | |||
250 | gns_handle = GNUNET_GNS_connect(cfg); | 247 | gns_handle = GNUNET_GNS_connect(cfg); |
251 | if (NULL == gns_handle) | 248 | if (NULL == gns_handle) |
252 | { | 249 | { |
253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
254 | "Failed to connect to GNS!\n"); | 251 | "Failed to connect to GNS!\n"); |
255 | } | 252 | } |
256 | |||
257 | GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN, | 253 | GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN, |
258 | &our_zone, | 254 | &our_zone, |
259 | GNUNET_GNS_RECORD_A, | 255 | GNUNET_GNS_RECORD_A, |
@@ -264,7 +260,7 @@ commence_testing (void *cls, int success) | |||
264 | 260 | ||
265 | 261 | ||
266 | static void | 262 | static void |
267 | put_pseu_dht(void *cls, int success) | 263 | put_pseu_dht (void *cls, int success) |
268 | { | 264 | { |
269 | struct GNSNameRecordBlock *nrb; | 265 | struct GNSNameRecordBlock *nrb; |
270 | struct GNUNET_CRYPTO_ShortHashCode name_hash; | 266 | struct GNUNET_CRYPTO_ShortHashCode name_hash; |
diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c index cc912b2e0..8204b03eb 100644 --- a/src/gns/test_gns_simple_lookup.c +++ b/src/gns/test_gns_simple_lookup.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2012 Christian Grothoff (and other contributing authors) |
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 |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -20,7 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file gns/test_gns_simple_lookup.c | 21 | * @file gns/test_gns_simple_lookup.c |
22 | * @brief base testcase for testing a local GNS record lookup | 22 | * @brief base testcase for testing a local GNS record lookup |
23 | * | 23 | * @author Martin Schanzenbach |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib-new.h" | 26 | #include "gnunet_testing_lib-new.h" |
@@ -31,33 +31,37 @@ | |||
31 | #include "gnunet_dnsparser_lib.h" | 31 | #include "gnunet_dnsparser_lib.h" |
32 | #include "gnunet_gns_service.h" | 32 | #include "gnunet_gns_service.h" |
33 | 33 | ||
34 | /* DEFINES */ | ||
35 | #define VERBOSE GNUNET_YES | ||
36 | |||
37 | /* Timeout for entire testcase */ | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) | ||
39 | 34 | ||
40 | /* If number of peers not in config file, use this number */ | 35 | /** |
41 | #define DEFAULT_NUM_PEERS 2 | 36 | * Timeout for entire testcase |
37 | */ | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | ||
42 | 39 | ||
43 | /* test records to resolve */ | 40 | /* test records to resolve */ |
44 | #define TEST_DOMAIN "www.gads" | 41 | #define TEST_DOMAIN "www.gads" |
45 | #define TEST_IP "127.0.0.1" | 42 | #define TEST_IP "127.0.0.1" |
46 | #define TEST_RECORD_NAME "www" | 43 | #define TEST_RECORD_NAME "www" |
47 | 44 | ||
48 | /* Globals */ | 45 | /** |
49 | 46 | * Task handle to use to schedule test failure | |
50 | /* Task handle to use to schedule test failure */ | 47 | */ |
51 | GNUNET_SCHEDULER_TaskIdentifier die_task; | 48 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
52 | 49 | ||
53 | /* Global return value (0 for success, anything else for failure) */ | 50 | /** |
51 | * Global return value (0 for success, anything else for failure) | ||
52 | */ | ||
54 | static int ok; | 53 | static int ok; |
55 | 54 | ||
56 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 55 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
57 | 56 | ||
58 | static struct GNUNET_GNS_Handle *gns_handle; | 57 | static struct GNUNET_GNS_Handle *gns_handle; |
59 | 58 | ||
60 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 59 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
60 | |||
61 | static struct GNUNET_GNS_LookupRequest *lr; | ||
62 | |||
63 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
64 | |||
61 | 65 | ||
62 | /** | 66 | /** |
63 | * Check if the get_handle is being used, if so stop the request. Either | 67 | * Check if the get_handle is being used, if so stop the request. Either |
@@ -65,11 +69,22 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
65 | * test. | 69 | * test. |
66 | */ | 70 | */ |
67 | static void | 71 | static void |
68 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 72 | end_badly (void *cls, |
73 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
69 | { | 74 | { |
75 | if (NULL != nsqe) | ||
76 | { | ||
77 | GNUNET_NAMESTORE_cancel (nsqe); | ||
78 | nsqe = NULL; | ||
79 | } | ||
80 | if (NULL != lr) | ||
81 | { | ||
82 | GNUNET_GNS_cancel_lookup_request (lr); | ||
83 | lr = NULL; | ||
84 | } | ||
70 | if (NULL != gns_handle) | 85 | if (NULL != gns_handle) |
71 | { | 86 | { |
72 | GNUNET_GNS_disconnect(gns_handle); | 87 | GNUNET_GNS_disconnect (gns_handle); |
73 | gns_handle = NULL; | 88 | gns_handle = NULL; |
74 | } | 89 | } |
75 | 90 | ||
@@ -83,38 +98,48 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
83 | ok = 1; | 98 | ok = 1; |
84 | } | 99 | } |
85 | 100 | ||
86 | void end_badly_now () | 101 | |
102 | static void | ||
103 | end_badly_now () | ||
87 | { | 104 | { |
88 | GNUNET_SCHEDULER_cancel (die_task); | 105 | GNUNET_SCHEDULER_cancel (die_task); |
89 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 106 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
90 | } | 107 | } |
91 | 108 | ||
92 | 109 | ||
93 | static void shutdown_task (void *cls, | 110 | static void |
94 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 111 | shutdown_task (void *cls, |
112 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
95 | { | 113 | { |
96 | GNUNET_GNS_disconnect(gns_handle); | 114 | GNUNET_GNS_disconnect (gns_handle); |
97 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); |
98 | GNUNET_SCHEDULER_shutdown (); | 116 | GNUNET_SCHEDULER_shutdown (); |
99 | } | 117 | } |
100 | 118 | ||
101 | 119 | ||
120 | /** | ||
121 | * Function called on result for a GNS lookup | ||
122 | * | ||
123 | * @param cls closure, unused | ||
124 | * @param rd_count number of records | ||
125 | * @param rd the records in reply | ||
126 | */ | ||
102 | static void | 127 | static void |
103 | on_lookup_result(void *cls, uint32_t rd_count, | 128 | on_lookup_result(void *cls, uint32_t rd_count, |
104 | const struct GNUNET_NAMESTORE_RecordData *rd) | 129 | const struct GNUNET_NAMESTORE_RecordData *rd) |
105 | { | 130 | { |
106 | |||
107 | struct in_addr a; | 131 | struct in_addr a; |
108 | int i; | 132 | uint32_t i; |
109 | char* addr; | 133 | char* addr; |
110 | 134 | ||
135 | lr = NULL; | ||
111 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 136 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
112 | { | 137 | { |
113 | GNUNET_SCHEDULER_cancel (die_task); | 138 | GNUNET_SCHEDULER_cancel (die_task); |
114 | die_task = GNUNET_SCHEDULER_NO_TASK; | 139 | die_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 140 | } |
116 | |||
117 | GNUNET_NAMESTORE_disconnect (namestore_handle); | 141 | GNUNET_NAMESTORE_disconnect (namestore_handle); |
142 | namestore_handle = NULL; | ||
118 | if (rd_count == 0) | 143 | if (rd_count == 0) |
119 | { | 144 | { |
120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -130,23 +155,24 @@ on_lookup_result(void *cls, uint32_t rd_count, | |||
130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); |
131 | if (rd[i].record_type == GNUNET_GNS_RECORD_A) | 156 | if (rd[i].record_type == GNUNET_GNS_RECORD_A) |
132 | { | 157 | { |
133 | memcpy(&a, rd[i].data, sizeof(a)); | 158 | memcpy (&a, rd[i].data, sizeof(a)); |
134 | addr = inet_ntoa(a); | 159 | addr = inet_ntoa(a); |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | 160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); |
136 | if (0 == strcmp(addr, TEST_IP)) | 161 | if (0 == strcmp (addr, TEST_IP)) |
137 | { | 162 | { |
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
139 | "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); | 164 | "%s correctly resolved to %s!\n", |
165 | TEST_DOMAIN, addr); | ||
140 | ok = 0; | 166 | ok = 0; |
141 | } | 167 | } |
142 | } | 168 | } |
143 | else | 169 | else |
144 | { | 170 | { |
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
172 | "No resolution!\n"); | ||
146 | } | 173 | } |
147 | } | 174 | } |
148 | } | 175 | } |
149 | |||
150 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 176 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
151 | } | 177 | } |
152 | 178 | ||
@@ -154,25 +180,42 @@ on_lookup_result(void *cls, uint32_t rd_count, | |||
154 | /** | 180 | /** |
155 | * Function scheduled to be run on the successful start of services | 181 | * Function scheduled to be run on the successful start of services |
156 | * tries to look up the dns record for TEST_DOMAIN | 182 | * tries to look up the dns record for TEST_DOMAIN |
183 | * | ||
184 | * @param cls closure | ||
185 | * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) | ||
186 | * GNUNET_NO if content was already there or not found | ||
187 | * GNUNET_YES (or other positive value) on success | ||
188 | * @param emsg NULL on success, otherwise an error message | ||
157 | */ | 189 | */ |
158 | static void | 190 | static void |
159 | commence_testing (void *cls, int32_t success, const char *emsg) | 191 | commence_testing (void *cls, |
192 | int32_t success, | ||
193 | const char *emsg) | ||
160 | { | 194 | { |
161 | gns_handle = GNUNET_GNS_connect(cfg); | 195 | nsqe = NULL; |
196 | if (NULL != emsg) | ||
197 | { | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
199 | "Failed to store record in namestore: %s\n", | ||
200 | emsg); | ||
201 | end_badly_now (); | ||
202 | return; | ||
203 | } | ||
204 | gns_handle = GNUNET_GNS_connect (cfg); | ||
162 | if (NULL == gns_handle) | 205 | if (NULL == gns_handle) |
163 | { | 206 | { |
164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
165 | "Failed to connect to GNS!\n"); | 208 | "Failed to connect to GNS!\n"); |
166 | end_badly_now(); | 209 | end_badly_now (); |
167 | return; | 210 | return; |
168 | } | 211 | } |
169 | 212 | lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, | |
170 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, | 213 | GNUNET_YES, |
171 | GNUNET_YES, | 214 | NULL, |
172 | NULL, | 215 | &on_lookup_result, TEST_DOMAIN); |
173 | &on_lookup_result, TEST_DOMAIN); | ||
174 | } | 216 | } |
175 | 217 | ||
218 | |||
176 | static void | 219 | static void |
177 | do_check (void *cls, | 220 | do_check (void *cls, |
178 | const struct GNUNET_CONFIGURATION_Handle *ccfg, | 221 | const struct GNUNET_CONFIGURATION_Handle *ccfg, |
@@ -183,7 +226,7 @@ do_check (void *cls, | |||
183 | struct GNUNET_NAMESTORE_RecordData rd; | 226 | struct GNUNET_NAMESTORE_RecordData rd; |
184 | char* alice_keyfile; | 227 | char* alice_keyfile; |
185 | char* ip = TEST_IP; | 228 | char* ip = TEST_IP; |
186 | struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); | 229 | struct in_addr web; |
187 | 230 | ||
188 | cfg = ccfg; | 231 | cfg = ccfg; |
189 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 232 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
@@ -192,61 +235,52 @@ do_check (void *cls, | |||
192 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | 235 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); |
193 | if (NULL == namestore_handle) | 236 | if (NULL == namestore_handle) |
194 | { | 237 | { |
195 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | 238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
196 | GNUNET_free (web); | 239 | "Failed to connect to namestore\n"); |
197 | end_badly_now () ; | 240 | end_badly_now (); |
198 | return; | 241 | return; |
199 | } | 242 | } |
200 | 243 | if (GNUNET_OK != | |
201 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | 244 | GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", |
202 | "ZONEKEY", | 245 | "ZONEKEY", |
203 | &alice_keyfile)) | 246 | &alice_keyfile)) |
204 | { | 247 | { |
205 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | 248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
206 | GNUNET_free (web); | 249 | "Failed to get key from cfg\n"); |
207 | end_badly_now () ; | 250 | end_badly_now (); |
208 | return; | 251 | return; |
209 | } | 252 | } |
210 | 253 | ||
211 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); | 254 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); |
212 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); | 255 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); |
213 | GNUNET_free(alice_keyfile); | 256 | GNUNET_free (alice_keyfile); |
214 | |||
215 | |||
216 | rd.expiration_time = UINT64_MAX; | 257 | rd.expiration_time = UINT64_MAX; |
217 | GNUNET_assert (1 == inet_pton (AF_INET, ip, web)); | 258 | GNUNET_assert (1 == inet_pton (AF_INET, ip, &web)); |
218 | rd.data_size = sizeof(struct in_addr); | 259 | rd.data_size = sizeof(struct in_addr); |
219 | rd.data = web; | 260 | rd.data = &web; |
220 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 261 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
221 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; | 262 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; |
222 | 263 | nsqe = GNUNET_NAMESTORE_record_create (namestore_handle, | |
223 | GNUNET_NAMESTORE_record_create (namestore_handle, | 264 | alice_key, |
224 | alice_key, | 265 | TEST_RECORD_NAME, |
225 | TEST_RECORD_NAME, | 266 | &rd, |
226 | &rd, | 267 | &commence_testing, |
227 | &commence_testing, | 268 | NULL); |
228 | NULL); | 269 | GNUNET_CRYPTO_rsa_key_free (alice_key); |
229 | |||
230 | GNUNET_CRYPTO_rsa_key_free(alice_key); | ||
231 | GNUNET_free(web); | ||
232 | } | 270 | } |
233 | 271 | ||
272 | |||
234 | int | 273 | int |
235 | main (int argc, char *argv[]) | 274 | main (int argc, char *argv[]) |
236 | { | 275 | { |
237 | ok = 1; | 276 | ok = 1; |
238 | |||
239 | GNUNET_log_setup ("test-gns-simple-lookup", | 277 | GNUNET_log_setup ("test-gns-simple-lookup", |
240 | #if VERBOSE | ||
241 | "DEBUG", | ||
242 | #else | ||
243 | "WARNING", | 278 | "WARNING", |
244 | #endif | ||
245 | NULL); | 279 | NULL); |
246 | 280 | GNUNET_TESTING_peer_run ("test-gns-simple-lookup", | |
247 | GNUNET_TESTING_peer_run ("test-gns-simple-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); | 281 | "test_gns_simple_lookup.conf", |
248 | 282 | &do_check, NULL); | |
249 | return ok; | 283 | return ok; |
250 | } | 284 | } |
251 | 285 | ||
252 | /* end of test_gns_simple_lookup.c */ | 286 | /* end of test_gns_simple_lookup.c */ |