aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-09-03 15:21:13 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-09-03 15:21:13 +0000
commit3eae6bd1c45fa2864dbf07e65ada8e1fe8c3cfcd (patch)
tree4f6ad5ef0a50225bfaaf4f1084de79dba8789a75 /src/gns
parent8b079ff34ea8049fa5635243e908b7fab9d42eeb (diff)
downloadgnunet-3eae6bd1c45fa2864dbf07e65ada8e1fe8c3cfcd.tar.gz
gnunet-3eae6bd1c45fa2864dbf07e65ada8e1fe8c3cfcd.zip
- next
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am8
-rw-r--r--src/gns/test_gns_ns_lookup.c184
-rw-r--r--src/gns/test_gns_simple_zkey_lookup.c1
3 files changed, 66 insertions, 127 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 232a99fb8..f752b43b4 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -256,12 +256,12 @@ test_gns_ns_lookup_LDADD = \
256 $(top_builddir)/src/util/libgnunetutil.la \ 256 $(top_builddir)/src/util/libgnunetutil.la \
257 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 257 $(top_builddir)/src/namestore/libgnunetnamestore.la \
258 $(top_builddir)/src/gns/libgnunetgns.la \ 258 $(top_builddir)/src/gns/libgnunetgns.la \
259 $(top_builddir)/src/testing_old/libgnunettesting_old.la 259 $(top_builddir)/src/testing/libgnunettesting.la
260test_gns_ns_lookup_DEPENDENCIES = \ 260test_gns_ns_lookup_DEPENDENCIES = \
261 $(top_builddir)/src/util/libgnunetutil.la \ 261 $(top_builddir)/src/util/libgnunetutil.la \
262 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 262 $(top_builddir)/src/namestore/libgnunetnamestore.la \
263 $(top_builddir)/src/gns/libgnunetgns.la \ 263 $(top_builddir)/src/gns/libgnunetgns.la \
264 $(top_builddir)/src/testing_old/libgnunettesting_old.la 264 $(top_builddir)/src/testing/libgnunettesting.la
265 265
266 266
267test_gns_revocation_SOURCES = \ 267test_gns_revocation_SOURCES = \
@@ -270,12 +270,12 @@ test_gns_revocation_LDADD = \
270 $(top_builddir)/src/util/libgnunetutil.la \ 270 $(top_builddir)/src/util/libgnunetutil.la \
271 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 271 $(top_builddir)/src/namestore/libgnunetnamestore.la \
272 $(top_builddir)/src/gns/libgnunetgns.la \ 272 $(top_builddir)/src/gns/libgnunetgns.la \
273 $(top_builddir)/src/testing_old/libgnunettesting_old.la 273 $(top_builddir)/src/testing_old/libgnunettesting.la
274test_gns_revocation_DEPENDENCIES = \ 274test_gns_revocation_DEPENDENCIES = \
275 $(top_builddir)/src/util/libgnunetutil.la \ 275 $(top_builddir)/src/util/libgnunetutil.la \
276 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 276 $(top_builddir)/src/namestore/libgnunetnamestore.la \
277 $(top_builddir)/src/gns/libgnunetgns.la \ 277 $(top_builddir)/src/gns/libgnunetgns.la \
278 $(top_builddir)/src/testing_old/libgnunettesting_old.la 278 $(top_builddir)/src/testing_old/libgnunettesting.la
279 279
280 280
281gnunet_gns_SOURCES = \ 281gnunet_gns_SOURCES = \
diff --git a/src/gns/test_gns_ns_lookup.c b/src/gns/test_gns_ns_lookup.c
index 440568509..fb3efebd0 100644
--- a/src/gns/test_gns_ns_lookup.c
+++ b/src/gns/test_gns_ns_lookup.c
@@ -23,7 +23,7 @@
23 * 23 *
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_testing_lib.h" 26#include "gnunet_testing_lib-new.h"
27#include "gnunet_core_service.h" 27#include "gnunet_core_service.h"
28#include "block_dns.h" 28#include "block_dns.h"
29#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
@@ -50,12 +50,6 @@
50 50
51/* Globals */ 51/* Globals */
52 52
53/**
54 * Directory to store temp data in, defined in config file
55 */
56static char *test_directory;
57
58static struct GNUNET_TESTING_PeerGroup *pg;
59 53
60/* Task handle to use to schedule test failure */ 54/* Task handle to use to schedule test failure */
61GNUNET_SCHEDULER_TaskIdentifier die_task; 55GNUNET_SCHEDULER_TaskIdentifier die_task;
@@ -74,19 +68,42 @@ static struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
74const struct GNUNET_CONFIGURATION_Handle *cfg; 68const struct GNUNET_CONFIGURATION_Handle *cfg;
75 69
76/** 70/**
77 * Check whether peers successfully shut down. 71 * Check if the get_handle is being used, if so stop the request. Either
72 * way, schedule the end_badly_cont function which actually shuts down the
73 * test.
78 */ 74 */
79void 75static void
80shutdown_callback (void *cls, const char *emsg) 76end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81{ 77{
82 if (emsg != NULL) 78 die_task = GNUNET_SCHEDULER_NO_TASK;
79
80 if (resolver_handle != NULL)
81 {
82 GNUNET_RESOLVER_request_cancel (resolver_handle);
83 resolver_handle = NULL;
84 }
85
86 if (NULL != gns_handle)
83 { 87 {
84 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); 88 GNUNET_GNS_disconnect(gns_handle);
85 if (ok == 0) 89 gns_handle = NULL;
86 ok = 2;
87 } 90 }
88 91
89 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 92 if (NULL != namestore_handle)
93 {
94 GNUNET_NAMESTORE_disconnect (namestore_handle);
95 namestore_handle = NULL;
96 }
97 GNUNET_break (0);
98 GNUNET_SCHEDULER_shutdown ();
99 ok = 1;
100}
101
102static void
103end_badly_now ()
104{
105 GNUNET_SCHEDULER_cancel (die_task);
106 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
90} 107}
91 108
92static void 109static void
@@ -97,6 +114,12 @@ on_lookup_result_alt2 (void *cls, uint32_t rd_count,
97 int i; 114 int i;
98 char* addr; 115 char* addr;
99 116
117 if (GNUNET_SCHEDULER_NO_TASK != die_task)
118 {
119 GNUNET_SCHEDULER_cancel (die_task);
120 die_task = GNUNET_SCHEDULER_NO_TASK;
121 }
122
100 if (rd_count == 0) 123 if (rd_count == 0)
101 { 124 {
102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -129,8 +152,9 @@ on_lookup_result_alt2 (void *cls, uint32_t rd_count,
129 } 152 }
130 } 153 }
131 GNUNET_GNS_disconnect(gns_handle); 154 GNUNET_GNS_disconnect(gns_handle);
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 155 gns_handle = NULL;
133 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 156 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
157 GNUNET_SCHEDULER_shutdown ();
134} 158}
135 159
136static void 160static void
@@ -229,16 +253,16 @@ on_lookup_result(void *cls, uint32_t rd_count,
229static void 253static void
230start_lookup (void) 254start_lookup (void)
231{ 255{
232
233
234 GNUNET_NAMESTORE_disconnect (namestore_handle); 256 GNUNET_NAMESTORE_disconnect (namestore_handle);
235 gns_handle = GNUNET_GNS_connect (cfg); 257 namestore_handle = NULL;
236 258
259 gns_handle = GNUNET_GNS_connect(cfg);
237 if (NULL == gns_handle) 260 if (NULL == gns_handle)
238 { 261 {
239 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
240 "Failed to connect to GNS!\n"); 263 "Failed to connect to GNS!\n");
241 ok = 2; 264 end_badly_now ();
265 return;
242 } 266 }
243 267
244 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 268 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
@@ -264,7 +288,7 @@ handle_dns_test (void *cls,
264 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
265 "System resolver not working. Test inconclusive!\n"); 289 "System resolver not working. Test inconclusive!\n");
266 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); 290 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
267 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 291 GNUNET_SCHEDULER_shutdown();
268 return; 292 return;
269 } 293 }
270 start_lookup (); 294 start_lookup ();
@@ -289,7 +313,6 @@ handle_dns_test (void *cls,
289static void 313static void
290commence_testing (void *cls, int32_t success, const char *emsg) 314commence_testing (void *cls, int32_t success, const char *emsg)
291{ 315{
292
293 resolver_working = GNUNET_NO; 316 resolver_working = GNUNET_NO;
294 317
295 GNUNET_RESOLVER_connect (cfg); 318 GNUNET_RESOLVER_connect (cfg);
@@ -300,54 +323,24 @@ commence_testing (void *cls, int32_t success, const char *emsg)
300 NULL); 323 NULL);
301} 324}
302 325
303
304/**
305 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
306 * down the peers without freeing memory associated with GET request.
307 */
308static void
309end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
310{
311 if (resolver_handle != NULL)
312 GNUNET_RESOLVER_request_cancel (resolver_handle);
313 if (pg != NULL)
314 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
315 GNUNET_SCHEDULER_cancel (die_task);
316}
317
318/**
319 * Check if the get_handle is being used, if so stop the request. Either
320 * way, schedule the end_badly_cont function which actually shuts down the
321 * test.
322 */
323static void
324end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
325{
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
327 (char *) cls);
328 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
329 ok = 1;
330}
331
332static void 326static void
333do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, 327do_check (void *cls,
334 const struct GNUNET_CONFIGURATION_Handle *_cfg, 328 const struct GNUNET_CONFIGURATION_Handle *ccfg,
335 struct GNUNET_TESTING_Daemon *d, const char *emsg) 329 struct GNUNET_TESTING_Peer *peer)
336{ 330{
337 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 331 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
338 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; 332 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
339 char* alice_keyfile; 333 char* alice_keyfile;
340 334
341 cfg = _cfg; 335 cfg = ccfg;
342 336 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
343 GNUNET_SCHEDULER_cancel (die_task);
344 337
345 /* put records into namestore */ 338 /* put records into namestore */
346 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 339 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
347 if (NULL == namestore_handle) 340 if (NULL == namestore_handle)
348 { 341 {
349 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 342 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
350 ok = -1; 343 end_badly_now ();
351 return; 344 return;
352 } 345 }
353 346
@@ -356,7 +349,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
356 &alice_keyfile)) 349 &alice_keyfile))
357 { 350 {
358 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 351 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
359 ok = -1; 352 end_badly_now ();
360 return; 353 return;
361 } 354 }
362 355
@@ -399,73 +392,20 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
399 392
400} 393}
401 394
402static void
403run (void *cls, char *const *args, const char *cfgfile,
404 const struct GNUNET_CONFIGURATION_Handle *c)
405{
406 cfg = c;
407 /* Get path from configuration file */
408 if (GNUNET_YES !=
409 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
410 &test_directory))
411 {
412 ok = 404;
413 return;
414 }
415
416
417 /* Set up a task to end testing if peer start fails */
418 die_task =
419 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
420 "didn't start all daemons in reasonable amount of time!!!");
421
422 /* Start alice */
423 pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
424 NULL, NULL, &do_lookup, NULL,
425 NULL, NULL, NULL);
426}
427
428static int
429check ()
430{
431 int ret;
432
433 /* Arguments for GNUNET_PROGRAM_run */
434 char *const argv[] = { "test-gns-ns-lookup", /* Name to give running binary */
435 "-c",
436 "test_gns_simple_lookup.conf", /* Config file to use */
437 NULL
438 };
439 struct GNUNET_GETOPT_CommandLineOption options[] = {
440 GNUNET_GETOPT_OPTION_END
441 };
442 /* Run the run function as a new program */
443 ret =
444 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
445 "test-gns-ns-lookup", "nohelp", options, &run,
446 &ok);
447 if (ret != GNUNET_OK)
448 {
449 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
450 "`test-gns-simple-lookup': Failed with error code %d\n", ret);
451 }
452 return ok;
453}
454
455int 395int
456main (int argc, char *argv[]) 396main (int argc, char *argv[])
457{ 397{
458 int ret; 398 ok = 1;
459 399
460 GNUNET_log_setup ("test-gns-simple-lookup", 400 GNUNET_log_setup ("test-gns-simple-ns-lookup",
401#if VERBOSE
402 "DEBUG",
403#else
461 "WARNING", 404 "WARNING",
405#endif
462 NULL); 406 NULL);
463 ret = check (); 407 GNUNET_TESTING_peer_run ("test-gns-simple-ns-lookup", "test_gns_simple_lookup.conf", &do_check, NULL);
464 /** 408 return ok;
465 * Need to remove base directory, subdirectories taken care
466 * of by the testing framework.
467 */
468 return ret;
469} 409}
470 410
471/* end of test_gns_twopeer.c */ 411/* end of test_gns_simple_ns_lookup.c */
diff --git a/src/gns/test_gns_simple_zkey_lookup.c b/src/gns/test_gns_simple_zkey_lookup.c
index 6be749c88..716ac7236 100644
--- a/src/gns/test_gns_simple_zkey_lookup.c
+++ b/src/gns/test_gns_simple_zkey_lookup.c
@@ -164,7 +164,6 @@ commence_testing (void *cls, int32_t success, const char *emsg)
164 struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str; 164 struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str;
165 165
166 gns_handle = GNUNET_GNS_connect(cfg); 166 gns_handle = GNUNET_GNS_connect(cfg);
167
168 if (NULL == gns_handle) 167 if (NULL == gns_handle)
169 { 168 {
170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,