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);
188 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
189 "memsize.pl", "totals.txt",
190 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,
261 "Disconnecting from peer 1 `%4s'\n",
262 GNUNET_i2s (&pos->peer1->id));
264 if (pos->peer1handle != NULL)
265 GNUNET_CORE_disconnect (pos->peer1handle);
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Disconnecting from peer 2 `%4s'\n",
269 GNUNET_i2s (&pos->peer2->id));
271 if (pos->peer2handle != NULL)
272 GNUNET_CORE_disconnect (pos->peer2handle);
273 /* Set handles to NULL so test case can be ended properly */
274 pos->peer1handle = NULL;
275 pos->peer2handle = NULL;
276 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
277 /* Decrement total connections so new can be established */
278 total_server_connections -= 2;
283 topology_cb (void *cls,
284 const struct GNUNET_PeerIdentity *first,
285 const struct GNUNET_PeerIdentity *second, const char *emsg)
293 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
294 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
296 topology_connections++;
301 "Finished iterating over topology, %d total connections!\n",
302 topology_connections);
305 fprintf (outfile, "}\n");
307 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
313 process_mtype (void *cls,
314 const struct GNUNET_PeerIdentity *peer,
315 const struct GNUNET_MessageHeader *message,
316 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
318 char *dotOutFileNameFinished;
319 FILE *dotOutFileFinished;
320 struct TestMessageContext *pos = cls;
321 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
323 if (pos->uid != ntohl (msg->uid))
327 if ((total_messages_received) % modnum == 0)
329 if (total_messages_received == 0)
330 fprintf (stdout, "0%%");
332 fprintf (stdout, "%d%%",
333 (int) (((float) total_messages_received /
334 expected_messages) * 100));
337 else if (total_messages_received % dotnum == 0)
339 fprintf (stdout, ".");
344 total_messages_received++;
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
349 ntohs (message->type));
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 "Total messages received %d, expected %d.\n",
352 total_messages_received, expected_messages);
355 if (total_messages_received == expected_messages)
358 fprintf (stdout, "100%%]\n");
360 GNUNET_SCHEDULER_cancel (die_task);
361 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
362 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
363 GNUNET_free (dotOutFileNameFinished);
364 if (dotOutFileFinished != NULL)
366 fprintf (dotOutFileFinished, "strict graph G {\n");
368 topology_connections = 0;
369 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
370 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
374 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
381 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
386 "End badly was called (%s)... stopping daemons.\n", msg);
387 struct TestMessageContext *pos;
388 struct TestMessageContext *free_pos;
393 if (pos->peer1handle != NULL)
395 GNUNET_CORE_disconnect (pos->peer1handle);
396 pos->peer1handle = NULL;
398 if (pos->peer2handle != NULL)
400 GNUNET_CORE_disconnect (pos->peer2handle);
401 pos->peer2handle = NULL;
405 GNUNET_free (free_pos);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
411 transmit_ready_scheduled, transmit_ready_failed,
412 transmit_ready_called);
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Total messages received %d, expected %d.\n",
415 total_messages_received, expected_messages);
420 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
421 ok = 7331; /* Opposite of leet */
424 ok = 401; /* Never got peers started */
426 if (dotOutFile != NULL)
428 fprintf (dotOutFile, "}");
434 transmit_ready (void *cls, size_t size, void *buf)
436 struct GNUNET_TestMessage *m;
437 struct TestMessageContext *pos = cls;
439 GNUNET_assert (buf != NULL);
440 m = (struct GNUNET_TestMessage *) buf;
441 m->header.type = htons (MTYPE);
442 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
443 m->uid = htonl (pos->uid);
444 transmit_ready_called++;
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
448 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
449 transmit_ready_called);
451 return sizeof (struct GNUNET_TestMessage);
455 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
459 static struct GNUNET_CORE_MessageHandler handlers[] = {
460 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
465 init_notify_peer2 (void *cls,
466 struct GNUNET_CORE_Handle *server,
467 const struct GNUNET_PeerIdentity *my_identity,
468 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
471 struct TestMessageContext *pos = cls;
473 total_server_connections++;
475 pos->peer2connected = GNUNET_YES;
476 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
480 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
481 GNUNET_i2s (my_identity),
482 GNUNET_h2s (&pos->peer1->id.hashPubKey));
484 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
490 &transmit_ready, pos))
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
494 GNUNET_i2s (&pos->peer2->id));
495 transmit_ready_failed++;
499 transmit_ready_scheduled++;
505 * Method called whenever a given peer connects.
508 * @param peer peer identity this notification is about
509 * @param atsi performance data for the connection
512 connect_notify_peers (void *cls,
514 GNUNET_PeerIdentity *peer,
515 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
517 struct TestMessageContext *pos = cls;
519 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
521 pos->peer1notified = GNUNET_YES;
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
524 "Peer `%s' notified of connection to peer `%s'\n",
525 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
531 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
535 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
536 GNUNET_i2s (&pos->peer2->id),
537 GNUNET_h2s (&pos->peer1->id.hashPubKey));
539 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
545 &transmit_ready, pos))
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
549 GNUNET_i2s (&pos->peer2->id));
550 transmit_ready_failed++;
554 transmit_ready_scheduled++;
560 init_notify_peer1 (void *cls,
561 struct GNUNET_CORE_Handle *server,
562 const struct GNUNET_PeerIdentity *my_identity,
563 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
566 struct TestMessageContext *pos = cls;
568 total_server_connections++;
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Core connection to `%4s' established, setting up handles\n",
573 GNUNET_i2s (my_identity));
577 * Connect to the receiving peer
579 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
586 GNUNET_YES, NULL, GNUNET_YES,
593 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
595 struct TestMessageContext *pos = cls;
597 if ((pos == test_messages) && (settle_time.rel_value > 0))
599 topology_connections = 0;
600 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
602 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
605 if (die_task == GNUNET_SCHEDULER_NO_TASK)
607 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
609 "from send test messages (timeout)");
612 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
614 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
615 (GNUNET_TIME_UNIT_SECONDS, 1),
616 &send_test_messages, pos);
617 return; /* Otherwise we'll double schedule messages here! */
621 * Connect to the sending peer
623 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
627 &connect_notify_peers, NULL,
630 GNUNET_NO, NULL, GNUNET_NO,
633 GNUNET_assert (pos->peer1handle != NULL);
635 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
637 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
641 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
642 (GNUNET_TIME_UNIT_SECONDS, 1),
643 &send_test_messages, pos->next);
649 topology_callback (void *cls,
650 const struct GNUNET_PeerIdentity *first,
651 const struct GNUNET_PeerIdentity *second,
653 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
654 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
655 struct GNUNET_TESTING_Daemon *first_daemon,
656 struct GNUNET_TESTING_Daemon *second_daemon,
659 struct TestMessageContext *temp_context;
664 if ((total_connections) % modnum == 0)
666 if (total_connections == 0)
667 fprintf (stdout, "0%%");
669 fprintf (stdout, "%d%%",
670 (int) (((float) total_connections /
671 expected_connections) * 100));
674 else if (total_connections % dotnum == 0)
676 fprintf (stdout, ".");
682 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
683 first_daemon->shortname, second_daemon->shortname);
685 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
686 temp_context->peer1 = first_daemon;
687 temp_context->peer2 = second_daemon;
688 temp_context->next = test_messages;
689 temp_context->uid = total_connections;
690 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
691 test_messages = temp_context;
694 if (dotOutFile != NULL)
695 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
696 second_daemon->shortname);
701 failed_connections++;
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "Failed to connect peer %s to peer %s with error :\n%s\n",
704 first_daemon->shortname, second_daemon->shortname, emsg);
708 if (total_connections == expected_connections)
711 fprintf (stdout, "100%%]\n");
714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Created %d total connections, which is our target number! Calling send messages.\n",
718 modnum = expected_messages / 4;
719 dotnum = (expected_messages / 50) + 1;
720 GNUNET_SCHEDULER_cancel (die_task);
721 die_task = GNUNET_SCHEDULER_NO_TASK;
722 #if DELAY_FOR_LOGGING
723 fprintf (stdout, "Sending test messages in 10 seconds.\n");
724 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
725 (GNUNET_TIME_UNIT_SECONDS, 10),
726 &send_test_messages, test_messages);
729 if (settle_time.rel_value > 0)
731 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
733 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
737 fprintf (stdout, "Test message progress: [");
741 else if (total_connections + failed_connections == expected_connections)
743 if (failed_connections <
744 (unsigned int) (fail_percentage * total_connections))
746 GNUNET_SCHEDULER_cancel (die_task);
747 die_task = GNUNET_SCHEDULER_NO_TASK;
748 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
752 GNUNET_SCHEDULER_cancel (die_task);
754 GNUNET_SCHEDULER_add_now (&end_badly,
755 "from topology_callback (too many failed connections)");
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
763 total_connections, failed_connections, expected_connections,
764 expected_connections -
765 (unsigned int) (fail_percentage * expected_connections));
771 topology_creation_finished (void *cls, const char *emsg)
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
776 "All topology connections created successfully!\n");
783 expected_connections = -1;
784 if ((pg != NULL) && (peers_left == 0))
786 expected_connections =
787 GNUNET_TESTING_connect_topology (pg, connection_topology,
788 connect_topology_option,
789 connect_topology_option_modifier,
792 &topology_creation_finished, NULL);
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "Have %d expected connections\n", expected_connections);
799 GNUNET_SCHEDULER_cancel (die_task);
800 if (expected_connections == GNUNET_SYSERR)
803 GNUNET_SCHEDULER_add_now (&end_badly,
804 "from connect topology (bad return)");
807 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
809 "from connect topology (timeout)");
810 modnum = expected_connections / 4;
811 dotnum = (expected_connections / 50) + 1;
813 fprintf (stdout, "Peer connection progress: [");
820 peers_left = num_peers; /* Reset counter */
821 if (GNUNET_TESTING_create_topology
822 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
826 "Topology set up, now starting peers!\n");
827 fprintf (stdout, "Daemon start progress [");
829 GNUNET_TESTING_daemons_continue_startup (pg);
833 GNUNET_SCHEDULER_cancel (die_task);
835 GNUNET_SCHEDULER_add_now (&end_badly,
836 "from create topology (bad return)");
838 GNUNET_SCHEDULER_cancel (die_task);
839 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
841 "from continue startup (timeout)");
846 peers_started_callback (void *cls,
847 const struct GNUNET_PeerIdentity *id,
848 const struct GNUNET_CONFIGURATION_Handle *cfg,
849 struct GNUNET_TESTING_Daemon *d, const char *emsg)
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Failed to start daemon with error: `%s'\n", emsg);
857 GNUNET_assert (id != NULL);
859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
860 (num_peers - peers_left) + 1, num_peers);
863 if ((num_peers - peers_left) % modnum == 0)
865 if (num_peers - peers_left == 0)
866 fprintf (stdout, "0%%");
868 fprintf (stdout, "%d%%",
869 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
872 else if ((num_peers - peers_left) % dotnum == 0)
874 fprintf (stdout, ".");
882 fprintf (stdout, "100%%]\n");
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
886 "All %d daemons started, now connecting peers!\n", num_peers);
888 GNUNET_SCHEDULER_cancel (die_task);
889 /* Set up task in case topology creation doesn't finish
890 * within a reasonable amount of time */
891 die_task = GNUNET_SCHEDULER_add_delayed (timeout,
893 "from peers_started_callback");
894 #if DELAY_FOR_LOGGING
895 fprintf (stdout, "Connecting topology in 10 seconds\n");
897 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
898 (GNUNET_TIME_UNIT_SECONDS, 10),
899 &connect_topology, NULL);
908 * Callback indicating that the hostkey was created for a peer.
911 * @param id the peer identity
912 * @param d the daemon handle (pretty useless at this point, remove?)
913 * @param emsg non-null on failure
916 hostkey_callback (void *cls,
917 const struct GNUNET_PeerIdentity *id,
918 struct GNUNET_TESTING_Daemon *d, const char *emsg)
922 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
923 "Hostkey callback received error: %s\n", emsg);
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
928 "Hostkey (%d/%d) created for peer `%s'\n",
929 num_peers - peers_left, num_peers, GNUNET_i2s (id));
933 if ((num_peers - peers_left) % modnum == 0)
935 if (num_peers - peers_left == 0)
936 fprintf (stdout, "0%%");
938 fprintf (stdout, "%d%%",
939 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
942 else if ((num_peers - peers_left) % dotnum == 0)
944 fprintf (stdout, ".");
952 fprintf (stdout, "100%%]\n");
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
954 "All %d hostkeys created, now creating topology!\n", num_peers);
956 GNUNET_SCHEDULER_cancel (die_task);
957 /* Set up task in case topology creation doesn't finish
958 * within a reasonable amount of time */
959 die_task = GNUNET_SCHEDULER_add_delayed (test_timeout,
961 "from create_topology");
962 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
970 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
973 char *connect_topology_str;
974 char *blacklist_topology_str;
975 char *connect_topology_option_str;
976 char *connect_topology_option_modifier_string;
977 unsigned long long temp_settle;
981 dotOutFile = fopen (dotOutFileName, "w");
982 if (dotOutFile != NULL)
984 fprintf (dotOutFile, "strict graph G {\n");
988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
989 "Starting daemons based on config file %s\n", cfgfile);
993 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1001 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1003 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1005 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1006 "Invalid topology `%s' given for section %s option %s\n",
1007 topology_str, "TESTING", "TOPOLOGY");
1008 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1012 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1014 &connect_topology_str))
1016 GNUNET_TESTING_topology_get (&connection_topology,
1017 connect_topology_str)))
1019 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1020 "Invalid connect topology `%s' given for section %s option %s\n",
1021 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1023 GNUNET_free_non_null (connect_topology_str);
1025 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1026 "connect_topology_option",
1027 &connect_topology_option_str))
1029 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1030 connect_topology_option_str)))
1032 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1033 "Invalid connect topology option `%s' given for section %s option %s\n",
1034 connect_topology_option_str, "TESTING",
1035 "CONNECT_TOPOLOGY_OPTION");
1036 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1038 GNUNET_free_non_null (connect_topology_option_str);
1040 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1041 "connect_topology_option_modifier",
1042 &connect_topology_option_modifier_string))
1045 (connect_topology_option_modifier_string, "%lf",
1046 &connect_topology_option_modifier) != 1)
1048 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1050 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1051 connect_topology_option_modifier_string,
1052 "connect_topology_option_modifier", "TESTING");
1054 GNUNET_free (connect_topology_option_modifier_string);
1058 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1059 "blacklist_transports",
1060 &blacklist_transports))
1061 blacklist_transports = NULL;
1064 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1065 "blacklist_topology",
1066 &blacklist_topology_str))
1068 GNUNET_TESTING_topology_get (&blacklist_topology,
1069 blacklist_topology_str)))
1071 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1072 "Invalid topology `%s' given for section %s option %s\n",
1073 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1075 GNUNET_free_non_null (topology_str);
1076 GNUNET_free_non_null (blacklist_topology_str);
1079 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1082 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1084 if (GNUNET_SYSERR ==
1085 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1087 num_peers = DEFAULT_NUM_PEERS;
1090 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1093 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1097 "testing", "connect_timeout");
1103 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1107 "testing", "connect_attempts");
1113 peers_left = num_peers;
1116 * How long until we fail the whole testcase?
1119 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1120 (GNUNET_TIME_UNIT_SECONDS,
1121 SECONDS_PER_PEER_START), num_peers * 2);
1124 * How long until we give up on starting the peers?
1127 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1128 (GNUNET_TIME_UNIT_SECONDS,
1129 SECONDS_PER_PEER_START), num_peers);
1131 modnum = num_peers / 4;
1132 dotnum = (num_peers / 50) + 1;
1134 fprintf (stdout, "Hostkey generation progress: [");
1136 /* Set up a task to end testing if peer start fails */
1138 GNUNET_SCHEDULER_add_delayed (timeout,
1140 "didn't generate all hostkeys within a reasonable amount of time!!!");
1142 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1143 pg = GNUNET_TESTING_daemons_start (cfg,
1148 &hostkey_callback, NULL,
1149 &peers_started_callback, NULL,
1150 &topology_callback, NULL, NULL);
1158 char *config_file_name;
1160 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1161 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1165 char *const argv[] = { binary_name,
1173 struct GNUNET_GETOPT_CommandLineOption options[] = {
1174 GNUNET_GETOPT_OPTION_END
1176 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1177 argv, binary_name, "nohelp", options, &run, &ok);
1178 if (ret != GNUNET_OK)
1180 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1181 "`test-testing-topology-%s': Failed with error code %d\n",
1182 topology_string, ret);
1184 GNUNET_free (binary_name);
1185 GNUNET_free (config_file_name);
1190 main (int argc, char *argv[])
1193 char *binary_start_pos;
1194 char *our_binary_name;
1196 binary_start_pos = rindex (argv[0], '/');
1197 GNUNET_assert (binary_start_pos != NULL);
1198 topology_string = strstr (binary_start_pos, "_topology");
1199 GNUNET_assert (topology_string != NULL);
1201 topology_string = strstr (topology_string, "_");
1202 GNUNET_assert (topology_string != NULL);
1205 GNUNET_asprintf (&our_binary_name, "test-testing-large-topology_%s",
1207 GNUNET_asprintf (&dotOutFileName, "large_topology_%s.dot", topology_string);
1209 GNUNET_log_setup (our_binary_name,
1219 * Need to remove base directory, subdirectories taken care
1220 * of by the testing framework.
1222 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1225 "Failed to remove testing directory %s\n", test_directory);
1227 GNUNET_free (our_binary_name);
1231 /* end of test_testing_topology.c */