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_NO
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 120
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 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
75 GNUNET_SCHEDULER_TaskIdentifier die_task;
77 static char *dotOutFileName;
79 static struct GNUNET_TIME_Relative settle_time;
81 static FILE *dotOutFile;
83 static char *topology_string;
85 static char *blacklist_transports;
87 static int transmit_ready_scheduled;
89 static int transmit_ready_failed;
91 static int transmit_ready_called;
93 static unsigned int modnum;
95 static unsigned int dotnum;
97 static enum GNUNET_TESTING_Topology topology;
99 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
101 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
103 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
105 static double connect_topology_option_modifier = 0.0;
107 static char *test_directory;
111 struct GNUNET_TestMessage
114 * Header of the message
116 struct GNUNET_MessageHeader header;
119 * Unique identifier for this message.
124 struct TestMessageContext
126 /* This is a linked list */
127 struct TestMessageContext *next;
129 /* Handle to the sending peer core */
130 struct GNUNET_CORE_Handle *peer1handle;
132 /* Handle to the receiving peer core */
133 struct GNUNET_CORE_Handle *peer2handle;
135 /* Handle to the sending peer daemon */
136 struct GNUNET_TESTING_Daemon *peer1;
138 /* Handle to the receiving peer daemon */
139 struct GNUNET_TESTING_Daemon *peer2;
141 /* Identifier for this message, so we don't disconnect other peers! */
144 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
145 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
149 static struct TestMessageContext *test_messages;
152 * Check whether peers successfully shut down.
154 void shutdown_callback (void *cls,
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
161 "Shutdown of peers failed!\n");
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "All peers successfully shut down!\n");
175 #if DELAY_FOR_LOGGING
176 static void gather_log_data ()
179 char *connect_number;
180 struct GNUNET_OS_Process *mem_process;
181 GNUNET_asprintf(&peer_number, "%llu", num_peers);
182 GNUNET_asprintf(&connect_number, "%llu", expected_connections);
183 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
184 "memsize.pl", "totals.txt", peer_number, connect_number, NULL);
185 GNUNET_OS_process_wait (mem_process);
186 GNUNET_OS_process_close (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");
206 if (pos->peer1handle != NULL)
208 GNUNET_CORE_disconnect(pos->peer1handle);
209 pos->peer1handle = NULL;
211 if (pos->peer2handle != NULL)
213 GNUNET_CORE_disconnect(pos->peer2handle);
214 pos->peer2handle = NULL;
218 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
220 GNUNET_SCHEDULER_cancel(free_pos->disconnect_task);
222 GNUNET_free(free_pos);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Calling daemons_stop\n");
233 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
235 if (dotOutFile != NULL)
237 fprintf(dotOutFile, "}");
246 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
248 struct TestMessageContext *pos = cls;
250 /* Disconnect from the respective cores */
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
255 if (pos->peer1handle != NULL)
256 GNUNET_CORE_disconnect(pos->peer1handle);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
261 if (pos->peer2handle != NULL)
262 GNUNET_CORE_disconnect(pos->peer2handle);
263 /* Set handles to NULL so test case can be ended properly */
264 pos->peer1handle = NULL;
265 pos->peer2handle = NULL;
266 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
267 /* Decrement total connections so new can be established */
268 total_server_connections -= 2;
271 static void stats_finished (void *cls, int result)
273 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
277 * Callback function to process statistic values.
280 * @param peer the peer the statistics belong to
281 * @param subsystem name of subsystem that created the statistic
282 * @param name the name of the datum
283 * @param value the current value
284 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
285 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
287 static int stats_print (void *cls,
288 const struct GNUNET_PeerIdentity *peer,
289 const char *subsystem,
294 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value);
298 static void topology_cb (void *cls,
299 const struct GNUNET_PeerIdentity *first,
300 const struct GNUNET_PeerIdentity *second,
301 struct GNUNET_TIME_Relative latency,
311 fprintf(outfile, "\t\"%s\" -- ", GNUNET_i2s(first));
312 fprintf(outfile, "\"%s\";\n", GNUNET_i2s(second));
314 topology_connections++;
318 fprintf(stderr, "Finished iterating over topology, %d total connections!\n", topology_connections);
321 fprintf(outfile, "}\n");
323 GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_print, NULL);
324 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
330 process_mtype (void *cls,
331 const struct GNUNET_PeerIdentity *peer,
332 const struct GNUNET_MessageHeader *message,
333 struct GNUNET_TIME_Relative latency,
336 char *dotOutFileNameFinished;
337 FILE *dotOutFileFinished;
338 struct TestMessageContext *pos = cls;
339 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
340 if (pos->uid != ntohl(msg->uid))
344 if ((total_messages_received) % modnum == 0)
346 if (total_messages_received == 0)
347 fprintf (stdout, "0%%");
349 fprintf (stdout, "%d%%",
350 (int) (((float) total_messages_received /
351 expected_messages) * 100));
354 else if (total_messages_received % dotnum == 0)
356 fprintf (stdout, ".");
361 total_messages_received++;
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs(message->type));
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
369 if (total_messages_received == expected_messages)
372 fprintf(stdout, "100%%]\n");
374 GNUNET_SCHEDULER_cancel (die_task);
375 GNUNET_asprintf(&dotOutFileNameFinished, "%s.dot", "final_topology");
376 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
377 GNUNET_free(dotOutFileNameFinished);
378 if (dotOutFileFinished != NULL)
380 fprintf(dotOutFileFinished, "strict graph G {\n");
382 topology_connections = 0;
383 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
384 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
388 pos->disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cores, pos);
395 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
398 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
399 "End badly was called (%s)... stopping daemons.\n", msg);
400 struct TestMessageContext *pos;
401 struct TestMessageContext *free_pos;
406 if (pos->peer1handle != NULL)
408 GNUNET_CORE_disconnect(pos->peer1handle);
409 pos->peer1handle = NULL;
411 if (pos->peer2handle != NULL)
413 GNUNET_CORE_disconnect(pos->peer2handle);
414 pos->peer2handle = NULL;
418 GNUNET_free(free_pos);
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
430 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
431 ok = 7331; /* Opposite of leet */
434 ok = 401; /* Never got peers started */
436 if (dotOutFile != NULL)
438 fprintf(dotOutFile, "}");
444 transmit_ready (void *cls, size_t size, void *buf)
446 struct GNUNET_TestMessage *m;
447 struct TestMessageContext *pos = cls;
449 GNUNET_assert (buf != NULL);
450 m = (struct GNUNET_TestMessage *) buf;
451 m->header.type = htons (MTYPE);
452 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
453 m->uid = htonl(pos->uid);
454 transmit_ready_called++;
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 "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);
459 return sizeof (struct GNUNET_TestMessage);
463 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
467 static struct GNUNET_CORE_MessageHandler handlers[] = {
468 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
473 init_notify_peer2 (void *cls,
474 struct GNUNET_CORE_Handle *server,
475 const struct GNUNET_PeerIdentity *my_identity,
476 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
478 struct TestMessageContext *pos = cls;
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "Core connection to `%4s' established, scheduling message send\n",
483 GNUNET_i2s (my_identity));
485 total_server_connections++;
487 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
491 sizeof (struct GNUNET_TestMessage),
492 &transmit_ready, pos))
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
496 GNUNET_i2s (&pos->peer2->id));
497 transmit_ready_failed++;
501 transmit_ready_scheduled++;
507 init_notify_peer1 (void *cls,
508 struct GNUNET_CORE_Handle *server,
509 const struct GNUNET_PeerIdentity *my_identity,
510 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
512 struct TestMessageContext *pos = cls;
513 total_server_connections++;
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "Core connection to `%4s' established, setting up handles\n",
518 GNUNET_i2s (my_identity));
522 * Connect to the receiving peer
524 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
531 GNUNET_YES, NULL, GNUNET_YES, handlers);
537 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
539 struct TestMessageContext *pos = cls;
541 if ((pos == test_messages) && (settle_time.rel_value > 0))
543 topology_connections = 0;
544 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
546 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
549 if (die_task == GNUNET_SCHEDULER_NO_TASK)
551 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
552 &end_badly, "from send test messages (timeout)");
555 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
557 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
558 &send_test_messages, pos);
559 return; /* Otherwise we'll double schedule messages here! */
563 * Connect to the sending peer
565 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
572 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
574 GNUNET_assert(pos->peer1handle != NULL);
576 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
578 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
582 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
583 &send_test_messages, pos->next);
589 topology_callback (void *cls,
590 const struct GNUNET_PeerIdentity *first,
591 const struct GNUNET_PeerIdentity *second,
593 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
594 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
595 struct GNUNET_TESTING_Daemon *first_daemon,
596 struct GNUNET_TESTING_Daemon *second_daemon,
599 struct TestMessageContext *temp_context;
603 if ((total_connections) % modnum == 0)
605 if (total_connections == 0)
606 fprintf (stdout, "0%%");
608 fprintf (stdout, "%d%%",
609 (int) (((float) total_connections /
610 expected_connections) * 100));
613 else if (total_connections % dotnum == 0)
615 fprintf (stdout, ".");
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
622 first_daemon->shortname,
623 second_daemon->shortname);
625 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
626 temp_context->peer1 = first_daemon;
627 temp_context->peer2 = second_daemon;
628 temp_context->next = test_messages;
629 temp_context->uid = total_connections;
630 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
631 test_messages = temp_context;
634 if (dotOutFile != NULL)
635 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
640 failed_connections++;
641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
642 first_daemon->shortname,
643 second_daemon->shortname, emsg);
647 if (total_connections == expected_connections)
650 fprintf(stdout, "100%%]\n");
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Created %d total connections, which is our target number! Calling send messages.\n",
657 modnum = expected_messages / 4;
658 dotnum = (expected_messages / 50) + 1;
659 GNUNET_SCHEDULER_cancel (die_task);
660 die_task = GNUNET_SCHEDULER_NO_TASK;
661 #if DELAY_FOR_LOGGING
662 fprintf(stdout, "Sending test messages in 10 seconds.\n");
663 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
664 (GNUNET_TIME_UNIT_SECONDS, 10),
665 &send_test_messages, test_messages);
668 if (settle_time.rel_value > 0)
670 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
672 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages, test_messages);
675 fprintf(stdout, "Test message progress: [");
679 else if (total_connections + failed_connections == expected_connections)
681 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
683 GNUNET_SCHEDULER_cancel (die_task);
684 die_task = GNUNET_SCHEDULER_NO_TASK;
685 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
689 GNUNET_SCHEDULER_cancel (die_task);
690 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
698 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
703 static void topology_creation_finished (void *cls,
708 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All topology connections created successfully!\n");
715 expected_connections = -1;
716 if ((pg != NULL) && (peers_left == 0))
718 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, &topology_creation_finished, NULL);
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
721 "Have %d expected connections\n", expected_connections);
725 GNUNET_SCHEDULER_cancel (die_task);
726 if (expected_connections == GNUNET_SYSERR)
728 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
731 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
732 &end_badly, "from connect topology (timeout)");
733 modnum = expected_connections / 4;
734 dotnum = (expected_connections / 50) + 1;
736 fprintf(stdout, "Peer connection progress: [");
743 peers_left = num_peers; /* Reset counter */
744 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Topology set up, now starting peers!\n");
749 fprintf(stdout, "Daemon start progress [");
751 GNUNET_TESTING_daemons_continue_startup(pg);
755 GNUNET_SCHEDULER_cancel (die_task);
756 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)");
758 GNUNET_SCHEDULER_cancel (die_task);
759 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
760 &end_badly, "from continue startup (timeout)");
765 peers_started_callback (void *cls,
766 const struct GNUNET_PeerIdentity *id,
767 const struct GNUNET_CONFIGURATION_Handle *cfg,
768 struct GNUNET_TESTING_Daemon *d, const char *emsg)
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
776 GNUNET_assert (id != NULL);
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
779 (num_peers - peers_left) + 1, num_peers);
782 if ((num_peers - peers_left) % modnum == 0)
784 if (num_peers - peers_left == 0)
785 fprintf (stdout, "0%%");
787 fprintf (stdout, "%d%%",
788 (int) (((float) (num_peers - peers_left) /
792 else if ((num_peers - peers_left) % dotnum == 0)
794 fprintf (stdout, ".");
802 fprintf(stdout, "100%%]\n");
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
806 "All %d daemons started, now connecting peers!\n",
809 GNUNET_SCHEDULER_cancel (die_task);
810 /* Set up task in case topology creation doesn't finish
811 * within a reasonable amount of time */
812 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
813 (GNUNET_TIME_UNIT_MINUTES, 8),
814 &end_badly, "from peers_started_callback");
815 #if DELAY_FOR_LOGGING
816 fprintf(stdout, "Connecting topology in 10 seconds\n");
818 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
819 (GNUNET_TIME_UNIT_SECONDS, 10),
820 &connect_topology, NULL);
829 * Callback indicating that the hostkey was created for a peer.
832 * @param id the peer identity
833 * @param d the daemon handle (pretty useless at this point, remove?)
834 * @param emsg non-null on failure
836 void hostkey_callback (void *cls,
837 const struct GNUNET_PeerIdentity *id,
838 struct GNUNET_TESTING_Daemon *d,
843 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
848 "Hostkey (%d/%d) created for peer `%s'\n",
849 num_peers - peers_left, num_peers, GNUNET_i2s(id));
853 if ((num_peers - peers_left) % modnum == 0)
855 if (num_peers - peers_left == 0)
856 fprintf (stdout, "0%%");
858 fprintf (stdout, "%d%%",
859 (int) (((float) (num_peers - peers_left) /
863 else if ((num_peers - peers_left) % dotnum == 0)
865 fprintf (stdout, ".");
873 fprintf(stdout, "100%%]\n");
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
875 "All %d hostkeys created, now creating topology!\n",
878 GNUNET_SCHEDULER_cancel (die_task);
879 /* Set up task in case topology creation doesn't finish
880 * within a reasonable amount of time */
881 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
882 &end_badly, "from create_topology");
883 GNUNET_SCHEDULER_add_now(&create_topology, NULL);
891 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
894 char * connect_topology_str;
895 char * blacklist_topology_str;
896 char * connect_topology_option_str;
897 char * connect_topology_option_modifier_string;
898 unsigned long long temp_settle;
901 dotOutFile = fopen (dotOutFileName, "w");
902 if (dotOutFile != NULL)
904 fprintf (dotOutFile, "strict graph G {\n");
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Starting daemons based on config file %s\n", cfgfile);
912 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
919 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
920 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
922 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
923 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
924 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
928 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
929 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
931 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
932 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
934 GNUNET_free_non_null(connect_topology_str);
936 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
937 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
939 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
940 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
941 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
943 GNUNET_free_non_null(connect_topology_option_str);
945 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
946 &connect_topology_option_modifier_string))
948 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
950 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
951 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
952 connect_topology_option_modifier_string,
953 "connect_topology_option_modifier",
956 GNUNET_free (connect_topology_option_modifier_string);
959 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
960 &blacklist_transports))
961 blacklist_transports = NULL;
964 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
965 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
967 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
968 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
970 GNUNET_free_non_null(topology_str);
971 GNUNET_free_non_null(blacklist_topology_str);
974 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
976 settle_time = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_settle);
979 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
981 num_peers = DEFAULT_NUM_PEERS;
985 peers_left = num_peers;
986 modnum = num_peers / 4;
987 dotnum = (num_peers / 50) + 1;
989 fprintf (stdout, "Hostkey generation progress: [");
991 /* Set up a task to end testing if peer start fails */
992 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
993 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
995 GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1);
996 pg = GNUNET_TESTING_daemons_start (cfg,
997 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
998 &topology_callback, NULL, NULL);
1006 char *config_file_name;
1007 GNUNET_asprintf(&binary_name, "test-testing-topology-%s", topology_string);
1008 GNUNET_asprintf(&config_file_name, "test_testing_data_topology_%s.conf", topology_string);
1010 char *const argv[] = {binary_name,
1018 struct GNUNET_GETOPT_CommandLineOption options[] = {
1019 GNUNET_GETOPT_OPTION_END
1021 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1022 argv, binary_name, "nohelp",
1023 options, &run, &ok);
1024 if (ret != GNUNET_OK)
1026 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret);
1028 GNUNET_free(binary_name);
1029 GNUNET_free(config_file_name);
1034 main (int argc, char *argv[])
1037 char *binary_start_pos;
1038 char *our_binary_name;
1040 binary_start_pos = rindex(argv[0], '/');
1041 GNUNET_assert(binary_start_pos != NULL);
1042 topology_string = strstr (binary_start_pos,
1044 GNUNET_assert (topology_string != NULL);
1046 topology_string = strstr (topology_string, "_");
1047 GNUNET_assert (topology_string != NULL);
1050 GNUNET_asprintf(&our_binary_name, "test-testing-topology_%s", topology_string);
1051 GNUNET_asprintf(&dotOutFileName, "topology_%s.dot", topology_string);
1053 GNUNET_log_setup (our_binary_name,
1063 * Need to remove base directory, subdirectories taken care
1064 * of by the testing framework.
1066 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1068 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1070 GNUNET_free(our_binary_name);
1074 /* end of test_testing_topology.c */