2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file testing/test_testing_topology.c
22 * @brief base testcase for testing all the topologies provided
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_core_service.h"
27 #include "gnunet_os_lib.h"
29 #define VERBOSE GNUNET_YES
31 #define DELAY_FOR_LOGGING GNUNET_NO
34 * How long until we fail the whole testcase?
36 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 240)
39 * How long until we give up on starting the peers?
41 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 500)
43 #define SECONDS_PER_PEER_START 45
45 #define DEFAULT_NUM_PEERS 4
47 #define MAX_OUTSTANDING_CONNECTIONS 100
49 static float fail_percentage = 0.05;
53 static unsigned long long num_peers;
55 static unsigned int topology_connections;
57 static unsigned int total_connections;
59 static unsigned int failed_connections;
61 static unsigned int total_server_connections;
63 static unsigned int total_messages_received;
65 static unsigned int expected_messages;
67 static unsigned int expected_connections;
69 static unsigned long long peers_left;
71 static struct GNUNET_TESTING_PeerGroup *pg;
73 static struct GNUNET_SCHEDULER_Handle *sched;
75 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
77 GNUNET_SCHEDULER_TaskIdentifier die_task;
79 static char *dotOutFileName;
81 static struct GNUNET_TIME_Relative settle_time;
83 static FILE *dotOutFile;
85 static char *topology_string;
87 static char *blacklist_transports;
89 static int transmit_ready_scheduled;
91 static int transmit_ready_failed;
93 static int transmit_ready_called;
95 static unsigned int modnum;
97 static unsigned int dotnum;
99 static enum GNUNET_TESTING_Topology topology;
101 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
103 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
105 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
107 static double connect_topology_option_modifier = 0.0;
109 static char *test_directory;
113 struct GNUNET_TestMessage
116 * Header of the message
118 struct GNUNET_MessageHeader header;
121 * Unique identifier for this message.
126 struct TestMessageContext
128 /* This is a linked list */
129 struct TestMessageContext *next;
131 /* Handle to the sending peer core */
132 struct GNUNET_CORE_Handle *peer1handle;
134 /* Handle to the receiving peer core */
135 struct GNUNET_CORE_Handle *peer2handle;
137 /* Handle to the sending peer daemon */
138 struct GNUNET_TESTING_Daemon *peer1;
140 /* Handle to the receiving peer daemon */
141 struct GNUNET_TESTING_Daemon *peer2;
143 /* Identifier for this message, so we don't disconnect other peers! */
146 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
147 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
151 static struct TestMessageContext *test_messages;
154 * Check whether peers successfully shut down.
156 void shutdown_callback (void *cls,
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Shutdown of peers failed!\n");
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "All peers successfully shut down!\n");
177 #if DELAY_FOR_LOGGING
178 static void gather_log_data ()
181 char *connect_number;
183 GNUNET_asprintf(&peer_number, "%llu", num_peers);
184 GNUNET_asprintf(&connect_number, "%llu", expected_connections);
185 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
186 "memsize.pl", "totals.txt", peer_number, connect_number, NULL);
187 GNUNET_OS_process_wait(mem_process);
195 GNUNET_assert (pg != NULL);
196 struct TestMessageContext *pos;
197 struct TestMessageContext *free_pos;
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
200 "Called finish testing, stopping daemons.\n");
208 if (pos->peer1handle != NULL)
210 GNUNET_CORE_disconnect(pos->peer1handle);
211 pos->peer1handle = NULL;
213 if (pos->peer2handle != NULL)
215 GNUNET_CORE_disconnect(pos->peer2handle);
216 pos->peer2handle = NULL;
220 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
222 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
224 GNUNET_free(free_pos);
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Calling daemons_stop\n");
235 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
237 if (dotOutFile != NULL)
239 fprintf(dotOutFile, "}");
248 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
250 struct TestMessageContext *pos = cls;
252 /* Disconnect from the respective cores */
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
257 if (pos->peer1handle != NULL)
258 GNUNET_CORE_disconnect(pos->peer1handle);
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
263 if (pos->peer2handle != NULL)
264 GNUNET_CORE_disconnect(pos->peer2handle);
265 /* Set handles to NULL so test case can be ended properly */
266 pos->peer1handle = NULL;
267 pos->peer2handle = NULL;
268 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
269 /* Decrement total connections so new can be established */
270 total_server_connections -= 2;
273 static void stats_finished (void *cls, int result)
275 fprintf(stderr, "Finished getting all peers statistics!\n");
276 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
280 * Callback function to process statistic values.
283 * @param peer the peer the statistics belong to
284 * @param subsystem name of subsystem that created the statistic
285 * @param name the name of the datum
286 * @param value the current value
287 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
288 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
290 static int stats_print (void *cls,
291 const struct GNUNET_PeerIdentity *peer,
292 const char *subsystem,
297 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value);
301 static void topology_cb (void *cls,
302 const struct GNUNET_PeerIdentity *first,
303 const struct GNUNET_PeerIdentity *second,
304 struct GNUNET_TIME_Relative latency,
314 fprintf(outfile, "\t\"%s\" -- ", GNUNET_i2s(first));
315 fprintf(outfile, "\"%s\";\n", GNUNET_i2s(second));
317 topology_connections++;
321 fprintf(stderr, "Finished iterating over topology, %d total connections!\n", topology_connections);
324 fprintf(outfile, "}\n");
326 GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_print, NULL);
327 //GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
333 process_mtype (void *cls,
334 const struct GNUNET_PeerIdentity *peer,
335 const struct GNUNET_MessageHeader *message,
336 struct GNUNET_TIME_Relative latency,
339 char *dotOutFileNameFinished;
340 FILE *dotOutFileFinished;
341 struct TestMessageContext *pos = cls;
342 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
343 if (pos->uid != ntohl(msg->uid))
347 if ((total_messages_received) % modnum == 0)
349 if (total_messages_received == 0)
350 fprintf (stdout, "0%%");
352 fprintf (stdout, "%d%%",
353 (int) (((float) total_messages_received /
354 expected_messages) * 100));
357 else if (total_messages_received % dotnum == 0)
359 fprintf (stdout, ".");
364 total_messages_received++;
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs(message->type));
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
372 if (total_messages_received == expected_messages)
375 fprintf(stdout, "100%%]\n");
377 GNUNET_SCHEDULER_cancel (sched, die_task);
378 GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology");
379 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
380 if (dotOutFileFinished != NULL)
382 fprintf(dotOutFileFinished, "strict graph G {\n");
384 topology_connections = 0;
385 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
386 //GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
390 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
397 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
400 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
401 "End badly was called (%s)... stopping daemons.\n", msg);
402 struct TestMessageContext *pos;
403 struct TestMessageContext *free_pos;
408 if (pos->peer1handle != NULL)
410 GNUNET_CORE_disconnect(pos->peer1handle);
411 pos->peer1handle = NULL;
413 if (pos->peer2handle != NULL)
415 GNUNET_CORE_disconnect(pos->peer2handle);
416 pos->peer2handle = NULL;
420 GNUNET_free(free_pos);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
432 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
433 ok = 7331; /* Opposite of leet */
436 ok = 401; /* Never got peers started */
438 if (dotOutFile != NULL)
440 fprintf(dotOutFile, "}");
446 transmit_ready (void *cls, size_t size, void *buf)
448 struct GNUNET_TestMessage *m;
449 struct TestMessageContext *pos = cls;
451 GNUNET_assert (buf != NULL);
452 m = (struct GNUNET_TestMessage *) buf;
453 m->header.type = htons (MTYPE);
454 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
455 m->uid = htonl(pos->uid);
456 transmit_ready_called++;
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called);
461 return sizeof (struct GNUNET_TestMessage);
465 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
469 static struct GNUNET_CORE_MessageHandler handlers[] = {
470 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
475 init_notify_peer2 (void *cls,
476 struct GNUNET_CORE_Handle *server,
477 const struct GNUNET_PeerIdentity *my_identity,
478 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
480 struct TestMessageContext *pos = cls;
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "Core connection to `%4s' established, scheduling message send\n",
485 GNUNET_i2s (my_identity));
487 total_server_connections++;
489 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
493 sizeof (struct GNUNET_TestMessage),
494 &transmit_ready, pos))
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
498 GNUNET_i2s (&pos->peer2->id));
499 transmit_ready_failed++;
503 transmit_ready_scheduled++;
509 init_notify_peer1 (void *cls,
510 struct GNUNET_CORE_Handle *server,
511 const struct GNUNET_PeerIdentity *my_identity,
512 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
514 struct TestMessageContext *pos = cls;
515 total_server_connections++;
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
519 "Core connection to `%4s' established, setting up handles\n",
520 GNUNET_i2s (my_identity));
524 * Connect to the receiving peer
526 pos->peer2handle = GNUNET_CORE_connect (sched,
534 GNUNET_YES, NULL, GNUNET_YES, handlers);
540 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
542 struct TestMessageContext *pos = cls;
544 if ((pos == test_messages) && (settle_time.value > 0))
546 topology_connections = 0;
547 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
549 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
552 if (die_task == GNUNET_SCHEDULER_NO_TASK)
554 die_task = GNUNET_SCHEDULER_add_delayed (sched,
556 &end_badly, "from send test messages (timeout)");
559 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
561 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
562 &send_test_messages, pos);
563 return; /* Otherwise we'll double schedule messages here! */
567 * Connect to the sending peer
569 pos->peer1handle = GNUNET_CORE_connect (sched,
577 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
579 GNUNET_assert(pos->peer1handle != NULL);
581 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
583 GNUNET_SCHEDULER_add_now (sched,
584 &send_test_messages, pos->next);
588 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
589 &send_test_messages, pos->next);
595 topology_callback (void *cls,
596 const struct GNUNET_PeerIdentity *first,
597 const struct GNUNET_PeerIdentity *second,
599 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
600 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
601 struct GNUNET_TESTING_Daemon *first_daemon,
602 struct GNUNET_TESTING_Daemon *second_daemon,
605 struct TestMessageContext *temp_context;
609 if ((total_connections) % modnum == 0)
611 if (total_connections == 0)
612 fprintf (stdout, "0%%");
614 fprintf (stdout, "%d%%",
615 (int) (((float) total_connections /
616 expected_connections) * 100));
619 else if (total_connections % dotnum == 0)
621 fprintf (stdout, ".");
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
628 first_daemon->shortname,
629 second_daemon->shortname);
631 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
632 temp_context->peer1 = first_daemon;
633 temp_context->peer2 = second_daemon;
634 temp_context->next = test_messages;
635 temp_context->uid = total_connections;
636 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
637 test_messages = temp_context;
640 if (dotOutFile != NULL)
641 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
646 failed_connections++;
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
648 first_daemon->shortname,
649 second_daemon->shortname, emsg);
653 if (total_connections == expected_connections)
656 fprintf(stdout, "100%%]\n");
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
660 "Created %d total connections, which is our target number! Calling send messages.\n",
663 modnum = expected_messages / 4;
664 dotnum = (expected_messages / 50) + 1;
665 GNUNET_SCHEDULER_cancel (sched, die_task);
666 die_task = GNUNET_SCHEDULER_NO_TASK;
667 #if DELAY_FOR_LOGGING
668 fprintf(stdout, "Sending test messages in 10 seconds.\n");
669 GNUNET_SCHEDULER_add_delayed (sched,
670 GNUNET_TIME_relative_multiply
671 (GNUNET_TIME_UNIT_SECONDS, 10),
672 &send_test_messages, test_messages);
675 if (settle_time.value > 0)
677 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
679 GNUNET_SCHEDULER_add_delayed (sched, settle_time, &send_test_messages, test_messages);
682 fprintf(stdout, "Test message progress: [");
686 else if (total_connections + failed_connections == expected_connections)
688 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
690 GNUNET_SCHEDULER_cancel (sched, die_task);
691 die_task = GNUNET_SCHEDULER_NO_TASK;
692 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
696 GNUNET_SCHEDULER_cancel (sched, die_task);
697 die_task = GNUNET_SCHEDULER_add_now (sched,
698 &end_badly, "from topology_callback (too many failed connections)");
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
706 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
714 expected_connections = -1;
715 if ((pg != NULL) && (peers_left == 0))
717 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
720 "Have %d expected connections\n", expected_connections);
724 GNUNET_SCHEDULER_cancel (sched, die_task);
725 if (expected_connections == GNUNET_SYSERR)
727 die_task = GNUNET_SCHEDULER_add_now (sched,
728 &end_badly, "from connect topology (bad return)");
731 die_task = GNUNET_SCHEDULER_add_delayed (sched,
733 &end_badly, "from connect topology (timeout)");
734 modnum = expected_connections / 4;
735 dotnum = (expected_connections / 50) + 1;
737 fprintf(stdout, "Peer connection progress: [");
744 peers_left = num_peers; /* Reset counter */
745 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
749 "Topology set up, now starting peers!\n");
750 fprintf(stdout, "Daemon start progress [");
752 GNUNET_TESTING_daemons_continue_startup(pg);
756 GNUNET_SCHEDULER_cancel (sched, die_task);
757 die_task = GNUNET_SCHEDULER_add_now (sched,
758 &end_badly, "from create topology (bad return)");
760 GNUNET_SCHEDULER_cancel (sched, die_task);
761 die_task = GNUNET_SCHEDULER_add_delayed (sched,
763 &end_badly, "from continue startup (timeout)");
768 peers_started_callback (void *cls,
769 const struct GNUNET_PeerIdentity *id,
770 const struct GNUNET_CONFIGURATION_Handle *cfg,
771 struct GNUNET_TESTING_Daemon *d, const char *emsg)
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
779 GNUNET_assert (id != NULL);
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
782 (num_peers - peers_left) + 1, num_peers);
785 if ((num_peers - peers_left) % modnum == 0)
787 if (num_peers - peers_left == 0)
788 fprintf (stdout, "0%%");
790 fprintf (stdout, "%d%%",
791 (int) (((float) (num_peers - peers_left) /
795 else if ((num_peers - peers_left) % dotnum == 0)
797 fprintf (stdout, ".");
805 fprintf(stdout, "100%%]\n");
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
809 "All %d daemons started, now connecting peers!\n",
812 GNUNET_SCHEDULER_cancel (sched, die_task);
813 /* Set up task in case topology creation doesn't finish
814 * within a reasonable amount of time */
815 die_task = GNUNET_SCHEDULER_add_delayed (sched,
816 GNUNET_TIME_relative_multiply
817 (GNUNET_TIME_UNIT_MINUTES, 8),
818 &end_badly, "from peers_started_callback");
819 #if DELAY_FOR_LOGGING
820 fprintf(stdout, "Connecting topology in 10 seconds\n");
822 GNUNET_SCHEDULER_add_delayed (sched,
823 GNUNET_TIME_relative_multiply
824 (GNUNET_TIME_UNIT_SECONDS, 10),
825 &connect_topology, NULL);
834 * Callback indicating that the hostkey was created for a peer.
837 * @param id the peer identity
838 * @param d the daemon handle (pretty useless at this point, remove?)
839 * @param emsg non-null on failure
841 void hostkey_callback (void *cls,
842 const struct GNUNET_PeerIdentity *id,
843 struct GNUNET_TESTING_Daemon *d,
848 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Hostkey (%d/%d) created for peer `%s'\n",
854 num_peers - peers_left, num_peers, GNUNET_i2s(id));
858 if ((num_peers - peers_left) % modnum == 0)
860 if (num_peers - peers_left == 0)
861 fprintf (stdout, "0%%");
863 fprintf (stdout, "%d%%",
864 (int) (((float) (num_peers - peers_left) /
868 else if ((num_peers - peers_left) % dotnum == 0)
870 fprintf (stdout, ".");
878 fprintf(stdout, "100%%]\n");
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "All %d hostkeys created, now creating topology!\n",
883 GNUNET_SCHEDULER_cancel (sched, die_task);
884 /* Set up task in case topology creation doesn't finish
885 * within a reasonable amount of time */
886 die_task = GNUNET_SCHEDULER_add_delayed (sched,
888 &end_badly, "from create_topology");
889 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
896 struct GNUNET_SCHEDULER_Handle *s,
898 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
901 char * connect_topology_str;
902 char * blacklist_topology_str;
903 char * connect_topology_option_str;
904 char * connect_topology_option_modifier_string;
905 unsigned long long temp_settle;
909 dotOutFile = fopen (dotOutFileName, "w");
910 if (dotOutFile != NULL)
912 fprintf (dotOutFile, "strict graph G {\n");
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "Starting daemons based on config file %s\n", cfgfile);
920 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
927 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
928 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
930 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
931 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
932 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
936 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
937 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
939 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
940 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
942 GNUNET_free_non_null(connect_topology_str);
944 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
945 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
947 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
948 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
949 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
951 GNUNET_free_non_null(connect_topology_option_str);
953 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
954 &connect_topology_option_modifier_string))
956 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
958 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
959 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
960 connect_topology_option_modifier_string,
961 "connect_topology_option_modifier",
964 GNUNET_free (connect_topology_option_modifier_string);
967 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
968 &blacklist_transports))
969 blacklist_transports = NULL;
972 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
973 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
975 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
976 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
978 GNUNET_free_non_null(topology_str);
979 GNUNET_free_non_null(blacklist_topology_str);
982 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
984 settle_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_settle);
987 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
989 num_peers = DEFAULT_NUM_PEERS;
993 peers_left = num_peers;
994 modnum = num_peers / 4;
995 dotnum = (num_peers / 50) + 1;
997 fprintf (stdout, "Hostkey generation progress: \[");
999 /* Set up a task to end testing if peer start fails */
1000 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1001 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
1002 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
1004 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1005 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
1006 &topology_callback, NULL, NULL);
1014 char *config_file_name;
1015 GNUNET_asprintf(&binary_name, "test-testing-topology-%s", topology_string);
1016 GNUNET_asprintf(&config_file_name, "test_testing_data_topology_%s.conf", topology_string);
1018 char *const argv[] = {binary_name,
1026 struct GNUNET_GETOPT_CommandLineOption options[] = {
1027 GNUNET_GETOPT_OPTION_END
1029 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1030 argv, binary_name, "nohelp",
1031 options, &run, &ok);
1032 if (ret != GNUNET_OK)
1034 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret);
1036 GNUNET_free(binary_name);
1037 GNUNET_free(config_file_name);
1042 main (int argc, char *argv[])
1045 char *binary_start_pos;
1046 char *our_binary_name;
1048 binary_start_pos = rindex(argv[0], '/');
1049 topology_string = strstr (binary_start_pos,
1051 GNUNET_assert (topology_string != NULL);
1053 topology_string = strstr (topology_string, "_");
1054 GNUNET_assert (topology_string != NULL);
1057 GNUNET_asprintf(&our_binary_name, "test-testing-topology_%s", topology_string);
1058 GNUNET_asprintf(&dotOutFileName, "topology_%s.dot", topology_string);
1060 GNUNET_log_setup (our_binary_name,
1070 * Need to remove base directory, subdirectories taken care
1071 * of by the testing framework.
1073 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1075 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1077 GNUNET_free(our_binary_name);
1081 /* end of test_testing_topology.c */