diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-31 21:21:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-31 21:21:01 +0000 |
commit | 521b89ad0aab592c9a0a7af05a34a19056958e37 (patch) | |
tree | 8cfb442f11c65cae554a6222bacb2096a9845f7f /src/dht | |
parent | 2c050a03a07c6877d32e6017af1b26898cda081d (diff) | |
download | gnunet-521b89ad0aab592c9a0a7af05a34a19056958e37.tar.gz gnunet-521b89ad0aab592c9a0a7af05a34a19056958e37.zip |
-code cleanup and better error messages for failures
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/test_dht_topo.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c index f69f5dca9..03fe49408 100644 --- a/src/dht/test_dht_topo.c +++ b/src/dht/test_dht_topo.c | |||
@@ -53,11 +53,6 @@ | |||
53 | static int ok; | 53 | static int ok; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Be verbose | ||
57 | */ | ||
58 | static int verbose; | ||
59 | |||
60 | /** | ||
61 | * Total number of peers in the test. | 56 | * Total number of peers in the test. |
62 | */ | 57 | */ |
63 | static unsigned long long num_peers; | 58 | static unsigned long long num_peers; |
@@ -114,27 +109,30 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | |||
114 | 109 | ||
115 | static char *topology_file; | 110 | static char *topology_file; |
116 | 111 | ||
117 | struct GNUNET_TESTING_Daemon *d1; | 112 | static struct GNUNET_TESTING_Daemon *d1; |
113 | |||
114 | static struct GNUNET_TESTING_Daemon *d2; | ||
118 | 115 | ||
119 | struct GNUNET_TESTING_Daemon *d2; | 116 | static struct GNUNET_DHT_Handle **hs; |
120 | 117 | ||
121 | struct GNUNET_DHT_Handle **hs; | 118 | static struct GNUNET_DHT_GetHandle *get_h; |
122 | 119 | ||
123 | struct GNUNET_DHT_GetHandle *get_h; | 120 | static struct GNUNET_DHT_GetHandle *get_h_2; |
124 | 121 | ||
125 | struct GNUNET_DHT_GetHandle *get_h_2; | 122 | static struct GNUNET_DHT_GetHandle *get_h_far; |
126 | 123 | ||
127 | struct GNUNET_DHT_GetHandle *get_h_far; | 124 | static int found_1; |
128 | 125 | ||
129 | int found_1; | 126 | static int found_2; |
130 | int found_2; | 127 | |
131 | int found_far; | 128 | static int found_far; |
132 | 129 | ||
133 | /** | 130 | /** |
134 | * Which topology are we to run | 131 | * Which topology are we to run |
135 | */ | 132 | */ |
136 | static int test_topology; | 133 | static int test_topology; |
137 | 134 | ||
135 | |||
138 | /** | 136 | /** |
139 | * Check whether peers successfully shut down. | 137 | * Check whether peers successfully shut down. |
140 | */ | 138 | */ |
@@ -193,6 +191,7 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
193 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 191 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
194 | } | 192 | } |
195 | 193 | ||
194 | |||
196 | static void | 195 | static void |
197 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | 196 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
198 | const GNUNET_HashCode * key, | 197 | const GNUNET_HashCode * key, |
@@ -246,14 +245,15 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
246 | default: | 245 | default: |
247 | GNUNET_break(0); | 246 | GNUNET_break(0); |
248 | } | 247 | } |
249 | if (TORUS == test_topology && | 248 | if ( (TORUS == test_topology) && |
250 | (found_1 == 0 || found_2 == 0 || found_far == 0)) | 249 | ( (found_1 == 0) || (found_2 == 0) || (found_far == 0)) ) |
251 | return; | 250 | return; |
252 | ok = 0; | 251 | ok = 0; |
253 | GNUNET_SCHEDULER_cancel (disconnect_task); | 252 | GNUNET_SCHEDULER_cancel (disconnect_task); |
254 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | 253 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); |
255 | } | 254 | } |
256 | 255 | ||
256 | |||
257 | static void | 257 | static void |
258 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 258 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
259 | { | 259 | { |
@@ -393,7 +393,8 @@ peergroup_ready (void *cls, const char *emsg) | |||
393 | { | 393 | { |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
395 | "Peergroup callback called with error, aborting test!\n"); | 395 | "Peergroup callback called with error, aborting test!\n"); |
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n", | 396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
397 | "Error from testing: `%s'\n", | ||
397 | emsg); | 398 | emsg); |
398 | ok++; | 399 | ok++; |
399 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 400 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
@@ -450,7 +451,6 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
450 | struct GNUNET_TESTING_Daemon *first_daemon, | 451 | struct GNUNET_TESTING_Daemon *first_daemon, |
451 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) | 452 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) |
452 | { | 453 | { |
453 | |||
454 | if (emsg == NULL) | 454 | if (emsg == NULL) |
455 | { | 455 | { |
456 | total_connections++; | 456 | total_connections++; |
@@ -462,7 +462,6 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
462 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 462 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
463 | "Problem with new connection (%s)\n", emsg); | 463 | "Problem with new connection (%s)\n", emsg); |
464 | } | 464 | } |
465 | |||
466 | } | 465 | } |
467 | 466 | ||
468 | 467 | ||
@@ -556,30 +555,21 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
556 | } | 555 | } |
557 | 556 | ||
558 | 557 | ||
559 | |||
560 | /** | ||
561 | * test_dht_2d command line options | ||
562 | */ | ||
563 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
564 | {'V', "verbose", NULL, | ||
565 | gettext_noop ("be verbose (print progress information)"), | ||
566 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
567 | GNUNET_GETOPT_OPTION_END | ||
568 | }; | ||
569 | |||
570 | |||
571 | /** | 558 | /** |
572 | * Main: start test | 559 | * Main: start test |
573 | */ | 560 | */ |
574 | int | 561 | int |
575 | main (int xargc, char *xargv[]) | 562 | main (int xargc, char *xargv[]) |
576 | { | 563 | { |
577 | char *const argv_torus[] = { "test-dht-2dtorus", | 564 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
565 | GNUNET_GETOPT_OPTION_END | ||
566 | }; | ||
567 | static char *const argv_torus[] = { "test-dht-2dtorus", | ||
578 | "-c", | 568 | "-c", |
579 | "test_dht_2dtorus.conf", | 569 | "test_dht_2dtorus.conf", |
580 | NULL | 570 | NULL |
581 | }; | 571 | }; |
582 | char *const argv_line[] = { "test-dht-line", | 572 | static char *const argv_line[] = { "test-dht-line", |
583 | "-c", | 573 | "-c", |
584 | "test_dht_line.conf", | 574 | "test_dht_line.conf", |
585 | NULL | 575 | NULL |
@@ -612,17 +602,17 @@ main (int xargc, char *xargv[]) | |||
612 | #if REMOVE_DIR | 602 | #if REMOVE_DIR |
613 | GNUNET_DISK_directory_remove ("/tmp/test_dht_topo"); | 603 | GNUNET_DISK_directory_remove ("/tmp/test_dht_topo"); |
614 | #endif | 604 | #endif |
615 | if (found_1 == 0) | 605 | if (0 == found_1) |
616 | { | 606 | { |
617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 1 not found!\n"); | 607 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 1 not found!\n"); |
618 | } | 608 | } |
619 | if (TORUS == test_topology) | 609 | if (TORUS == test_topology) |
620 | { | 610 | { |
621 | if (found_2 == 0) | 611 | if (0 == found_2) |
622 | { | 612 | { |
623 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 2 not found!\n"); | 613 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 2 not found!\n"); |
624 | } | 614 | } |
625 | if (found_far == 0) | 615 | if (0 == found_far) |
626 | { | 616 | { |
627 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID far not found!\n"); | 617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID far not found!\n"); |
628 | } | 618 | } |