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 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 /* Has peer1 been notified already of a connection to peer2? */
148 /* Has the core of peer2 been connected already? */
151 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
152 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
156 static struct TestMessageContext *test_messages;
159 * Check whether peers successfully shut down.
162 shutdown_callback (void *cls, const char *emsg)
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
176 "All peers successfully shut down!\n");
181 #if DELAY_FOR_LOGGING
186 char *connect_number;
187 struct GNUNET_OS_Process *mem_process;
188 GNUNET_asprintf (&peer_number, "%llu", num_peers);
189 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
190 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
191 "memsize.pl", "totals.txt",
192 peer_number, connect_number, NULL);
193 GNUNET_OS_process_wait (mem_process);
194 GNUNET_OS_process_close (mem_process);
203 GNUNET_assert (pg != NULL);
204 struct TestMessageContext *pos;
205 struct TestMessageContext *free_pos;
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Called finish testing, stopping daemons.\n");
214 if (pos->peer1handle != NULL)
216 GNUNET_CORE_disconnect (pos->peer1handle);
217 pos->peer1handle = NULL;
219 if (pos->peer2handle != NULL)
221 GNUNET_CORE_disconnect (pos->peer2handle);
222 pos->peer2handle = NULL;
226 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
228 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
230 GNUNET_free (free_pos);
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
235 transmit_ready_scheduled, transmit_ready_failed,
236 transmit_ready_called);
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
242 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
244 if (dotOutFile != NULL)
246 fprintf (dotOutFile, "}");
255 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
257 struct TestMessageContext *pos = cls;
259 /* Disconnect from the respective cores */
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Disconnecting from peer 1 `%4s'\n",
263 GNUNET_i2s (&pos->peer1->id));
265 if (pos->peer1handle != NULL)
266 GNUNET_CORE_disconnect (pos->peer1handle);
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "Disconnecting from peer 2 `%4s'\n",
270 GNUNET_i2s (&pos->peer2->id));
272 if (pos->peer2handle != NULL)
273 GNUNET_CORE_disconnect (pos->peer2handle);
274 /* Set handles to NULL so test case can be ended properly */
275 pos->peer1handle = NULL;
276 pos->peer2handle = NULL;
277 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
278 /* Decrement total connections so new can be established */
279 total_server_connections -= 2;
284 stats_finished (void *cls, int result)
286 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
290 * Callback function to process statistic values.
293 * @param peer the peer the statistics belong to
294 * @param subsystem name of subsystem that created the statistic
295 * @param name the name of the datum
296 * @param value the current value
297 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
298 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
301 stats_print (void *cls,
302 const struct GNUNET_PeerIdentity *peer,
303 const char *subsystem,
304 const char *name, uint64_t value, int is_persistent)
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
307 GNUNET_i2s (peer), subsystem, name, value);
313 topology_cb (void *cls,
314 const struct GNUNET_PeerIdentity *first,
315 const struct GNUNET_PeerIdentity *second, const char *emsg)
322 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
323 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
325 topology_connections++;
330 "Finished iterating over topology, %d total connections!\n",
331 topology_connections);
334 fprintf (outfile, "}\n");
337 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
340 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
346 process_mtype (void *cls,
347 const struct GNUNET_PeerIdentity *peer,
348 const struct GNUNET_MessageHeader *message,
349 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
351 char *dotOutFileNameFinished;
352 FILE *dotOutFileFinished;
353 struct TestMessageContext *pos = cls;
354 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
355 if (pos->uid != ntohl (msg->uid))
359 if ((total_messages_received) % modnum == 0)
361 if (total_messages_received == 0)
362 fprintf (stdout, "0%%");
364 fprintf (stdout, "%d%%",
365 (int) (((float) total_messages_received /
366 expected_messages) * 100));
369 else if (total_messages_received % dotnum == 0)
371 fprintf (stdout, ".");
376 total_messages_received++;
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
381 ntohs (message->type));
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
383 "Total messages received %d, expected %d.\n",
384 total_messages_received, expected_messages);
387 if (total_messages_received == expected_messages)
390 fprintf (stdout, "100%%]\n");
392 GNUNET_SCHEDULER_cancel (die_task);
393 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
394 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
395 GNUNET_free (dotOutFileNameFinished);
396 if (dotOutFileFinished != NULL)
398 fprintf (dotOutFileFinished, "strict graph G {\n");
400 topology_connections = 0;
401 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
402 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
406 pos->disconnect_task =
407 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
414 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
417 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
418 "End badly was called (%s)... stopping daemons.\n", msg);
419 struct TestMessageContext *pos;
420 struct TestMessageContext *free_pos;
425 if (pos->peer1handle != NULL)
427 GNUNET_CORE_disconnect (pos->peer1handle);
428 pos->peer1handle = NULL;
430 if (pos->peer2handle != NULL)
432 GNUNET_CORE_disconnect (pos->peer2handle);
433 pos->peer2handle = NULL;
437 GNUNET_free (free_pos);
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
443 transmit_ready_scheduled, transmit_ready_failed,
444 transmit_ready_called);
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
446 "Total messages received %d, expected %d.\n",
447 total_messages_received, expected_messages);
452 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
453 ok = 7331; /* Opposite of leet */
456 ok = 401; /* Never got peers started */
458 if (dotOutFile != NULL)
460 fprintf (dotOutFile, "}");
466 transmit_ready (void *cls, size_t size, void *buf)
468 struct GNUNET_TestMessage *m;
469 struct TestMessageContext *pos = cls;
471 GNUNET_assert (buf != NULL);
472 m = (struct GNUNET_TestMessage *) buf;
473 m->header.type = htons (MTYPE);
474 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
475 m->uid = htonl (pos->uid);
476 transmit_ready_called++;
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
480 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
481 transmit_ready_called);
483 return sizeof (struct GNUNET_TestMessage);
487 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
491 static struct GNUNET_CORE_MessageHandler handlers[] = {
492 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
497 init_notify_peer2 (void *cls,
498 struct GNUNET_CORE_Handle *server,
499 const struct GNUNET_PeerIdentity *my_identity,
500 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
503 struct TestMessageContext *pos = cls;
505 total_server_connections++;
507 pos->peer2connected = GNUNET_YES;
508 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
513 GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey));
515 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
521 &transmit_ready, pos))
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
524 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
525 GNUNET_i2s (&pos->peer2->id));
526 transmit_ready_failed++;
530 transmit_ready_scheduled++;
536 * Method called whenever a given peer connects.
539 * @param peer peer identity this notification is about
540 * @param atsi performance data for the connection
542 static void connect_notify_peers (void *cls,
544 GNUNET_PeerIdentity *peer,
545 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
547 struct TestMessageContext *pos = cls;
549 if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
551 pos->peer1notified = GNUNET_YES;
553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
554 "Peer `%s' notified of connection to peer `%s'\n",
555 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
561 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
566 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey));
568 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
574 &transmit_ready, pos))
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
577 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
578 GNUNET_i2s (&pos->peer2->id));
579 transmit_ready_failed++;
583 transmit_ready_scheduled++;
589 init_notify_peer1 (void *cls,
590 struct GNUNET_CORE_Handle *server,
591 const struct GNUNET_PeerIdentity *my_identity,
592 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
595 struct TestMessageContext *pos = cls;
596 total_server_connections++;
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
600 "Core connection to `%4s' established, setting up handles\n",
601 GNUNET_i2s (my_identity));
605 * Connect to the receiving peer
607 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
614 GNUNET_YES, NULL, GNUNET_YES,
621 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
623 struct TestMessageContext *pos = cls;
625 if ((pos == test_messages) && (settle_time.rel_value > 0))
627 topology_connections = 0;
628 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
630 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
633 if (die_task == GNUNET_SCHEDULER_NO_TASK)
635 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
637 "from send test messages (timeout)");
640 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
642 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
643 (GNUNET_TIME_UNIT_SECONDS, 1),
644 &send_test_messages, pos);
645 return; /* Otherwise we'll double schedule messages here! */
649 * Connect to the sending peer
651 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
655 &connect_notify_peers, NULL,
658 GNUNET_NO, NULL, GNUNET_NO,
661 GNUNET_assert (pos->peer1handle != NULL);
663 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
665 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
669 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
670 (GNUNET_TIME_UNIT_SECONDS, 1),
671 &send_test_messages, pos->next);
677 topology_callback (void *cls,
678 const struct GNUNET_PeerIdentity *first,
679 const struct GNUNET_PeerIdentity *second,
681 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
682 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
683 struct GNUNET_TESTING_Daemon *first_daemon,
684 struct GNUNET_TESTING_Daemon *second_daemon,
687 struct TestMessageContext *temp_context;
691 if ((total_connections) % modnum == 0)
693 if (total_connections == 0)
694 fprintf (stdout, "0%%");
696 fprintf (stdout, "%d%%",
697 (int) (((float) total_connections /
698 expected_connections) * 100));
701 else if (total_connections % dotnum == 0)
703 fprintf (stdout, ".");
709 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
710 first_daemon->shortname, second_daemon->shortname);
712 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
713 temp_context->peer1 = first_daemon;
714 temp_context->peer2 = second_daemon;
715 temp_context->next = test_messages;
716 temp_context->uid = total_connections;
717 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
718 test_messages = temp_context;
721 if (dotOutFile != NULL)
722 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
723 second_daemon->shortname);
728 failed_connections++;
729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
730 "Failed to connect peer %s to peer %s with error :\n%s\n",
731 first_daemon->shortname, second_daemon->shortname, emsg);
735 if (total_connections == expected_connections)
738 fprintf (stdout, "100%%]\n");
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Created %d total connections, which is our target number! Calling send messages.\n",
745 modnum = expected_messages / 4;
746 dotnum = (expected_messages / 50) + 1;
747 GNUNET_SCHEDULER_cancel (die_task);
748 die_task = GNUNET_SCHEDULER_NO_TASK;
749 #if DELAY_FOR_LOGGING
750 fprintf (stdout, "Sending test messages in 10 seconds.\n");
751 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
752 (GNUNET_TIME_UNIT_SECONDS, 10),
753 &send_test_messages, test_messages);
756 if (settle_time.rel_value > 0)
758 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
760 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
764 fprintf (stdout, "Test message progress: [");
768 else if (total_connections + failed_connections == expected_connections)
770 if (failed_connections <
771 (unsigned int) (fail_percentage * total_connections))
773 GNUNET_SCHEDULER_cancel (die_task);
774 die_task = GNUNET_SCHEDULER_NO_TASK;
775 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
779 GNUNET_SCHEDULER_cancel (die_task);
781 GNUNET_SCHEDULER_add_now (&end_badly,
782 "from topology_callback (too many failed connections)");
788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
790 total_connections, failed_connections, expected_connections,
791 expected_connections -
792 (unsigned int) (fail_percentage * expected_connections));
798 topology_creation_finished (void *cls, const char *emsg)
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "All topology connections created successfully!\n");
810 expected_connections = -1;
811 if ((pg != NULL) && (peers_left == 0))
813 expected_connections =
814 GNUNET_TESTING_connect_topology (pg, connection_topology,
815 connect_topology_option,
816 connect_topology_option_modifier,
817 &topology_creation_finished, NULL);
819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
820 "Have %d expected connections\n", expected_connections);
824 GNUNET_SCHEDULER_cancel (die_task);
825 if (expected_connections < 1)
828 GNUNET_SCHEDULER_add_now (&end_badly,
829 "from connect topology (bad return)");
833 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
835 "from connect topology (timeout)");
836 modnum = expected_connections / 4;
837 dotnum = (expected_connections / 50) + 1;
839 fprintf (stdout, "Peer connection progress: [");
846 peers_left = num_peers; /* Reset counter */
847 if (GNUNET_TESTING_create_topology
848 (pg, topology, blacklist_topology,
849 blacklist_transports) != GNUNET_SYSERR)
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Topology set up, now starting peers!\n");
854 fprintf (stdout, "Daemon start progress [");
856 GNUNET_TESTING_daemons_continue_startup (pg);
860 GNUNET_SCHEDULER_cancel (die_task);
862 GNUNET_SCHEDULER_add_now (&end_badly,
863 "from create topology (bad return)");
865 GNUNET_SCHEDULER_cancel (die_task);
866 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
868 "from continue startup (timeout)");
873 peers_started_callback (void *cls,
874 const struct GNUNET_PeerIdentity *id,
875 const struct GNUNET_CONFIGURATION_Handle *cfg,
876 struct GNUNET_TESTING_Daemon *d, const char *emsg)
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "Failed to start daemon with error: `%s'\n", emsg);
884 GNUNET_assert (id != NULL);
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
887 (num_peers - peers_left) + 1, num_peers);
890 if ((num_peers - peers_left) % modnum == 0)
892 if (num_peers - peers_left == 0)
893 fprintf (stdout, "0%%");
895 fprintf (stdout, "%d%%",
896 (int) (((float) (num_peers - peers_left) /
900 else if ((num_peers - peers_left) % dotnum == 0)
902 fprintf (stdout, ".");
910 fprintf (stdout, "100%%]\n");
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
914 "All %d daemons started, now connecting peers!\n",
917 GNUNET_SCHEDULER_cancel (die_task);
918 /* Set up task in case topology creation doesn't finish
919 * within a reasonable amount of time */
920 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
921 (GNUNET_TIME_UNIT_MINUTES, 8),
923 "from peers_started_callback");
924 #if DELAY_FOR_LOGGING
925 fprintf (stdout, "Connecting topology in 10 seconds\n");
927 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
928 (GNUNET_TIME_UNIT_SECONDS, 10),
929 &connect_topology, NULL);
938 * Callback indicating that the hostkey was created for a peer.
941 * @param id the peer identity
942 * @param d the daemon handle (pretty useless at this point, remove?)
943 * @param emsg non-null on failure
946 hostkey_callback (void *cls,
947 const struct GNUNET_PeerIdentity *id,
948 struct GNUNET_TESTING_Daemon *d, const char *emsg)
952 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
953 "Hostkey callback received error: %s\n", emsg);
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Hostkey (%d/%d) created for peer `%s'\n",
959 num_peers - peers_left, num_peers, GNUNET_i2s (id));
963 if ((num_peers - peers_left) % modnum == 0)
965 if (num_peers - peers_left == 0)
966 fprintf (stdout, "0%%");
968 fprintf (stdout, "%d%%",
969 (int) (((float) (num_peers - peers_left) /
973 else if ((num_peers - peers_left) % dotnum == 0)
975 fprintf (stdout, ".");
983 fprintf (stdout, "100%%]\n");
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
985 "All %d hostkeys created, now creating topology!\n",
988 GNUNET_SCHEDULER_cancel (die_task);
989 /* Set up task in case topology creation doesn't finish
990 * within a reasonable amount of time */
991 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
993 "from create_topology");
994 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1002 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1005 char *connect_topology_str;
1006 char *blacklist_topology_str;
1007 char *connect_topology_option_str;
1008 char *connect_topology_option_modifier_string;
1009 unsigned long long temp_settle;
1012 dotOutFile = fopen (dotOutFileName, "w");
1013 if (dotOutFile != NULL)
1015 fprintf (dotOutFile, "strict graph G {\n");
1019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 "Starting daemons based on config file %s\n", cfgfile);
1024 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1032 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1034 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1036 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1037 "Invalid topology `%s' given for section %s option %s\n",
1038 topology_str, "TESTING", "TOPOLOGY");
1039 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1043 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1045 &connect_topology_str))
1047 GNUNET_TESTING_topology_get (&connection_topology,
1048 connect_topology_str)))
1050 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1051 "Invalid connect topology `%s' given for section %s option %s\n",
1052 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1054 GNUNET_free_non_null (connect_topology_str);
1056 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1057 "connect_topology_option",
1058 &connect_topology_option_str))
1060 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1061 connect_topology_option_str)))
1063 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1064 "Invalid connect topology option `%s' given for section %s option %s\n",
1065 connect_topology_option_str, "TESTING",
1066 "CONNECT_TOPOLOGY_OPTION");
1067 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1069 GNUNET_free_non_null (connect_topology_option_str);
1071 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1072 "connect_topology_option_modifier",
1073 &connect_topology_option_modifier_string))
1076 (connect_topology_option_modifier_string, "%lf",
1077 &connect_topology_option_modifier) != 1)
1079 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1081 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1082 connect_topology_option_modifier_string,
1083 "connect_topology_option_modifier", "TESTING");
1085 GNUNET_free (connect_topology_option_modifier_string);
1089 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1090 "blacklist_transports",
1091 &blacklist_transports))
1092 blacklist_transports = NULL;
1095 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1096 "blacklist_topology",
1097 &blacklist_topology_str))
1099 GNUNET_TESTING_topology_get (&blacklist_topology,
1100 blacklist_topology_str)))
1102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1103 "Invalid topology `%s' given for section %s option %s\n",
1104 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1106 GNUNET_free_non_null (topology_str);
1107 GNUNET_free_non_null (blacklist_topology_str);
1110 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1113 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1115 if (GNUNET_SYSERR ==
1116 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1118 num_peers = DEFAULT_NUM_PEERS;
1122 peers_left = num_peers;
1123 modnum = num_peers / 4;
1124 dotnum = (num_peers / 50) + 1;
1126 fprintf (stdout, "Hostkey generation progress: [");
1128 /* Set up a task to end testing if peer start fails */
1130 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1131 (GNUNET_TIME_UNIT_SECONDS,
1132 SECONDS_PER_PEER_START * num_peers),
1134 "didn't generate all hostkeys within a reasonable amount of time!!!");
1136 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1137 pg = GNUNET_TESTING_daemons_start (cfg,
1139 GNUNET_TIME_relative_multiply
1140 (GNUNET_TIME_UNIT_SECONDS,
1141 SECONDS_PER_PEER_START * num_peers),
1142 &hostkey_callback, NULL,
1143 &peers_started_callback, NULL,
1144 &topology_callback, NULL, NULL);
1152 char *config_file_name;
1153 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1154 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1157 char *const argv[] = { binary_name,
1165 struct GNUNET_GETOPT_CommandLineOption options[] = {
1166 GNUNET_GETOPT_OPTION_END
1168 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1169 argv, binary_name, "nohelp", options, &run, &ok);
1170 if (ret != GNUNET_OK)
1172 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1173 "`test-testing-topology-%s': Failed with error code %d\n",
1174 topology_string, ret);
1176 GNUNET_free (binary_name);
1177 GNUNET_free (config_file_name);
1182 main (int argc, char *argv[])
1185 char *binary_start_pos;
1186 char *our_binary_name;
1188 binary_start_pos = strchr (argv[0], '/');
1189 GNUNET_assert (binary_start_pos != NULL);
1190 topology_string = strstr (binary_start_pos, "_topology");
1191 GNUNET_assert (topology_string != NULL);
1193 topology_string = strstr (topology_string, "_");
1194 GNUNET_assert (topology_string != NULL);
1197 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1199 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1201 GNUNET_log_setup (our_binary_name,
1211 * Need to remove base directory, subdirectories taken care
1212 * of by the testing framework.
1214 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1217 "Failed to remove testing directory %s\n", test_directory);
1219 GNUNET_free (our_binary_name);
1223 /* end of test_testing_topology.c */