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 =
104 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
106 static double connect_topology_option_modifier = 0.0;
108 static char *test_directory;
112 struct GNUNET_TestMessage
115 * Header of the message
117 struct GNUNET_MessageHeader header;
120 * Unique identifier for this message.
125 struct TestMessageContext
127 /* This is a linked list */
128 struct TestMessageContext *next;
130 /* Handle to the sending peer core */
131 struct GNUNET_CORE_Handle *peer1handle;
133 /* Handle to the receiving peer core */
134 struct GNUNET_CORE_Handle *peer2handle;
136 /* Handle to the sending peer daemon */
137 struct GNUNET_TESTING_Daemon *peer1;
139 /* Handle to the receiving peer daemon */
140 struct GNUNET_TESTING_Daemon *peer2;
142 /* Identifier for this message, so we don't disconnect other peers! */
145 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
146 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
150 static struct TestMessageContext *test_messages;
153 * Check whether peers successfully shut down.
156 shutdown_callback (void *cls, const char *emsg)
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "All peers successfully shut down!\n");
175 #if DELAY_FOR_LOGGING
180 char *connect_number;
181 struct GNUNET_OS_Process *mem_process;
182 GNUNET_asprintf (&peer_number, "%llu", num_peers);
183 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
184 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
185 "memsize.pl", "totals.txt",
186 peer_number, connect_number, NULL);
187 GNUNET_OS_process_wait (mem_process);
188 GNUNET_OS_process_close (mem_process);
197 GNUNET_assert (pg != NULL);
198 struct TestMessageContext *pos;
199 struct TestMessageContext *free_pos;
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "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 (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",
229 transmit_ready_scheduled, transmit_ready_failed,
230 transmit_ready_called);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
236 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
238 if (dotOutFile != NULL)
240 fprintf (dotOutFile, "}");
249 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 struct TestMessageContext *pos = cls;
253 /* Disconnect from the respective cores */
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Disconnecting from peer 1 `%4s'\n",
257 GNUNET_i2s (&pos->peer1->id));
259 if (pos->peer1handle != NULL)
260 GNUNET_CORE_disconnect (pos->peer1handle);
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "Disconnecting from peer 2 `%4s'\n",
264 GNUNET_i2s (&pos->peer2->id));
266 if (pos->peer2handle != NULL)
267 GNUNET_CORE_disconnect (pos->peer2handle);
268 /* Set handles to NULL so test case can be ended properly */
269 pos->peer1handle = NULL;
270 pos->peer2handle = NULL;
271 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
272 /* Decrement total connections so new can be established */
273 total_server_connections -= 2;
277 stats_finished (void *cls, int result)
279 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
283 * Callback function to process statistic values.
286 * @param peer the peer the statistics belong to
287 * @param subsystem name of subsystem that created the statistic
288 * @param name the name of the datum
289 * @param value the current value
290 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
291 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
294 stats_print (void *cls,
295 const struct GNUNET_PeerIdentity *peer,
296 const char *subsystem,
297 const char *name, uint64_t value, int is_persistent)
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
300 GNUNET_i2s (peer), subsystem, name, value);
305 topology_cb (void *cls,
306 const struct GNUNET_PeerIdentity *first,
307 const struct GNUNET_PeerIdentity *second, const char *emsg)
314 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
315 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
317 topology_connections++;
322 "Finished iterating over topology, %d total connections!\n",
323 topology_connections);
326 fprintf (outfile, "}\n");
328 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
330 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
336 process_mtype (void *cls,
337 const struct GNUNET_PeerIdentity *peer,
338 const struct GNUNET_MessageHeader *message,
339 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
341 char *dotOutFileNameFinished;
342 FILE *dotOutFileFinished;
343 struct TestMessageContext *pos = cls;
344 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
345 if (pos->uid != ntohl (msg->uid))
349 if ((total_messages_received) % modnum == 0)
351 if (total_messages_received == 0)
352 fprintf (stdout, "0%%");
354 fprintf (stdout, "%d%%",
355 (int) (((float) total_messages_received /
356 expected_messages) * 100));
359 else if (total_messages_received % dotnum == 0)
361 fprintf (stdout, ".");
366 total_messages_received++;
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
370 ntohs (message->type));
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
372 "Total messages received %d, expected %d.\n",
373 total_messages_received, expected_messages);
376 if (total_messages_received == expected_messages)
379 fprintf (stdout, "100%%]\n");
381 GNUNET_SCHEDULER_cancel (die_task);
382 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
383 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
384 GNUNET_free (dotOutFileNameFinished);
385 if (dotOutFileFinished != NULL)
387 fprintf (dotOutFileFinished, "strict graph G {\n");
389 topology_connections = 0;
390 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
391 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
395 pos->disconnect_task =
396 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
403 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
406 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
407 "End badly was called (%s)... stopping daemons.\n", msg);
408 struct TestMessageContext *pos;
409 struct TestMessageContext *free_pos;
414 if (pos->peer1handle != NULL)
416 GNUNET_CORE_disconnect (pos->peer1handle);
417 pos->peer1handle = NULL;
419 if (pos->peer2handle != NULL)
421 GNUNET_CORE_disconnect (pos->peer2handle);
422 pos->peer2handle = NULL;
426 GNUNET_free (free_pos);
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
432 transmit_ready_scheduled, transmit_ready_failed,
433 transmit_ready_called);
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
435 "Total messages received %d, expected %d.\n",
436 total_messages_received, expected_messages);
441 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
442 ok = 7331; /* Opposite of leet */
445 ok = 401; /* Never got peers started */
447 if (dotOutFile != NULL)
449 fprintf (dotOutFile, "}");
455 transmit_ready (void *cls, size_t size, void *buf)
457 struct GNUNET_TestMessage *m;
458 struct TestMessageContext *pos = cls;
460 GNUNET_assert (buf != NULL);
461 m = (struct GNUNET_TestMessage *) buf;
462 m->header.type = htons (MTYPE);
463 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
464 m->uid = htonl (pos->uid);
465 transmit_ready_called++;
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
469 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
470 transmit_ready_called);
472 return sizeof (struct GNUNET_TestMessage);
476 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
480 static struct GNUNET_CORE_MessageHandler handlers[] = {
481 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
486 init_notify_peer2 (void *cls,
487 struct GNUNET_CORE_Handle *server,
488 const struct GNUNET_PeerIdentity *my_identity,
489 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
492 struct TestMessageContext *pos = cls;
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Core connection to `%4s' established, scheduling message send\n",
497 GNUNET_i2s (my_identity));
499 total_server_connections++;
501 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
507 &transmit_ready, pos))
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
511 GNUNET_i2s (&pos->peer2->id));
512 transmit_ready_failed++;
516 transmit_ready_scheduled++;
522 init_notify_peer1 (void *cls,
523 struct GNUNET_CORE_Handle *server,
524 const struct GNUNET_PeerIdentity *my_identity,
525 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
528 struct TestMessageContext *pos = cls;
529 total_server_connections++;
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "Core connection to `%4s' established, setting up handles\n",
534 GNUNET_i2s (my_identity));
538 * Connect to the receiving peer
540 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
547 GNUNET_YES, NULL, GNUNET_YES,
554 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
556 struct TestMessageContext *pos = cls;
558 if ((pos == test_messages) && (settle_time.rel_value > 0))
560 topology_connections = 0;
561 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
563 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
566 if (die_task == GNUNET_SCHEDULER_NO_TASK)
568 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
570 "from send test messages (timeout)");
573 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
575 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
576 (GNUNET_TIME_UNIT_SECONDS, 1),
577 &send_test_messages, pos);
578 return; /* Otherwise we'll double schedule messages here! */
582 * Connect to the sending peer
584 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
591 GNUNET_NO, NULL, GNUNET_NO,
594 GNUNET_assert (pos->peer1handle != NULL);
596 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
598 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
602 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
603 (GNUNET_TIME_UNIT_SECONDS, 1),
604 &send_test_messages, pos->next);
610 topology_callback (void *cls,
611 const struct GNUNET_PeerIdentity *first,
612 const struct GNUNET_PeerIdentity *second,
614 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
615 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
616 struct GNUNET_TESTING_Daemon *first_daemon,
617 struct GNUNET_TESTING_Daemon *second_daemon,
620 struct TestMessageContext *temp_context;
624 if ((total_connections) % modnum == 0)
626 if (total_connections == 0)
627 fprintf (stdout, "0%%");
629 fprintf (stdout, "%d%%",
630 (int) (((float) total_connections /
631 expected_connections) * 100));
634 else if (total_connections % dotnum == 0)
636 fprintf (stdout, ".");
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
643 first_daemon->shortname, second_daemon->shortname);
645 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
646 temp_context->peer1 = first_daemon;
647 temp_context->peer2 = second_daemon;
648 temp_context->next = test_messages;
649 temp_context->uid = total_connections;
650 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
651 test_messages = temp_context;
654 if (dotOutFile != NULL)
655 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
656 second_daemon->shortname);
661 failed_connections++;
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
663 "Failed to connect peer %s to peer %s with error :\n%s\n",
664 first_daemon->shortname, second_daemon->shortname, emsg);
668 if (total_connections == expected_connections)
671 fprintf (stdout, "100%%]\n");
674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
675 "Created %d total connections, which is our target number! Calling send messages.\n",
678 modnum = expected_messages / 4;
679 dotnum = (expected_messages / 50) + 1;
680 GNUNET_SCHEDULER_cancel (die_task);
681 die_task = GNUNET_SCHEDULER_NO_TASK;
682 #if DELAY_FOR_LOGGING
683 fprintf (stdout, "Sending test messages in 10 seconds.\n");
684 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
685 (GNUNET_TIME_UNIT_SECONDS, 10),
686 &send_test_messages, test_messages);
689 if (settle_time.rel_value > 0)
691 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
693 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
697 fprintf (stdout, "Test message progress: [");
701 else if (total_connections + failed_connections == expected_connections)
703 if (failed_connections <
704 (unsigned int) (fail_percentage * total_connections))
706 GNUNET_SCHEDULER_cancel (die_task);
707 die_task = GNUNET_SCHEDULER_NO_TASK;
708 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
712 GNUNET_SCHEDULER_cancel (die_task);
714 GNUNET_SCHEDULER_add_now (&end_badly,
715 "from topology_callback (too many failed connections)");
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
723 total_connections, failed_connections, expected_connections,
724 expected_connections -
725 (unsigned int) (fail_percentage * expected_connections));
731 topology_creation_finished (void *cls, const char *emsg)
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "All topology connections created successfully!\n");
743 expected_connections = -1;
744 if ((pg != NULL) && (peers_left == 0))
746 expected_connections =
747 GNUNET_TESTING_connect_topology (pg, connection_topology,
748 connect_topology_option,
749 connect_topology_option_modifier,
750 &topology_creation_finished, NULL);
752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
753 "Have %d expected connections\n", expected_connections);
757 GNUNET_SCHEDULER_cancel (die_task);
758 if (expected_connections == GNUNET_SYSERR)
761 GNUNET_SCHEDULER_add_now (&end_badly,
762 "from connect topology (bad return)");
765 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
767 "from connect topology (timeout)");
768 modnum = expected_connections / 4;
769 dotnum = (expected_connections / 50) + 1;
771 fprintf (stdout, "Peer connection progress: [");
778 peers_left = num_peers; /* Reset counter */
779 if (GNUNET_TESTING_create_topology
780 (pg, topology, blacklist_topology,
781 blacklist_transports) != GNUNET_SYSERR)
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
785 "Topology set up, now starting peers!\n");
786 fprintf (stdout, "Daemon start progress [");
788 GNUNET_TESTING_daemons_continue_startup (pg);
792 GNUNET_SCHEDULER_cancel (die_task);
794 GNUNET_SCHEDULER_add_now (&end_badly,
795 "from create topology (bad return)");
797 GNUNET_SCHEDULER_cancel (die_task);
798 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
800 "from continue startup (timeout)");
805 peers_started_callback (void *cls,
806 const struct GNUNET_PeerIdentity *id,
807 const struct GNUNET_CONFIGURATION_Handle *cfg,
808 struct GNUNET_TESTING_Daemon *d, const char *emsg)
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
813 "Failed to start daemon with error: `%s'\n", emsg);
816 GNUNET_assert (id != NULL);
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
819 (num_peers - peers_left) + 1, num_peers);
822 if ((num_peers - peers_left) % modnum == 0)
824 if (num_peers - peers_left == 0)
825 fprintf (stdout, "0%%");
827 fprintf (stdout, "%d%%",
828 (int) (((float) (num_peers - peers_left) /
832 else if ((num_peers - peers_left) % dotnum == 0)
834 fprintf (stdout, ".");
842 fprintf (stdout, "100%%]\n");
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 "All %d daemons started, now connecting peers!\n",
849 GNUNET_SCHEDULER_cancel (die_task);
850 /* Set up task in case topology creation doesn't finish
851 * within a reasonable amount of time */
852 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
853 (GNUNET_TIME_UNIT_MINUTES, 8),
855 "from peers_started_callback");
856 #if DELAY_FOR_LOGGING
857 fprintf (stdout, "Connecting topology in 10 seconds\n");
859 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
860 (GNUNET_TIME_UNIT_SECONDS, 10),
861 &connect_topology, NULL);
870 * Callback indicating that the hostkey was created for a peer.
873 * @param id the peer identity
874 * @param d the daemon handle (pretty useless at this point, remove?)
875 * @param emsg non-null on failure
878 hostkey_callback (void *cls,
879 const struct GNUNET_PeerIdentity *id,
880 struct GNUNET_TESTING_Daemon *d, const char *emsg)
884 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
885 "Hostkey callback received error: %s\n", emsg);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "Hostkey (%d/%d) created for peer `%s'\n",
891 num_peers - peers_left, num_peers, GNUNET_i2s (id));
895 if ((num_peers - peers_left) % modnum == 0)
897 if (num_peers - peers_left == 0)
898 fprintf (stdout, "0%%");
900 fprintf (stdout, "%d%%",
901 (int) (((float) (num_peers - peers_left) /
905 else if ((num_peers - peers_left) % dotnum == 0)
907 fprintf (stdout, ".");
915 fprintf (stdout, "100%%]\n");
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "All %d hostkeys created, now creating topology!\n",
920 GNUNET_SCHEDULER_cancel (die_task);
921 /* Set up task in case topology creation doesn't finish
922 * within a reasonable amount of time */
923 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
925 "from create_topology");
926 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
934 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
937 char *connect_topology_str;
938 char *blacklist_topology_str;
939 char *connect_topology_option_str;
940 char *connect_topology_option_modifier_string;
941 unsigned long long temp_settle;
944 dotOutFile = fopen (dotOutFileName, "w");
945 if (dotOutFile != NULL)
947 fprintf (dotOutFile, "strict graph G {\n");
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
952 "Starting daemons based on config file %s\n", cfgfile);
956 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
964 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
966 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
968 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
969 "Invalid topology `%s' given for section %s option %s\n",
970 topology_str, "TESTING", "TOPOLOGY");
971 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
975 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
977 &connect_topology_str))
979 GNUNET_TESTING_topology_get (&connection_topology,
980 connect_topology_str)))
982 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
983 "Invalid connect topology `%s' given for section %s option %s\n",
984 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
986 GNUNET_free_non_null (connect_topology_str);
988 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
989 "connect_topology_option",
990 &connect_topology_option_str))
992 GNUNET_TESTING_topology_option_get (&connect_topology_option,
993 connect_topology_option_str)))
995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
996 "Invalid connect topology option `%s' given for section %s option %s\n",
997 connect_topology_option_str, "TESTING",
998 "CONNECT_TOPOLOGY_OPTION");
999 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1001 GNUNET_free_non_null (connect_topology_option_str);
1003 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1004 "connect_topology_option_modifier",
1005 &connect_topology_option_modifier_string))
1008 (connect_topology_option_modifier_string, "%lf",
1009 &connect_topology_option_modifier) != 1)
1011 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1013 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1014 connect_topology_option_modifier_string,
1015 "connect_topology_option_modifier", "TESTING");
1017 GNUNET_free (connect_topology_option_modifier_string);
1021 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1022 "blacklist_transports",
1023 &blacklist_transports))
1024 blacklist_transports = NULL;
1027 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1028 "blacklist_topology",
1029 &blacklist_topology_str))
1031 GNUNET_TESTING_topology_get (&blacklist_topology,
1032 blacklist_topology_str)))
1034 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1035 "Invalid topology `%s' given for section %s option %s\n",
1036 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1038 GNUNET_free_non_null (topology_str);
1039 GNUNET_free_non_null (blacklist_topology_str);
1042 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1045 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1047 if (GNUNET_SYSERR ==
1048 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1050 num_peers = DEFAULT_NUM_PEERS;
1054 peers_left = num_peers;
1055 modnum = num_peers / 4;
1056 dotnum = (num_peers / 50) + 1;
1058 fprintf (stdout, "Hostkey generation progress: [");
1060 /* Set up a task to end testing if peer start fails */
1062 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1063 (GNUNET_TIME_UNIT_SECONDS,
1064 SECONDS_PER_PEER_START * num_peers),
1066 "didn't generate all hostkeys within a reasonable amount of time!!!");
1068 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1069 pg = GNUNET_TESTING_daemons_start (cfg,
1071 GNUNET_TIME_relative_multiply
1072 (GNUNET_TIME_UNIT_SECONDS,
1073 SECONDS_PER_PEER_START * num_peers),
1074 &hostkey_callback, NULL,
1075 &peers_started_callback, NULL,
1076 &topology_callback, NULL, NULL);
1084 char *config_file_name;
1085 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1086 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1089 char *const argv[] = { binary_name,
1097 struct GNUNET_GETOPT_CommandLineOption options[] = {
1098 GNUNET_GETOPT_OPTION_END
1100 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1101 argv, binary_name, "nohelp", options, &run, &ok);
1102 if (ret != GNUNET_OK)
1104 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1105 "`test-testing-topology-%s': Failed with error code %d\n",
1106 topology_string, ret);
1108 GNUNET_free (binary_name);
1109 GNUNET_free (config_file_name);
1114 main (int argc, char *argv[])
1117 char *binary_start_pos;
1118 char *our_binary_name;
1120 binary_start_pos = rindex (argv[0], '/');
1121 GNUNET_assert (binary_start_pos != NULL);
1122 topology_string = strstr (binary_start_pos, "_topology");
1123 GNUNET_assert (topology_string != NULL);
1125 topology_string = strstr (topology_string, "_");
1126 GNUNET_assert (topology_string != NULL);
1129 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1131 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1133 GNUNET_log_setup (our_binary_name,
1143 * Need to remove base directory, subdirectories taken care
1144 * of by the testing framework.
1146 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1149 "Failed to remove testing directory %s\n", test_directory);
1151 GNUNET_free (our_binary_name);
1155 /* end of test_testing_topology.c */