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 void topology_cb (void *cls,
274 const struct GNUNET_PeerIdentity *first,
275 const struct GNUNET_PeerIdentity *second,
276 struct GNUNET_TIME_Relative latency,
286 fprintf(outfile, "\t\"%s\" -- ", GNUNET_i2s(first));
287 fprintf(outfile, "\"%s\";\n", GNUNET_i2s(second));
289 topology_connections++;
293 fprintf(stderr, "Finished iterating over topology, %d total connections!\n", topology_connections);
296 fprintf(outfile, "}\n");
298 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
304 process_mtype (void *cls,
305 const struct GNUNET_PeerIdentity *peer,
306 const struct GNUNET_MessageHeader *message,
307 struct GNUNET_TIME_Relative latency,
310 char *dotOutFileNameFinished;
311 FILE *dotOutFileFinished;
312 struct TestMessageContext *pos = cls;
313 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
314 if (pos->uid != ntohl(msg->uid))
318 if ((total_messages_received) % modnum == 0)
320 if (total_messages_received == 0)
321 fprintf (stdout, "0%%");
323 fprintf (stdout, "%d%%",
324 (int) (((float) total_messages_received /
325 expected_messages) * 100));
328 else if (total_messages_received % dotnum == 0)
330 fprintf (stdout, ".");
335 total_messages_received++;
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs(message->type));
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
343 if (total_messages_received == expected_messages)
346 fprintf(stdout, "100%%]\n");
348 GNUNET_SCHEDULER_cancel (sched, die_task);
349 GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology");
350 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
351 if (dotOutFileFinished != NULL)
353 fprintf(dotOutFileFinished, "strict graph G {\n");
355 topology_connections = 0;
356 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
357 //GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
361 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
368 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
371 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
372 "End badly was called (%s)... stopping daemons.\n", msg);
373 struct TestMessageContext *pos;
374 struct TestMessageContext *free_pos;
379 if (pos->peer1handle != NULL)
381 GNUNET_CORE_disconnect(pos->peer1handle);
382 pos->peer1handle = NULL;
384 if (pos->peer2handle != NULL)
386 GNUNET_CORE_disconnect(pos->peer2handle);
387 pos->peer2handle = NULL;
391 GNUNET_free(free_pos);
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
403 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
404 ok = 7331; /* Opposite of leet */
407 ok = 401; /* Never got peers started */
409 if (dotOutFile != NULL)
411 fprintf(dotOutFile, "}");
417 transmit_ready (void *cls, size_t size, void *buf)
419 struct GNUNET_TestMessage *m;
420 struct TestMessageContext *pos = cls;
422 GNUNET_assert (buf != NULL);
423 m = (struct GNUNET_TestMessage *) buf;
424 m->header.type = htons (MTYPE);
425 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
426 m->uid = htonl(pos->uid);
427 transmit_ready_called++;
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "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);
432 return sizeof (struct GNUNET_TestMessage);
436 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
440 static struct GNUNET_CORE_MessageHandler handlers[] = {
441 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
446 init_notify_peer2 (void *cls,
447 struct GNUNET_CORE_Handle *server,
448 const struct GNUNET_PeerIdentity *my_identity,
449 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
451 struct TestMessageContext *pos = cls;
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "Core connection to `%4s' established, scheduling message send\n",
456 GNUNET_i2s (my_identity));
458 total_server_connections++;
460 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
464 sizeof (struct GNUNET_TestMessage),
465 &transmit_ready, pos))
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
469 GNUNET_i2s (&pos->peer2->id));
470 transmit_ready_failed++;
474 transmit_ready_scheduled++;
480 init_notify_peer1 (void *cls,
481 struct GNUNET_CORE_Handle *server,
482 const struct GNUNET_PeerIdentity *my_identity,
483 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
485 struct TestMessageContext *pos = cls;
486 total_server_connections++;
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Core connection to `%4s' established, setting up handles\n",
491 GNUNET_i2s (my_identity));
495 * Connect to the receiving peer
497 pos->peer2handle = GNUNET_CORE_connect (sched,
505 GNUNET_YES, NULL, GNUNET_YES, handlers);
511 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
513 struct TestMessageContext *pos = cls;
515 if ((pos == test_messages) && (settle_time.value > 0))
517 topology_connections = 0;
518 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
520 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
523 if (die_task == GNUNET_SCHEDULER_NO_TASK)
525 die_task = GNUNET_SCHEDULER_add_delayed (sched,
527 &end_badly, "from send test messages (timeout)");
530 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
532 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
533 &send_test_messages, pos);
534 return; /* Otherwise we'll double schedule messages here! */
538 * Connect to the sending peer
540 pos->peer1handle = GNUNET_CORE_connect (sched,
548 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
550 GNUNET_assert(pos->peer1handle != NULL);
552 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
554 GNUNET_SCHEDULER_add_now (sched,
555 &send_test_messages, pos->next);
559 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
560 &send_test_messages, pos->next);
566 topology_callback (void *cls,
567 const struct GNUNET_PeerIdentity *first,
568 const struct GNUNET_PeerIdentity *second,
570 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
571 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
572 struct GNUNET_TESTING_Daemon *first_daemon,
573 struct GNUNET_TESTING_Daemon *second_daemon,
576 struct TestMessageContext *temp_context;
580 if ((total_connections) % modnum == 0)
582 if (total_connections == 0)
583 fprintf (stdout, "0%%");
585 fprintf (stdout, "%d%%",
586 (int) (((float) total_connections /
587 expected_connections) * 100));
590 else if (total_connections % dotnum == 0)
592 fprintf (stdout, ".");
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
599 first_daemon->shortname,
600 second_daemon->shortname);
602 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
603 temp_context->peer1 = first_daemon;
604 temp_context->peer2 = second_daemon;
605 temp_context->next = test_messages;
606 temp_context->uid = total_connections;
607 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
608 test_messages = temp_context;
611 if (dotOutFile != NULL)
612 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
617 failed_connections++;
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
619 first_daemon->shortname,
620 second_daemon->shortname, emsg);
624 if (total_connections == expected_connections)
627 fprintf(stdout, "100%%]\n");
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Created %d total connections, which is our target number! Calling send messages.\n",
634 modnum = expected_messages / 4;
635 dotnum = (expected_messages / 50) + 1;
636 GNUNET_SCHEDULER_cancel (sched, die_task);
637 die_task = GNUNET_SCHEDULER_NO_TASK;
638 #if DELAY_FOR_LOGGING
639 fprintf(stdout, "Sending test messages in 10 seconds.\n");
640 GNUNET_SCHEDULER_add_delayed (sched,
641 GNUNET_TIME_relative_multiply
642 (GNUNET_TIME_UNIT_SECONDS, 10),
643 &send_test_messages, test_messages);
646 if (settle_time.value > 0)
648 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
650 GNUNET_SCHEDULER_add_delayed (sched, settle_time, &send_test_messages, test_messages);
653 fprintf(stdout, "Test message progress: [");
657 else if (total_connections + failed_connections == expected_connections)
659 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
661 GNUNET_SCHEDULER_cancel (sched, die_task);
662 die_task = GNUNET_SCHEDULER_NO_TASK;
663 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
667 GNUNET_SCHEDULER_cancel (sched, die_task);
668 die_task = GNUNET_SCHEDULER_add_now (sched,
669 &end_badly, "from topology_callback (too many failed connections)");
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
677 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
685 expected_connections = -1;
686 if ((pg != NULL) && (peers_left == 0))
688 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "Have %d expected connections\n", expected_connections);
695 GNUNET_SCHEDULER_cancel (sched, die_task);
696 if (expected_connections == GNUNET_SYSERR)
698 die_task = GNUNET_SCHEDULER_add_now (sched,
699 &end_badly, "from connect topology (bad return)");
702 die_task = GNUNET_SCHEDULER_add_delayed (sched,
704 &end_badly, "from connect topology (timeout)");
705 modnum = expected_connections / 4;
706 dotnum = (expected_connections / 50) + 1;
708 fprintf(stdout, "Peer connection progress: [");
715 peers_left = num_peers; /* Reset counter */
716 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
720 "Topology set up, now starting peers!\n");
721 fprintf(stdout, "Daemon start progress [");
723 GNUNET_TESTING_daemons_continue_startup(pg);
727 GNUNET_SCHEDULER_cancel (sched, die_task);
728 die_task = GNUNET_SCHEDULER_add_now (sched,
729 &end_badly, "from create topology (bad return)");
731 GNUNET_SCHEDULER_cancel (sched, die_task);
732 die_task = GNUNET_SCHEDULER_add_delayed (sched,
734 &end_badly, "from continue startup (timeout)");
739 peers_started_callback (void *cls,
740 const struct GNUNET_PeerIdentity *id,
741 const struct GNUNET_CONFIGURATION_Handle *cfg,
742 struct GNUNET_TESTING_Daemon *d, const char *emsg)
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
750 GNUNET_assert (id != NULL);
752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
753 (num_peers - peers_left) + 1, num_peers);
756 if ((num_peers - peers_left) % modnum == 0)
758 if (num_peers - peers_left == 0)
759 fprintf (stdout, "0%%");
761 fprintf (stdout, "%d%%",
762 (int) (((float) (num_peers - peers_left) /
766 else if ((num_peers - peers_left) % dotnum == 0)
768 fprintf (stdout, ".");
776 fprintf(stdout, "100%%]\n");
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "All %d daemons started, now connecting peers!\n",
783 GNUNET_SCHEDULER_cancel (sched, die_task);
784 /* Set up task in case topology creation doesn't finish
785 * within a reasonable amount of time */
786 die_task = GNUNET_SCHEDULER_add_delayed (sched,
787 GNUNET_TIME_relative_multiply
788 (GNUNET_TIME_UNIT_MINUTES, 8),
789 &end_badly, "from peers_started_callback");
790 #if DELAY_FOR_LOGGING
791 fprintf(stdout, "Connecting topology in 10 seconds\n");
793 GNUNET_SCHEDULER_add_delayed (sched,
794 GNUNET_TIME_relative_multiply
795 (GNUNET_TIME_UNIT_SECONDS, 10),
796 &connect_topology, NULL);
805 * Callback indicating that the hostkey was created for a peer.
808 * @param id the peer identity
809 * @param d the daemon handle (pretty useless at this point, remove?)
810 * @param emsg non-null on failure
812 void hostkey_callback (void *cls,
813 const struct GNUNET_PeerIdentity *id,
814 struct GNUNET_TESTING_Daemon *d,
819 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
824 "Hostkey (%d/%d) created for peer `%s'\n",
825 num_peers - peers_left, num_peers, GNUNET_i2s(id));
829 if ((num_peers - peers_left) % modnum == 0)
831 if (num_peers - peers_left == 0)
832 fprintf (stdout, "0%%");
834 fprintf (stdout, "%d%%",
835 (int) (((float) (num_peers - peers_left) /
839 else if ((num_peers - peers_left) % dotnum == 0)
841 fprintf (stdout, ".");
849 fprintf(stdout, "100%%]\n");
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
851 "All %d hostkeys created, now creating topology!\n",
854 GNUNET_SCHEDULER_cancel (sched, die_task);
855 /* Set up task in case topology creation doesn't finish
856 * within a reasonable amount of time */
857 die_task = GNUNET_SCHEDULER_add_delayed (sched,
859 &end_badly, "from create_topology");
860 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
867 struct GNUNET_SCHEDULER_Handle *s,
869 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
872 char * connect_topology_str;
873 char * blacklist_topology_str;
874 char * connect_topology_option_str;
875 char * connect_topology_option_modifier_string;
876 unsigned long long temp_settle;
880 dotOutFile = fopen (dotOutFileName, "w");
881 if (dotOutFile != NULL)
883 fprintf (dotOutFile, "strict graph G {\n");
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 "Starting daemons based on config file %s\n", cfgfile);
891 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
898 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
899 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
902 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
903 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
907 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
908 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
910 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
911 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
913 GNUNET_free_non_null(connect_topology_str);
915 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
916 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
918 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
919 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
920 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
922 GNUNET_free_non_null(connect_topology_option_str);
924 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
925 &connect_topology_option_modifier_string))
927 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
929 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
930 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
931 connect_topology_option_modifier_string,
932 "connect_topology_option_modifier",
935 GNUNET_free (connect_topology_option_modifier_string);
938 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
939 &blacklist_transports))
940 blacklist_transports = NULL;
943 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
944 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
946 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
947 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
949 GNUNET_free_non_null(topology_str);
950 GNUNET_free_non_null(blacklist_topology_str);
953 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
955 settle_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_settle);
958 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
960 num_peers = DEFAULT_NUM_PEERS;
964 peers_left = num_peers;
965 modnum = num_peers / 4;
966 dotnum = (num_peers / 50) + 1;
968 fprintf (stdout, "Hostkey generation progress: \[");
970 /* Set up a task to end testing if peer start fails */
971 die_task = GNUNET_SCHEDULER_add_delayed (sched,
972 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
973 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
975 pg = GNUNET_TESTING_daemons_start (sched, cfg,
976 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
977 &topology_callback, NULL, NULL);
985 char *config_file_name;
986 GNUNET_asprintf(&binary_name, "test-testing-topology-%s", topology_string);
987 GNUNET_asprintf(&config_file_name, "test_testing_data_topology_%s.conf", topology_string);
989 char *const argv[] = {binary_name,
997 struct GNUNET_GETOPT_CommandLineOption options[] = {
998 GNUNET_GETOPT_OPTION_END
1000 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1001 argv, binary_name, "nohelp",
1002 options, &run, &ok);
1003 if (ret != GNUNET_OK)
1005 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret);
1007 GNUNET_free(binary_name);
1008 GNUNET_free(config_file_name);
1013 main (int argc, char *argv[])
1016 char *binary_start_pos;
1017 char *our_binary_name;
1019 binary_start_pos = rindex(argv[0], '/');
1020 topology_string = strstr (binary_start_pos,
1022 GNUNET_assert (topology_string != NULL);
1024 topology_string = strstr (topology_string, "_");
1025 GNUNET_assert (topology_string != NULL);
1028 GNUNET_asprintf(&our_binary_name, "test-testing-topology_%s", topology_string);
1029 GNUNET_asprintf(&dotOutFileName, "topology_%s.dot", topology_string);
1031 GNUNET_log_setup (our_binary_name,
1041 * Need to remove base directory, subdirectories taken care
1042 * of by the testing framework.
1044 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1046 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1048 GNUNET_free(our_binary_name);
1052 /* end of test_testing_topology.c */