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_EXTRA_LOGGING
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);
197 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
198 "totals.txt", 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, "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, "Disconnecting from peer 2 `%4s'\n",
275 GNUNET_i2s (&pos->peer2->id));
277 if (pos->peer2handle != NULL)
278 GNUNET_CORE_disconnect (pos->peer2handle);
279 /* Set handles to NULL so test case can be ended properly */
280 pos->peer1handle = NULL;
281 pos->peer2handle = NULL;
282 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
283 /* Decrement total connections so new can be established */
284 total_server_connections -= 2;
289 stats_finished (void *cls, int result)
291 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
295 * Callback function to process statistic values.
298 * @param peer the peer the statistics belong to
299 * @param subsystem name of subsystem that created the statistic
300 * @param name the name of the datum
301 * @param value the current value
302 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
303 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
306 stats_print (void *cls, const struct GNUNET_PeerIdentity *peer,
307 const char *subsystem, const char *name, uint64_t value,
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s (peer),
311 subsystem, name, value);
317 topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
318 const struct GNUNET_PeerIdentity *second, const char *emsg)
326 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
327 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
329 topology_connections++;
334 "Finished iterating over topology, %d total connections!\n",
335 topology_connections);
338 fprintf (outfile, "}\n");
341 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, NULL);
343 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
349 process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
350 const struct GNUNET_MessageHeader *message,
351 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
353 char *dotOutFileNameFinished;
354 FILE *dotOutFileFinished;
355 struct TestMessageContext *pos = cls;
356 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
358 if (pos->uid != ntohl (msg->uid))
362 if ((total_messages_received) % modnum == 0)
364 if (total_messages_received == 0)
365 fprintf (stdout, "0%%");
367 fprintf (stdout, "%d%%",
368 (int) (((float) total_messages_received / expected_messages) *
372 else if (total_messages_received % dotnum == 0)
374 fprintf (stdout, ".");
379 total_messages_received++;
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
383 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
384 ntohs (message->type));
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Total messages received %d, expected %d.\n",
387 total_messages_received, expected_messages);
390 if (total_messages_received == expected_messages)
393 fprintf (stdout, "100%%]\n");
395 GNUNET_SCHEDULER_cancel (die_task);
396 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
397 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
398 GNUNET_free (dotOutFileNameFinished);
399 if (dotOutFileFinished != NULL)
401 fprintf (dotOutFileFinished, "strict graph G {\n");
403 topology_connections = 0;
404 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
405 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
409 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
416 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
420 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
421 "End badly was called (%s)... stopping daemons.\n", msg);
422 struct TestMessageContext *pos;
423 struct TestMessageContext *free_pos;
428 if (pos->peer1handle != NULL)
430 GNUNET_CORE_disconnect (pos->peer1handle);
431 pos->peer1handle = NULL;
433 if (pos->peer2handle != NULL)
435 GNUNET_CORE_disconnect (pos->peer2handle);
436 pos->peer2handle = NULL;
440 GNUNET_free (free_pos);
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
446 transmit_ready_scheduled, transmit_ready_failed,
447 transmit_ready_called);
448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
449 "Total messages received %d, expected %d.\n",
450 total_messages_received, expected_messages);
455 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
456 ok = 7331; /* Opposite of leet */
459 ok = 401; /* Never got peers started */
461 if (dotOutFile != NULL)
463 fprintf (dotOutFile, "}");
469 transmit_ready (void *cls, size_t size, void *buf)
471 struct GNUNET_TestMessage *m;
472 struct TestMessageContext *pos = cls;
474 GNUNET_assert (buf != NULL);
475 m = (struct GNUNET_TestMessage *) buf;
476 m->header.type = htons (MTYPE);
477 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
478 m->uid = htonl (pos->uid);
479 transmit_ready_called++;
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
483 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
484 transmit_ready_called);
486 return sizeof (struct GNUNET_TestMessage);
490 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
494 static struct GNUNET_CORE_MessageHandler handlers[] = {
495 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
500 init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
501 const struct GNUNET_PeerIdentity *my_identity)
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),
514 GNUNET_h2s (&pos->peer1->id.hashPubKey));
517 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
518 TIMEOUT, &pos->peer2->id,
519 sizeof (struct GNUNET_TestMessage),
520 &transmit_ready, pos))
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
524 GNUNET_i2s (&pos->peer2->id));
525 transmit_ready_failed++;
529 transmit_ready_scheduled++;
535 * Method called whenever a given peer connects.
538 * @param peer peer identity this notification is about
539 * @param atsi performance data for the connection
542 connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
543 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
545 struct TestMessageContext *pos = cls;
547 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
549 pos->peer1notified = GNUNET_YES;
551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
552 "Peer `%s' notified of connection to peer `%s'\n",
553 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
559 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
563 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
564 GNUNET_i2s (&pos->peer2->id),
565 GNUNET_h2s (&pos->peer1->id.hashPubKey));
568 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
569 TIMEOUT, &pos->peer2->id,
570 sizeof (struct GNUNET_TestMessage),
571 &transmit_ready, pos))
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
574 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
575 GNUNET_i2s (&pos->peer2->id));
576 transmit_ready_failed++;
580 transmit_ready_scheduled++;
586 init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
587 const struct GNUNET_PeerIdentity *my_identity)
589 struct TestMessageContext *pos = cls;
591 total_server_connections++;
594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
595 "Core connection to `%4s' established, setting up handles\n",
596 GNUNET_i2s (my_identity));
600 * Connect to the receiving peer
603 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
604 NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
611 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
613 struct TestMessageContext *pos = cls;
615 if ((pos == test_messages) && (settle_time.rel_value > 0))
617 topology_connections = 0;
618 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
620 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
623 if (die_task == GNUNET_SCHEDULER_NO_TASK)
626 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
627 "from send test messages (timeout)");
630 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
632 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
633 (GNUNET_TIME_UNIT_SECONDS, 1),
634 &send_test_messages, pos);
635 return; /* Otherwise we'll double schedule messages here! */
639 * Connect to the sending peer
642 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
643 &connect_notify_peers, NULL, NULL, GNUNET_NO,
644 NULL, GNUNET_NO, no_handlers);
646 GNUNET_assert (pos->peer1handle != NULL);
648 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
650 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
654 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
655 (GNUNET_TIME_UNIT_SECONDS, 1),
656 &send_test_messages, pos->next);
662 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
663 const struct GNUNET_PeerIdentity *second, uint32_t distance,
664 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
665 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
666 struct GNUNET_TESTING_Daemon *first_daemon,
667 struct GNUNET_TESTING_Daemon *second_daemon,
670 struct TestMessageContext *temp_context;
675 if ((total_connections) % modnum == 0)
677 if (total_connections == 0)
678 fprintf (stdout, "0%%");
680 fprintf (stdout, "%d%%",
681 (int) (((float) total_connections / expected_connections) *
685 else if (total_connections % dotnum == 0)
687 fprintf (stdout, ".");
693 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
694 first_daemon->shortname, second_daemon->shortname);
696 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
697 temp_context->peer1 = first_daemon;
698 temp_context->peer2 = second_daemon;
699 temp_context->next = test_messages;
700 temp_context->uid = total_connections;
701 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
702 test_messages = temp_context;
705 if (dotOutFile != NULL)
706 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
707 second_daemon->shortname);
712 failed_connections++;
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
714 "Failed to connect peer %s to peer %s with error :\n%s\n",
715 first_daemon->shortname, second_daemon->shortname, emsg);
719 if (total_connections == expected_connections)
722 fprintf (stdout, "100%%]\n");
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Created %d total connections, which is our target number! Calling send messages.\n",
729 modnum = expected_messages / 4;
730 dotnum = (expected_messages / 50) + 1;
735 GNUNET_SCHEDULER_cancel (die_task);
736 die_task = GNUNET_SCHEDULER_NO_TASK;
737 #if DELAY_FOR_LOGGING
738 fprintf (stdout, "Sending test messages in 10 seconds.\n");
739 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
740 (GNUNET_TIME_UNIT_SECONDS, 10),
741 &send_test_messages, test_messages);
744 if (settle_time.rel_value > 0)
746 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
748 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
752 fprintf (stdout, "Test message progress: [");
756 else if (total_connections + failed_connections == expected_connections)
758 if (failed_connections <
759 (unsigned int) (fail_percentage * total_connections))
761 GNUNET_SCHEDULER_cancel (die_task);
762 die_task = GNUNET_SCHEDULER_NO_TASK;
763 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
767 GNUNET_SCHEDULER_cancel (die_task);
769 GNUNET_SCHEDULER_add_now (&end_badly,
770 "from topology_callback (too many failed connections)");
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
777 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
778 total_connections, failed_connections, expected_connections,
779 expected_connections -
780 (unsigned int) (fail_percentage * expected_connections));
786 topology_creation_finished (void *cls, const char *emsg)
790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
791 "All topology connections created successfully!\n");
798 expected_connections = -1;
799 if ((pg != NULL) && (peers_left == 0))
801 expected_connections =
802 GNUNET_TESTING_connect_topology (pg, connection_topology,
803 connect_topology_option,
804 connect_topology_option_modifier,
805 connect_timeout, connect_attempts,
806 &topology_creation_finished, NULL);
808 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %d expected connections\n",
809 expected_connections);
813 GNUNET_SCHEDULER_cancel (die_task);
814 if (expected_connections < 1)
817 GNUNET_SCHEDULER_add_now (&end_badly,
818 "from connect topology (bad return)");
823 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
824 (GNUNET_TIME_UNIT_SECONDS,
825 SECONDS_PER_PEER_START * num_peers),
827 "from connect topology (timeout)");
828 modnum = expected_connections / 4;
829 dotnum = (expected_connections / 50) + 1;
835 fprintf (stdout, "Peer connection progress: [");
842 peers_left = num_peers; /* Reset counter */
843 if (GNUNET_TESTING_create_topology
844 (pg, topology, blacklist_topology, 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);
862 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
863 (GNUNET_TIME_UNIT_SECONDS,
864 SECONDS_PER_PEER_START * num_peers),
866 "from continue startup (timeout)");
871 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
872 const struct GNUNET_CONFIGURATION_Handle *cfg,
873 struct GNUNET_TESTING_Daemon *d, const char *emsg)
877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
878 "Failed to start daemon with error: `%s'\n", emsg);
881 GNUNET_assert (id != NULL);
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
884 (num_peers - peers_left) + 1, num_peers);
887 if ((num_peers - peers_left) % modnum == 0)
889 if (num_peers - peers_left == 0)
890 fprintf (stdout, "0%%");
892 fprintf (stdout, "%d%%",
893 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
896 else if ((num_peers - peers_left) % dotnum == 0)
898 fprintf (stdout, ".");
906 fprintf (stdout, "100%%]\n");
909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 "All %d daemons started, now connecting peers!\n", num_peers);
912 GNUNET_SCHEDULER_cancel (die_task);
913 /* Set up task in case topology creation doesn't finish
914 * within a reasonable amount of time */
916 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
917 (GNUNET_TIME_UNIT_MINUTES, 8), &end_badly,
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, const struct GNUNET_PeerIdentity *id,
942 struct GNUNET_TESTING_Daemon *d, const char *emsg)
946 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
947 "Hostkey callback received error: %s\n", emsg);
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
952 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
953 num_peers, GNUNET_i2s (id));
957 if ((num_peers - peers_left) % modnum == 0)
959 if (num_peers - peers_left == 0)
960 fprintf (stdout, "0%%");
962 fprintf (stdout, "%d%%",
963 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
966 else if ((num_peers - peers_left) % dotnum == 0)
968 fprintf (stdout, ".");
976 fprintf (stdout, "100%%]\n");
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
978 "All %d hostkeys created, now creating topology!\n", num_peers);
980 GNUNET_SCHEDULER_cancel (die_task);
981 /* Set up task in case topology creation doesn't finish
982 * within a reasonable amount of time */
984 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
985 "from create_topology");
986 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
992 run (void *cls, char *const *args, const char *cfgfile,
993 const struct GNUNET_CONFIGURATION_Handle *cfg)
996 char *connect_topology_str;
997 char *blacklist_topology_str;
998 char *connect_topology_option_str;
999 char *connect_topology_option_modifier_string;
1000 unsigned long long temp_settle;
1001 unsigned long long max_outstanding_connections;
1005 dotOutFile = fopen (dotOutFileName, "w");
1006 if (dotOutFile != NULL)
1008 fprintf (dotOutFile, "strict graph G {\n");
1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1013 "Starting daemons based on config file %s\n", cfgfile);
1017 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1025 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1027 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1029 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1030 "Invalid topology `%s' given for section %s option %s\n",
1031 topology_str, "TESTING", "TOPOLOGY");
1032 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1036 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1038 &connect_topology_str)) &&
1040 GNUNET_TESTING_topology_get (&connection_topology,
1041 connect_topology_str)))
1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1044 "Invalid connect topology `%s' given for section %s option %s\n",
1045 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1047 GNUNET_free_non_null (connect_topology_str);
1049 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1050 "connect_topology_option",
1051 &connect_topology_option_str)) &&
1053 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1054 connect_topology_option_str)))
1056 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1057 "Invalid connect topology option `%s' given for section %s option %s\n",
1058 connect_topology_option_str, "TESTING",
1059 "CONNECT_TOPOLOGY_OPTION");
1060 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1062 GNUNET_free_non_null (connect_topology_option_str);
1064 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1065 "connect_topology_option_modifier",
1066 &connect_topology_option_modifier_string))
1069 (connect_topology_option_modifier_string, "%lf",
1070 &connect_topology_option_modifier) != 1)
1072 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1074 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1075 connect_topology_option_modifier_string,
1076 "connect_topology_option_modifier", "TESTING");
1078 GNUNET_free (connect_topology_option_modifier_string);
1082 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1083 "blacklist_transports",
1084 &blacklist_transports))
1085 blacklist_transports = NULL;
1088 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1089 "blacklist_topology",
1090 &blacklist_topology_str)) &&
1092 GNUNET_TESTING_topology_get (&blacklist_topology,
1093 blacklist_topology_str)))
1095 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1096 "Invalid topology `%s' given for section %s option %s\n",
1097 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1099 GNUNET_free_non_null (topology_str);
1100 GNUNET_free_non_null (blacklist_topology_str);
1103 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1106 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1109 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1112 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1116 "testing", "connect_timeout");
1122 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1126 "testing", "connect_attempts");
1131 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
1132 "max_outstanding_connections",
1133 &max_outstanding_connections))
1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1136 "testing", "max_outstanding_connections");
1140 if (GNUNET_SYSERR ==
1141 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1143 num_peers = DEFAULT_NUM_PEERS;
1147 peers_left = num_peers;
1148 modnum = num_peers / 4;
1149 dotnum = (num_peers / 50) + 1;
1155 fprintf (stdout, "Hostkey generation progress: [");
1157 /* Set up a task to end testing if peer start fails */
1159 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1160 (GNUNET_TIME_UNIT_SECONDS,
1161 SECONDS_PER_PEER_START * num_peers),
1163 "didn't generate all hostkeys within a reasonable amount of time!!!");
1165 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1166 pg = GNUNET_TESTING_daemons_start (cfg, peers_left,
1167 max_outstanding_connections, peers_left,
1168 GNUNET_TIME_relative_multiply
1169 (GNUNET_TIME_UNIT_SECONDS,
1170 SECONDS_PER_PEER_START * num_peers),
1171 &hostkey_callback, NULL,
1172 &peers_started_callback, NULL,
1173 &topology_callback, NULL, NULL);
1181 char *config_file_name;
1183 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1184 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1188 char *const argv[] = { binary_name,
1196 struct GNUNET_GETOPT_CommandLineOption options[] = {
1197 GNUNET_GETOPT_OPTION_END
1200 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1201 binary_name, "nohelp", options, &run, &ok);
1202 if (ret != GNUNET_OK)
1204 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1205 "`test-testing-topology-%s': Failed with error code %d\n",
1206 topology_string, ret);
1208 GNUNET_free (binary_name);
1209 GNUNET_free (config_file_name);
1214 main (int argc, char *argv[])
1217 char *binary_start_pos;
1218 char *our_binary_name;
1221 binary_start_pos = strchr (argv[0], '/');
1222 GNUNET_assert (binary_start_pos != NULL);
1223 topology_string = strstr (binary_start_pos, "_topology");
1224 GNUNET_assert (topology_string != NULL);
1226 topology_string = strstr (topology_string, "_");
1227 GNUNET_assert (topology_string != NULL);
1229 topology_string = GNUNET_strdup (topology_string);
1230 if (NULL != (dotexe = strstr (topology_string, ".exe")))
1232 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1234 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1236 GNUNET_log_setup (our_binary_name,
1244 GNUNET_free (topology_string);
1247 * Need to remove base directory, subdirectories taken care
1248 * of by the testing framework.
1250 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1252 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1253 "Failed to remove testing directory %s\n", test_directory);
1255 GNUNET_free (our_binary_name);
1259 /* end of test_testing_topology.c */