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 GNUNET_NETWORK_STRUCT_BEGIN
112 struct GNUNET_TestMessage
115 * Header of the message
117 struct GNUNET_MessageHeader header;
120 * Unique identifier for this message.
124 GNUNET_NETWORK_STRUCT_END
126 struct TestMessageContext
128 /* This is a linked list */
129 struct TestMessageContext *next;
131 /* Handle to the sending peer core */
132 struct GNUNET_CORE_Handle *peer1handle;
134 /* Handle to the receiving peer core */
135 struct GNUNET_CORE_Handle *peer2handle;
137 /* Handle to the sending peer daemon */
138 struct GNUNET_TESTING_Daemon *peer1;
140 /* Handle to the receiving peer daemon */
141 struct GNUNET_TESTING_Daemon *peer2;
143 /* Identifier for this message, so we don't disconnect other peers! */
146 /* Has peer1 been notified already of a connection to peer2? */
149 /* Has the core of peer2 been connected already? */
152 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
153 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
157 static struct TestMessageContext *test_messages;
160 * Check whether peers successfully shut down.
163 shutdown_callback (void *cls, const char *emsg)
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
181 #if DELAY_FOR_LOGGING
186 char *connect_number;
187 struct GNUNET_OS_Process *mem_process;
189 GNUNET_asprintf (&peer_number, "%llu", num_peers);
190 GNUNET_asprintf (&connect_number, "%llu", expected_connections);
192 GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl",
193 "totals.txt", peer_number, connect_number, NULL);
194 GNUNET_OS_process_wait (mem_process);
195 GNUNET_OS_process_close (mem_process);
204 GNUNET_assert (pg != NULL);
205 struct TestMessageContext *pos;
206 struct TestMessageContext *free_pos;
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Called finish testing, stopping daemons.\n");
216 if (pos->peer1handle != NULL)
218 GNUNET_CORE_disconnect (pos->peer1handle);
219 pos->peer1handle = NULL;
221 if (pos->peer2handle != NULL)
223 GNUNET_CORE_disconnect (pos->peer2handle);
224 pos->peer2handle = NULL;
228 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
230 GNUNET_SCHEDULER_cancel (free_pos->disconnect_task);
232 GNUNET_free (free_pos);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
237 transmit_ready_scheduled, transmit_ready_failed,
238 transmit_ready_called);
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n");
244 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
246 if (dotOutFile != NULL)
248 FPRINTF (dotOutFile, "%s", "}");
257 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
259 struct TestMessageContext *pos = cls;
261 /* Disconnect from the respective cores */
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
264 GNUNET_i2s (&pos->peer1->id));
266 if (pos->peer1handle != NULL)
267 GNUNET_CORE_disconnect (pos->peer1handle);
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
270 GNUNET_i2s (&pos->peer2->id));
272 if (pos->peer2handle != NULL)
273 GNUNET_CORE_disconnect (pos->peer2handle);
274 /* Set handles to NULL so test case can be ended properly */
275 pos->peer1handle = NULL;
276 pos->peer2handle = NULL;
277 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
278 /* Decrement total connections so new can be established */
279 total_server_connections -= 2;
284 topology_cb (void *cls, 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, "%s", "}\n");
307 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
313 process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
314 const struct GNUNET_MessageHeader *message,
315 const struct GNUNET_ATS_Information *atsi)
317 char *dotOutFileNameFinished;
318 FILE *dotOutFileFinished;
319 struct TestMessageContext *pos = cls;
320 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *) message;
322 if (pos->uid != ntohl (msg->uid))
326 if ((total_messages_received) % modnum == 0)
328 if (total_messages_received == 0)
329 FPRINTF (stdout, "%s", "0%%");
331 FPRINTF (stdout, "%d%%",
332 (int) (((float) total_messages_received / expected_messages) *
336 else if (total_messages_received % dotnum == 0)
338 FPRINTF (stdout, "%s", ".");
343 total_messages_received++;
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Received message from `%4s', type %d.\n", GNUNET_i2s (peer),
348 ntohs (message->type));
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Total messages received %d, expected %d.\n",
351 total_messages_received, expected_messages);
354 if (total_messages_received == expected_messages)
357 FPRINTF (stdout, "%s", "100%%]\n");
359 GNUNET_SCHEDULER_cancel (die_task);
360 GNUNET_asprintf (&dotOutFileNameFinished, "%s.dot", "final_topology");
361 dotOutFileFinished = FOPEN (dotOutFileNameFinished, "w");
362 GNUNET_free (dotOutFileNameFinished);
363 if (dotOutFileFinished != NULL)
365 FPRINTF (dotOutFileFinished, "%s", "strict graph G {\n");
367 topology_connections = 0;
368 GNUNET_TESTING_get_topology (pg, &topology_cb, dotOutFileFinished);
369 //GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
373 pos->disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cores, pos);
380 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
384 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
385 "End badly was called (%s)... stopping daemons.\n", msg);
386 struct TestMessageContext *pos;
387 struct TestMessageContext *free_pos;
392 if (pos->peer1handle != NULL)
394 GNUNET_CORE_disconnect (pos->peer1handle);
395 pos->peer1handle = NULL;
397 if (pos->peer2handle != NULL)
399 GNUNET_CORE_disconnect (pos->peer2handle);
400 pos->peer2handle = NULL;
404 GNUNET_free (free_pos);
408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
409 "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n",
410 transmit_ready_scheduled, transmit_ready_failed,
411 transmit_ready_called);
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Total messages received %d, expected %d.\n",
414 total_messages_received, expected_messages);
419 GNUNET_TESTING_daemons_stop (pg, timeout, &shutdown_callback, NULL);
420 ok = 7331; /* Opposite of leet */
423 ok = 401; /* Never got peers started */
425 if (dotOutFile != NULL)
427 FPRINTF (dotOutFile, "%s", "}");
433 transmit_ready (void *cls, size_t size, void *buf)
435 struct GNUNET_TestMessage *m;
436 struct TestMessageContext *pos = cls;
438 GNUNET_assert (buf != NULL);
439 m = (struct GNUNET_TestMessage *) buf;
440 m->header.type = htons (MTYPE);
441 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
442 m->uid = htonl (pos->uid);
443 transmit_ready_called++;
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
446 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n",
447 GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled,
448 transmit_ready_called);
450 return sizeof (struct GNUNET_TestMessage);
454 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
458 static struct GNUNET_CORE_MessageHandler handlers[] = {
459 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
464 init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
465 const struct GNUNET_PeerIdentity *my_identity)
467 struct TestMessageContext *pos = cls;
469 total_server_connections++;
471 pos->peer2connected = GNUNET_YES;
472 if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
477 GNUNET_i2s (my_identity),
478 GNUNET_h2s (&pos->peer1->id.hashPubKey));
481 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
483 sizeof (struct GNUNET_TestMessage),
484 &transmit_ready, pos))
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
487 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
488 GNUNET_i2s (&pos->peer2->id));
489 transmit_ready_failed++;
493 transmit_ready_scheduled++;
499 * Method called whenever a given peer connects.
502 * @param peer peer identity this notification is about
503 * @param atsi performance data for the connection
506 connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
507 const struct GNUNET_ATS_Information *atsi)
509 struct TestMessageContext *pos = cls;
511 if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
513 pos->peer1notified = GNUNET_YES;
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "Peer `%s' notified of connection to peer `%s'\n",
517 GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
523 if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
528 GNUNET_i2s (&pos->peer2->id),
529 GNUNET_h2s (&pos->peer1->id.hashPubKey));
532 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
534 sizeof (struct GNUNET_TestMessage),
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, struct GNUNET_CORE_Handle *server,
551 const struct GNUNET_PeerIdentity *my_identity)
553 struct TestMessageContext *pos = cls;
555 total_server_connections++;
558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
559 "Core connection to `%4s' established, setting up handles\n",
560 GNUNET_i2s (my_identity));
564 * Connect to the receiving peer
567 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2, NULL,
568 NULL, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES,
575 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
577 struct TestMessageContext *pos = cls;
579 if ((pos == test_messages) && (settle_time.rel_value > 0))
581 topology_connections = 0;
582 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
584 if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
587 if (die_task == GNUNET_SCHEDULER_NO_TASK)
590 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
591 "from send test messages (timeout)");
594 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
596 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
597 (GNUNET_TIME_UNIT_SECONDS, 1),
598 &send_test_messages, pos);
599 return; /* Otherwise we'll double schedule messages here! */
603 * Connect to the sending peer
606 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
607 &connect_notify_peers, NULL, NULL, NULL, GNUNET_NO,
608 NULL, GNUNET_NO, no_handlers);
610 GNUNET_assert (pos->peer1handle != NULL);
612 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
614 GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next);
618 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
619 (GNUNET_TIME_UNIT_SECONDS, 1),
620 &send_test_messages, pos->next);
626 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
627 const struct GNUNET_PeerIdentity *second, uint32_t distance,
628 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
629 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
630 struct GNUNET_TESTING_Daemon *first_daemon,
631 struct GNUNET_TESTING_Daemon *second_daemon,
634 struct TestMessageContext *temp_context;
639 if ((total_connections) % modnum == 0)
641 if (total_connections == 0)
642 FPRINTF (stdout, "%s", "0%%");
644 FPRINTF (stdout, "%d%%",
645 (int) (((float) total_connections / expected_connections) *
649 else if (total_connections % dotnum == 0)
651 FPRINTF (stdout, "%s", ".");
657 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n",
658 first_daemon->shortname, second_daemon->shortname);
660 temp_context = GNUNET_malloc (sizeof (struct TestMessageContext));
661 temp_context->peer1 = first_daemon;
662 temp_context->peer2 = second_daemon;
663 temp_context->next = test_messages;
664 temp_context->uid = total_connections;
665 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
666 test_messages = temp_context;
669 if (dotOutFile != NULL)
670 FPRINTF (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname,
671 second_daemon->shortname);
676 failed_connections++;
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "Failed to connect peer %s to peer %s with error :\n%s\n",
679 first_daemon->shortname, second_daemon->shortname, emsg);
683 if (total_connections == expected_connections)
686 FPRINTF (stdout, "%s", "100%%]\n");
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "Created %d total connections, which is our target number! Calling send messages.\n",
693 modnum = expected_messages / 4;
694 dotnum = (expected_messages / 50) + 1;
695 GNUNET_SCHEDULER_cancel (die_task);
696 die_task = GNUNET_SCHEDULER_NO_TASK;
697 #if DELAY_FOR_LOGGING
698 FPRINTF (stdout, "%s", "Sending test messages in 10 seconds.\n");
699 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
700 (GNUNET_TIME_UNIT_SECONDS, 10),
701 &send_test_messages, test_messages);
704 if (settle_time.rel_value > 0)
706 GNUNET_TESTING_get_topology (pg, &topology_cb, NULL);
708 GNUNET_SCHEDULER_add_delayed (settle_time, &send_test_messages,
712 FPRINTF (stdout, "%s", "Test message progress: [");
716 else if (total_connections + failed_connections == expected_connections)
718 if (failed_connections <
719 (unsigned int) (fail_percentage * total_connections))
721 GNUNET_SCHEDULER_cancel (die_task);
722 die_task = GNUNET_SCHEDULER_NO_TASK;
723 GNUNET_SCHEDULER_add_now (&send_test_messages, test_messages);
727 GNUNET_SCHEDULER_cancel (die_task);
729 GNUNET_SCHEDULER_add_now (&end_badly,
730 "from topology_callback (too many failed connections)");
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
738 total_connections, failed_connections, expected_connections,
739 expected_connections -
740 (unsigned int) (fail_percentage * expected_connections));
746 topology_creation_finished (void *cls, const char *emsg)
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
751 "All topology connections created successfully!\n");
758 expected_connections = -1;
759 if ((pg != NULL) && (peers_left == 0))
761 expected_connections =
762 GNUNET_TESTING_connect_topology (pg, connection_topology,
763 connect_topology_option,
764 connect_topology_option_modifier,
765 connect_timeout, connect_attempts,
766 &topology_creation_finished, NULL);
768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
769 expected_connections);
773 GNUNET_SCHEDULER_cancel (die_task);
774 if (expected_connections == GNUNET_SYSERR)
777 GNUNET_SCHEDULER_add_now (&end_badly,
778 "from connect topology (bad return)");
782 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
783 "from connect topology (timeout)");
784 modnum = expected_connections / 4;
785 dotnum = (expected_connections / 50) + 1;
787 FPRINTF (stdout, "%s", "Peer connection progress: [");
794 peers_left = num_peers; /* Reset counter */
795 if (GNUNET_TESTING_create_topology
796 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
800 "Topology set up, now starting peers!\n");
801 FPRINTF (stdout, "%s", "Daemon start progress [");
803 GNUNET_TESTING_daemons_continue_startup (pg);
807 GNUNET_SCHEDULER_cancel (die_task);
809 GNUNET_SCHEDULER_add_now (&end_badly,
810 "from create topology (bad return)");
812 GNUNET_SCHEDULER_cancel (die_task);
814 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
815 "from continue startup (timeout)");
820 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
821 const struct GNUNET_CONFIGURATION_Handle *cfg,
822 struct GNUNET_TESTING_Daemon *d, const char *emsg)
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
827 "Failed to start daemon with error: `%s'\n", emsg);
830 GNUNET_assert (id != NULL);
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
833 (num_peers - peers_left) + 1, num_peers);
836 if ((num_peers - peers_left) % modnum == 0)
838 if (num_peers - peers_left == 0)
839 FPRINTF (stdout, "%s", "0%%");
841 FPRINTF (stdout, "%d%%",
842 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
845 else if ((num_peers - peers_left) % dotnum == 0)
847 FPRINTF (stdout, "%s", ".");
855 FPRINTF (stdout, "%s", "100%%]\n");
858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
859 "All %d daemons started, now connecting peers!\n", num_peers);
861 GNUNET_SCHEDULER_cancel (die_task);
862 /* Set up task in case topology creation doesn't finish
863 * within a reasonable amount of time */
865 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
866 "from peers_started_callback");
867 #if DELAY_FOR_LOGGING
868 FPRINTF (stdout, "%s", "Connecting topology in 10 seconds\n");
870 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
871 (GNUNET_TIME_UNIT_SECONDS, 10),
872 &connect_topology, NULL);
881 * Callback indicating that the hostkey was created for a peer.
884 * @param id the peer identity
885 * @param d the daemon handle (pretty useless at this point, remove?)
886 * @param emsg non-null on failure
889 hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
890 struct GNUNET_TESTING_Daemon *d, const char *emsg)
894 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
895 "Hostkey callback received error: %s\n", emsg);
899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
900 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
901 num_peers, GNUNET_i2s (id));
905 if ((num_peers - peers_left) % modnum == 0)
907 if (num_peers - peers_left == 0)
908 FPRINTF (stdout, "%s", "0%%");
910 FPRINTF (stdout, "%d%%",
911 (int) (((float) (num_peers - peers_left) / num_peers) * 100));
914 else if ((num_peers - peers_left) % dotnum == 0)
916 FPRINTF (stdout, "%s", ".");
924 FPRINTF (stdout, "%s", "100%%]\n");
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "All %d hostkeys created, now creating topology!\n", num_peers);
928 GNUNET_SCHEDULER_cancel (die_task);
929 /* Set up task in case topology creation doesn't finish
930 * within a reasonable amount of time */
932 GNUNET_SCHEDULER_add_delayed (test_timeout, &end_badly,
933 "from create_topology");
934 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
940 run (void *cls, char *const *args, const char *cfgfile,
941 const struct GNUNET_CONFIGURATION_Handle *cfg)
944 char *connect_topology_str;
945 char *blacklist_topology_str;
946 char *connect_topology_option_str;
947 char *connect_topology_option_modifier_string;
948 unsigned long long temp_settle;
952 dotOutFile = FOPEN (dotOutFileName, "w");
953 if (dotOutFile != NULL)
955 FPRINTF (dotOutFile, "%s", "strict graph G {\n");
959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
960 "Starting daemons based on config file %s\n", cfgfile);
964 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
972 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
974 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
976 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
977 "Invalid topology `%s' given for section %s option %s\n",
978 topology_str, "TESTING", "TOPOLOGY");
979 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
983 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
985 &connect_topology_str)) &&
987 GNUNET_TESTING_topology_get (&connection_topology,
988 connect_topology_str)))
990 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
991 "Invalid connect topology `%s' given for section %s option %s\n",
992 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
994 GNUNET_free_non_null (connect_topology_str);
996 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
997 "connect_topology_option",
998 &connect_topology_option_str)) &&
1000 GNUNET_TESTING_topology_option_get (&connect_topology_option,
1001 connect_topology_option_str)))
1003 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1004 "Invalid connect topology option `%s' given for section %s option %s\n",
1005 connect_topology_option_str, "TESTING",
1006 "CONNECT_TOPOLOGY_OPTION");
1007 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1009 GNUNET_free_non_null (connect_topology_option_str);
1011 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1012 "connect_topology_option_modifier",
1013 &connect_topology_option_modifier_string))
1016 (connect_topology_option_modifier_string, "%lf",
1017 &connect_topology_option_modifier) != 1)
1019 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1021 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1022 connect_topology_option_modifier_string,
1023 "connect_topology_option_modifier", "TESTING");
1025 GNUNET_free (connect_topology_option_modifier_string);
1029 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1030 "blacklist_transports",
1031 &blacklist_transports))
1032 blacklist_transports = NULL;
1035 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
1036 "blacklist_topology",
1037 &blacklist_topology_str)) &&
1039 GNUNET_TESTING_topology_get (&blacklist_topology,
1040 blacklist_topology_str)))
1042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1043 "Invalid topology `%s' given for section %s option %s\n",
1044 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1046 GNUNET_free_non_null (topology_str);
1047 GNUNET_free_non_null (blacklist_topology_str);
1050 GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SETTLE_TIME",
1053 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1054 "testing", "SETTLE_TIME");
1057 if (GNUNET_SYSERR ==
1058 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1060 num_peers = DEFAULT_NUM_PEERS;
1063 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "CONNECT_TIMEOUT",
1066 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1067 "testing", "CONNECT_TIMEOUT");
1073 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "connect_attempts",
1076 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Must provide option %s:%s!\n",
1077 "testing", "connect_attempts");
1083 peers_left = num_peers;
1086 * How long until we fail the whole testcase?
1089 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1090 (GNUNET_TIME_UNIT_SECONDS,
1091 SECONDS_PER_PEER_START), num_peers * 2);
1094 * How long until we give up on starting the peers?
1097 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_multiply
1098 (GNUNET_TIME_UNIT_SECONDS,
1099 SECONDS_PER_PEER_START), num_peers);
1101 modnum = num_peers / 4;
1102 dotnum = (num_peers / 50) + 1;
1104 FPRINTF (stdout, "%s", "Hostkey generation progress: [");
1106 /* Set up a task to end testing if peer start fails */
1108 GNUNET_SCHEDULER_add_delayed (timeout, &end_badly,
1109 "didn't generate all hostkeys within a reasonable amount of time!!!");
1111 GNUNET_assert (num_peers > 0 && num_peers < (unsigned int) -1);
1112 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, peers_left / 2,
1113 peers_left, timeout, &hostkey_callback,
1114 NULL, &peers_started_callback, NULL,
1115 &topology_callback, NULL, NULL);
1123 char *config_file_name;
1125 GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string);
1126 GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf",
1130 char *const argv[] = { binary_name,
1138 struct GNUNET_GETOPT_CommandLineOption options[] = {
1139 GNUNET_GETOPT_OPTION_END
1142 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1143 binary_name, "nohelp", options, &run, &ok);
1144 if (ret != GNUNET_OK)
1146 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1147 "`test-testing-topology-%s': Failed with error code %d\n",
1148 topology_string, ret);
1150 GNUNET_free (binary_name);
1151 GNUNET_free (config_file_name);
1156 main (int argc, char *argv[])
1159 char *binary_start_pos;
1160 char *our_binary_name;
1162 binary_start_pos = rindex (argv[0], '/');
1163 GNUNET_assert (binary_start_pos != NULL);
1164 topology_string = strstr (binary_start_pos, "_topology");
1165 GNUNET_assert (topology_string != NULL);
1167 topology_string = strstr (topology_string, "_");
1168 GNUNET_assert (topology_string != NULL);
1171 GNUNET_asprintf (&our_binary_name, "test-testing-large-topology_%s",
1173 GNUNET_asprintf (&dotOutFileName, "large_topology_%s.dot", topology_string);
1175 GNUNET_log_setup (our_binary_name,
1185 * Need to remove base directory, subdirectories taken care
1186 * of by the testing framework.
1188 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1191 "Failed to remove testing directory %s\n", test_directory);
1193 GNUNET_free (our_binary_name);
1197 /* end of test_testing_topology.c */