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, "All peers successfully shut down!\n");
186 #if DELAY_FOR_LOGGING
191 char *connect_number;
192 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;
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Called finish testing, stopping daemons.\n");
221 if (pos->peer1handle != NULL)
223 GNUNET_CORE_disconnect (pos->peer1handle);
224 pos->peer1handle = NULL;
226 if (pos->peer2handle != NULL)
228 GNUNET_CORE_disconnect (pos->peer2handle);
229 pos->peer2handle = NULL;
233 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
235 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
237 GNUNET_free (free_pos);
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
242 transmit_ready_scheduled, transmit_ready_failed,
243 transmit_ready_called);
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
249 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
251 if (dotOutFile != NULL)
253 fprintf (dotOutFile, "}");
262 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264 struct TestMessageContext *pos = cls;
266 /* Disconnect from the respective cores */
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "Disconnecting from peer 1 `%4s'\n",
270 GNUNET_i2s (&pos->peer1->id));
272 if (pos->peer1handle != NULL)
273 GNUNET_CORE_disconnect (pos->peer1handle);
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
276 "Disconnecting from peer 2 `%4s'\n",
277 GNUNET_i2s (&pos->peer2->id));
279 if (pos->peer2handle != NULL)
280 GNUNET_CORE_disconnect (pos->peer2handle);
281 /* Set handles to NULL so test case can be ended properly */
282 pos->peer1handle = NULL;
283 pos->peer2handle = NULL;
284 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
285 /* Decrement total connections so new can be established */
286 total_server_connections -= 2;
291 stats_finished (void *cls, int result)
293 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
297 * Callback function to process statistic values.
300 * @param peer the peer the statistics belong to
301 * @param subsystem name of subsystem that created the statistic
302 * @param name the name of the datum
303 * @param value the current value
304 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
305 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
308 stats_print (void *cls,
309 const struct GNUNET_PeerIdentity *peer,
310 const char *subsystem,
311 const char *name, uint64_t value, int is_persistent)
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
314 GNUNET_i2s (peer), subsystem, name, value);
320 topology_cb (void *cls,
321 const struct GNUNET_PeerIdentity *first,
322 const struct GNUNET_PeerIdentity *second, const char *emsg)
330 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
331 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
333 topology_connections++;
338 "Finished iterating over topology, %d total connections!\n",
339 topology_connections);
342 fprintf (outfile, "}\n");
345 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, NULL);
347 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
353 process_mtype (void *cls,
354 const struct GNUNET_PeerIdentity *peer,
355 const struct GNUNET_MessageHeader *message,
356 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
358 char *dotOutFileNameFinished;
359 FILE *dotOutFileFinished;
360 struct TestMessageContext *pos = cls;
361 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
363 if (pos->uid != ntohl (msg->uid))
367 if ((total_messages_received) % modnum == 0)
369 if (total_messages_received == 0)
370 fprintf (stdout, "0%%");
372 fprintf (stdout, "%d%%",
373 (int) (((float) total_messages_received /
374 expected_messages) * 100));
377 else if (total_messages_received % dotnum == 0)
379 fprintf (stdout, ".");
384 total_messages_received++;
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
388 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
389 ntohs (message->type));
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
391 "Total messages received %d, expected %d.\n",
392 total_messages_received, expected_messages);
395 if (total_messages_received == expected_messages)
398 fprintf (stdout, "100%%]\n");
400 GNUNET_SCHEDULER_cancel (die_task);
401 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
402 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
403 GNUNET_free (dotOutFileNameFinished);
404 if (dotOutFileFinished != NULL)
406 fprintf (dotOutFileFinished, "strict graph G {\n");
408 topology_connections = 0;
409 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
410 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
414 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
421 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
425 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
426 "End badly was called (%s)... stopping daemons.\n", msg);
427 struct TestMessageContext *pos;
428 struct TestMessageContext *free_pos;
433 if (pos->peer1handle != NULL)
435 GNUNET_CORE_disconnect (pos->peer1handle);
436 pos->peer1handle = NULL;
438 if (pos->peer2handle != NULL)
440 GNUNET_CORE_disconnect (pos->peer2handle);
441 pos->peer2handle = NULL;
445 GNUNET_free (free_pos);
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
450 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
451 transmit_ready_scheduled, transmit_ready_failed,
452 transmit_ready_called);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
454 "Total messages received %d, expected %d.\n",
455 total_messages_received, expected_messages);
460 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
461 ok = 7331; /* Opposite of leet */
464 ok = 401; /* Never got peers started */
466 if (dotOutFile != NULL)
468 fprintf (dotOutFile, "}");
474 transmit_ready (void *cls, size_t size, void *buf)
476 struct GNUNET_TestMessage *m;
477 struct TestMessageContext *pos = cls;
479 GNUNET_assert (buf != NULL);
480 m = (struct GNUNET_TestMessage *) buf;
481 m->header.type = htons (MTYPE);
482 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
483 m->uid = htonl (pos->uid);
484 transmit_ready_called++;
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
487 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
488 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
489 transmit_ready_called);
491 return sizeof (struct GNUNET_TestMessage);
495 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
499 static struct GNUNET_CORE_MessageHandler handlers[] = {
500 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
505 init_notify_peer2 (void *cls,
506 struct GNUNET_CORE_Handle *server,
507 const struct GNUNET_PeerIdentity *my_identity,
508 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
511 struct TestMessageContext *pos = cls;
513 total_server_connections++;
515 pos->peer2connected = GNUNET_YES;
516 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
520 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
521 GNUNET_i2s (my_identity),
522 GNUNET_h2s (&pos->peer1->id.hashPubKey));
524 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
531 &transmit_ready, pos))
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
535 GNUNET_i2s (&pos->peer2->id));
536 transmit_ready_failed++;
540 transmit_ready_scheduled++;
546 * Method called whenever a given peer connects.
549 * @param peer peer identity this notification is about
550 * @param atsi performance data for the connection
553 connect_notify_peers (void *cls,
555 GNUNET_PeerIdentity *peer,
556 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
558 struct TestMessageContext *pos = cls;
560 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
562 pos->peer1notified = GNUNET_YES;
564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 "Peer `%s' notified of connection to peer `%s'\n",
566 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
572 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
576 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
577 GNUNET_i2s (&pos->peer2->id),
578 GNUNET_h2s (&pos->peer1->id.hashPubKey));
580 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
587 &transmit_ready, pos))
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
590 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
591 GNUNET_i2s (&pos->peer2->id));
592 transmit_ready_failed++;
596 transmit_ready_scheduled++;
602 init_notify_peer1 (void *cls,
603 struct GNUNET_CORE_Handle *server,
604 const struct GNUNET_PeerIdentity *my_identity,
605 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
608 struct TestMessageContext *pos = cls;
610 total_server_connections++;
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Core connection to `%4s' established, setting up handles\n",
615 GNUNET_i2s (my_identity));
619 * Connect to the receiving peer
621 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
628 GNUNET_YES, NULL, GNUNET_YES,
635 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
637 struct TestMessageContext *pos = cls;
639 if ((pos == test_messages) && (settle_time.rel_value > 0))
641 topology_connections = 0;
642 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
644 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
647 if (die_task == GNUNET_SCHEDULER_NO_TASK)
649 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
651 "from send test messages (timeout)");
654 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
656 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
657 (GNUNET_TIME_UNIT_SECONDS, 1),
658 &send_test_messages, pos);
659 return; /* Otherwise we'll double schedule messages here! */
663 * Connect to the sending peer
665 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
669 &connect_notify_peers, NULL,
672 GNUNET_NO, NULL, GNUNET_NO,
675 GNUNET_assert (pos->peer1handle != NULL);
677 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
679 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
683 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
684 (GNUNET_TIME_UNIT_SECONDS, 1),
685 &send_test_messages, pos->next);
691 topology_callback (void *cls,
692 const struct GNUNET_PeerIdentity *first,
693 const struct GNUNET_PeerIdentity *second,
695 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
696 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
697 struct GNUNET_TESTING_Daemon *first_daemon,
698 struct GNUNET_TESTING_Daemon *second_daemon,
701 struct TestMessageContext *temp_context;
706 if ((total_connections) % modnum == 0)
708 if (total_connections == 0)
709 fprintf (stdout, "0%%");
711 fprintf (stdout, "%d%%",
712 (int) (((float) total_connections /
713 expected_connections) * 100));
716 else if (total_connections % dotnum == 0)
718 fprintf (stdout, ".");
724 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
725 first_daemon->shortname, second_daemon->shortname);
727 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
728 temp_context->peer1 = first_daemon;
729 temp_context->peer2 = second_daemon;
730 temp_context->next = test_messages;
731 temp_context->uid = total_connections;
732 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
733 test_messages = temp_context;
736 if (dotOutFile != NULL)
737 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
738 second_daemon->shortname);
743 failed_connections++;
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "Failed to connect peer %s to peer %s with error :\n%s\n",
746 first_daemon->shortname, second_daemon->shortname, emsg);
750 if (total_connections == expected_connections)
753 fprintf (stdout, "100%%]\n");
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
757 "Created %d total connections, which is our target number! Calling send messages.\n",
760 modnum = expected_messages / 4;
761 dotnum = (expected_messages / 50) + 1;
766 GNUNET_SCHEDULER_cancel (die_task);
767 die_task = GNUNET_SCHEDULER_NO_TASK;
768 #if DELAY_FOR_LOGGING
769 fprintf (stdout, "Sending test messages in 10 seconds.\n");
770 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
771 (GNUNET_TIME_UNIT_SECONDS, 10),
772 &send_test_messages, test_messages);
775 if (settle_time.rel_value > 0)
777 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
779 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
783 fprintf (stdout, "Test message progress: [");
787 else if (total_connections + failed_connections == expected_connections)
789 if (failed_connections <
790 (unsigned int) (fail_percentage * total_connections))
792 GNUNET_SCHEDULER_cancel (die_task);
793 die_task = GNUNET_SCHEDULER_NO_TASK;
794 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
798 GNUNET_SCHEDULER_cancel (die_task);
800 GNUNET_SCHEDULER_add_now (&end_badly,
801 "from topology_callback (too many failed connections)");
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
809 total_connections, failed_connections, expected_connections,
810 expected_connections -
811 (unsigned int) (fail_percentage * expected_connections));
817 topology_creation_finished (void *cls, const char *emsg)
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "All topology connections created successfully!\n");
829 expected_connections = -1;
830 if ((pg != NULL) && (peers_left == 0))
832 expected_connections =
833 GNUNET_TESTING_connect_topology (pg, connection_topology,
834 connect_topology_option,
835 connect_topology_option_modifier,
838 &topology_creation_finished, NULL);
840 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
841 "Have %d expected connections\n", expected_connections);
845 GNUNET_SCHEDULER_cancel (die_task);
846 if (expected_connections < 1)
849 GNUNET_SCHEDULER_add_now (&end_badly,
850 "from connect topology (bad return)");
854 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
855 (GNUNET_TIME_UNIT_SECONDS,
856 SECONDS_PER_PEER_START * num_peers),
858 "from connect topology (timeout)");
859 modnum = expected_connections / 4;
860 dotnum = (expected_connections / 50) + 1;
866 fprintf (stdout, "Peer connection progress: [");
873 peers_left = num_peers; /* Reset counter */
874 if (GNUNET_TESTING_create_topology
875 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
879 "Topology set up, now starting peers!\n");
880 fprintf (stdout, "Daemon start progress [");
882 GNUNET_TESTING_daemons_continue_startup (pg);
886 GNUNET_SCHEDULER_cancel (die_task);
888 GNUNET_SCHEDULER_add_now (&end_badly,
889 "from create topology (bad return)");
891 GNUNET_SCHEDULER_cancel (die_task);
892 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
893 (GNUNET_TIME_UNIT_SECONDS,
894 SECONDS_PER_PEER_START * num_peers),
896 "from continue startup (timeout)");
901 peers_started_callback (void *cls,
902 const struct GNUNET_PeerIdentity *id,
903 const struct GNUNET_CONFIGURATION_Handle *cfg,
904 struct GNUNET_TESTING_Daemon *d, const char *emsg)
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Failed to start daemon with error: `%s'\n", emsg);
912 GNUNET_assert (id != NULL);
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
915 (num_peers - peers_left) + 1, num_peers);
918 if ((num_peers - peers_left) % modnum == 0)
920 if (num_peers - peers_left == 0)
921 fprintf (stdout, "0%%");
923 fprintf (stdout, "%d%%",
924 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
927 else if ((num_peers - peers_left) % dotnum == 0)
929 fprintf (stdout, ".");
937 fprintf (stdout, "100%%]\n");
940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
941 "All %d daemons started, now connecting peers!\n", num_peers);
943 GNUNET_SCHEDULER_cancel (die_task);
944 /* Set up task in case topology creation doesn't finish
945 * within a reasonable amount of time */
946 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
947 (GNUNET_TIME_UNIT_MINUTES, 8),
949 "from peers_started_callback");
950 #if DELAY_FOR_LOGGING
951 fprintf (stdout, "Connecting topology in 10 seconds\n");
953 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
954 (GNUNET_TIME_UNIT_SECONDS, 10),
955 &connect_topology, NULL);
964 * Callback indicating that the hostkey was created for a peer.
967 * @param id the peer identity
968 * @param d the daemon handle (pretty useless at this point, remove?)
969 * @param emsg non-null on failure
972 hostkey_callback (void *cls,
973 const struct GNUNET_PeerIdentity *id,
974 struct GNUNET_TESTING_Daemon *d, const char *emsg)
978 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
979 "Hostkey callback received error: %s\n", emsg);
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Hostkey (%d/%d) created for peer `%s'\n",
985 num_peers - peers_left, num_peers, GNUNET_i2s (id));
989 if ((num_peers - peers_left) % modnum == 0)
991 if (num_peers - peers_left == 0)
992 fprintf (stdout, "0%%");
994 fprintf (stdout, "%d%%",
995 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
998 else if ((num_peers - peers_left) % dotnum == 0)
1000 fprintf (stdout, ".");
1005 if (peers_left == 0)
1008 fprintf (stdout, "100%%]\n");
1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1010 "All %d hostkeys created, now creating topology!\n", num_peers);
1012 GNUNET_SCHEDULER_cancel (die_task);
1013 /* Set up task in case topology creation doesn't finish
1014 * within a reasonable amount of time */
1015 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1017 "from create_topology");
1018 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1026 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1029 char *connect_topology_str;
1030 char *blacklist_topology_str;
1031 char *connect_topology_option_str;
1032 char *connect_topology_option_modifier_string;
1033 unsigned long long temp_settle;
1034 unsigned long long max_outstanding_connections;
1038 dotOutFile = fopen (dotOutFileName, "w");
1039 if (dotOutFile != NULL)
1041 fprintf (dotOutFile, "strict graph G {\n");
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Starting daemons based on config file %s\n", cfgfile);
1050 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1058 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1060 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1062 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1063 "Invalid topology `%s' given for section %s option %s\n",
1064 topology_str, "TESTING", "TOPOLOGY");
1065 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1069 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1071 &connect_topology_str))
1073 GNUNET_TESTING_topology_get (&connection_topology,
1074 connect_topology_str)))
1076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1077 "Invalid connect topology `%s' given for section %s option %s\n",
1078 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1080 GNUNET_free_non_null (connect_topology_str);
1082 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1083 "connect_topology_option",
1084 &connect_topology_option_str))
1086 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1087 connect_topology_option_str)))
1089 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1090 "Invalid connect topology option `%s' given for section %s option %s\n",
1091 connect_topology_option_str, "TESTING",
1092 "CONNECT_TOPOLOGY_OPTION");
1093 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1095 GNUNET_free_non_null (connect_topology_option_str);
1097 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1098 "connect_topology_option_modifier",
1099 &connect_topology_option_modifier_string))
1102 (connect_topology_option_modifier_string, "%lf",
1103 &connect_topology_option_modifier) != 1)
1105 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1107 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1108 connect_topology_option_modifier_string,
1109 "connect_topology_option_modifier", "TESTING");
1111 GNUNET_free (connect_topology_option_modifier_string);
1115 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1116 "blacklist_transports",
1117 &blacklist_transports))
1118 blacklist_transports = NULL;
1121 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1122 "blacklist_topology",
1123 &blacklist_topology_str))
1125 GNUNET_TESTING_topology_get (&blacklist_topology,
1126 blacklist_topology_str)))
1128 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1129 "Invalid topology `%s' given for section %s option %s\n",
1130 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1132 GNUNET_free_non_null (topology_str);
1133 GNUNET_free_non_null (blacklist_topology_str);
1136 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1139 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1142 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1145 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1149 "testing", "connect_timeout");
1155 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1159 "testing", "connect_attempts");
1164 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
1165 "max_outstanding_connections",
1166 &max_outstanding_connections))
1168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1169 "testing", "max_outstanding_connections");
1173 if (GNUNET_SYSERR ==
1174 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1176 num_peers = DEFAULT_NUM_PEERS;
1180 peers_left = num_peers;
1181 modnum = num_peers / 4;
1182 dotnum = (num_peers / 50) + 1;
1188 fprintf (stdout, "Hostkey generation progress: [");
1190 /* Set up a task to end testing if peer start fails */
1192 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1193 (GNUNET_TIME_UNIT_SECONDS,
1194 SECONDS_PER_PEER_START * num_peers),
1196 "didn't generate all hostkeys within a reasonable amount of time!!!");
1198 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1199 pg = GNUNET_TESTING_daemons_start (cfg,
1201 max_outstanding_connections,
1203 GNUNET_TIME_relative_multiply
1204 (GNUNET_TIME_UNIT_SECONDS,
1205 SECONDS_PER_PEER_START * num_peers),
1206 &hostkey_callback, NULL,
1207 &peers_started_callback, NULL,
1208 &topology_callback, NULL, NULL);
1216 char *config_file_name;
1218 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1219 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1223 char *const argv[] = { binary_name,
1231 struct GNUNET_GETOPT_CommandLineOption options[] = {
1232 GNUNET_GETOPT_OPTION_END
1234 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1235 argv, binary_name, "nohelp", options, &run, &ok);
1236 if (ret != GNUNET_OK)
1238 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1239 "`test-testing-topology-%s': Failed with error code %d\n",
1240 topology_string, ret);
1242 GNUNET_free (binary_name);
1243 GNUNET_free (config_file_name);
1248 main (int argc, char *argv[])
1251 char *binary_start_pos;
1252 char *our_binary_name;
1255 binary_start_pos = strchr (argv[0], '/');
1256 GNUNET_assert (binary_start_pos != NULL);
1257 topology_string = strstr (binary_start_pos, "_topology");
1258 GNUNET_assert (topology_string != NULL);
1260 topology_string = strstr (topology_string, "_");
1261 GNUNET_assert (topology_string != NULL);
1263 topology_string = GNUNET_strdup (topology_string);
1264 if (NULL != (dotexe = strstr (topology_string, ".exe")))
1266 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1268 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1270 GNUNET_log_setup (our_binary_name,
1278 GNUNET_free (topology_string);
1281 * Need to remove base directory, subdirectories taken care
1282 * of by the testing framework.
1284 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1287 "Failed to remove testing directory %s\n", test_directory);
1289 GNUNET_free (our_binary_name);
1293 /* end of test_testing_topology.c */