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, 600)
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 total_connections;
57 static unsigned int failed_connections;
59 static unsigned int total_server_connections;
61 static unsigned int total_messages_received;
63 static unsigned int expected_messages;
65 static unsigned int expected_connections;
67 static unsigned long long peers_left;
69 static struct GNUNET_TESTING_PeerGroup *pg;
71 static struct GNUNET_SCHEDULER_Handle *sched;
73 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
75 GNUNET_SCHEDULER_TaskIdentifier die_task;
77 static char *dotOutFileName;
79 static FILE *dotOutFile;
81 static char *topology_string;
83 static char *blacklist_transports;
85 static int transmit_ready_scheduled;
87 static int transmit_ready_failed;
89 static int transmit_ready_called;
91 static unsigned int modnum;
93 static unsigned int dotnum;
95 static enum GNUNET_TESTING_Topology topology;
97 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
99 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
101 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
103 static double connect_topology_option_modifier = 0.0;
105 static char *test_directory;
109 struct GNUNET_TestMessage
112 * Header of the message
114 struct GNUNET_MessageHeader header;
117 * Unique identifier for this message.
122 struct TestMessageContext
124 /* This is a linked list */
125 struct TestMessageContext *next;
127 /* Handle to the sending peer core */
128 struct GNUNET_CORE_Handle *peer1handle;
130 /* Handle to the receiving peer core */
131 struct GNUNET_CORE_Handle *peer2handle;
133 /* Handle to the sending peer daemon */
134 struct GNUNET_TESTING_Daemon *peer1;
136 /* Handle to the receiving peer daemon */
137 struct GNUNET_TESTING_Daemon *peer2;
139 /* Identifier for this message, so we don't disconnect other peers! */
142 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
143 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
147 static struct TestMessageContext *test_messages;
150 * Check whether peers successfully shut down.
152 void shutdown_callback (void *cls,
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "Shutdown of peers failed!\n");
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "All peers successfully shut down!\n");
173 #if DELAY_FOR_LOGGING
174 static void gather_log_data ()
177 char *connect_number;
179 GNUNET_asprintf(&peer_number, "%llu", num_peers);
180 GNUNET_asprintf(&connect_number, "%llu", expected_connections);
181 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
182 "memsize.pl", "totals.txt", peer_number, connect_number, NULL);
183 GNUNET_OS_process_wait(mem_process);
190 GNUNET_assert (pg != NULL);
191 struct TestMessageContext *pos;
192 struct TestMessageContext *free_pos;
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Called finish testing, stopping daemons.\n");
203 if (pos->peer1handle != NULL)
205 GNUNET_CORE_disconnect(pos->peer1handle);
206 pos->peer1handle = NULL;
208 if (pos->peer2handle != NULL)
210 GNUNET_CORE_disconnect(pos->peer2handle);
211 pos->peer2handle = NULL;
215 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
217 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
219 GNUNET_free(free_pos);
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
223 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Calling daemons_stop\n");
230 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
232 if (dotOutFile != NULL)
234 fprintf(dotOutFile, "}");
243 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
245 struct TestMessageContext *pos = cls;
247 /* Disconnect from the respective cores */
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
252 if (pos->peer1handle != NULL)
253 GNUNET_CORE_disconnect(pos->peer1handle);
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
258 if (pos->peer2handle != NULL)
259 GNUNET_CORE_disconnect(pos->peer2handle);
260 /* Set handles to NULL so test case can be ended properly */
261 pos->peer1handle = NULL;
262 pos->peer2handle = NULL;
263 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
264 /* Decrement total connections so new can be established */
265 total_server_connections -= 2;
268 void topology_cb (void *cls,
269 const struct GNUNET_PeerIdentity *first,
270 const struct GNUNET_PeerIdentity *second,
271 struct GNUNET_TIME_Relative latency,
280 fprintf(stderr, "Peer %s connected to %s\n", GNUNET_i2s(first), GNUNET_h2s(&second->hashPubKey));
283 fprintf(outfile, "\t\"%s\" -- ", GNUNET_i2s(first));
284 fprintf(outfile, "\"%s\";\n", GNUNET_i2s(second));
289 fprintf(stderr, "Finished iterating over topology!\n");
292 fprintf(outfile, "}\n");
295 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
300 process_mtype (void *cls,
301 const struct GNUNET_PeerIdentity *peer,
302 const struct GNUNET_MessageHeader *message,
303 struct GNUNET_TIME_Relative latency,
306 char *dotOutFileNameFinished;
307 FILE *dotOutFileFinished;
308 struct TestMessageContext *pos = cls;
309 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
310 if (pos->uid != ntohl(msg->uid))
314 if ((total_messages_received) % modnum == 0)
316 if (total_messages_received == 0)
317 fprintf (stdout, "0%%");
319 fprintf (stdout, "%d%%",
320 (int) (((float) total_messages_received /
321 expected_messages) * 100));
324 else if (total_messages_received % dotnum == 0)
326 fprintf (stdout, ".");
331 total_messages_received++;
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs(message->type));
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
339 if (total_messages_received == expected_messages)
342 fprintf(stdout, "100%%]\n");
344 GNUNET_SCHEDULER_cancel (sched, die_task);
345 GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology");
346 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
347 if (dotOutFileFinished != NULL)
349 fprintf(dotOutFileFinished, "strict graph G {\n");
351 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
352 //GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
356 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
363 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
367 "End badly was called (%s)... stopping daemons.\n", msg);
368 struct TestMessageContext *pos;
369 struct TestMessageContext *free_pos;
374 if (pos->peer1handle != NULL)
376 GNUNET_CORE_disconnect(pos->peer1handle);
377 pos->peer1handle = NULL;
379 if (pos->peer2handle != NULL)
381 GNUNET_CORE_disconnect(pos->peer2handle);
382 pos->peer2handle = NULL;
386 GNUNET_free(free_pos);
391 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
392 ok = 7331; /* Opposite of leet */
395 ok = 401; /* Never got peers started */
397 if (dotOutFile != NULL)
399 fprintf(dotOutFile, "}");
405 transmit_ready (void *cls, size_t size, void *buf)
407 struct GNUNET_TestMessage *m;
408 struct TestMessageContext *pos = cls;
410 GNUNET_assert (buf != NULL);
411 m = (struct GNUNET_TestMessage *) buf;
412 m->header.type = htons (MTYPE);
413 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
414 m->uid = htonl(pos->uid);
415 transmit_ready_called++;
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418 "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);
420 return sizeof (struct GNUNET_TestMessage);
424 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
428 static struct GNUNET_CORE_MessageHandler handlers[] = {
429 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
434 init_notify_peer2 (void *cls,
435 struct GNUNET_CORE_Handle *server,
436 const struct GNUNET_PeerIdentity *my_identity,
437 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
439 struct TestMessageContext *pos = cls;
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "Core connection to `%4s' established, scheduling message send\n",
444 GNUNET_i2s (my_identity));
446 total_server_connections++;
448 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
452 sizeof (struct GNUNET_TestMessage),
453 &transmit_ready, pos))
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
457 GNUNET_i2s (&pos->peer2->id));
458 transmit_ready_failed++;
462 transmit_ready_scheduled++;
468 init_notify_peer1 (void *cls,
469 struct GNUNET_CORE_Handle *server,
470 const struct GNUNET_PeerIdentity *my_identity,
471 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
473 struct TestMessageContext *pos = cls;
474 total_server_connections++;
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 "Core connection to `%4s' established, setting up handles\n",
479 GNUNET_i2s (my_identity));
483 * Connect to the receiving peer
485 pos->peer2handle = GNUNET_CORE_connect (sched,
493 GNUNET_YES, NULL, GNUNET_YES, handlers);
499 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
501 struct TestMessageContext *pos = cls;
503 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
506 if (die_task == GNUNET_SCHEDULER_NO_TASK)
508 die_task = GNUNET_SCHEDULER_add_delayed (sched,
510 &end_badly, "from create topology (timeout)");
513 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
515 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
516 &send_test_messages, pos);
517 return; /* Otherwise we'll double schedule messages here! */
521 * Connect to the sending peer
523 pos->peer1handle = GNUNET_CORE_connect (sched,
531 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
533 GNUNET_assert(pos->peer1handle != NULL);
535 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
537 GNUNET_SCHEDULER_add_now (sched,
538 &send_test_messages, pos->next);
542 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
543 &send_test_messages, pos->next);
549 topology_callback (void *cls,
550 const struct GNUNET_PeerIdentity *first,
551 const struct GNUNET_PeerIdentity *second,
553 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
554 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
555 struct GNUNET_TESTING_Daemon *first_daemon,
556 struct GNUNET_TESTING_Daemon *second_daemon,
559 struct TestMessageContext *temp_context;
563 if ((total_connections) % modnum == 0)
565 if (total_connections == 0)
566 fprintf (stdout, "0%%");
568 fprintf (stdout, "%d%%",
569 (int) (((float) total_connections /
570 expected_connections) * 100));
573 else if (total_connections % dotnum == 0)
575 fprintf (stdout, ".");
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
582 first_daemon->shortname,
583 second_daemon->shortname);
585 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
586 temp_context->peer1 = first_daemon;
587 temp_context->peer2 = second_daemon;
588 temp_context->next = test_messages;
589 temp_context->uid = total_connections;
590 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
591 test_messages = temp_context;
594 if (dotOutFile != NULL)
595 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
600 failed_connections++;
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
602 first_daemon->shortname,
603 second_daemon->shortname, emsg);
607 if (total_connections == expected_connections)
610 fprintf(stdout, "100%%]\n");
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Created %d total connections, which is our target number! Calling send messages.\n",
617 modnum = expected_messages / 4;
618 dotnum = (expected_messages / 50) + 1;
619 GNUNET_SCHEDULER_cancel (sched, die_task);
620 die_task = GNUNET_SCHEDULER_NO_TASK;
621 #if DELAY_FOR_LOGGING
622 fprintf(stdout, "Sending test messages in 10 seconds.\n");
623 GNUNET_SCHEDULER_add_delayed (sched,
624 GNUNET_TIME_relative_multiply
625 (GNUNET_TIME_UNIT_SECONDS, 10),
626 &send_test_messages, test_messages);
629 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
632 fprintf(stdout, "Test message progress: [");
636 else if (total_connections + failed_connections == expected_connections)
638 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
640 GNUNET_SCHEDULER_cancel (sched, die_task);
641 die_task = GNUNET_SCHEDULER_NO_TASK;
642 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
646 GNUNET_SCHEDULER_cancel (sched, die_task);
647 die_task = GNUNET_SCHEDULER_add_now (sched,
648 &end_badly, "from topology_callback (too many failed connections)");
654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
656 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
664 expected_connections = -1;
665 if ((pg != NULL) && (peers_left == 0))
667 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
670 "Have %d expected connections\n", expected_connections);
674 GNUNET_SCHEDULER_cancel (sched, die_task);
675 if (expected_connections == GNUNET_SYSERR)
677 die_task = GNUNET_SCHEDULER_add_now (sched,
678 &end_badly, "from connect topology (bad return)");
681 die_task = GNUNET_SCHEDULER_add_delayed (sched,
683 &end_badly, "from connect topology (timeout)");
684 modnum = expected_connections / 4;
685 dotnum = (expected_connections / 50) + 1;
687 fprintf(stdout, "Peer connection progress: [");
694 peers_left = num_peers; /* Reset counter */
695 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Topology set up, now starting peers!\n");
700 fprintf(stdout, "Daemon start progress [");
702 GNUNET_TESTING_daemons_continue_startup(pg);
706 GNUNET_SCHEDULER_cancel (sched, die_task);
707 die_task = GNUNET_SCHEDULER_add_now (sched,
708 &end_badly, "from create topology (bad return)");
710 GNUNET_SCHEDULER_cancel (sched, die_task);
711 die_task = GNUNET_SCHEDULER_add_delayed (sched,
713 &end_badly, "from continue startup (timeout)");
718 peers_started_callback (void *cls,
719 const struct GNUNET_PeerIdentity *id,
720 const struct GNUNET_CONFIGURATION_Handle *cfg,
721 struct GNUNET_TESTING_Daemon *d, const char *emsg)
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
729 GNUNET_assert (id != NULL);
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
732 (num_peers - peers_left) + 1, num_peers);
735 if ((num_peers - peers_left) % modnum == 0)
737 if (num_peers - peers_left == 0)
738 fprintf (stdout, "0%%");
740 fprintf (stdout, "%d%%",
741 (int) (((float) (num_peers - peers_left) /
745 else if ((num_peers - peers_left) % dotnum == 0)
747 fprintf (stdout, ".");
755 fprintf(stdout, "100%%]\n");
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
759 "All %d daemons started, now connecting peers!\n",
762 GNUNET_SCHEDULER_cancel (sched, die_task);
763 /* Set up task in case topology creation doesn't finish
764 * within a reasonable amount of time */
765 die_task = GNUNET_SCHEDULER_add_delayed (sched,
766 GNUNET_TIME_relative_multiply
767 (GNUNET_TIME_UNIT_MINUTES, 8),
768 &end_badly, "from peers_started_callback");
769 #if DELAY_FOR_LOGGING
770 fprintf(stdout, "Connecting topology in 10 seconds\n");
772 GNUNET_SCHEDULER_add_delayed (sched,
773 GNUNET_TIME_relative_multiply
774 (GNUNET_TIME_UNIT_SECONDS, 10),
775 &connect_topology, NULL);
784 * Callback indicating that the hostkey was created for a peer.
787 * @param id the peer identity
788 * @param d the daemon handle (pretty useless at this point, remove?)
789 * @param emsg non-null on failure
791 void hostkey_callback (void *cls,
792 const struct GNUNET_PeerIdentity *id,
793 struct GNUNET_TESTING_Daemon *d,
798 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "Hostkey (%d/%d) created for peer `%s'\n",
804 num_peers - peers_left, num_peers, GNUNET_i2s(id));
808 if ((num_peers - peers_left) % modnum == 0)
810 if (num_peers - peers_left == 0)
811 fprintf (stdout, "0%%");
813 fprintf (stdout, "%d%%",
814 (int) (((float) (num_peers - peers_left) /
818 else if ((num_peers - peers_left) % dotnum == 0)
820 fprintf (stdout, ".");
828 fprintf(stdout, "100%%]\n");
829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
830 "All %d hostkeys created, now creating topology!\n",
833 GNUNET_SCHEDULER_cancel (sched, die_task);
834 /* Set up task in case topology creation doesn't finish
835 * within a reasonable amount of time */
836 die_task = GNUNET_SCHEDULER_add_delayed (sched,
838 &end_badly, "from create_topology");
839 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
846 struct GNUNET_SCHEDULER_Handle *s,
848 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
851 char * connect_topology_str;
852 char * blacklist_topology_str;
853 char * connect_topology_option_str;
854 char * connect_topology_option_modifier_string;
858 dotOutFile = fopen (dotOutFileName, "w");
859 if (dotOutFile != NULL)
861 fprintf (dotOutFile, "strict graph G {\n");
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
866 "Starting daemons based on config file %s\n", cfgfile);
869 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
876 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
877 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
879 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
880 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
881 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
885 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
886 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
888 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
889 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
891 GNUNET_free_non_null(connect_topology_str);
893 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
894 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
896 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
897 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
898 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
900 GNUNET_free_non_null(connect_topology_option_str);
902 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
903 &connect_topology_option_modifier_string))
905 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
907 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
908 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
909 connect_topology_option_modifier_string,
910 "connect_topology_option_modifier",
913 GNUNET_free (connect_topology_option_modifier_string);
916 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
917 &blacklist_transports))
918 blacklist_transports = NULL;
921 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
922 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
924 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
925 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
927 GNUNET_free_non_null(topology_str);
928 GNUNET_free_non_null(blacklist_topology_str);
931 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
933 num_peers = DEFAULT_NUM_PEERS;
937 peers_left = num_peers;
938 modnum = num_peers / 4;
939 dotnum = (num_peers / 50) + 1;
941 fprintf (stdout, "Hostkey generation progress: \[");
943 /* Set up a task to end testing if peer start fails */
944 die_task = GNUNET_SCHEDULER_add_delayed (sched,
945 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
946 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
948 pg = GNUNET_TESTING_daemons_start (sched, cfg,
949 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
950 &topology_callback, NULL, NULL);
958 char *config_file_name;
959 GNUNET_asprintf(&binary_name, "test-testing-topology-%s", topology_string);
960 GNUNET_asprintf(&config_file_name, "test_testing_data_topology_%s.conf", topology_string);
962 char *const argv[] = {binary_name,
970 struct GNUNET_GETOPT_CommandLineOption options[] = {
971 GNUNET_GETOPT_OPTION_END
973 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
974 argv, binary_name, "nohelp",
976 if (ret != GNUNET_OK)
978 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret);
980 GNUNET_free(binary_name);
981 GNUNET_free(config_file_name);
986 main (int argc, char *argv[])
989 char *binary_start_pos;
990 char *our_binary_name;
992 binary_start_pos = rindex(argv[0], '/');
993 topology_string = strstr (binary_start_pos,
995 GNUNET_assert (topology_string != NULL);
997 topology_string = strstr (topology_string, "_");
998 GNUNET_assert (topology_string != NULL);
1001 GNUNET_asprintf(&our_binary_name, "test-testing-topology_%s", topology_string);
1002 GNUNET_asprintf(&dotOutFileName, "topology_%s.dot", topology_string);
1004 GNUNET_log_setup (our_binary_name,
1014 * Need to remove base directory, subdirectories taken care
1015 * of by the testing framework.
1017 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1019 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1021 GNUNET_free(our_binary_name);
1025 /* end of test_testing_topology.c */