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_NO
31 #define PROGRESS_BARS GNUNET_YES
33 #define DELAY_FOR_LOGGING GNUNET_NO
36 * How long until we fail the whole testcase?
38 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 240)
41 * How long until we give up on starting the peers?
43 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 500)
45 #define SECONDS_PER_PEER_START 120
47 #define DEFAULT_NUM_PEERS 4
49 #define MAX_OUTSTANDING_CONNECTIONS 100
51 static float fail_percentage = 0.05;
55 static unsigned long long num_peers;
57 struct GNUNET_TIME_Relative connect_timeout;
59 static unsigned long long connect_attempts;
61 static unsigned int topology_connections;
63 static unsigned int total_connections;
65 static unsigned int failed_connections;
67 static unsigned int total_server_connections;
69 static unsigned int total_messages_received;
71 static unsigned int expected_messages;
73 static unsigned int expected_connections;
75 static unsigned long long peers_left;
77 static struct GNUNET_TESTING_PeerGroup *pg;
79 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
81 GNUNET_SCHEDULER_TaskIdentifier die_task;
83 static char *dotOutFileName;
85 static struct GNUNET_TIME_Relative settle_time;
87 static FILE *dotOutFile;
89 static char *topology_string;
91 static char *blacklist_transports;
93 static int transmit_ready_scheduled;
95 static int transmit_ready_failed;
97 static int transmit_ready_called;
99 static unsigned int modnum;
101 static unsigned int dotnum;
103 static enum GNUNET_TESTING_Topology topology;
105 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
107 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
109 static enum GNUNET_TESTING_TopologyOption connect_topology_option =
110 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
112 static double connect_topology_option_modifier = 0.0;
114 static char *test_directory;
118 struct GNUNET_TestMessage
121 * Header of the message
123 struct GNUNET_MessageHeader header;
126 * Unique identifier for this message.
131 struct TestMessageContext
133 /* This is a linked list */
134 struct TestMessageContext *next;
136 /* Handle to the sending peer core */
137 struct GNUNET_CORE_Handle *peer1handle;
139 /* Handle to the receiving peer core */
140 struct GNUNET_CORE_Handle *peer2handle;
142 /* Handle to the sending peer daemon */
143 struct GNUNET_TESTING_Daemon *peer1;
145 /* Handle to the receiving peer daemon */
146 struct GNUNET_TESTING_Daemon *peer2;
148 /* Identifier for this message, so we don't disconnect other peers! */
151 /* Has peer1 been notified already of a connection to peer2? */
154 /* Has the core of peer2 been connected already? */
157 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
158 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
162 static struct TestMessageContext *test_messages;
165 * Check whether peers successfully shut down.
168 shutdown_callback (void *cls, const char *emsg)
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 "All peers successfully shut down!\n");
187 #if DELAY_FOR_LOGGING
192 char *connect_number;
193 struct GNUNET_OS_Process *mem_process;
194 GNUNET_asprintf (&peer_number, "%llu", num_peers);
195 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
196 mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl",
197 "memsize.pl", "totals.txt",
198 peer_number, connect_number, NULL);
199 GNUNET_OS_process_wait (mem_process);
200 GNUNET_OS_process_close (mem_process);
209 GNUNET_assert (pg != NULL);
210 struct TestMessageContext *pos;
211 struct TestMessageContext *free_pos;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Called finish testing, stopping daemons.\n");
220 if (pos->peer1handle != NULL)
222 GNUNET_CORE_disconnect (pos->peer1handle);
223 pos->peer1handle = NULL;
225 if (pos->peer2handle != NULL)
227 GNUNET_CORE_disconnect (pos->peer2handle);
228 pos->peer2handle = NULL;
232 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
234 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
236 GNUNET_free (free_pos);
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
241 transmit_ready_scheduled, transmit_ready_failed,
242 transmit_ready_called);
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
248 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
250 if (dotOutFile != NULL)
252 fprintf (dotOutFile, "}");
261 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 struct TestMessageContext *pos = cls;
265 /* Disconnect from the respective cores */
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Disconnecting from peer 1 `%4s'\n",
269 GNUNET_i2s (&pos->peer1->id));
271 if (pos->peer1handle != NULL)
272 GNUNET_CORE_disconnect (pos->peer1handle);
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
275 "Disconnecting from peer 2 `%4s'\n",
276 GNUNET_i2s (&pos->peer2->id));
278 if (pos->peer2handle != NULL)
279 GNUNET_CORE_disconnect (pos->peer2handle);
280 /* Set handles to NULL so test case can be ended properly */
281 pos->peer1handle = NULL;
282 pos->peer2handle = NULL;
283 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
284 /* Decrement total connections so new can be established */
285 total_server_connections -= 2;
290 stats_finished (void *cls, int result)
292 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
296 * Callback function to process statistic values.
299 * @param peer the peer the statistics belong to
300 * @param subsystem name of subsystem that created the statistic
301 * @param name the name of the datum
302 * @param value the current value
303 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
304 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
307 stats_print (void *cls,
308 const struct GNUNET_PeerIdentity *peer,
309 const char *subsystem,
310 const char *name, uint64_t value, int is_persistent)
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s:%s -- %llu\n",
313 GNUNET_i2s (peer), subsystem, name, value);
319 topology_cb (void *cls,
320 const struct GNUNET_PeerIdentity *first,
321 const struct GNUNET_PeerIdentity *second, const char *emsg)
328 fprintf (outfile, "\t\"%s\" -- ", GNUNET_i2s (first));
329 fprintf (outfile, "\"%s\";\n", GNUNET_i2s (second));
331 topology_connections++;
336 "Finished iterating over topology, %d total connections!\n",
337 topology_connections);
340 fprintf (outfile, "}\n");
343 GNUNET_TESTING_get_statistics (pg, &stats_finished, &stats_print,
346 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
352 process_mtype (void *cls,
353 const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_MessageHeader *message,
355 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
357 char *dotOutFileNameFinished;
358 FILE *dotOutFileFinished;
359 struct TestMessageContext *pos = cls;
360 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
361 if (pos->uid != ntohl (msg->uid))
365 if ((total_messages_received) % modnum == 0)
367 if (total_messages_received == 0)
368 fprintf (stdout, "0%%");
370 fprintf (stdout, "%d%%",
371 (int) (((float) total_messages_received /
372 expected_messages) * 100));
375 else if (total_messages_received % dotnum == 0)
377 fprintf (stdout, ".");
382 total_messages_received++;
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
387 ntohs (message->type));
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Total messages received %d, expected %d.\n",
390 total_messages_received, expected_messages);
393 if (total_messages_received == expected_messages)
396 fprintf (stdout, "100%%]\n");
398 GNUNET_SCHEDULER_cancel (die_task);
399 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
400 dotOutFileFinished = fopen (dotOutFileNameFinished, "w");
401 GNUNET_free (dotOutFileNameFinished);
402 if (dotOutFileFinished != NULL)
404 fprintf (dotOutFileFinished, "strict graph G {\n");
406 topology_connections = 0;
407 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
408 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
412 pos->disconnect_task =
413 GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
420 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
424 "End badly was called (%s)... stopping daemons.\n", msg);
425 struct TestMessageContext *pos;
426 struct TestMessageContext *free_pos;
431 if (pos->peer1handle != NULL)
433 GNUNET_CORE_disconnect (pos->peer1handle);
434 pos->peer1handle = NULL;
436 if (pos->peer2handle != NULL)
438 GNUNET_CORE_disconnect (pos->peer2handle);
439 pos->peer2handle = NULL;
443 GNUNET_free (free_pos);
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
449 transmit_ready_scheduled, transmit_ready_failed,
450 transmit_ready_called);
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 "Total messages received %d, expected %d.\n",
453 total_messages_received, expected_messages);
458 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
459 ok = 7331; /* Opposite of leet */
462 ok = 401; /* Never got peers started */
464 if (dotOutFile != NULL)
466 fprintf (dotOutFile, "}");
472 transmit_ready (void *cls, size_t size, void *buf)
474 struct GNUNET_TestMessage *m;
475 struct TestMessageContext *pos = cls;
477 GNUNET_assert (buf != NULL);
478 m = (struct GNUNET_TestMessage *) buf;
479 m->header.type = htons (MTYPE);
480 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
481 m->uid = htonl (pos->uid);
482 transmit_ready_called++;
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
486 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
487 transmit_ready_called);
489 return sizeof (struct GNUNET_TestMessage);
493 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
497 static struct GNUNET_CORE_MessageHandler handlers[] = {
498 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
503 init_notify_peer2 (void *cls,
504 struct GNUNET_CORE_Handle *server,
505 const struct GNUNET_PeerIdentity *my_identity,
506 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
509 struct TestMessageContext *pos = cls;
511 total_server_connections++;
513 pos->peer2connected = GNUNET_YES;
514 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
519 GNUNET_i2s (my_identity), GNUNET_h2s(&pos->peer1->id.hashPubKey));
521 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
528 &transmit_ready, pos))
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
531 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
532 GNUNET_i2s (&pos->peer2->id));
533 transmit_ready_failed++;
537 transmit_ready_scheduled++;
543 * Method called whenever a given peer connects.
546 * @param peer peer identity this notification is about
547 * @param atsi performance data for the connection
549 static void connect_notify_peers (void *cls,
551 GNUNET_PeerIdentity *peer,
552 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
554 struct TestMessageContext *pos = cls;
556 if (0 == memcmp(peer, &pos->peer2->id, sizeof(struct GNUNET_PeerIdentity)))
558 pos->peer1notified = GNUNET_YES;
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 "Peer `%s' notified of connection to peer `%s'\n",
562 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s(&peer->hashPubKey));
568 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
573 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s(&pos->peer1->id.hashPubKey));
575 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
582 &transmit_ready, pos))
584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
585 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
586 GNUNET_i2s (&pos->peer2->id));
587 transmit_ready_failed++;
591 transmit_ready_scheduled++;
597 init_notify_peer1 (void *cls,
598 struct GNUNET_CORE_Handle *server,
599 const struct GNUNET_PeerIdentity *my_identity,
600 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
603 struct TestMessageContext *pos = cls;
604 total_server_connections++;
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Core connection to `%4s' established, setting up handles\n",
609 GNUNET_i2s (my_identity));
613 * Connect to the receiving peer
615 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
622 GNUNET_YES, NULL, GNUNET_YES,
629 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
631 struct TestMessageContext *pos = cls;
633 if ((pos == test_messages) && (settle_time.rel_value > 0))
635 topology_connections = 0;
636 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
638 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
641 if (die_task == GNUNET_SCHEDULER_NO_TASK)
643 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT,
645 "from send test messages (timeout)");
648 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
650 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
651 (GNUNET_TIME_UNIT_SECONDS, 1),
652 &send_test_messages, pos);
653 return; /* Otherwise we'll double schedule messages here! */
657 * Connect to the sending peer
659 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
663 &connect_notify_peers, NULL,
666 GNUNET_NO, NULL, GNUNET_NO,
669 GNUNET_assert (pos->peer1handle != NULL);
671 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
673 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
677 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
678 (GNUNET_TIME_UNIT_SECONDS, 1),
679 &send_test_messages, pos->next);
685 topology_callback (void *cls,
686 const struct GNUNET_PeerIdentity *first,
687 const struct GNUNET_PeerIdentity *second,
689 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
690 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
691 struct GNUNET_TESTING_Daemon *first_daemon,
692 struct GNUNET_TESTING_Daemon *second_daemon,
695 struct TestMessageContext *temp_context;
699 if ((total_connections) % modnum == 0)
701 if (total_connections == 0)
702 fprintf (stdout, "0%%");
704 fprintf (stdout, "%d%%",
705 (int) (((float) total_connections /
706 expected_connections) * 100));
709 else if (total_connections % dotnum == 0)
711 fprintf (stdout, ".");
717 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
718 first_daemon->shortname, second_daemon->shortname);
720 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
721 temp_context->peer1 = first_daemon;
722 temp_context->peer2 = second_daemon;
723 temp_context->next = test_messages;
724 temp_context->uid = total_connections;
725 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
726 test_messages = temp_context;
729 if (dotOutFile != NULL)
730 fprintf (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
731 second_daemon->shortname);
736 failed_connections++;
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Failed to connect peer %s to peer %s with error :\n%s\n",
739 first_daemon->shortname, second_daemon->shortname, emsg);
743 if (total_connections == expected_connections)
746 fprintf (stdout, "100%%]\n");
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Created %d total connections, which is our target number! Calling send messages.\n",
753 modnum = expected_messages / 4;
754 dotnum = (expected_messages / 50) + 1;
759 GNUNET_SCHEDULER_cancel (die_task);
760 die_task = GNUNET_SCHEDULER_NO_TASK;
761 #if DELAY_FOR_LOGGING
762 fprintf (stdout, "Sending test messages in 10 seconds.\n");
763 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
764 (GNUNET_TIME_UNIT_SECONDS, 10),
765 &send_test_messages, test_messages);
768 if (settle_time.rel_value > 0)
770 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
772 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
776 fprintf (stdout, "Test message progress: [");
780 else if (total_connections + failed_connections == expected_connections)
782 if (failed_connections <
783 (unsigned int) (fail_percentage * total_connections))
785 GNUNET_SCHEDULER_cancel (die_task);
786 die_task = GNUNET_SCHEDULER_NO_TASK;
787 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
791 GNUNET_SCHEDULER_cancel (die_task);
793 GNUNET_SCHEDULER_add_now (&end_badly,
794 "from topology_callback (too many failed connections)");
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
801 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
802 total_connections, failed_connections, expected_connections,
803 expected_connections -
804 (unsigned int) (fail_percentage * expected_connections));
810 topology_creation_finished (void *cls, const char *emsg)
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 "All topology connections created successfully!\n");
822 expected_connections = -1;
823 if ((pg != NULL) && (peers_left == 0))
825 expected_connections =
826 GNUNET_TESTING_connect_topology (pg, connection_topology,
827 connect_topology_option,
828 connect_topology_option_modifier,
831 &topology_creation_finished, NULL);
833 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
834 "Have %d expected connections\n", expected_connections);
838 GNUNET_SCHEDULER_cancel (die_task);
839 if (expected_connections < 1)
842 GNUNET_SCHEDULER_add_now (&end_badly,
843 "from connect topology (bad return)");
847 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
848 (GNUNET_TIME_UNIT_SECONDS,
849 SECONDS_PER_PEER_START * num_peers),
851 "from connect topology (timeout)");
852 modnum = expected_connections / 4;
853 dotnum = (expected_connections / 50) + 1;
859 fprintf (stdout, "Peer connection progress: [");
866 peers_left = num_peers; /* Reset counter */
867 if (GNUNET_TESTING_create_topology
868 (pg, topology, blacklist_topology,
869 blacklist_transports) != GNUNET_SYSERR)
872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
873 "Topology set up, now starting peers!\n");
874 fprintf (stdout, "Daemon start progress [");
876 GNUNET_TESTING_daemons_continue_startup (pg);
880 GNUNET_SCHEDULER_cancel (die_task);
882 GNUNET_SCHEDULER_add_now (&end_badly,
883 "from create topology (bad return)");
885 GNUNET_SCHEDULER_cancel (die_task);
886 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
887 (GNUNET_TIME_UNIT_SECONDS,
888 SECONDS_PER_PEER_START * num_peers),
890 "from continue startup (timeout)");
895 peers_started_callback (void *cls,
896 const struct GNUNET_PeerIdentity *id,
897 const struct GNUNET_CONFIGURATION_Handle *cfg,
898 struct GNUNET_TESTING_Daemon *d, const char *emsg)
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
903 "Failed to start daemon with error: `%s'\n", emsg);
906 GNUNET_assert (id != NULL);
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
909 (num_peers - peers_left) + 1, num_peers);
912 if ((num_peers - peers_left) % modnum == 0)
914 if (num_peers - peers_left == 0)
915 fprintf (stdout, "0%%");
917 fprintf (stdout, "%d%%",
918 (int) (((float) (num_peers - peers_left) /
922 else if ((num_peers - peers_left) % dotnum == 0)
924 fprintf (stdout, ".");
932 fprintf (stdout, "100%%]\n");
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "All %d daemons started, now connecting peers!\n",
939 GNUNET_SCHEDULER_cancel (die_task);
940 /* Set up task in case topology creation doesn't finish
941 * within a reasonable amount of time */
942 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
943 (GNUNET_TIME_UNIT_MINUTES, 8),
945 "from peers_started_callback");
946 #if DELAY_FOR_LOGGING
947 fprintf (stdout, "Connecting topology in 10 seconds\n");
949 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
950 (GNUNET_TIME_UNIT_SECONDS, 10),
951 &connect_topology, NULL);
960 * Callback indicating that the hostkey was created for a peer.
963 * @param id the peer identity
964 * @param d the daemon handle (pretty useless at this point, remove?)
965 * @param emsg non-null on failure
968 hostkey_callback (void *cls,
969 const struct GNUNET_PeerIdentity *id,
970 struct GNUNET_TESTING_Daemon *d, const char *emsg)
974 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
975 "Hostkey callback received error: %s\n", emsg);
979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
980 "Hostkey (%d/%d) created for peer `%s'\n",
981 num_peers - peers_left, num_peers, GNUNET_i2s (id));
985 if ((num_peers - peers_left) % modnum == 0)
987 if (num_peers - peers_left == 0)
988 fprintf (stdout, "0%%");
990 fprintf (stdout, "%d%%",
991 (int) (((float) (num_peers - peers_left) /
995 else if ((num_peers - peers_left) % dotnum == 0)
997 fprintf (stdout, ".");
1002 if (peers_left == 0)
1005 fprintf (stdout, "100%%]\n");
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1007 "All %d hostkeys created, now creating topology!\n",
1010 GNUNET_SCHEDULER_cancel (die_task);
1011 /* Set up task in case topology creation doesn't finish
1012 * within a reasonable amount of time */
1013 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1015 "from create_topology");
1016 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1024 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1027 char *connect_topology_str;
1028 char *blacklist_topology_str;
1029 char *connect_topology_option_str;
1030 char *connect_topology_option_modifier_string;
1031 unsigned long long temp_settle;
1032 unsigned long long max_outstanding_connections;
1035 dotOutFile = fopen (dotOutFileName, "w");
1036 if (dotOutFile != NULL)
1038 fprintf (dotOutFile, "strict graph G {\n");
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1043 "Starting daemons based on config file %s\n", cfgfile);
1047 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
1055 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
1057 && (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
1059 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1060 "Invalid topology `%s' given for section %s option %s\n",
1061 topology_str, "TESTING", "TOPOLOGY");
1062 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1066 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1068 &connect_topology_str))
1070 GNUNET_TESTING_topology_get (&connection_topology,
1071 connect_topology_str)))
1073 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1074 "Invalid connect topology `%s' given for section %s option %s\n",
1075 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1077 GNUNET_free_non_null (connect_topology_str);
1079 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1080 "connect_topology_option",
1081 &connect_topology_option_str))
1083 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1084 connect_topology_option_str)))
1086 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1087 "Invalid connect topology option `%s' given for section %s option %s\n",
1088 connect_topology_option_str, "TESTING",
1089 "CONNECT_TOPOLOGY_OPTION");
1090 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1092 GNUNET_free_non_null (connect_topology_option_str);
1094 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1095 "connect_topology_option_modifier",
1096 &connect_topology_option_modifier_string))
1099 (connect_topology_option_modifier_string, "%lf",
1100 &connect_topology_option_modifier) != 1)
1102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1104 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1105 connect_topology_option_modifier_string,
1106 "connect_topology_option_modifier", "TESTING");
1108 GNUNET_free (connect_topology_option_modifier_string);
1112 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1113 "blacklist_transports",
1114 &blacklist_transports))
1115 blacklist_transports = NULL;
1118 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1119 "blacklist_topology",
1120 &blacklist_topology_str))
1122 GNUNET_TESTING_topology_get (&blacklist_topology,
1123 blacklist_topology_str)))
1125 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1126 "Invalid topology `%s' given for section %s option %s\n",
1127 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1129 GNUNET_free_non_null (topology_str);
1130 GNUNET_free_non_null (blacklist_topology_str);
1133 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "settle_time",
1136 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1139 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_timeout",
1142 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_settle);
1145 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_timeout");
1151 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1154 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "connect_attempts");
1159 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "max_outstanding_connections",
1160 &max_outstanding_connections))
1162 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n", "testing", "max_outstanding_connections");
1166 if (GNUNET_SYSERR ==
1167 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1169 num_peers = DEFAULT_NUM_PEERS;
1173 peers_left = num_peers;
1174 modnum = num_peers / 4;
1175 dotnum = (num_peers / 50) + 1;
1181 fprintf (stdout, "Hostkey generation progress: [");
1183 /* Set up a task to end testing if peer start fails */
1185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1186 (GNUNET_TIME_UNIT_SECONDS,
1187 SECONDS_PER_PEER_START * num_peers),
1189 "didn't generate all hostkeys within a reasonable amount of time!!!");
1191 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1192 pg = GNUNET_TESTING_daemons_start (cfg,
1194 max_outstanding_connections,
1196 GNUNET_TIME_relative_multiply
1197 (GNUNET_TIME_UNIT_SECONDS,
1198 SECONDS_PER_PEER_START * num_peers),
1199 &hostkey_callback, NULL,
1200 &peers_started_callback, NULL,
1201 &topology_callback, NULL, NULL);
1209 char *config_file_name;
1210 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1211 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1214 char *const argv[] = { binary_name,
1222 struct GNUNET_GETOPT_CommandLineOption options[] = {
1223 GNUNET_GETOPT_OPTION_END
1225 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1226 argv, binary_name, "nohelp", options, &run, &ok);
1227 if (ret != GNUNET_OK)
1229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1230 "`test-testing-topology-%s': Failed with error code %d\n",
1231 topology_string, ret);
1233 GNUNET_free (binary_name);
1234 GNUNET_free (config_file_name);
1239 main (int argc, char *argv[])
1242 char *binary_start_pos;
1243 char *our_binary_name;
1245 binary_start_pos = strchr (argv[0], '/');
1246 GNUNET_assert (binary_start_pos != NULL);
1247 topology_string = strstr (binary_start_pos, "_topology");
1248 GNUNET_assert (topology_string != NULL);
1250 topology_string = strstr (topology_string, "_");
1251 GNUNET_assert (topology_string != NULL);
1254 GNUNET_asprintf (&our_binary_name, "test-testing-topology_%s",
1256 GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string);
1258 GNUNET_log_setup (our_binary_name,
1268 * Need to remove base directory, subdirectories taken care
1269 * of by the testing framework.
1271 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1274 "Failed to remove testing directory %s\n", test_directory);
1276 GNUNET_free (our_binary_name);
1280 /* end of test_testing_topology.c */