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 2, 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 dv/test_transport_api_dv.c
22 * @brief base testcase for testing distance vector transport
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_core_service.h"
28 #define VERBOSE GNUNET_YES
30 #define TEST_ALL GNUNET_NO
33 * How long until we fail the whole testcase?
35 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
38 * How long until we give up on starting the peers?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 500)
42 #define DEFAULT_NUM_PEERS 4
44 #define MAX_OUTSTANDING_CONNECTIONS 100
46 static float fail_percentage = 0.00;
50 static unsigned long long num_peers;
52 static unsigned int total_connections;
54 static unsigned int failed_connections;
56 static unsigned int total_server_connections;
58 static unsigned int total_messages_received;
60 static unsigned int total_other_expected_messages;
62 static unsigned int temp_total_other_messages;
64 static unsigned int total_other_messages;
66 static unsigned int expected_messages;
68 static unsigned int expected_connections;
70 static unsigned long long peers_left;
72 static struct GNUNET_TESTING_PeerGroup *pg;
74 static struct GNUNET_SCHEDULER_Handle *sched;
76 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
78 GNUNET_SCHEDULER_TaskIdentifier die_task;
80 static char *dotOutFileName = "topology.dot";
82 static FILE *dotOutFile;
84 static char *blacklist_transports;
86 static int transmit_ready_scheduled;
88 static int transmit_ready_failed;
90 static int transmit_ready_called;
92 static enum GNUNET_TESTING_Topology topology;
94 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
96 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
98 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
100 static double connect_topology_option_modifier = 0.0;
102 static char *test_directory;
104 struct GNUNET_CONTAINER_MultiHashMap *peer_daemon_hash;
108 struct GNUNET_TestMessage
111 * Header of the message
113 struct GNUNET_MessageHeader header;
116 * Unique identifier for this message.
123 /* This is a linked list */
124 struct PeerContext *next;
127 * Handle to the daemon
129 struct GNUNET_TESTING_Daemon *daemon;
131 /* Handle to the peer core */
132 struct GNUNET_CORE_Handle *peer_handle;
135 static struct PeerContext *all_peers;
137 struct TestMessageContext
139 /* This is a linked list */
140 struct TestMessageContext *next;
142 /* Handle to the sending peer core */
143 struct GNUNET_CORE_Handle *peer1handle;
145 /* Handle to the receiving peer core */
146 struct GNUNET_CORE_Handle *peer2handle;
148 /* Handle to the sending peer daemon */
149 struct GNUNET_TESTING_Daemon *peer1;
151 /* Handle to the receiving peer daemon */
152 struct GNUNET_TESTING_Daemon *peer2;
154 /* Identifier for this message, so we don't disconnect other peers! */
157 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
158 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
161 static struct TestMessageContext *test_messages;
163 static struct TestMessageContext *other_test_messages;
168 GNUNET_assert (pg != NULL);
169 struct PeerContext *peer_pos;
170 struct PeerContext *free_peer_pos;
171 struct TestMessageContext *pos;
172 struct TestMessageContext *free_pos;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Called finish testing, stopping daemons.\n");
179 peer_pos = all_peers;
180 while (peer_pos != NULL)
182 if (peer_pos->peer_handle != NULL)
183 GNUNET_CORE_disconnect(peer_pos->peer_handle);
184 free_peer_pos = peer_pos;
185 peer_pos = peer_pos->next;
186 GNUNET_free(free_peer_pos);
194 if (pos->peer1handle != NULL)
196 GNUNET_CORE_disconnect(pos->peer1handle);
197 pos->peer1handle = NULL;
199 if (pos->peer2handle != NULL)
201 GNUNET_CORE_disconnect(pos->peer2handle);
202 pos->peer2handle = NULL;
206 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
208 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
210 GNUNET_free(free_pos);
213 pos = other_test_messages;
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(sched, 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", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "Calling daemons_stop\n");
243 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "daemons_stop finished\n");
248 if (dotOutFile != NULL)
250 fprintf(dotOutFile, "}");
259 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
261 struct TestMessageContext *pos = cls;
263 /* Disconnect from the respective cores */
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
266 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
268 if (pos->peer1handle != NULL)
269 GNUNET_CORE_disconnect(pos->peer1handle);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
274 if (pos->peer2handle != NULL)
275 GNUNET_CORE_disconnect(pos->peer2handle);
276 /* Set handles to NULL so test case can be ended properly */
277 pos->peer1handle = NULL;
278 pos->peer2handle = NULL;
279 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
280 /* Decrement total connections so new can be established */
281 total_server_connections -= 2;
285 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
288 process_mtype (void *cls,
289 const struct GNUNET_PeerIdentity *peer,
290 const struct GNUNET_MessageHeader *message,
291 struct GNUNET_TIME_Relative latency,
294 struct TestMessageContext *pos = cls;
295 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
296 if (pos->uid != ntohl(msg->uid))
299 if (total_other_expected_messages == 0)
301 total_messages_received++;
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
304 "Received message from `%4s', type %d, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), distance);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
311 total_other_messages++;
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "Received message from `%4s', type %d, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), distance);
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
320 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
322 GNUNET_SCHEDULER_cancel (sched, die_task);
323 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 40), &send_other_messages, NULL);
325 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
327 GNUNET_SCHEDULER_cancel (sched, die_task);
328 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
332 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
339 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
342 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
343 "End badly was called (%s)... stopping daemons.\n", msg);
344 struct TestMessageContext *pos;
345 struct TestMessageContext *free_pos;
346 struct PeerContext * peer_pos;
347 struct PeerContext * free_peer_pos;
349 peer_pos = all_peers;
350 while (peer_pos != NULL)
352 if (peer_pos->peer_handle != NULL)
353 GNUNET_CORE_disconnect(peer_pos->peer_handle);
354 free_peer_pos = peer_pos;
355 peer_pos = peer_pos->next;
356 GNUNET_free(free_peer_pos);
363 if (pos->peer1handle != NULL)
365 GNUNET_CORE_disconnect(pos->peer1handle);
366 pos->peer1handle = NULL;
368 if (pos->peer2handle != NULL)
370 GNUNET_CORE_disconnect(pos->peer2handle);
371 pos->peer2handle = NULL;
375 GNUNET_free(free_pos);
378 pos = other_test_messages;
381 if (pos->peer1handle != NULL)
383 GNUNET_CORE_disconnect(pos->peer1handle);
384 pos->peer1handle = NULL;
386 if (pos->peer2handle != NULL)
388 GNUNET_CORE_disconnect(pos->peer2handle);
389 pos->peer2handle = NULL;
393 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
395 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
397 GNUNET_free(free_pos);
402 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
403 ok = 7331; /* Opposite of leet */
406 ok = 401; /* Never got peers started */
408 if (dotOutFile != NULL)
410 fprintf(dotOutFile, "}");
416 transmit_ready (void *cls, size_t size, void *buf)
418 struct GNUNET_TestMessage *m;
419 struct TestMessageContext *pos = cls;
421 GNUNET_assert (buf != NULL);
422 m = (struct GNUNET_TestMessage *) buf;
423 m->header.type = htons (MTYPE);
424 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
425 m->uid = htonl(pos->uid);
426 transmit_ready_called++;
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called);
431 return sizeof (struct GNUNET_TestMessage);
435 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
439 static struct GNUNET_CORE_MessageHandler handlers[] = {
440 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
445 init_notify_peer2 (void *cls,
446 struct GNUNET_CORE_Handle *server,
447 const struct GNUNET_PeerIdentity *my_identity,
448 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
450 struct TestMessageContext *pos = cls;
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
454 "Core connection to `%4s' established, scheduling message send\n",
455 GNUNET_i2s (my_identity));
457 total_server_connections++;
459 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
463 sizeof (struct GNUNET_TestMessage),
464 &transmit_ready, pos))
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
468 GNUNET_i2s (&pos->peer2->id));
469 transmit_ready_failed++;
473 transmit_ready_scheduled++;
479 init_notify_peer1 (void *cls,
480 struct GNUNET_CORE_Handle *server,
481 const struct GNUNET_PeerIdentity *my_identity,
482 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
484 struct TestMessageContext *pos = cls;
485 total_server_connections++;
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "Core connection to `%4s' established, setting up handles\n",
490 GNUNET_i2s (my_identity));
494 * Connect to the receiving peer
496 pos->peer2handle = GNUNET_CORE_connect (sched,
504 GNUNET_YES, NULL, GNUNET_YES, handlers);
510 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
512 struct TestMessageContext *pos = cls;
514 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
517 if (die_task == GNUNET_SCHEDULER_NO_TASK)
519 die_task = GNUNET_SCHEDULER_add_delayed (sched,
521 &end_badly, "from create topology (timeout)");
524 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
526 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
527 &send_test_messages, pos);
528 return; /* Otherwise we'll double schedule messages here! */
531 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
534 * Connect to the sending peer
536 pos->peer1handle = GNUNET_CORE_connect (sched,
544 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
546 GNUNET_assert(pos->peer1handle != NULL);
548 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
550 GNUNET_SCHEDULER_add_now (sched,
551 &send_test_messages, pos->next);
555 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
556 &send_test_messages, pos->next);
561 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
563 struct TestMessageContext *pos;
564 struct TestMessageContext *free_pos;
565 struct PeerContext *peer_pos;
567 struct PeerContext *inner_peer_pos;
568 struct TestMessageContext *temp_context;
570 peer_pos = all_peers;
571 while (peer_pos != NULL)
573 if (peer_pos->peer_handle != NULL)
575 GNUNET_CORE_disconnect(peer_pos->peer_handle);
576 peer_pos->peer_handle = NULL;
579 inner_peer_pos = all_peers;
580 while (inner_peer_pos != NULL)
582 if (inner_peer_pos != peer_pos)
584 temp_total_other_messages++;
585 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
586 temp_context->peer1 = peer_pos->daemon;
587 temp_context->peer2 = inner_peer_pos->daemon;
588 temp_context->next = other_test_messages;
589 temp_context->uid = total_connections + temp_total_other_messages;
590 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
591 other_test_messages = temp_context;
593 inner_peer_pos = inner_peer_pos->next;
596 peer_pos = peer_pos->next;
603 if (pos->peer1handle != NULL)
605 GNUNET_CORE_disconnect(pos->peer1handle);
606 pos->peer1handle = NULL;
608 if (pos->peer2handle != NULL)
610 GNUNET_CORE_disconnect(pos->peer2handle);
611 pos->peer2handle = NULL;
615 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
617 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
619 GNUNET_free(free_pos);
621 test_messages = NULL;
623 total_other_expected_messages = temp_total_other_messages;
625 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
628 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
629 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
633 topology_callback (void *cls,
634 const struct GNUNET_PeerIdentity *first,
635 const struct GNUNET_PeerIdentity *second,
637 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
638 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
639 struct GNUNET_TESTING_Daemon *first_daemon,
640 struct GNUNET_TESTING_Daemon *second_daemon,
643 struct TestMessageContext *temp_context;
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
649 first_daemon->shortname,
650 second_daemon->shortname,
653 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
654 temp_context->peer1 = first_daemon;
655 temp_context->peer2 = second_daemon;
656 temp_context->next = test_messages;
657 temp_context->uid = total_connections;
658 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
659 test_messages = temp_context;
667 failed_connections++;
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
669 first_daemon->shortname,
670 second_daemon->shortname, emsg);
674 if (total_connections == expected_connections)
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "Created %d total connections, which is our target number! Calling send messages.\n",
682 GNUNET_SCHEDULER_cancel (sched, die_task);
683 die_task = GNUNET_SCHEDULER_NO_TASK;
684 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
685 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
687 else if (total_connections + failed_connections == expected_connections)
689 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
691 GNUNET_SCHEDULER_cancel (sched, die_task);
692 die_task = GNUNET_SCHEDULER_NO_TASK;
693 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
694 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
698 GNUNET_SCHEDULER_cancel (sched, die_task);
699 die_task = GNUNET_SCHEDULER_add_now (sched,
700 &end_badly, "from topology_callback (too many failed connections)");
706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
708 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
716 expected_connections = -1;
717 if ((pg != NULL) && (peers_left == 0))
719 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Have %d expected connections\n", expected_connections);
726 GNUNET_SCHEDULER_cancel (sched, die_task);
727 if (expected_connections == GNUNET_SYSERR)
729 die_task = GNUNET_SCHEDULER_add_now (sched,
730 &end_badly, "from connect topology (bad return)");
733 die_task = GNUNET_SCHEDULER_add_delayed (sched,
735 &end_badly, "from connect topology (timeout)");
741 peers_left = num_peers; /* Reset counter */
742 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
746 "Topology set up, now starting peers!\n");
748 GNUNET_TESTING_daemons_continue_startup(pg);
752 GNUNET_SCHEDULER_cancel (sched, die_task);
753 die_task = GNUNET_SCHEDULER_add_now (sched,
754 &end_badly, "from create topology (bad return)");
756 GNUNET_SCHEDULER_cancel (sched, die_task);
757 die_task = GNUNET_SCHEDULER_add_delayed (sched,
759 &end_badly, "from continue startup (timeout)");
763 * Method called whenever a given peer connects.
766 * @param peer peer identity this notification is about
767 * @param latency reported latency of the connection with 'other'
768 * @param distance reported distance (DV) to 'other'
770 static void all_connect_handler (void *cls,
772 GNUNET_PeerIdentity * peer,
773 struct GNUNET_TIME_Relative latency,
776 struct GNUNET_TESTING_Daemon *d = cls;
777 struct GNUNET_TESTING_Daemon *second_daemon;
778 char *second_shortname = strdup(GNUNET_i2s(peer));
780 struct TestMessageContext *temp_context;
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
789 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
791 if (second_daemon == NULL)
793 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
799 temp_total_other_messages++;
800 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
801 temp_context->peer1 = d;
802 temp_context->peer2 = second_daemon;
803 temp_context->next = other_test_messages;
804 temp_context->uid = total_connections;
805 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
806 other_test_messages = temp_context;
811 if (dotOutFile != NULL)
814 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
815 else if (distance == 2)
816 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
817 else if (distance == 3)
818 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
819 else if (distance == 4)
820 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
822 GNUNET_free(second_shortname);
826 peers_started_callback (void *cls,
827 const struct GNUNET_PeerIdentity *id,
828 const struct GNUNET_CONFIGURATION_Handle *cfg,
829 struct GNUNET_TESTING_Daemon *d, const char *emsg)
831 struct PeerContext *new_peer;
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
838 GNUNET_assert (id != NULL);
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
841 (num_peers - peers_left) + 1, num_peers);
843 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
845 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
846 new_peer->peer_handle = GNUNET_CORE_connect(sched, cfg, GNUNET_TIME_UNIT_FOREVER_REL, d, NULL, &all_connect_handler, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
847 new_peer->daemon = d;
848 new_peer->next = all_peers;
849 all_peers = new_peer;
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "All %d daemons started, now creating topology!\n",
859 GNUNET_SCHEDULER_cancel (sched, die_task);
860 /* Set up task in case topology creation doesn't finish
861 * within a reasonable amount of time */
862 die_task = GNUNET_SCHEDULER_add_delayed (sched,
863 GNUNET_TIME_relative_multiply
864 (GNUNET_TIME_UNIT_MINUTES, 5),
865 &end_badly, "from peers_started_callback");
873 * Callback indicating that the hostkey was created for a peer.
876 * @param id the peer identity
877 * @param d the daemon handle (pretty useless at this point, remove?)
878 * @param emsg non-null on failure
880 void hostkey_callback (void *cls,
881 const struct GNUNET_PeerIdentity *id,
882 struct GNUNET_TESTING_Daemon *d,
887 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
892 "Hostkey created for peer `%s'\n",
899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
900 "All %d hostkeys created, now creating topology!\n",
903 GNUNET_SCHEDULER_cancel (sched, die_task);
904 /* Set up task in case topology creation doesn't finish
905 * within a reasonable amount of time */
906 die_task = GNUNET_SCHEDULER_add_delayed (sched,
907 GNUNET_TIME_relative_multiply
908 (GNUNET_TIME_UNIT_MINUTES, 5),
909 &end_badly, "from hostkey_callback");
910 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
917 struct GNUNET_SCHEDULER_Handle *s,
919 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
922 char * connect_topology_str;
923 char * blacklist_topology_str;
924 char * connect_topology_option_str;
925 char * connect_topology_option_modifier_string;
929 dotOutFile = fopen (dotOutFileName, "w");
930 if (dotOutFile != NULL)
932 fprintf (dotOutFile, "strict graph G {\n");
936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
937 "Starting daemons based on config file %s\n", cfgfile);
940 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
947 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
948 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
950 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
951 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
952 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
956 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
957 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
959 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
960 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
962 GNUNET_free_non_null(connect_topology_str);
964 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
965 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
967 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
968 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
969 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
971 GNUNET_free_non_null(connect_topology_option_str);
973 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
974 &connect_topology_option_modifier_string))
976 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
978 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
979 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
980 connect_topology_option_modifier_string,
981 "connect_topology_option_modifier",
984 GNUNET_free (connect_topology_option_modifier_string);
987 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
988 &blacklist_transports))
989 blacklist_transports = NULL;
992 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
993 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
995 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
996 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
998 GNUNET_free_non_null(topology_str);
999 GNUNET_free_non_null(blacklist_topology_str);
1000 if (GNUNET_SYSERR ==
1001 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1003 num_peers = DEFAULT_NUM_PEERS;
1007 peers_left = num_peers;
1009 /* Set up a task to end testing if peer start fails */
1010 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1011 GNUNET_TIME_relative_multiply
1012 (GNUNET_TIME_UNIT_MINUTES, 5),
1013 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
1015 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
1016 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1017 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
1018 &topology_callback, NULL, NULL);
1026 char *const argv[] = {"test-transport-dv",
1028 "test_transport_dv_data.conf",
1034 struct GNUNET_GETOPT_CommandLineOption options[] = {
1035 GNUNET_GETOPT_OPTION_END
1037 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1038 argv, "test-transport-dv", "nohelp",
1039 options, &run, &ok);
1040 if (ret != GNUNET_OK)
1042 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret);
1048 main (int argc, char *argv[])
1052 GNUNET_log_setup ("test-transport-dv",
1062 * Need to remove base directory, subdirectories taken care
1063 * of by the testing framework.
1065 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1067 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1072 /* end of test_testing_topology.c */