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 static unsigned long long num_peers;
45 static unsigned int topology_connections;
47 static unsigned int total_connections;
49 static unsigned int failed_connections;
51 static unsigned int total_server_connections;
53 static unsigned int total_messages_received;
55 static unsigned int expected_messages;
57 static unsigned int expected_connections;
59 static unsigned long long peers_left;
61 static struct GNUNET_TESTING_PeerGroup *pg;
63 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
65 GNUNET_SCHEDULER_TaskIdentifier die_task;
67 static char *dotOutFileName;
69 static struct GNUNET_TIME_Relative settle_time;
71 static FILE *dotOutFile;
73 static char *topology_string;
75 static char *blacklist_transports;
77 static int transmit_ready_scheduled;
79 static int transmit_ready_failed;
81 static int transmit_ready_called;
83 struct GNUNET_TIME_Relative test_timeout;
85 struct GNUNET_TIME_Relative timeout;
87 static unsigned int modnum;
89 static unsigned int dotnum;
91 static enum GNUNET_TESTING_Topology topology;
93 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
95 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
97 static enum GNUNET_TESTING_TopologyOption connect_topology_option =
98 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
100 static double connect_topology_option_modifier = 0.0;
102 static char *test_directory;
106 struct GNUNET_TestMessage
109 * Header of the message
111 struct GNUNET_MessageHeader header;
114 * Unique identifier for this message.
119 struct TestMessageContext
121 /* This is a linked list */
122 struct TestMessageContext *next;
124 /* Handle to the sending peer core */
125 struct GNUNET_CORE_Handle *peer1handle;
127 /* Handle to the receiving peer core */
128 struct GNUNET_CORE_Handle *peer2handle;
130 /* Handle to the sending peer daemon */
131 struct GNUNET_TESTING_Daemon *peer1;
133 /* Handle to the receiving peer daemon */
134 struct GNUNET_TESTING_Daemon *peer2;
136 /* Identifier for this message, so we don't disconnect other peers! */
139 /* Has peer1 been notified already of a connection to peer2? */
142 /* Has the core of peer2 been connected already? */
145 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
146 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
150 static struct TestMessageContext *test_messages;
153 * Check whether peers successfully shut down.
156 shutdown_callback (void *cls, const char *emsg)
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "All peers successfully shut down!\n");
175 #if DELAY_FOR_LOGGING
180 char *connect_number;
181 struct GNUNET_OS_Process *mem_process;
182 GNUNET_asprintf (&peer_number, "%llu", num_peers);
183 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
184 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
185 "memsize.pl", "totals.txt",
186 peer_number, connect_number, NULL);
187 GNUNET_OS_process_wait (mem_process);
188 GNUNET_OS_process_close (mem_process);
197 GNUNET_assert (pg != NULL);
198 struct TestMessageContext *pos;
199 struct TestMessageContext *free_pos;
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "Called finish testing, stopping daemons.\n");
208 if (pos->peer1handle != NULL)
210 GNUNET_CORE_disconnect (pos->peer1handle);
211 pos->peer1handle = NULL;
213 if (pos->peer2handle != NULL)
215 GNUNET_CORE_disconnect (pos->peer2handle);
216 pos->peer2handle = NULL;
220 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
222 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
224 GNUNET_free (free_pos);
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
229 transmit_ready_scheduled, transmit_ready_failed,
230 transmit_ready_called);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
236 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
238 if (dotOutFile != NULL)
240 fprintf (dotOutFile, "}");
249 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 struct TestMessageContext *pos = cls;
253 /* Disconnect from the respective cores */
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Disconnecting from peer 1 `%4s'\n",
257 GNUNET_i2s (&pos->peer1->id));
259 if (pos->peer1handle != NULL)
260 GNUNET_CORE_disconnect (pos->peer1handle);
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "Disconnecting from peer 2 `%4s'\n",
264 GNUNET_i2s (&pos->peer2->id));
266 if (pos->peer2handle != NULL)
267 GNUNET_CORE_disconnect (pos->peer2handle);
268 /* Set handles to NULL so test case can be ended properly */
269 pos->peer1handle = NULL;
270 pos->peer2handle = NULL;
271 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
272 /* Decrement total connections so new can be established */
273 total_server_connections -= 2;
278 topology_cb (void *cls,
279 const struct GNUNET_PeerIdentity *first,
280 const struct GNUNET_PeerIdentity *second, const char *emsg)
287 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
288 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
290 topology_connections++;
295 "Finished iterating over topology, %d total connections!\n",
296 topology_connections);
299 fprintf (outfile, "}\n");
301 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
307 process_mtype (void *cls,
308 const struct GNUNET_PeerIdentity *peer,
309 const struct GNUNET_MessageHeader *message,
310 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
312 char *dotOutFileNameFinished;
313 FILE *dotOutFileFinished;
314 struct TestMessageContext *pos = cls;
315 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
316 if (pos->uid != ntohl (msg->uid))
320 if ((total_messages_received) % modnum == 0)
322 if (total_messages_received == 0)
323 fprintf (stdout, "0%%");
325 fprintf (stdout, "%d%%",
326 (int) (((float) total_messages_received /
327 expected_messages) * 100));
330 else if (total_messages_received % dotnum == 0)
332 fprintf (stdout, ".");
337 total_messages_received++;
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
342 ntohs (message->type));
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Total messages received %d, expected %d.\n",
345 total_messages_received, expected_messages);
348 if (total_messages_received == expected_messages)
351 fprintf (stdout, "100%%]\n");
353 GNUNET_SCHEDULER_cancel (die_task);
354 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
355 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
356 GNUNET_free (dotOutFileNameFinished);
357 if (dotOutFileFinished != NULL)
359 fprintf (dotOutFileFinished, "strict graph G {\n");
361 topology_connections = 0;
362 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
363 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
367 pos->disconnect_task =
368 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
375 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
378 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
379 "End badly was called (%s)... stopping daemons.\n", msg);
380 struct TestMessageContext *pos;
381 struct TestMessageContext *free_pos;
386 if (pos->peer1handle != NULL)
388 GNUNET_CORE_disconnect (pos->peer1handle);
389 pos->peer1handle = NULL;
391 if (pos->peer2handle != NULL)
393 GNUNET_CORE_disconnect (pos->peer2handle);
394 pos->peer2handle = NULL;
398 GNUNET_free (free_pos);
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
404 transmit_ready_scheduled, transmit_ready_failed,
405 transmit_ready_called);
406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407 "Total messages received %d, expected %d.\n",
408 total_messages_received, expected_messages);
413 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
414 ok = 7331; /* Opposite of leet */
417 ok = 401; /* Never got peers started */
419 if (dotOutFile != NULL)
421 fprintf (dotOutFile, "}");
427 transmit_ready (void *cls, size_t size, void *buf)
429 struct GNUNET_TestMessage *m;
430 struct TestMessageContext *pos = cls;
432 GNUNET_assert (buf != NULL);
433 m = (struct GNUNET_TestMessage *) buf;
434 m->header.type = htons (MTYPE);
435 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
436 m->uid = htonl (pos->uid);
437 transmit_ready_called++;
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
441 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
442 transmit_ready_called);
444 return sizeof (struct GNUNET_TestMessage);
448 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
452 static struct GNUNET_CORE_MessageHandler handlers[] = {
453 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
458 init_notify_peer2 (void *cls,
459 struct GNUNET_CORE_Handle *server,
460 const struct GNUNET_PeerIdentity *my_identity,
461 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
464 struct TestMessageContext *pos = cls;
466 total_server_connections++;
468 pos->peer2connected = GNUNET_YES;
469 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
474 GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey));
476 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
482 &transmit_ready, pos))
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
486 GNUNET_i2s (&pos->peer2->id));
487 transmit_ready_failed++;
491 transmit_ready_scheduled++;
497 * Method called whenever a given peer connects.
500 * @param peer peer identity this notification is about
501 * @param atsi performance data for the connection
503 static void connect_notify_peers (void *cls,
505 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), GNUNET_h2s(&pos->peer1->id.hashPubKey));
529 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
535 &transmit_ready, pos))
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
539 GNUNET_i2s (&pos->peer2->id));
540 transmit_ready_failed++;
544 transmit_ready_scheduled++;
550 init_notify_peer1 (void *cls,
551 struct GNUNET_CORE_Handle *server,
552 const struct GNUNET_PeerIdentity *my_identity,
553 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
556 struct TestMessageContext *pos = cls;
557 total_server_connections++;
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 "Core connection to `%4s' established, setting up handles\n",
562 GNUNET_i2s (my_identity));
566 * Connect to the receiving peer
568 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
575 GNUNET_YES, NULL, GNUNET_YES,
582 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
584 struct TestMessageContext *pos = cls;
586 if ((pos == test_messages) && (settle_time.rel_value > 0))
588 topology_connections = 0;
589 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
591 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
594 if (die_task == GNUNET_SCHEDULER_NO_TASK)
596 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
598 "from send test messages (timeout)");
601 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
603 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
604 (GNUNET_TIME_UNIT_SECONDS, 1),
605 &send_test_messages, pos);
606 return; /* Otherwise we'll double schedule messages here! */
610 * Connect to the sending peer
612 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
616 &connect_notify_peers, NULL,
619 GNUNET_NO, NULL, GNUNET_NO,
622 GNUNET_assert (pos->peer1handle != NULL);
624 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
626 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
630 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
631 (GNUNET_TIME_UNIT_SECONDS, 1),
632 &send_test_messages, pos->next);
638 topology_callback (void *cls,
639 const struct GNUNET_PeerIdentity *first,
640 const struct GNUNET_PeerIdentity *second,
642 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
643 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
644 struct GNUNET_TESTING_Daemon *first_daemon,
645 struct GNUNET_TESTING_Daemon *second_daemon,
648 struct TestMessageContext *temp_context;
652 if ((total_connections) % modnum == 0)
654 if (total_connections == 0)
655 fprintf (stdout, "0%%");
657 fprintf (stdout, "%d%%",
658 (int) (((float) total_connections /
659 expected_connections) * 100));
662 else if (total_connections % dotnum == 0)
664 fprintf (stdout, ".");
670 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
671 first_daemon->shortname, second_daemon->shortname);
673 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
674 temp_context->peer1 = first_daemon;
675 temp_context->peer2 = second_daemon;
676 temp_context->next = test_messages;
677 temp_context->uid = total_connections;
678 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
679 test_messages = temp_context;
682 if (dotOutFile != NULL)
683 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
684 second_daemon->shortname);
689 failed_connections++;
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "Failed to connect peer %s to peer %s with error :\n%s\n",
692 first_daemon->shortname, second_daemon->shortname, emsg);
696 if (total_connections == expected_connections)
699 fprintf (stdout, "100%%]\n");
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "Created %d total connections, which is our target number! Calling send messages.\n",
706 modnum = expected_messages / 4;
707 dotnum = (expected_messages / 50) + 1;
708 GNUNET_SCHEDULER_cancel (die_task);
709 die_task = GNUNET_SCHEDULER_NO_TASK;
710 #if DELAY_FOR_LOGGING
711 fprintf (stdout, "Sending test messages in 10 seconds.\n");
712 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
713 (GNUNET_TIME_UNIT_SECONDS, 10),
714 &send_test_messages, test_messages);
717 if (settle_time.rel_value > 0)
719 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
721 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
725 fprintf (stdout, "Test message progress: [");
729 else if (total_connections + failed_connections == expected_connections)
731 if (failed_connections <
732 (unsigned int) (fail_percentage * total_connections))
734 GNUNET_SCHEDULER_cancel (die_task);
735 die_task = GNUNET_SCHEDULER_NO_TASK;
736 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
740 GNUNET_SCHEDULER_cancel (die_task);
742 GNUNET_SCHEDULER_add_now (&end_badly,
743 "from topology_callback (too many failed connections)");
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
751 total_connections, failed_connections, expected_connections,
752 expected_connections -
753 (unsigned int) (fail_percentage * expected_connections));
759 topology_creation_finished (void *cls, const char *emsg)
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 "All topology connections created successfully!\n");
771 expected_connections = -1;
772 if ((pg != NULL) && (peers_left == 0))
774 expected_connections =
775 GNUNET_TESTING_connect_topology (pg, connection_topology,
776 connect_topology_option,
777 connect_topology_option_modifier,
778 &topology_creation_finished, NULL);
780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "Have %d expected connections\n", expected_connections);
785 GNUNET_SCHEDULER_cancel (die_task);
786 if (expected_connections == GNUNET_SYSERR)
789 GNUNET_SCHEDULER_add_now (&end_badly,
790 "from connect topology (bad return)");
793 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
795 "from connect topology (timeout)");
796 modnum = expected_connections / 4;
797 dotnum = (expected_connections / 50) + 1;
799 fprintf (stdout, "Peer connection progress: [");
806 peers_left = num_peers; /* Reset counter */
807 if (GNUNET_TESTING_create_topology
808 (pg, topology, blacklist_topology,
809 blacklist_transports) != GNUNET_SYSERR)
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
813 "Topology set up, now starting peers!\n");
814 fprintf (stdout, "Daemon start progress [");
816 GNUNET_TESTING_daemons_continue_startup (pg);
820 GNUNET_SCHEDULER_cancel (die_task);
822 GNUNET_SCHEDULER_add_now (&end_badly,
823 "from create topology (bad return)");
825 GNUNET_SCHEDULER_cancel (die_task);
826 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
828 "from continue startup (timeout)");
833 peers_started_callback (void *cls,
834 const struct GNUNET_PeerIdentity *id,
835 const struct GNUNET_CONFIGURATION_Handle *cfg,
836 struct GNUNET_TESTING_Daemon *d, const char *emsg)
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "Failed to start daemon with error: `%s'\n", emsg);
844 GNUNET_assert (id != NULL);
846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
847 (num_peers - peers_left) + 1, num_peers);
850 if ((num_peers - peers_left) % modnum == 0)
852 if (num_peers - peers_left == 0)
853 fprintf (stdout, "0%%");
855 fprintf (stdout, "%d%%",
856 (int) (((float) (num_peers - peers_left) /
860 else if ((num_peers - peers_left) % dotnum == 0)
862 fprintf (stdout, ".");
870 fprintf (stdout, "100%%]\n");
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
874 "All %d daemons started, now connecting peers!\n",
877 GNUNET_SCHEDULER_cancel (die_task);
878 /* Set up task in case topology creation doesn't finish
879 * within a reasonable amount of time */
880 die_task = GNUNET_SCHEDULER_add_delayed (timeout,
882 "from peers_started_callback");
883 #if DELAY_FOR_LOGGING
884 fprintf (stdout, "Connecting topology in 10 seconds\n");
886 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
887 (GNUNET_TIME_UNIT_SECONDS, 10),
888 &connect_topology, NULL);
897 * Callback indicating that the hostkey was created for a peer.
900 * @param id the peer identity
901 * @param d the daemon handle (pretty useless at this point, remove?)
902 * @param emsg non-null on failure
905 hostkey_callback (void *cls,
906 const struct GNUNET_PeerIdentity *id,
907 struct GNUNET_TESTING_Daemon *d, const char *emsg)
911 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
912 "Hostkey callback received error: %s\n", emsg);
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "Hostkey (%d/%d) created for peer `%s'\n",
918 num_peers - peers_left, num_peers, GNUNET_i2s (id));
922 if ((num_peers - peers_left) % modnum == 0)
924 if (num_peers - peers_left == 0)
925 fprintf (stdout, "0%%");
927 fprintf (stdout, "%d%%",
928 (int) (((float) (num_peers - peers_left) /
932 else if ((num_peers - peers_left) % dotnum == 0)
934 fprintf (stdout, ".");
942 fprintf (stdout, "100%%]\n");
943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
944 "All %d hostkeys created, now creating topology!\n",
947 GNUNET_SCHEDULER_cancel (die_task);
948 /* Set up task in case topology creation doesn't finish
949 * within a reasonable amount of time */
950 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
952 "from create_topology");
953 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
961 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
964 char *connect_topology_str;
965 char *blacklist_topology_str;
966 char *connect_topology_option_str;
967 char *connect_topology_option_modifier_string;
968 unsigned long long temp_settle;
971 dotOutFile = fopen (dotOutFileName, "w");
972 if (dotOutFile != NULL)
974 fprintf (dotOutFile, "strict graph G {\n");
978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
979 "Starting daemons based on config file %s\n", cfgfile);
983 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
991 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
993 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
996 "Invalid topology `%s' given for section %s option %s\n",
997 topology_str, "TESTING", "TOPOLOGY");
998 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1002 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1004 &connect_topology_str))
1006 GNUNET_TESTING_topology_get (&connection_topology,
1007 connect_topology_str)))
1009 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1010 "Invalid connect topology `%s' given for section %s option %s\n",
1011 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1013 GNUNET_free_non_null (connect_topology_str);
1015 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1016 "connect_topology_option",
1017 &connect_topology_option_str))
1019 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1020 connect_topology_option_str)))
1022 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1023 "Invalid connect topology option `%s' given for section %s option %s\n",
1024 connect_topology_option_str, "TESTING",
1025 "CONNECT_TOPOLOGY_OPTION");
1026 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1028 GNUNET_free_non_null (connect_topology_option_str);
1030 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1031 "connect_topology_option_modifier",
1032 &connect_topology_option_modifier_string))
1035 (connect_topology_option_modifier_string, "%lf",
1036 &connect_topology_option_modifier) != 1)
1038 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1040 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1041 connect_topology_option_modifier_string,
1042 "connect_topology_option_modifier", "TESTING");
1044 GNUNET_free (connect_topology_option_modifier_string);
1048 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1049 "blacklist_transports",
1050 &blacklist_transports))
1051 blacklist_transports = NULL;
1054 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1055 "blacklist_topology",
1056 &blacklist_topology_str))
1058 GNUNET_TESTING_topology_get (&blacklist_topology,
1059 blacklist_topology_str)))
1061 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1062 "Invalid topology `%s' given for section %s option %s\n",
1063 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1065 GNUNET_free_non_null (topology_str);
1066 GNUNET_free_non_null (blacklist_topology_str);
1069 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1072 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1074 if (GNUNET_SYSERR ==
1075 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1077 num_peers = DEFAULT_NUM_PEERS;
1081 peers_left = num_peers;
1084 * How long until we fail the whole testcase?
1086 test_timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers * 2);
1089 * How long until we give up on starting the peers?
1091 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START), num_peers);
1093 modnum = num_peers / 4;
1094 dotnum = (num_peers / 50) + 1;
1096 fprintf (stdout, "Hostkey generation progress: [");
1098 /* Set up a task to end testing if peer start fails */
1100 GNUNET_SCHEDULER_add_delayed (timeout,
1102 "didn't generate all hostkeys within a reasonable amount of time!!!");
1104 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1105 pg = GNUNET_TESTING_daemons_start (cfg,
1108 &hostkey_callback, NULL,
1109 &peers_started_callback, NULL,
1110 &topology_callback, NULL, NULL);
1118 char *config_file_name;
1119 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1120 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1123 char *const argv[] = { binary_name,
1131 struct GNUNET_GETOPT_CommandLineOption options[] = {
1132 GNUNET_GETOPT_OPTION_END
1134 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1135 argv, binary_name, "nohelp", options, &run, &ok);
1136 if (ret != GNUNET_OK)
1138 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1139 "`test-testing-topology-%s': Failed with error code %d\n",
1140 topology_string, ret);
1142 GNUNET_free (binary_name);
1143 GNUNET_free (config_file_name);
1148 main (int argc, char *argv[])
1151 char *binary_start_pos;
1152 char *our_binary_name;
1154 binary_start_pos = rindex (argv[0], '/');
1155 GNUNET_assert (binary_start_pos != NULL);
1156 topology_string = strstr (binary_start_pos, "_topology");
1157 GNUNET_assert (topology_string != NULL);
1159 topology_string = strstr (topology_string, "_");
1160 GNUNET_assert (topology_string != NULL);
1163 GNUNET_asprintf (&our_binary_name, "test-testing-large-topology_%s",
1165 GNUNET_asprintf (&dotOutFileName, "large_topology_%s.dot", topology_string);
1167 GNUNET_log_setup (our_binary_name,
1177 * Need to remove base directory, subdirectories taken care
1178 * of by the testing framework.
1180 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1182 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1183 "Failed to remove testing directory %s\n", test_directory);
1185 GNUNET_free (our_binary_name);
1189 /* end of test_testing_topology.c */