aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_topo.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-31 21:21:01 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-31 21:21:01 +0000
commit521b89ad0aab592c9a0a7af05a34a19056958e37 (patch)
tree8cfb442f11c65cae554a6222bacb2096a9845f7f /src/dht/test_dht_topo.c
parent2c050a03a07c6877d32e6017af1b26898cda081d (diff)
downloadgnunet-521b89ad0aab592c9a0a7af05a34a19056958e37.tar.gz
gnunet-521b89ad0aab592c9a0a7af05a34a19056958e37.zip
-code cleanup and better error messages for failures
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r--src/dht/test_dht_topo.c62
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 @@
53static int ok; 53static int ok;
54 54
55/** 55/**
56 * Be verbose
57 */
58static int verbose;
59
60/**
61 * Total number of peers in the test. 56 * Total number of peers in the test.
62 */ 57 */
63static unsigned long long num_peers; 58static unsigned long long num_peers;
@@ -114,27 +109,30 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
114 109
115static char *topology_file; 110static char *topology_file;
116 111
117struct GNUNET_TESTING_Daemon *d1; 112static struct GNUNET_TESTING_Daemon *d1;
113
114static struct GNUNET_TESTING_Daemon *d2;
118 115
119struct GNUNET_TESTING_Daemon *d2; 116static struct GNUNET_DHT_Handle **hs;
120 117
121struct GNUNET_DHT_Handle **hs; 118static struct GNUNET_DHT_GetHandle *get_h;
122 119
123struct GNUNET_DHT_GetHandle *get_h; 120static struct GNUNET_DHT_GetHandle *get_h_2;
124 121
125struct GNUNET_DHT_GetHandle *get_h_2; 122static struct GNUNET_DHT_GetHandle *get_h_far;
126 123
127struct GNUNET_DHT_GetHandle *get_h_far; 124static int found_1;
128 125
129int found_1; 126static int found_2;
130int found_2; 127
131int found_far; 128static int found_far;
132 129
133/** 130/**
134 * Which topology are we to run 131 * Which topology are we to run
135 */ 132 */
136static int test_topology; 133static 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
196static void 195static void
197dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, 196dht_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
257static void 257static void
258do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 258do_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 */
563static 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 */
574int 561int
575main (int xargc, char *xargv[]) 562main (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 }