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;
283 stats_finished (void *cls, int result)
285 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
289 * Callback function to process statistic values.
292 * @param peer the peer the statistics belong to
293 * @param subsystem name of subsystem that created the statistic
294 * @param name the name of the datum
295 * @param value the current value
296 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
297 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
300 stats_print (void *cls,
301 const struct GNUNET_PeerIdentity *peer,
302 const char *subsystem,
303 const char *name, uint64_t value, int is_persistent)
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
306 GNUNET_i2s (peer), subsystem, name, value);
311 topology_cb (void *cls,
312 const struct GNUNET_PeerIdentity *first,
313 const struct GNUNET_PeerIdentity *second, const char *emsg)
320 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
321 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
323 topology_connections++;
328 "Finished iterating over topology, %d total connections!\n",
329 topology_connections);
332 fprintf (outfile, "}\n");
334 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
336 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
342 process_mtype (void *cls,
343 const struct GNUNET_PeerIdentity *peer,
344 const struct GNUNET_MessageHeader *message,
345 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
347 char *dotOutFileNameFinished;
348 FILE *dotOutFileFinished;
349 struct TestMessageContext *pos = cls;
350 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
351 if (pos->uid != ntohl (msg->uid))
355 if ((total_messages_received) % modnum == 0)
357 if (total_messages_received == 0)
358 fprintf (stdout, "0%%");
360 fprintf (stdout, "%d%%",
361 (int) (((float) total_messages_received /
362 expected_messages) * 100));
365 else if (total_messages_received % dotnum == 0)
367 fprintf (stdout, ".");
372 total_messages_received++;
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
377 ntohs (message->type));
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Total messages received %d, expected %d.\n",
380 total_messages_received, expected_messages);
383 if (total_messages_received == expected_messages)
386 fprintf (stdout, "100%%]\n");
388 GNUNET_SCHEDULER_cancel (die_task);
389 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
390 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
391 GNUNET_free (dotOutFileNameFinished);
392 if (dotOutFileFinished != NULL)
394 fprintf (dotOutFileFinished, "strict graph G {\n");
396 topology_connections = 0;
397 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
398 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
402 pos->disconnect_task =
403 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
410 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
414 "End badly was called (%s)... stopping daemons.\n", msg);
415 struct TestMessageContext *pos;
416 struct TestMessageContext *free_pos;
421 if (pos->peer1handle != NULL)
423 GNUNET_CORE_disconnect (pos->peer1handle);
424 pos->peer1handle = NULL;
426 if (pos->peer2handle != NULL)
428 GNUNET_CORE_disconnect (pos->peer2handle);
429 pos->peer2handle = NULL;
433 GNUNET_free (free_pos);
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
438 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
439 transmit_ready_scheduled, transmit_ready_failed,
440 transmit_ready_called);
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Total messages received %d, expected %d.\n",
443 total_messages_received, expected_messages);
448 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
449 ok = 7331; /* Opposite of leet */
452 ok = 401; /* Never got peers started */
454 if (dotOutFile != NULL)
456 fprintf (dotOutFile, "}");
462 transmit_ready (void *cls, size_t size, void *buf)
464 struct GNUNET_TestMessage *m;
465 struct TestMessageContext *pos = cls;
467 GNUNET_assert (buf != NULL);
468 m = (struct GNUNET_TestMessage *) buf;
469 m->header.type = htons (MTYPE);
470 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
471 m->uid = htonl (pos->uid);
472 transmit_ready_called++;
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
476 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
477 transmit_ready_called);
479 return sizeof (struct GNUNET_TestMessage);
483 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
487 static struct GNUNET_CORE_MessageHandler handlers[] = {
488 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
493 init_notify_peer2 (void *cls,
494 struct GNUNET_CORE_Handle *server,
495 const struct GNUNET_PeerIdentity *my_identity,
496 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
499 struct TestMessageContext *pos = cls;
501 total_server_connections++;
503 pos->peer2connected = GNUNET_YES;
504 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
508 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
509 GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey));
511 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
517 &transmit_ready, pos))
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
520 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
521 GNUNET_i2s (&pos->peer2->id));
522 transmit_ready_failed++;
526 transmit_ready_scheduled++;
532 * Method called whenever a given peer connects.
535 * @param peer peer identity this notification is about
536 * @param atsi performance data for the connection
538 static void connect_notify_peers (void *cls,
540 GNUNET_PeerIdentity *peer,
541 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
543 struct TestMessageContext *pos = cls;
545 if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
547 pos->peer1notified = GNUNET_YES;
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "Peer `%s' notified of connection to peer `%s'\n",
551 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
557 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
562 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey));
564 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
570 &transmit_ready, pos))
572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
573 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
574 GNUNET_i2s (&pos->peer2->id));
575 transmit_ready_failed++;
579 transmit_ready_scheduled++;
585 init_notify_peer1 (void *cls,
586 struct GNUNET_CORE_Handle *server,
587 const struct GNUNET_PeerIdentity *my_identity,
588 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
591 struct TestMessageContext *pos = cls;
592 total_server_connections++;
595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
596 "Core connection to `%4s' established, setting up handles\n",
597 GNUNET_i2s (my_identity));
601 * Connect to the receiving peer
603 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
610 GNUNET_YES, NULL, GNUNET_YES,
617 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
619 struct TestMessageContext *pos = cls;
621 if ((pos == test_messages) && (settle_time.rel_value > 0))
623 topology_connections = 0;
624 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
626 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
629 if (die_task == GNUNET_SCHEDULER_NO_TASK)
631 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
633 "from send test messages (timeout)");
636 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
638 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
639 (GNUNET_TIME_UNIT_SECONDS, 1),
640 &send_test_messages, pos);
641 return; /* Otherwise we'll double schedule messages here! */
645 * Connect to the sending peer
647 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
651 &connect_notify_peers, NULL,
654 GNUNET_NO, NULL, GNUNET_NO,
657 GNUNET_assert (pos->peer1handle != NULL);
659 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
661 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
665 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
666 (GNUNET_TIME_UNIT_SECONDS, 1),
667 &send_test_messages, pos->next);
673 topology_callback (void *cls,
674 const struct GNUNET_PeerIdentity *first,
675 const struct GNUNET_PeerIdentity *second,
677 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
678 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
679 struct GNUNET_TESTING_Daemon *first_daemon,
680 struct GNUNET_TESTING_Daemon *second_daemon,
683 struct TestMessageContext *temp_context;
687 if ((total_connections) % modnum == 0)
689 if (total_connections == 0)
690 fprintf (stdout, "0%%");
692 fprintf (stdout, "%d%%",
693 (int) (((float) total_connections /
694 expected_connections) * 100));
697 else if (total_connections % dotnum == 0)
699 fprintf (stdout, ".");
705 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
706 first_daemon->shortname, second_daemon->shortname);
708 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
709 temp_context->peer1 = first_daemon;
710 temp_context->peer2 = second_daemon;
711 temp_context->next = test_messages;
712 temp_context->uid = total_connections;
713 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
714 test_messages = temp_context;
717 if (dotOutFile != NULL)
718 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
719 second_daemon->shortname);
724 failed_connections++;
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Failed to connect peer %s to peer %s with error :\n%s\n",
727 first_daemon->shortname, second_daemon->shortname, emsg);
731 if (total_connections == expected_connections)
734 fprintf (stdout, "100%%]\n");
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Created %d total connections, which is our target number! Calling send messages.\n",
741 modnum = expected_messages / 4;
742 dotnum = (expected_messages / 50) + 1;
743 GNUNET_SCHEDULER_cancel (die_task);
744 die_task = GNUNET_SCHEDULER_NO_TASK;
745 #if DELAY_FOR_LOGGING
746 fprintf (stdout, "Sending test messages in 10 seconds.\n");
747 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
748 (GNUNET_TIME_UNIT_SECONDS, 10),
749 &send_test_messages, test_messages);
752 if (settle_time.rel_value > 0)
754 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
756 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
760 fprintf (stdout, "Test message progress: [");
764 else if (total_connections + failed_connections == expected_connections)
766 if (failed_connections <
767 (unsigned int) (fail_percentage * total_connections))
769 GNUNET_SCHEDULER_cancel (die_task);
770 die_task = GNUNET_SCHEDULER_NO_TASK;
771 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
775 GNUNET_SCHEDULER_cancel (die_task);
777 GNUNET_SCHEDULER_add_now (&end_badly,
778 "from topology_callback (too many failed connections)");
784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
785 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
786 total_connections, failed_connections, expected_connections,
787 expected_connections -
788 (unsigned int) (fail_percentage * expected_connections));
794 topology_creation_finished (void *cls, const char *emsg)
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "All topology connections created successfully!\n");
806 expected_connections = -1;
807 if ((pg != NULL) && (peers_left == 0))
809 expected_connections =
810 GNUNET_TESTING_connect_topology (pg, connection_topology,
811 connect_topology_option,
812 connect_topology_option_modifier,
813 &topology_creation_finished, NULL);
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "Have %d expected connections\n", expected_connections);
820 GNUNET_SCHEDULER_cancel (die_task);
821 if (expected_connections == GNUNET_SYSERR)
824 GNUNET_SCHEDULER_add_now (&end_badly,
825 "from connect topology (bad return)");
828 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
830 "from connect topology (timeout)");
831 modnum = expected_connections / 4;
832 dotnum = (expected_connections / 50) + 1;
834 fprintf (stdout, "Peer connection progress: [");
841 peers_left = num_peers; /* Reset counter */
842 if (GNUNET_TESTING_create_topology
843 (pg, topology, blacklist_topology,
844 blacklist_transports) != GNUNET_SYSERR)
847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
848 "Topology set up, now starting peers!\n");
849 fprintf (stdout, "Daemon start progress [");
851 GNUNET_TESTING_daemons_continue_startup (pg);
855 GNUNET_SCHEDULER_cancel (die_task);
857 GNUNET_SCHEDULER_add_now (&end_badly,
858 "from create topology (bad return)");
860 GNUNET_SCHEDULER_cancel (die_task);
861 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
863 "from continue startup (timeout)");
868 peers_started_callback (void *cls,
869 const struct GNUNET_PeerIdentity *id,
870 const struct GNUNET_CONFIGURATION_Handle *cfg,
871 struct GNUNET_TESTING_Daemon *d, const char *emsg)
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876 "Failed to start daemon with error: `%s'\n", emsg);
879 GNUNET_assert (id != NULL);
881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
882 (num_peers - peers_left) + 1, num_peers);
885 if ((num_peers - peers_left) % modnum == 0)
887 if (num_peers - peers_left == 0)
888 fprintf (stdout, "0%%");
890 fprintf (stdout, "%d%%",
891 (int) (((float) (num_peers - peers_left) /
895 else if ((num_peers - peers_left) % dotnum == 0)
897 fprintf (stdout, ".");
905 fprintf (stdout, "100%%]\n");
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "All %d daemons started, now connecting peers!\n",
912 GNUNET_SCHEDULER_cancel (die_task);
913 /* Set up task in case topology creation doesn't finish
914 * within a reasonable amount of time */
915 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
916 (GNUNET_TIME_UNIT_MINUTES, 8),
918 "from peers_started_callback");
919 #if DELAY_FOR_LOGGING
920 fprintf (stdout, "Connecting topology in 10 seconds\n");
922 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
923 (GNUNET_TIME_UNIT_SECONDS, 10),
924 &connect_topology, NULL);
933 * Callback indicating that the hostkey was created for a peer.
936 * @param id the peer identity
937 * @param d the daemon handle (pretty useless at this point, remove?)
938 * @param emsg non-null on failure
941 hostkey_callback (void *cls,
942 const struct GNUNET_PeerIdentity *id,
943 struct GNUNET_TESTING_Daemon *d, const char *emsg)
947 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
948 "Hostkey callback received error: %s\n", emsg);
952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
953 "Hostkey (%d/%d) created for peer `%s'\n",
954 num_peers - peers_left, num_peers, GNUNET_i2s (id));
958 if ((num_peers - peers_left) % modnum == 0)
960 if (num_peers - peers_left == 0)
961 fprintf (stdout, "0%%");
963 fprintf (stdout, "%d%%",
964 (int) (((float) (num_peers - peers_left) /
968 else if ((num_peers - peers_left) % dotnum == 0)
970 fprintf (stdout, ".");
978 fprintf (stdout, "100%%]\n");
979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
980 "All %d hostkeys created, now creating topology!\n",
983 GNUNET_SCHEDULER_cancel (die_task);
984 /* Set up task in case topology creation doesn't finish
985 * within a reasonable amount of time */
986 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
988 "from create_topology");
989 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
997 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1000 char *connect_topology_str;
1001 char *blacklist_topology_str;
1002 char *connect_topology_option_str;
1003 char *connect_topology_option_modifier_string;
1004 unsigned long long temp_settle;
1007 dotOutFile = fopen (dotOutFileName, "w");
1008 if (dotOutFile != NULL)
1010 fprintf (dotOutFile, "strict graph G {\n");
1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1015 "Starting daemons based on config file %s\n", cfgfile);
1019 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1027 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1029 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1031 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1032 "Invalid topology `%s' given for section %s option %s\n",
1033 topology_str, "TESTING", "TOPOLOGY");
1034 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1038 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1040 &connect_topology_str))
1042 GNUNET_TESTING_topology_get (&connection_topology,
1043 connect_topology_str)))
1045 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1046 "Invalid connect topology `%s' given for section %s option %s\n",
1047 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1049 GNUNET_free_non_null (connect_topology_str);
1051 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1052 "connect_topology_option",
1053 &connect_topology_option_str))
1055 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1056 connect_topology_option_str)))
1058 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1059 "Invalid connect topology option `%s' given for section %s option %s\n",
1060 connect_topology_option_str, "TESTING",
1061 "CONNECT_TOPOLOGY_OPTION");
1062 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1064 GNUNET_free_non_null (connect_topology_option_str);
1066 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1067 "connect_topology_option_modifier",
1068 &connect_topology_option_modifier_string))
1071 (connect_topology_option_modifier_string, "%lf",
1072 &connect_topology_option_modifier) != 1)
1074 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1076 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1077 connect_topology_option_modifier_string,
1078 "connect_topology_option_modifier", "TESTING");
1080 GNUNET_free (connect_topology_option_modifier_string);
1084 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1085 "blacklist_transports",
1086 &blacklist_transports))
1087 blacklist_transports = NULL;
1090 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1091 "blacklist_topology",
1092 &blacklist_topology_str))
1094 GNUNET_TESTING_topology_get (&blacklist_topology,
1095 blacklist_topology_str)))
1097 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1098 "Invalid topology `%s' given for section %s option %s\n",
1099 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1101 GNUNET_free_non_null (topology_str);
1102 GNUNET_free_non_null (blacklist_topology_str);
1105 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1108 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1110 if (GNUNET_SYSERR ==
1111 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1113 num_peers = DEFAULT_NUM_PEERS;
1117 peers_left = num_peers;
1118 modnum = num_peers / 4;
1119 dotnum = (num_peers / 50) + 1;
1121 fprintf (stdout, "Hostkey generation progress: [");
1123 /* Set up a task to end testing if peer start fails */
1125 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1126 (GNUNET_TIME_UNIT_SECONDS,
1127 SECONDS_PER_PEER_START * num_peers),
1129 "didn't generate all hostkeys within a reasonable amount of time!!!");
1131 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1132 pg = GNUNET_TESTING_daemons_start (cfg,
1134 GNUNET_TIME_relative_multiply
1135 (GNUNET_TIME_UNIT_SECONDS,
1136 SECONDS_PER_PEER_START * num_peers),
1137 &hostkey_callback, NULL,
1138 &peers_started_callback, NULL,
1139 &topology_callback, NULL, NULL);
1147 char *config_file_name;
1148 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1149 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1152 char *const argv[] = { binary_name,
1160 struct GNUNET_GETOPT_CommandLineOption options[] = {
1161 GNUNET_GETOPT_OPTION_END
1163 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1164 argv, binary_name, "nohelp", options, &run, &ok);
1165 if (ret != GNUNET_OK)
1167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1168 "`test-testing-topology-%s': Failed with error code %d\n",
1169 topology_string, ret);
1171 GNUNET_free (binary_name);
1172 GNUNET_free (config_file_name);
1177 main (int argc, char *argv[])
1180 char *binary_start_pos;
1181 char *our_binary_name;
1183 binary_start_pos = strchr (argv[0], '/');
1184 GNUNET_assert (binary_start_pos != NULL);
1185 topology_string = strstr (binary_start_pos, "_topology");
1186 GNUNET_assert (topology_string != NULL);
1188 topology_string = strstr (topology_string, "_");
1189 GNUNET_assert (topology_string != NULL);
1192 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1194 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1196 GNUNET_log_setup (our_binary_name,
1206 * Need to remove base directory, subdirectories taken care
1207 * of by the testing framework.
1209 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1212 "Failed to remove testing directory %s\n", test_directory);
1214 GNUNET_free (our_binary_name);
1218 /* end of test_testing_topology.c */