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 PROGRESS_BARS GNUNET_YES
33 #define DELAY_FOR_LOGGING GNUNET_NO
36 * How long until we fail the whole testcase?
38 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 240)
41 * How long until we give up on starting the peers?
43 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 500)
45 #define SECONDS_PER_PEER_START 120
47 #define DEFAULT_NUM_PEERS 4
49 #define MAX_OUTSTANDING_CONNECTIONS 100
51 static float fail_percentage = 0.05;
55 static unsigned long long num_peers;
57 struct GNUNET_TIME_Relative connect_timeout;
59 static unsigned long long connect_attempts;
61 static unsigned int topology_connections;
63 static unsigned int total_connections;
65 static unsigned int failed_connections;
67 static unsigned int total_server_connections;
69 static unsigned int total_messages_received;
71 static unsigned int expected_messages;
73 static unsigned int expected_connections;
75 static unsigned long long peers_left;
77 static struct GNUNET_TESTING_PeerGroup *pg;
79 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
81 GNUNET_SCHEDULER_TaskIdentifier die_task;
83 static char *dotOutFileName;
85 static struct GNUNET_TIME_Relative settle_time;
87 static FILE *dotOutFile;
89 static char *topology_string;
91 static char *blacklist_transports;
93 static int transmit_ready_scheduled;
95 static int transmit_ready_failed;
97 static int transmit_ready_called;
99 static unsigned int modnum;
101 static unsigned int dotnum;
103 static enum GNUNET_TESTING_Topology topology;
105 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
107 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
109 static enum GNUNET_TESTING_TopologyOption connect_topology_option =
110 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
112 static double connect_topology_option_modifier = 0.0;
114 static char *test_directory;
118 struct GNUNET_TestMessage
121 * Header of the message
123 struct GNUNET_MessageHeader header;
126 * Unique identifier for this message.
131 struct TestMessageContext
133 /* This is a linked list */
134 struct TestMessageContext *next;
136 /* Handle to the sending peer core */
137 struct GNUNET_CORE_Handle *peer1handle;
139 /* Handle to the receiving peer core */
140 struct GNUNET_CORE_Handle *peer2handle;
142 /* Handle to the sending peer daemon */
143 struct GNUNET_TESTING_Daemon *peer1;
145 /* Handle to the receiving peer daemon */
146 struct GNUNET_TESTING_Daemon *peer2;
148 /* Identifier for this message, so we don't disconnect other peers! */
151 /* Has peer1 been notified already of a connection to peer2? */
154 /* Has the core of peer2 been connected already? */
157 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
158 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
162 static struct TestMessageContext *test_messages;
165 * Check whether peers successfully shut down.
168 shutdown_callback (void *cls, const char *emsg)
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 "All peers successfully shut down!\n");
187 #if DELAY_FOR_LOGGING
192 char *connect_number;
193 struct GNUNET_OS_Process *mem_process;
194 GNUNET_asprintf (&peer_number, "%llu", num_peers);
195 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
196 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
197 "memsize.pl", "totals.txt",
198 peer_number, connect_number, NULL);
199 GNUNET_OS_process_wait (mem_process);
200 GNUNET_OS_process_close (mem_process);
209 GNUNET_assert (pg != NULL);
210 struct TestMessageContext *pos;
211 struct TestMessageContext *free_pos;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Called finish testing, stopping daemons.\n");
220 if (pos->peer1handle != NULL)
222 GNUNET_CORE_disconnect (pos->peer1handle);
223 pos->peer1handle = NULL;
225 if (pos->peer2handle != NULL)
227 GNUNET_CORE_disconnect (pos->peer2handle);
228 pos->peer2handle = NULL;
232 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
234 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
236 GNUNET_free (free_pos);
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
241 transmit_ready_scheduled, transmit_ready_failed,
242 transmit_ready_called);
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
248 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
250 if (dotOutFile != NULL)
252 fprintf (dotOutFile, "}");
261 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 struct TestMessageContext *pos = cls;
265 /* Disconnect from the respective cores */
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Disconnecting from peer 1 `%4s'\n",
269 GNUNET_i2s (&pos->peer1->id));
271 if (pos->peer1handle != NULL)
272 GNUNET_CORE_disconnect (pos->peer1handle);
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
275 "Disconnecting from peer 2 `%4s'\n",
276 GNUNET_i2s (&pos->peer2->id));
278 if (pos->peer2handle != NULL)
279 GNUNET_CORE_disconnect (pos->peer2handle);
280 /* Set handles to NULL so test case can be ended properly */
281 pos->peer1handle = NULL;
282 pos->peer2handle = NULL;
283 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
284 /* Decrement total connections so new can be established */
285 total_server_connections -= 2;
290 stats_finished (void *cls, int result)
292 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
296 * Callback function to process statistic values.
299 * @param peer the peer the statistics belong to
300 * @param subsystem name of subsystem that created the statistic
301 * @param name the name of the datum
302 * @param value the current value
303 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
304 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
307 stats_print (void *cls,
308 const struct GNUNET_PeerIdentity *peer,
309 const char *subsystem,
310 const char *name, uint64_t value, int is_persistent)
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
313 GNUNET_i2s (peer), subsystem, name, value);
319 topology_cb (void *cls,
320 const struct GNUNET_PeerIdentity *first,
321 const struct GNUNET_PeerIdentity *second, const char *emsg)
328 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
329 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
331 topology_connections++;
336 "Finished iterating over topology, %d total connections!\n",
337 topology_connections);
340 fprintf (outfile, "}\n");
343 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
346 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
352 process_mtype (void *cls,
353 const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_MessageHeader *message,
355 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
357 char *dotOutFileNameFinished;
358 FILE *dotOutFileFinished;
359 struct TestMessageContext *pos = cls;
360 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
361 if (pos->uid != ntohl (msg->uid))
365 if ((total_messages_received) % modnum == 0)
367 if (total_messages_received == 0)
368 fprintf (stdout, "0%%");
370 fprintf (stdout, "%d%%",
371 (int) (((float) total_messages_received /
372 expected_messages) * 100));
375 else if (total_messages_received % dotnum == 0)
377 fprintf (stdout, ".");
382 total_messages_received++;
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
387 ntohs (message->type));
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Total messages received %d, expected %d.\n",
390 total_messages_received, expected_messages);
393 if (total_messages_received == expected_messages)
396 fprintf (stdout, "100%%]\n");
398 GNUNET_SCHEDULER_cancel (die_task);
399 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
400 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
401 GNUNET_free (dotOutFileNameFinished);
402 if (dotOutFileFinished != NULL)
404 fprintf (dotOutFileFinished, "strict graph G {\n");
406 topology_connections = 0;
407 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
408 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
412 pos->disconnect_task =
413 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
420 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
424 "End badly was called (%s)... stopping daemons.\n", msg);
425 struct TestMessageContext *pos;
426 struct TestMessageContext *free_pos;
431 if (pos->peer1handle != NULL)
433 GNUNET_CORE_disconnect (pos->peer1handle);
434 pos->peer1handle = NULL;
436 if (pos->peer2handle != NULL)
438 GNUNET_CORE_disconnect (pos->peer2handle);
439 pos->peer2handle = NULL;
443 GNUNET_free (free_pos);
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
449 transmit_ready_scheduled, transmit_ready_failed,
450 transmit_ready_called);
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 "Total messages received %d, expected %d.\n",
453 total_messages_received, expected_messages);
458 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
459 ok = 7331; /* Opposite of leet */
462 ok = 401; /* Never got peers started */
464 if (dotOutFile != NULL)
466 fprintf (dotOutFile, "}");
472 transmit_ready (void *cls, size_t size, void *buf)
474 struct GNUNET_TestMessage *m;
475 struct TestMessageContext *pos = cls;
477 GNUNET_assert (buf != NULL);
478 m = (struct GNUNET_TestMessage *) buf;
479 m->header.type = htons (MTYPE);
480 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
481 m->uid = htonl (pos->uid);
482 transmit_ready_called++;
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
486 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
487 transmit_ready_called);
489 return sizeof (struct GNUNET_TestMessage);
493 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
497 static struct GNUNET_CORE_MessageHandler handlers[] = {
498 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
503 init_notify_peer2 (void *cls,
504 struct GNUNET_CORE_Handle *server,
505 const struct GNUNET_PeerIdentity *my_identity,
506 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
509 struct TestMessageContext *pos = cls;
511 total_server_connections++;
513 pos->peer2connected = GNUNET_YES;
514 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
519 GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey));
521 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
527 &transmit_ready, pos))
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
531 GNUNET_i2s (&pos->peer2->id));
532 transmit_ready_failed++;
536 transmit_ready_scheduled++;
542 * Method called whenever a given peer connects.
545 * @param peer peer identity this notification is about
546 * @param atsi performance data for the connection
548 static void connect_notify_peers (void *cls,
550 GNUNET_PeerIdentity *peer,
551 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
553 struct TestMessageContext *pos = cls;
555 if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
557 pos->peer1notified = GNUNET_YES;
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "Peer `%s' notified of connection to peer `%s'\n",
561 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
567 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
572 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey));
574 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
580 &transmit_ready, pos))
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
584 GNUNET_i2s (&pos->peer2->id));
585 transmit_ready_failed++;
589 transmit_ready_scheduled++;
595 init_notify_peer1 (void *cls,
596 struct GNUNET_CORE_Handle *server,
597 const struct GNUNET_PeerIdentity *my_identity,
598 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
601 struct TestMessageContext *pos = cls;
602 total_server_connections++;
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606 "Core connection to `%4s' established, setting up handles\n",
607 GNUNET_i2s (my_identity));
611 * Connect to the receiving peer
613 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
620 GNUNET_YES, NULL, GNUNET_YES,
627 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
629 struct TestMessageContext *pos = cls;
631 if ((pos == test_messages) && (settle_time.rel_value > 0))
633 topology_connections = 0;
634 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
636 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
639 if (die_task == GNUNET_SCHEDULER_NO_TASK)
641 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
643 "from send test messages (timeout)");
646 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
648 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
649 (GNUNET_TIME_UNIT_SECONDS, 1),
650 &send_test_messages, pos);
651 return; /* Otherwise we'll double schedule messages here! */
655 * Connect to the sending peer
657 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
661 &connect_notify_peers, NULL,
664 GNUNET_NO, NULL, GNUNET_NO,
667 GNUNET_assert (pos->peer1handle != NULL);
669 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
671 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
675 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
676 (GNUNET_TIME_UNIT_SECONDS, 1),
677 &send_test_messages, pos->next);
683 topology_callback (void *cls,
684 const struct GNUNET_PeerIdentity *first,
685 const struct GNUNET_PeerIdentity *second,
687 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
688 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
689 struct GNUNET_TESTING_Daemon *first_daemon,
690 struct GNUNET_TESTING_Daemon *second_daemon,
693 struct TestMessageContext *temp_context;
697 if ((total_connections) % modnum == 0)
699 if (total_connections == 0)
700 fprintf (stdout, "0%%");
702 fprintf (stdout, "%d%%",
703 (int) (((float) total_connections /
704 expected_connections) * 100));
707 else if (total_connections % dotnum == 0)
709 fprintf (stdout, ".");
715 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
716 first_daemon->shortname, second_daemon->shortname);
718 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
719 temp_context->peer1 = first_daemon;
720 temp_context->peer2 = second_daemon;
721 temp_context->next = test_messages;
722 temp_context->uid = total_connections;
723 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
724 test_messages = temp_context;
727 if (dotOutFile != NULL)
728 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
729 second_daemon->shortname);
734 failed_connections++;
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Failed to connect peer %s to peer %s with error :\n%s\n",
737 first_daemon->shortname, second_daemon->shortname, emsg);
741 if (total_connections == expected_connections)
744 fprintf (stdout, "100%%]\n");
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Created %d total connections, which is our target number! Calling send messages.\n",
751 modnum = expected_messages / 4;
752 dotnum = (expected_messages / 50) + 1;
757 GNUNET_SCHEDULER_cancel (die_task);
758 die_task = GNUNET_SCHEDULER_NO_TASK;
759 #if DELAY_FOR_LOGGING
760 fprintf (stdout, "Sending test messages in 10 seconds.\n");
761 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
762 (GNUNET_TIME_UNIT_SECONDS, 10),
763 &send_test_messages, test_messages);
766 if (settle_time.rel_value > 0)
768 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
770 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
774 fprintf (stdout, "Test message progress: [");
778 else if (total_connections + failed_connections == expected_connections)
780 if (failed_connections <
781 (unsigned int) (fail_percentage * total_connections))
783 GNUNET_SCHEDULER_cancel (die_task);
784 die_task = GNUNET_SCHEDULER_NO_TASK;
785 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
789 GNUNET_SCHEDULER_cancel (die_task);
791 GNUNET_SCHEDULER_add_now (&end_badly,
792 "from topology_callback (too many failed connections)");
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
800 total_connections, failed_connections, expected_connections,
801 expected_connections -
802 (unsigned int) (fail_percentage * expected_connections));
808 topology_creation_finished (void *cls, const char *emsg)
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
813 "All topology connections created successfully!\n");
820 expected_connections = -1;
821 if ((pg != NULL) && (peers_left == 0))
823 expected_connections =
824 GNUNET_TESTING_connect_topology (pg, connection_topology,
825 connect_topology_option,
826 connect_topology_option_modifier,
829 &topology_creation_finished, NULL);
831 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
832 "Have %d expected connections\n", expected_connections);
836 GNUNET_SCHEDULER_cancel (die_task);
837 if (expected_connections < 1)
840 GNUNET_SCHEDULER_add_now (&end_badly,
841 "from connect topology (bad return)");
845 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
846 (GNUNET_TIME_UNIT_SECONDS,
847 SECONDS_PER_PEER_START * num_peers),
849 "from connect topology (timeout)");
850 modnum = expected_connections / 4;
851 dotnum = (expected_connections / 50) + 1;
857 fprintf (stdout, "Peer connection progress: [");
864 peers_left = num_peers; /* Reset counter */
865 if (GNUNET_TESTING_create_topology
866 (pg, topology, blacklist_topology,
867 blacklist_transports) != GNUNET_SYSERR)
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "Topology set up, now starting peers!\n");
872 fprintf (stdout, "Daemon start progress [");
874 GNUNET_TESTING_daemons_continue_startup (pg);
878 GNUNET_SCHEDULER_cancel (die_task);
880 GNUNET_SCHEDULER_add_now (&end_badly,
881 "from create topology (bad return)");
883 GNUNET_SCHEDULER_cancel (die_task);
884 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
885 (GNUNET_TIME_UNIT_SECONDS,
886 SECONDS_PER_PEER_START * num_peers),
888 "from continue startup (timeout)");
893 peers_started_callback (void *cls,
894 const struct GNUNET_PeerIdentity *id,
895 const struct GNUNET_CONFIGURATION_Handle *cfg,
896 struct GNUNET_TESTING_Daemon *d, const char *emsg)
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
901 "Failed to start daemon with error: `%s'\n", emsg);
904 GNUNET_assert (id != NULL);
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
907 (num_peers - peers_left) + 1, num_peers);
910 if ((num_peers - peers_left) % modnum == 0)
912 if (num_peers - peers_left == 0)
913 fprintf (stdout, "0%%");
915 fprintf (stdout, "%d%%",
916 (int) (((float) (num_peers - peers_left) /
920 else if ((num_peers - peers_left) % dotnum == 0)
922 fprintf (stdout, ".");
930 fprintf (stdout, "100%%]\n");
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
934 "All %d daemons started, now connecting peers!\n",
937 GNUNET_SCHEDULER_cancel (die_task);
938 /* Set up task in case topology creation doesn't finish
939 * within a reasonable amount of time */
940 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
941 (GNUNET_TIME_UNIT_MINUTES, 8),
943 "from peers_started_callback");
944 #if DELAY_FOR_LOGGING
945 fprintf (stdout, "Connecting topology in 10 seconds\n");
947 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
948 (GNUNET_TIME_UNIT_SECONDS, 10),
949 &connect_topology, NULL);
958 * Callback indicating that the hostkey was created for a peer.
961 * @param id the peer identity
962 * @param d the daemon handle (pretty useless at this point, remove?)
963 * @param emsg non-null on failure
966 hostkey_callback (void *cls,
967 const struct GNUNET_PeerIdentity *id,
968 struct GNUNET_TESTING_Daemon *d, const char *emsg)
972 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
973 "Hostkey callback received error: %s\n", emsg);
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
978 "Hostkey (%d/%d) created for peer `%s'\n",
979 num_peers - peers_left, num_peers, GNUNET_i2s (id));
983 if ((num_peers - peers_left) % modnum == 0)
985 if (num_peers - peers_left == 0)
986 fprintf (stdout, "0%%");
988 fprintf (stdout, "%d%%",
989 (int) (((float) (num_peers - peers_left) /
993 else if ((num_peers - peers_left) % dotnum == 0)
995 fprintf (stdout, ".");
1000 if (peers_left == 0)
1003 fprintf (stdout, "100%%]\n");
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 "All %d hostkeys created, now creating topology!\n",
1008 GNUNET_SCHEDULER_cancel (die_task);
1009 /* Set up task in case topology creation doesn't finish
1010 * within a reasonable amount of time */
1011 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1013 "from create_topology");
1014 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1022 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1025 char *connect_topology_str;
1026 char *blacklist_topology_str;
1027 char *connect_topology_option_str;
1028 char *connect_topology_option_modifier_string;
1029 unsigned long long temp_settle;
1032 dotOutFile = fopen (dotOutFileName, "w");
1033 if (dotOutFile != NULL)
1035 fprintf (dotOutFile, "strict graph G {\n");
1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1040 "Starting daemons based on config file %s\n", cfgfile);
1044 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1052 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1054 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1056 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1057 "Invalid topology `%s' given for section %s option %s\n",
1058 topology_str, "TESTING", "TOPOLOGY");
1059 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1063 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1065 &connect_topology_str))
1067 GNUNET_TESTING_topology_get (&connection_topology,
1068 connect_topology_str)))
1070 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1071 "Invalid connect topology `%s' given for section %s option %s\n",
1072 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1074 GNUNET_free_non_null (connect_topology_str);
1076 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1077 "connect_topology_option",
1078 &connect_topology_option_str))
1080 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1081 connect_topology_option_str)))
1083 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1084 "Invalid connect topology option `%s' given for section %s option %s\n",
1085 connect_topology_option_str, "TESTING",
1086 "CONNECT_TOPOLOGY_OPTION");
1087 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1089 GNUNET_free_non_null (connect_topology_option_str);
1091 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1092 "connect_topology_option_modifier",
1093 &connect_topology_option_modifier_string))
1096 (connect_topology_option_modifier_string, "%lf",
1097 &connect_topology_option_modifier) != 1)
1099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1101 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1102 connect_topology_option_modifier_string,
1103 "connect_topology_option_modifier", "TESTING");
1105 GNUNET_free (connect_topology_option_modifier_string);
1109 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1110 "blacklist_transports",
1111 &blacklist_transports))
1112 blacklist_transports = NULL;
1115 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1116 "blacklist_topology",
1117 &blacklist_topology_str))
1119 GNUNET_TESTING_topology_get (&blacklist_topology,
1120 blacklist_topology_str)))
1122 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1123 "Invalid topology `%s' given for section %s option %s\n",
1124 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1126 GNUNET_free_non_null (topology_str);
1127 GNUNET_free_non_null (blacklist_topology_str);
1130 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1133 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1136 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1139 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_timeout");
1148 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1151 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_attempts");
1155 if (GNUNET_SYSERR ==
1156 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1158 num_peers = DEFAULT_NUM_PEERS;
1162 peers_left = num_peers;
1163 modnum = num_peers / 4;
1164 dotnum = (num_peers / 50) + 1;
1170 fprintf (stdout, "Hostkey generation progress: [");
1172 /* Set up a task to end testing if peer start fails */
1174 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1175 (GNUNET_TIME_UNIT_SECONDS,
1176 SECONDS_PER_PEER_START * num_peers),
1178 "didn't generate all hostkeys within a reasonable amount of time!!!");
1180 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1181 pg = GNUNET_TESTING_daemons_start (cfg,
1184 GNUNET_TIME_relative_multiply
1185 (GNUNET_TIME_UNIT_SECONDS,
1186 SECONDS_PER_PEER_START * num_peers),
1187 &hostkey_callback, NULL,
1188 &peers_started_callback, NULL,
1189 &topology_callback, NULL, NULL);
1197 char *config_file_name;
1198 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1199 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1202 char *const argv[] = { binary_name,
1210 struct GNUNET_GETOPT_CommandLineOption options[] = {
1211 GNUNET_GETOPT_OPTION_END
1213 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1214 argv, binary_name, "nohelp", options, &run, &ok);
1215 if (ret != GNUNET_OK)
1217 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1218 "`test-testing-topology-%s': Failed with error code %d\n",
1219 topology_string, ret);
1221 GNUNET_free (binary_name);
1222 GNUNET_free (config_file_name);
1227 main (int argc, char *argv[])
1230 char *binary_start_pos;
1231 char *our_binary_name;
1233 binary_start_pos = strchr (argv[0], '/');
1234 GNUNET_assert (binary_start_pos != NULL);
1235 topology_string = strstr (binary_start_pos, "_topology");
1236 GNUNET_assert (topology_string != NULL);
1238 topology_string = strstr (topology_string, "_");
1239 GNUNET_assert (topology_string != NULL);
1242 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1244 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1246 GNUNET_log_setup (our_binary_name,
1256 * Need to remove base directory, subdirectories taken care
1257 * of by the testing framework.
1259 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1261 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1262 "Failed to remove testing directory %s\n", test_directory);
1264 GNUNET_free (our_binary_name);
1268 /* end of test_testing_topology.c */