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 GNUNET_NETWORK_STRUCT_BEGIN
120 struct GNUNET_TestMessage
123 * Header of the message
125 struct GNUNET_MessageHeader header;
128 * Unique identifier for this message.
132 GNUNET_NETWORK_STRUCT_END
134 struct TestMessageContext
136 /* This is a linked list */
137 struct TestMessageContext *next;
139 /* Handle to the sending peer core */
140 struct GNUNET_CORE_Handle *peer1handle;
142 /* Handle to the receiving peer core */
143 struct GNUNET_CORE_Handle *peer2handle;
145 /* Handle to the sending peer daemon */
146 struct GNUNET_TESTING_Daemon *peer1;
148 /* Handle to the receiving peer daemon */
149 struct GNUNET_TESTING_Daemon *peer2;
151 /* Identifier for this message, so we don't disconnect other peers! */
154 /* Has peer1 been notified already of a connection to peer2? */
157 /* Has the core of peer2 been connected already? */
160 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
161 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
165 static struct TestMessageContext *test_messages;
168 * Check whether peers successfully shut down.
171 shutdown_callback (void *cls, const char *emsg)
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
189 #if DELAY_FOR_LOGGING
194 char *connect_number;
195 struct GNUNET_OS_Process *mem_process;
197 GNUNET_asprintf (&peer_number, "%llu", num_peers);
198 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
200 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
201 "totals.txt", peer_number, connect_number, NULL);
202 GNUNET_OS_process_wait (mem_process);
203 GNUNET_OS_process_close (mem_process);
212 GNUNET_assert (pg != NULL);
213 struct TestMessageContext *pos;
214 struct TestMessageContext *free_pos;
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Called finish testing, stopping daemons.\n");
224 if (pos->peer1handle != NULL)
226 GNUNET_CORE_disconnect (pos->peer1handle);
227 pos->peer1handle = NULL;
229 if (pos->peer2handle != NULL)
231 GNUNET_CORE_disconnect (pos->peer2handle);
232 pos->peer2handle = NULL;
236 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
238 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
240 GNUNET_free (free_pos);
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
245 transmit_ready_scheduled, transmit_ready_failed,
246 transmit_ready_called);
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
252 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
254 if (dotOutFile != NULL)
256 FPRINTF (dotOutFile, "%s", "}");
265 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
267 struct TestMessageContext *pos = cls;
269 /* Disconnect from the respective cores */
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
272 GNUNET_i2s (&pos->peer1->id));
274 if (pos->peer1handle != NULL)
275 GNUNET_CORE_disconnect (pos->peer1handle);
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
278 GNUNET_i2s (&pos->peer2->id));
280 if (pos->peer2handle != NULL)
281 GNUNET_CORE_disconnect (pos->peer2handle);
282 /* Set handles to NULL so test case can be ended properly */
283 pos->peer1handle = NULL;
284 pos->peer2handle = NULL;
285 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
286 /* Decrement total connections so new can be established */
287 total_server_connections -= 2;
292 stats_finished (void *cls, int result)
294 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
298 * Callback function to process statistic values.
301 * @param peer the peer the statistics belong to
302 * @param subsystem name of subsystem that created the statistic
303 * @param name the name of the datum
304 * @param value the current value
305 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
306 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
309 stats_print (void *cls, const struct GNUNET_PeerIdentity *peer,
310 const char *subsystem, const char *name, uint64_t value,
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n", GNUNET_i2s (peer),
314 subsystem, name, value);
320 topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
321 const struct GNUNET_PeerIdentity *second, const char *emsg)
329 FPRINTF (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
330 FPRINTF (outfile, "\"%s\";\n", GNUNET_i2s (second));
332 topology_connections++;
337 "Finished iterating over topology, %d total connections!\n",
338 topology_connections);
341 FPRINTF (outfile, "%s", "}\n");
344 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print, NULL);
346 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
352 process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
353 const struct GNUNET_MessageHeader *message,
354 const struct GNUNET_ATS_Information *atsi,
355 unsigned int atsi_count)
357 char *dotOutFileNameFinished;
358 FILE *dotOutFileFinished;
359 struct TestMessageContext *pos = cls;
360 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
362 if (pos->uid != ntohl (msg->uid))
366 if ((total_messages_received) % modnum == 0)
368 if (total_messages_received == 0)
369 FPRINTF (stdout, "%s", "0%%");
371 FPRINTF (stdout, "%d%%",
372 (int) (((float) total_messages_received / expected_messages) *
376 else if (total_messages_received % dotnum == 0)
378 FPRINTF (stdout, "%s", ".");
383 total_messages_received++;
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
388 ntohs (message->type));
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Total messages received %d, expected %d.\n",
391 total_messages_received, expected_messages);
394 if (total_messages_received == expected_messages)
397 FPRINTF (stdout, "%s", "100%%]\n");
399 GNUNET_SCHEDULER_cancel (die_task);
400 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
401 dotOutFileFinished = FOPEN (dotOutFileNameFinished, "w");
402 GNUNET_free (dotOutFileNameFinished);
403 if (dotOutFileFinished != NULL)
405 FPRINTF (dotOutFileFinished, "%s", "strict graph G {\n");
407 topology_connections = 0;
408 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
409 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
413 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
420 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
424 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
425 "End badly was called (%s)... stopping daemons.\n", msg);
426 struct TestMessageContext *pos;
427 struct TestMessageContext *free_pos;
432 if (pos->peer1handle != NULL)
434 GNUNET_CORE_disconnect (pos->peer1handle);
435 pos->peer1handle = NULL;
437 if (pos->peer2handle != NULL)
439 GNUNET_CORE_disconnect (pos->peer2handle);
440 pos->peer2handle = NULL;
444 GNUNET_free (free_pos);
448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
449 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
450 transmit_ready_scheduled, transmit_ready_failed,
451 transmit_ready_called);
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Total messages received %d, expected %d.\n",
454 total_messages_received, expected_messages);
459 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
460 ok = 7331; /* Opposite of leet */
463 ok = 401; /* Never got peers started */
465 if (dotOutFile != NULL)
467 FPRINTF (dotOutFile, "%s", "}");
473 transmit_ready (void *cls, size_t size, void *buf)
475 struct GNUNET_TestMessage *m;
476 struct TestMessageContext *pos = cls;
478 GNUNET_assert (buf != NULL);
479 m = (struct GNUNET_TestMessage *) buf;
480 m->header.type = htons (MTYPE);
481 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
482 m->uid = htonl (pos->uid);
483 transmit_ready_called++;
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
486 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
487 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
488 transmit_ready_called);
490 return sizeof (struct GNUNET_TestMessage);
494 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
498 static struct GNUNET_CORE_MessageHandler handlers[] = {
499 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
504 init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
505 const struct GNUNET_PeerIdentity *my_identity)
507 struct TestMessageContext *pos = cls;
509 total_server_connections++;
511 pos->peer2connected = GNUNET_YES;
512 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
517 GNUNET_i2s (my_identity),
518 GNUNET_h2s (&pos->peer1->id.hashPubKey));
521 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
522 TIMEOUT, &pos->peer2->id,
523 sizeof (struct GNUNET_TestMessage),
524 &transmit_ready, pos))
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
528 GNUNET_i2s (&pos->peer2->id));
529 transmit_ready_failed++;
533 transmit_ready_scheduled++;
539 * Method called whenever a given peer connects.
542 * @param peer peer identity this notification is about
543 * @param atsi performance data for the connection
544 * @param atsi_count number of records in 'atsi'
547 connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
548 const struct GNUNET_ATS_Information *atsi,
549 unsigned int atsi_count)
551 struct TestMessageContext *pos = cls;
553 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
555 pos->peer1notified = GNUNET_YES;
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
558 "Peer `%s' notified of connection to peer `%s'\n",
559 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
565 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
569 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
570 GNUNET_i2s (&pos->peer2->id),
571 GNUNET_h2s (&pos->peer1->id.hashPubKey));
574 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
575 TIMEOUT, &pos->peer2->id,
576 sizeof (struct GNUNET_TestMessage),
577 &transmit_ready, pos))
579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
580 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
581 GNUNET_i2s (&pos->peer2->id));
582 transmit_ready_failed++;
586 transmit_ready_scheduled++;
592 init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
593 const struct GNUNET_PeerIdentity *my_identity)
595 struct TestMessageContext *pos = cls;
597 total_server_connections++;
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "Core connection to `%4s' established, setting up handles\n",
602 GNUNET_i2s (my_identity));
606 * Connect to the receiving peer
609 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
610 NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers);
616 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
618 struct TestMessageContext *pos = cls;
620 if ((pos == test_messages) && (settle_time.rel_value > 0))
622 topology_connections = 0;
623 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
625 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
628 if (die_task == GNUNET_SCHEDULER_NO_TASK)
631 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
632 "from send test messages (timeout)");
635 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
637 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
638 (GNUNET_TIME_UNIT_SECONDS, 1),
639 &send_test_messages, pos);
640 return; /* Otherwise we'll double schedule messages here! */
644 * Connect to the sending peer
647 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
648 &connect_notify_peers, NULL, NULL, GNUNET_NO, NULL,
649 GNUNET_NO, no_handlers);
651 GNUNET_assert (pos->peer1handle != NULL);
653 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
655 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
659 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
660 (GNUNET_TIME_UNIT_SECONDS, 1),
661 &send_test_messages, pos->next);
667 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
668 const struct GNUNET_PeerIdentity *second, uint32_t distance,
669 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
670 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
671 struct GNUNET_TESTING_Daemon *first_daemon,
672 struct GNUNET_TESTING_Daemon *second_daemon,
675 struct TestMessageContext *temp_context;
680 if ((total_connections) % modnum == 0)
682 if (total_connections == 0)
683 FPRINTF (stdout, "%s", "0%%");
685 FPRINTF (stdout, "%d%%",
686 (int) (((float) total_connections / expected_connections) *
690 else if (total_connections % dotnum == 0)
692 FPRINTF (stdout, "%s", ".");
698 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
699 first_daemon->shortname, second_daemon->shortname);
701 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
702 temp_context->peer1 = first_daemon;
703 temp_context->peer2 = second_daemon;
704 temp_context->next = test_messages;
705 temp_context->uid = total_connections;
706 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
707 test_messages = temp_context;
710 if (dotOutFile != NULL)
711 FPRINTF (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
712 second_daemon->shortname);
717 failed_connections++;
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719 "Failed to connect peer %s to peer %s with error :\n%s\n",
720 first_daemon->shortname, second_daemon->shortname, emsg);
724 if (total_connections == expected_connections)
727 FPRINTF (stdout, "%s", "100%%]\n");
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Created %d total connections, which is our target number! Calling send messages.\n",
734 modnum = expected_messages / 4;
735 dotnum = (expected_messages / 50) + 1;
740 GNUNET_SCHEDULER_cancel (die_task);
741 die_task = GNUNET_SCHEDULER_NO_TASK;
742 #if DELAY_FOR_LOGGING
743 FPRINTF (stdout, "%s", "Sending test messages in 10 seconds.\n");
744 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
745 (GNUNET_TIME_UNIT_SECONDS, 10),
746 &send_test_messages, test_messages);
749 if (settle_time.rel_value > 0)
751 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
753 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
757 FPRINTF (stdout, "%s", "Test message progress: [");
761 else if (total_connections + failed_connections == expected_connections)
763 if (failed_connections <
764 (unsigned int) (fail_percentage * total_connections))
766 GNUNET_SCHEDULER_cancel (die_task);
767 die_task = GNUNET_SCHEDULER_NO_TASK;
768 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
772 GNUNET_SCHEDULER_cancel (die_task);
774 GNUNET_SCHEDULER_add_now (&end_badly,
775 "from topology_callback (too many failed connections)");
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
783 total_connections, failed_connections, expected_connections,
784 expected_connections -
785 (unsigned int) (fail_percentage * expected_connections));
791 topology_creation_finished (void *cls, const char *emsg)
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "All topology connections created successfully!\n");
803 expected_connections = -1;
804 if ((pg != NULL) && (peers_left == 0))
806 expected_connections =
807 GNUNET_TESTING_connect_topology (pg, connection_topology,
808 connect_topology_option,
809 connect_topology_option_modifier,
810 connect_timeout, connect_attempts,
811 &topology_creation_finished, NULL);
813 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %d expected connections\n",
814 expected_connections);
818 GNUNET_SCHEDULER_cancel (die_task);
819 if (expected_connections < 1)
822 GNUNET_SCHEDULER_add_now (&end_badly,
823 "from connect topology (bad return)");
828 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
829 (GNUNET_TIME_UNIT_SECONDS,
830 SECONDS_PER_PEER_START * num_peers),
832 "from connect topology (timeout)");
833 modnum = expected_connections / 4;
834 dotnum = (expected_connections / 50) + 1;
840 FPRINTF (stdout, "%s", "Peer connection progress: [");
847 peers_left = num_peers; /* Reset counter */
848 if (GNUNET_TESTING_create_topology
849 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Topology set up, now starting peers!\n");
854 FPRINTF (stdout, "%s", "Daemon start progress [");
856 GNUNET_TESTING_daemons_continue_startup (pg);
860 GNUNET_SCHEDULER_cancel (die_task);
862 GNUNET_SCHEDULER_add_now (&end_badly,
863 "from create topology (bad return)");
865 GNUNET_SCHEDULER_cancel (die_task);
867 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
868 (GNUNET_TIME_UNIT_SECONDS,
869 SECONDS_PER_PEER_START * num_peers),
871 "from continue startup (timeout)");
876 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
877 const struct GNUNET_CONFIGURATION_Handle *cfg,
878 struct GNUNET_TESTING_Daemon *d, const char *emsg)
882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
883 "Failed to start daemon with error: `%s'\n", emsg);
886 GNUNET_assert (id != NULL);
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
889 (num_peers - peers_left) + 1, num_peers);
892 if ((num_peers - peers_left) % modnum == 0)
894 if (num_peers - peers_left == 0)
895 FPRINTF (stdout, "%s", "0%%");
897 FPRINTF (stdout, "%d%%",
898 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
901 else if ((num_peers - peers_left) % dotnum == 0)
903 FPRINTF (stdout, "%s", ".");
911 FPRINTF (stdout, "%s", "100%%]\n");
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
915 "All %d daemons started, now connecting peers!\n", num_peers);
917 GNUNET_SCHEDULER_cancel (die_task);
918 /* Set up task in case topology creation doesn't finish
919 * within a reasonable amount of time */
921 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
922 (GNUNET_TIME_UNIT_MINUTES, 8), &end_badly,
923 "from peers_started_callback");
924 #if DELAY_FOR_LOGGING
925 FPRINTF (stdout, "%s", "Connecting topology in 10 seconds\n");
927 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
928 (GNUNET_TIME_UNIT_SECONDS, 10),
929 &connect_topology, NULL);
938 * Callback indicating that the hostkey was created for a peer.
941 * @param id the peer identity
942 * @param d the daemon handle (pretty useless at this point, remove?)
943 * @param emsg non-null on failure
946 hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
947 struct GNUNET_TESTING_Daemon *d, const char *emsg)
951 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
952 "Hostkey callback received error: %s\n", emsg);
956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
957 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
958 num_peers, GNUNET_i2s (id));
962 if ((num_peers - peers_left) % modnum == 0)
964 if (num_peers - peers_left == 0)
965 FPRINTF (stdout, "%s", "0%%");
967 FPRINTF (stdout, "%d%%",
968 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
971 else if ((num_peers - peers_left) % dotnum == 0)
973 FPRINTF (stdout, "%s", ".");
981 FPRINTF (stdout, "%s", "100%%]\n");
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
983 "All %d hostkeys created, now creating topology!\n", num_peers);
985 GNUNET_SCHEDULER_cancel (die_task);
986 /* Set up task in case topology creation doesn't finish
987 * within a reasonable amount of time */
989 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
990 "from create_topology");
991 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
997 run (void *cls, char *const *args, const char *cfgfile,
998 const struct GNUNET_CONFIGURATION_Handle *cfg)
1001 char *connect_topology_str;
1002 char *blacklist_topology_str;
1003 char *connect_topology_option_str;
1004 char *connect_topology_option_modifier_string;
1005 unsigned long long max_outstanding_connections;
1009 dotOutFile = FOPEN (dotOutFileName, "w");
1010 if (dotOutFile != NULL)
1012 FPRINTF (dotOutFile, "%s", "strict graph G {\n");
1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1017 "Starting daemons based on config file %s\n", cfgfile);
1021 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1029 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1031 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1033 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1034 "Invalid topology `%s' given for section %s option %s\n",
1035 topology_str, "TESTING", "TOPOLOGY");
1036 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1040 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1042 &connect_topology_str)) &&
1044 GNUNET_TESTING_topology_get (&connection_topology,
1045 connect_topology_str)))
1047 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1048 "Invalid connect topology `%s' given for section %s option %s\n",
1049 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1051 GNUNET_free_non_null (connect_topology_str);
1053 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1054 "connect_topology_option",
1055 &connect_topology_option_str)) &&
1057 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1058 connect_topology_option_str)))
1060 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1061 "Invalid connect topology option `%s' given for section %s option %s\n",
1062 connect_topology_option_str, "TESTING",
1063 "CONNECT_TOPOLOGY_OPTION");
1064 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1066 GNUNET_free_non_null (connect_topology_option_str);
1068 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1069 "connect_topology_option_modifier",
1070 &connect_topology_option_modifier_string))
1073 (connect_topology_option_modifier_string, "%lf",
1074 &connect_topology_option_modifier) != 1)
1076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1078 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1079 connect_topology_option_modifier_string,
1080 "connect_topology_option_modifier", "TESTING");
1082 GNUNET_free (connect_topology_option_modifier_string);
1086 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1087 "blacklist_transports",
1088 &blacklist_transports))
1089 blacklist_transports = NULL;
1092 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1093 "blacklist_topology",
1094 &blacklist_topology_str)) &&
1096 GNUNET_TESTING_topology_get (&blacklist_topology,
1097 blacklist_topology_str)))
1099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1100 "Invalid topology `%s' given for section %s option %s\n",
1101 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1103 GNUNET_free_non_null (topology_str);
1104 GNUNET_free_non_null (blacklist_topology_str);
1107 GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SETTLE_TIME",
1110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1111 "testing", "SETTLE_TIME");
1116 GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "CONNECT_TIMEOUT",
1119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1120 "testing", "CONNECT_TIMEOUT");
1126 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1130 "testing", "connect_attempts");
1135 GNUNET_CONFIGURATION_get_value_number (cfg, "testing",
1136 "max_outstanding_connections",
1137 &max_outstanding_connections))
1139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1140 "testing", "max_outstanding_connections");
1144 if (GNUNET_SYSERR ==
1145 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1147 num_peers = DEFAULT_NUM_PEERS;
1151 peers_left = num_peers;
1152 modnum = num_peers / 4;
1153 dotnum = (num_peers / 50) + 1;
1159 FPRINTF (stdout, "%s", "Hostkey generation progress: [");
1161 /* Set up a task to end testing if peer start fails */
1163 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1164 (GNUNET_TIME_UNIT_SECONDS,
1165 SECONDS_PER_PEER_START * num_peers),
1167 "didn't generate all hostkeys within a reasonable amount of time!!!");
1169 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1170 pg = GNUNET_TESTING_daemons_start (cfg, peers_left,
1171 max_outstanding_connections, peers_left,
1172 GNUNET_TIME_relative_multiply
1173 (GNUNET_TIME_UNIT_SECONDS,
1174 SECONDS_PER_PEER_START * num_peers),
1175 &hostkey_callback, NULL,
1176 &peers_started_callback, NULL,
1177 &topology_callback, NULL, NULL);
1185 char *config_file_name;
1187 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1188 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1192 char *const argv[] = { binary_name,
1200 struct GNUNET_GETOPT_CommandLineOption options[] = {
1201 GNUNET_GETOPT_OPTION_END
1204 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1205 binary_name, "nohelp", options, &run, &ok);
1206 if (ret != GNUNET_OK)
1208 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1209 "`test-testing-topology-%s': Failed with error code %d\n",
1210 topology_string, ret);
1212 GNUNET_free (binary_name);
1213 GNUNET_free (config_file_name);
1218 main (int argc, char *argv[])
1221 char *binary_start_pos;
1222 char *our_binary_name;
1225 binary_start_pos = strchr (argv[0], '/');
1226 GNUNET_assert (binary_start_pos != NULL);
1227 topology_string = strstr (binary_start_pos, "_topology");
1228 GNUNET_assert (topology_string != NULL);
1230 topology_string = strstr (topology_string, "_");
1231 GNUNET_assert (topology_string != NULL);
1233 topology_string = GNUNET_strdup (topology_string);
1234 if (NULL != (dotexe = strstr (topology_string, ".exe")))
1236 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1238 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1240 GNUNET_log_setup (our_binary_name,
1248 GNUNET_free (topology_string);
1251 * Need to remove base directory, subdirectories taken care
1252 * of by the testing framework.
1254 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1257 "Failed to remove testing directory %s\n", test_directory);
1259 GNUNET_free (our_binary_name);
1263 /* end of test_testing_topology.c */