2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file testing/test_testing_topology.c
22 * @brief base testcase for testing all the topologies provided
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_core_service.h"
27 #include "gnunet_os_lib.h"
29 #define VERBOSE GNUNET_YES
31 #define DELAY_FOR_LOGGING GNUNET_NO
33 #define SECONDS_PER_PEER_START 120
35 #define DEFAULT_NUM_PEERS 4
37 #define MAX_OUTSTANDING_CONNECTIONS 100
39 static float fail_percentage = 0.05;
43 struct GNUNET_TIME_Relative connect_timeout;
45 static unsigned long long connect_attempts;
47 static unsigned long long num_peers;
49 static unsigned int topology_connections;
51 static unsigned int total_connections;
53 static unsigned int failed_connections;
55 static unsigned int total_server_connections;
57 static unsigned int total_messages_received;
59 static unsigned int expected_messages;
61 static unsigned int expected_connections;
63 static unsigned long long peers_left;
65 static struct GNUNET_TESTING_PeerGroup *pg;
67 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
69 GNUNET_SCHEDULER_TaskIdentifier die_task;
71 static char *dotOutFileName;
73 static struct GNUNET_TIME_Relative settle_time;
75 static FILE *dotOutFile;
77 static char *topology_string;
79 static char *blacklist_transports;
81 static int transmit_ready_scheduled;
83 static int transmit_ready_failed;
85 static int transmit_ready_called;
87 struct GNUNET_TIME_Relative test_timeout;
89 struct GNUNET_TIME_Relative timeout;
91 static unsigned int modnum;
93 static unsigned int dotnum;
95 static enum GNUNET_TESTING_Topology topology;
97 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
99 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
101 static enum GNUNET_TESTING_TopologyOption connect_topology_option =
102 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
104 static double connect_topology_option_modifier = 0.0;
106 static char *test_directory;
110 struct GNUNET_TestMessage
113 * Header of the message
115 struct GNUNET_MessageHeader header;
118 * Unique identifier for this message.
123 struct TestMessageContext
125 /* This is a linked list */
126 struct TestMessageContext *next;
128 /* Handle to the sending peer core */
129 struct GNUNET_CORE_Handle *peer1handle;
131 /* Handle to the receiving peer core */
132 struct GNUNET_CORE_Handle *peer2handle;
134 /* Handle to the sending peer daemon */
135 struct GNUNET_TESTING_Daemon *peer1;
137 /* Handle to the receiving peer daemon */
138 struct GNUNET_TESTING_Daemon *peer2;
140 /* Identifier for this message, so we don't disconnect other peers! */
143 /* Has peer1 been notified already of a connection to peer2? */
146 /* Has the core of peer2 been connected already? */
149 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
150 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
154 static struct TestMessageContext *test_messages;
157 * Check whether peers successfully shut down.
160 shutdown_callback (void *cls, const char *emsg)
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
178 #if DELAY_FOR_LOGGING
183 char *connect_number;
184 struct GNUNET_OS_Process *mem_process;
186 GNUNET_asprintf (&peer_number, "%llu", num_peers);
187 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
189 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
190 "totals.txt", peer_number, connect_number, NULL);
191 GNUNET_OS_process_wait (mem_process);
192 GNUNET_OS_process_close (mem_process);
201 GNUNET_assert (pg != NULL);
202 struct TestMessageContext *pos;
203 struct TestMessageContext *free_pos;
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Called finish testing, stopping daemons.\n");
213 if (pos->peer1handle != NULL)
215 GNUNET_CORE_disconnect (pos->peer1handle);
216 pos->peer1handle = NULL;
218 if (pos->peer2handle != NULL)
220 GNUNET_CORE_disconnect (pos->peer2handle);
221 pos->peer2handle = NULL;
225 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
227 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
229 GNUNET_free (free_pos);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
234 transmit_ready_scheduled, transmit_ready_failed,
235 transmit_ready_called);
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
241 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
243 if (dotOutFile != NULL)
245 fprintf (dotOutFile, "}");
254 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256 struct TestMessageContext *pos = cls;
258 /* Disconnect from the respective cores */
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
261 GNUNET_i2s (&pos->peer1->id));
263 if (pos->peer1handle != NULL)
264 GNUNET_CORE_disconnect (pos->peer1handle);
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
267 GNUNET_i2s (&pos->peer2->id));
269 if (pos->peer2handle != NULL)
270 GNUNET_CORE_disconnect (pos->peer2handle);
271 /* Set handles to NULL so test case can be ended properly */
272 pos->peer1handle = NULL;
273 pos->peer2handle = NULL;
274 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
275 /* Decrement total connections so new can be established */
276 total_server_connections -= 2;
281 topology_cb (void *cls, const struct GNUNET_PeerIdentity *first,
282 const struct GNUNET_PeerIdentity *second, const char *emsg)
290 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
291 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
293 topology_connections++;
298 "Finished iterating over topology, %d total connections!\n",
299 topology_connections);
302 fprintf (outfile, "}\n");
304 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
310 process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
311 const struct GNUNET_MessageHeader *message,
312 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
314 char *dotOutFileNameFinished;
315 FILE *dotOutFileFinished;
316 struct TestMessageContext *pos = cls;
317 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
319 if (pos->uid != ntohl (msg->uid))
323 if ((total_messages_received) % modnum == 0)
325 if (total_messages_received == 0)
326 fprintf (stdout, "0%%");
328 fprintf (stdout, "%d%%",
329 (int) (((float) total_messages_received / expected_messages) *
333 else if (total_messages_received % dotnum == 0)
335 fprintf (stdout, ".");
340 total_messages_received++;
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
345 ntohs (message->type));
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Total messages received %d, expected %d.\n",
348 total_messages_received, expected_messages);
351 if (total_messages_received == expected_messages)
354 fprintf (stdout, "100%%]\n");
356 GNUNET_SCHEDULER_cancel (die_task);
357 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
358 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
359 GNUNET_free (dotOutFileNameFinished);
360 if (dotOutFileFinished != NULL)
362 fprintf (dotOutFileFinished, "strict graph G {\n");
364 topology_connections = 0;
365 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
366 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
370 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
377 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
382 "End badly was called (%s)... stopping daemons.\n", msg);
383 struct TestMessageContext *pos;
384 struct TestMessageContext *free_pos;
389 if (pos->peer1handle != NULL)
391 GNUNET_CORE_disconnect (pos->peer1handle);
392 pos->peer1handle = NULL;
394 if (pos->peer2handle != NULL)
396 GNUNET_CORE_disconnect (pos->peer2handle);
397 pos->peer2handle = NULL;
401 GNUNET_free (free_pos);
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
406 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
407 transmit_ready_scheduled, transmit_ready_failed,
408 transmit_ready_called);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Total messages received %d, expected %d.\n",
411 total_messages_received, expected_messages);
416 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
417 ok = 7331; /* Opposite of leet */
420 ok = 401; /* Never got peers started */
422 if (dotOutFile != NULL)
424 fprintf (dotOutFile, "}");
430 transmit_ready (void *cls, size_t size, void *buf)
432 struct GNUNET_TestMessage *m;
433 struct TestMessageContext *pos = cls;
435 GNUNET_assert (buf != NULL);
436 m = (struct GNUNET_TestMessage *) buf;
437 m->header.type = htons (MTYPE);
438 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
439 m->uid = htonl (pos->uid);
440 transmit_ready_called++;
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
444 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
445 transmit_ready_called);
447 return sizeof (struct GNUNET_TestMessage);
451 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
455 static struct GNUNET_CORE_MessageHandler handlers[] = {
456 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
461 init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
462 const struct GNUNET_PeerIdentity *my_identity,
463 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
466 struct TestMessageContext *pos = cls;
468 total_server_connections++;
470 pos->peer2connected = GNUNET_YES;
471 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
476 GNUNET_i2s (my_identity),
477 GNUNET_h2s (&pos->peer1->id.hashPubKey));
480 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
482 sizeof (struct GNUNET_TestMessage),
483 &transmit_ready, pos))
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
486 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
487 GNUNET_i2s (&pos->peer2->id));
488 transmit_ready_failed++;
492 transmit_ready_scheduled++;
498 * Method called whenever a given peer connects.
501 * @param peer peer identity this notification is about
502 * @param atsi performance data for the connection
505 connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
506 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
508 struct TestMessageContext *pos = cls;
510 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
512 pos->peer1notified = GNUNET_YES;
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Peer `%s' notified of connection to peer `%s'\n",
516 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
522 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
526 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
527 GNUNET_i2s (&pos->peer2->id),
528 GNUNET_h2s (&pos->peer1->id.hashPubKey));
531 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
533 sizeof (struct GNUNET_TestMessage),
534 &transmit_ready, pos))
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
538 GNUNET_i2s (&pos->peer2->id));
539 transmit_ready_failed++;
543 transmit_ready_scheduled++;
549 init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
550 const struct GNUNET_PeerIdentity *my_identity,
551 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
554 struct TestMessageContext *pos = cls;
556 total_server_connections++;
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "Core connection to `%4s' established, setting up handles\n",
561 GNUNET_i2s (my_identity));
565 * Connect to the receiving peer
568 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
569 NULL, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
576 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
578 struct TestMessageContext *pos = cls;
580 if ((pos == test_messages) && (settle_time.rel_value > 0))
582 topology_connections = 0;
583 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
585 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
588 if (die_task == GNUNET_SCHEDULER_NO_TASK)
591 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
592 "from send test messages (timeout)");
595 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
597 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
598 (GNUNET_TIME_UNIT_SECONDS, 1),
599 &send_test_messages, pos);
600 return; /* Otherwise we'll double schedule messages here! */
604 * Connect to the sending peer
607 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
608 &connect_notify_peers, NULL, NULL, NULL, GNUNET_NO,
609 NULL, GNUNET_NO, no_handlers);
611 GNUNET_assert (pos->peer1handle != NULL);
613 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
615 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
619 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
620 (GNUNET_TIME_UNIT_SECONDS, 1),
621 &send_test_messages, pos->next);
627 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
628 const struct GNUNET_PeerIdentity *second, uint32_t distance,
629 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
630 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
631 struct GNUNET_TESTING_Daemon *first_daemon,
632 struct GNUNET_TESTING_Daemon *second_daemon,
635 struct TestMessageContext *temp_context;
640 if ((total_connections) % modnum == 0)
642 if (total_connections == 0)
643 fprintf (stdout, "0%%");
645 fprintf (stdout, "%d%%",
646 (int) (((float) total_connections / expected_connections) *
650 else if (total_connections % dotnum == 0)
652 fprintf (stdout, ".");
658 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
659 first_daemon->shortname, second_daemon->shortname);
661 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
662 temp_context->peer1 = first_daemon;
663 temp_context->peer2 = second_daemon;
664 temp_context->next = test_messages;
665 temp_context->uid = total_connections;
666 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
667 test_messages = temp_context;
670 if (dotOutFile != NULL)
671 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
672 second_daemon->shortname);
677 failed_connections++;
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
679 "Failed to connect peer %s to peer %s with error :\n%s\n",
680 first_daemon->shortname, second_daemon->shortname, emsg);
684 if (total_connections == expected_connections)
687 fprintf (stdout, "100%%]\n");
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "Created %d total connections, which is our target number! Calling send messages.\n",
694 modnum = expected_messages / 4;
695 dotnum = (expected_messages / 50) + 1;
696 GNUNET_SCHEDULER_cancel (die_task);
697 die_task = GNUNET_SCHEDULER_NO_TASK;
698 #if DELAY_FOR_LOGGING
699 fprintf (stdout, "Sending test messages in 10 seconds.\n");
700 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
701 (GNUNET_TIME_UNIT_SECONDS, 10),
702 &send_test_messages, test_messages);
705 if (settle_time.rel_value > 0)
707 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
709 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
713 fprintf (stdout, "Test message progress: [");
717 else if (total_connections + failed_connections == expected_connections)
719 if (failed_connections <
720 (unsigned int) (fail_percentage * total_connections))
722 GNUNET_SCHEDULER_cancel (die_task);
723 die_task = GNUNET_SCHEDULER_NO_TASK;
724 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
728 GNUNET_SCHEDULER_cancel (die_task);
730 GNUNET_SCHEDULER_add_now (&end_badly,
731 "from topology_callback (too many failed connections)");
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
739 total_connections, failed_connections, expected_connections,
740 expected_connections -
741 (unsigned int) (fail_percentage * expected_connections));
747 topology_creation_finished (void *cls, const char *emsg)
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "All topology connections created successfully!\n");
759 expected_connections = -1;
760 if ((pg != NULL) && (peers_left == 0))
762 expected_connections =
763 GNUNET_TESTING_connect_topology (pg, connection_topology,
764 connect_topology_option,
765 connect_topology_option_modifier,
766 connect_timeout, connect_attempts,
767 &topology_creation_finished, NULL);
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
770 expected_connections);
774 GNUNET_SCHEDULER_cancel (die_task);
775 if (expected_connections == GNUNET_SYSERR)
778 GNUNET_SCHEDULER_add_now (&end_badly,
779 "from connect topology (bad return)");
783 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
784 "from connect topology (timeout)");
785 modnum = expected_connections / 4;
786 dotnum = (expected_connections / 50) + 1;
788 fprintf (stdout, "Peer connection progress: [");
795 peers_left = num_peers; /* Reset counter */
796 if (GNUNET_TESTING_create_topology
797 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
801 "Topology set up, now starting peers!\n");
802 fprintf (stdout, "Daemon start progress [");
804 GNUNET_TESTING_daemons_continue_startup (pg);
808 GNUNET_SCHEDULER_cancel (die_task);
810 GNUNET_SCHEDULER_add_now (&end_badly,
811 "from create topology (bad return)");
813 GNUNET_SCHEDULER_cancel (die_task);
815 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
816 "from continue startup (timeout)");
821 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
822 const struct GNUNET_CONFIGURATION_Handle *cfg,
823 struct GNUNET_TESTING_Daemon *d, const char *emsg)
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
828 "Failed to start daemon with error: `%s'\n", emsg);
831 GNUNET_assert (id != NULL);
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
834 (num_peers - peers_left) + 1, num_peers);
837 if ((num_peers - peers_left) % modnum == 0)
839 if (num_peers - peers_left == 0)
840 fprintf (stdout, "0%%");
842 fprintf (stdout, "%d%%",
843 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
846 else if ((num_peers - peers_left) % dotnum == 0)
848 fprintf (stdout, ".");
856 fprintf (stdout, "100%%]\n");
859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
860 "All %d daemons started, now connecting peers!\n", num_peers);
862 GNUNET_SCHEDULER_cancel (die_task);
863 /* Set up task in case topology creation doesn't finish
864 * within a reasonable amount of time */
866 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
867 "from peers_started_callback");
868 #if DELAY_FOR_LOGGING
869 fprintf (stdout, "Connecting topology in 10 seconds\n");
871 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
872 (GNUNET_TIME_UNIT_SECONDS, 10),
873 &connect_topology, NULL);
882 * Callback indicating that the hostkey was created for a peer.
885 * @param id the peer identity
886 * @param d the daemon handle (pretty useless at this point, remove?)
887 * @param emsg non-null on failure
890 hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
891 struct GNUNET_TESTING_Daemon *d, const char *emsg)
895 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
896 "Hostkey callback received error: %s\n", emsg);
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
901 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
902 num_peers, GNUNET_i2s (id));
906 if ((num_peers - peers_left) % modnum == 0)
908 if (num_peers - peers_left == 0)
909 fprintf (stdout, "0%%");
911 fprintf (stdout, "%d%%",
912 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
915 else if ((num_peers - peers_left) % dotnum == 0)
917 fprintf (stdout, ".");
925 fprintf (stdout, "100%%]\n");
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 "All %d hostkeys created, now creating topology!\n", num_peers);
929 GNUNET_SCHEDULER_cancel (die_task);
930 /* Set up task in case topology creation doesn't finish
931 * within a reasonable amount of time */
933 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
934 "from create_topology");
935 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
941 run (void *cls, char *const *args, const char *cfgfile,
942 const struct GNUNET_CONFIGURATION_Handle *cfg)
945 char *connect_topology_str;
946 char *blacklist_topology_str;
947 char *connect_topology_option_str;
948 char *connect_topology_option_modifier_string;
949 unsigned long long temp_settle;
953 dotOutFile = fopen (dotOutFileName, "w");
954 if (dotOutFile != NULL)
956 fprintf (dotOutFile, "strict graph G {\n");
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 "Starting daemons based on config file %s\n", cfgfile);
965 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
973 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
975 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
977 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
978 "Invalid topology `%s' given for section %s option %s\n",
979 topology_str, "TESTING", "TOPOLOGY");
980 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
984 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
986 &connect_topology_str)) &&
988 GNUNET_TESTING_topology_get (&connection_topology,
989 connect_topology_str)))
991 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
992 "Invalid connect topology `%s' given for section %s option %s\n",
993 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
995 GNUNET_free_non_null (connect_topology_str);
997 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
998 "connect_topology_option",
999 &connect_topology_option_str)) &&
1001 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1002 connect_topology_option_str)))
1004 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1005 "Invalid connect topology option `%s' given for section %s option %s\n",
1006 connect_topology_option_str, "TESTING",
1007 "CONNECT_TOPOLOGY_OPTION");
1008 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1010 GNUNET_free_non_null (connect_topology_option_str);
1012 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1013 "connect_topology_option_modifier",
1014 &connect_topology_option_modifier_string))
1017 (connect_topology_option_modifier_string, "%lf",
1018 &connect_topology_option_modifier) != 1)
1020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1022 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1023 connect_topology_option_modifier_string,
1024 "connect_topology_option_modifier", "TESTING");
1026 GNUNET_free (connect_topology_option_modifier_string);
1030 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1031 "blacklist_transports",
1032 &blacklist_transports))
1033 blacklist_transports = NULL;
1036 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1037 "blacklist_topology",
1038 &blacklist_topology_str)) &&
1040 GNUNET_TESTING_topology_get (&blacklist_topology,
1041 blacklist_topology_str)))
1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1044 "Invalid topology `%s' given for section %s option %s\n",
1045 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1047 GNUNET_free_non_null (topology_str);
1048 GNUNET_free_non_null (blacklist_topology_str);
1051 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1054 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1056 if (GNUNET_SYSERR ==
1057 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1059 num_peers = DEFAULT_NUM_PEERS;
1062 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1065 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1068 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1069 "testing", "connect_timeout");
1075 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1078 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1079 "testing", "connect_attempts");
1085 peers_left = num_peers;
1088 * How long until we fail the whole testcase?
1091 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1092 (GNUNET_TIME_UNIT_SECONDS,
1093 SECONDS_PER_PEER_START), num_peers * 2);
1096 * How long until we give up on starting the peers?
1099 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1100 (GNUNET_TIME_UNIT_SECONDS,
1101 SECONDS_PER_PEER_START), num_peers);
1103 modnum = num_peers / 4;
1104 dotnum = (num_peers / 50) + 1;
1106 fprintf (stdout, "Hostkey generation progress: [");
1108 /* Set up a task to end testing if peer start fails */
1110 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
1111 "didn't generate all hostkeys within a reasonable amount of time!!!");
1113 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1114 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left / 2,
1115 peers_left, timeout, &hostkey_callback,
1116 NULL, &peers_started_callback, NULL,
1117 &topology_callback, NULL, NULL);
1125 char *config_file_name;
1127 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1128 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1132 char *const argv[] = { binary_name,
1140 struct GNUNET_GETOPT_CommandLineOption options[] = {
1141 GNUNET_GETOPT_OPTION_END
1144 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1145 binary_name, "nohelp", options, &run, &ok);
1146 if (ret != GNUNET_OK)
1148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1149 "`test-testing-topology-%s': Failed with error code %d\n",
1150 topology_string, ret);
1152 GNUNET_free (binary_name);
1153 GNUNET_free (config_file_name);
1158 main (int argc, char *argv[])
1161 char *binary_start_pos;
1162 char *our_binary_name;
1164 binary_start_pos = rindex (argv[0], '/');
1165 GNUNET_assert (binary_start_pos != NULL);
1166 topology_string = strstr (binary_start_pos, "_topology");
1167 GNUNET_assert (topology_string != NULL);
1169 topology_string = strstr (topology_string, "_");
1170 GNUNET_assert (topology_string != NULL);
1173 GNUNET_asprintf (&our_binary_name, "test-testing-large-topology_%s",
1175 GNUNET_asprintf (&dotOutFileName, "large_topology_%s.dot", topology_string);
1177 GNUNET_log_setup (our_binary_name,
1187 * Need to remove base directory, subdirectories taken care
1188 * of by the testing framework.
1190 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1192 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1193 "Failed to remove testing directory %s\n", test_directory);
1195 GNUNET_free (our_binary_name);
1199 /* end of test_testing_topology.c */