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 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_NO
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 DEFAULT_ADDITIONAL_MESSAGES 2
46 #define MAX_OUTSTANDING_CONNECTIONS 100
48 static float fail_percentage = 0.00;
52 static unsigned long long num_additional_messages;
54 static unsigned long long num_peers;
56 static unsigned int total_connections;
58 static unsigned int failed_connections;
60 static unsigned int total_server_connections;
62 static unsigned int total_messages_received;
64 static unsigned int total_other_expected_messages;
66 static unsigned int temp_total_other_messages;
68 static unsigned int total_other_messages;
70 static unsigned int expected_messages;
72 static unsigned int expected_connections;
74 static unsigned long long peers_left;
76 static struct GNUNET_TESTING_PeerGroup *pg;
78 static struct GNUNET_SCHEDULER_Handle *sched;
80 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
82 GNUNET_SCHEDULER_TaskIdentifier die_task;
84 static char *dotOutFileName = "topology.dot";
86 static FILE *dotOutFile;
88 static char *blacklist_transports;
90 static int transmit_ready_scheduled;
92 static int transmit_ready_failed;
94 static int transmit_ready_called;
96 static enum GNUNET_TESTING_Topology topology;
98 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
100 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
102 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
104 static double connect_topology_option_modifier = 0.0;
106 static char *test_directory;
108 struct GNUNET_CONTAINER_MultiHashMap *peer_daemon_hash;
112 struct GNUNET_TestMessage
115 * Header of the message
117 struct GNUNET_MessageHeader header;
120 * Unique identifier for this message.
127 /* This is a linked list */
128 struct PeerContext *next;
131 * Handle to the daemon
133 struct GNUNET_TESTING_Daemon *daemon;
135 /* Handle to the peer core */
136 struct GNUNET_CORE_Handle *peer_handle;
139 static struct PeerContext *all_peers;
141 struct TestMessageContext
143 /* This is a linked list */
144 struct TestMessageContext *next;
146 /* Handle to the sending peer core */
147 struct GNUNET_CORE_Handle *peer1handle;
149 /* Handle to the receiving peer core */
150 struct GNUNET_CORE_Handle *peer2handle;
152 /* Handle to the sending peer daemon */
153 struct GNUNET_TESTING_Daemon *peer1;
155 /* Handle to the receiving peer daemon */
156 struct GNUNET_TESTING_Daemon *peer2;
158 /* Identifier for this message, so we don't disconnect other peers! */
161 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
162 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
165 static struct TestMessageContext *test_messages;
167 static struct TestMessageContext *other_test_messages;
170 * Check whether peers successfully shut down.
172 void shutdown_callback (void *cls,
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Shutdown of peers failed!\n");
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "All peers successfully shut down!\n");
196 GNUNET_assert (pg != NULL);
197 struct PeerContext *peer_pos;
198 struct PeerContext *free_peer_pos;
199 struct TestMessageContext *pos;
200 struct TestMessageContext *free_pos;
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Called finish testing, stopping daemons.\n");
207 peer_pos = all_peers;
208 while (peer_pos != NULL)
210 if (peer_pos->peer_handle != NULL)
211 GNUNET_CORE_disconnect(peer_pos->peer_handle);
212 free_peer_pos = peer_pos;
213 peer_pos = peer_pos->next;
214 GNUNET_free(free_peer_pos);
222 if (pos->peer1handle != NULL)
224 GNUNET_CORE_disconnect(pos->peer1handle);
225 pos->peer1handle = NULL;
227 if (pos->peer2handle != NULL)
229 GNUNET_CORE_disconnect(pos->peer2handle);
230 pos->peer2handle = NULL;
234 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
236 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
238 GNUNET_free(free_pos);
241 pos = other_test_messages;
244 if (pos->peer1handle != NULL)
246 GNUNET_CORE_disconnect(pos->peer1handle);
247 pos->peer1handle = NULL;
249 if (pos->peer2handle != NULL)
251 GNUNET_CORE_disconnect(pos->peer2handle);
252 pos->peer2handle = NULL;
256 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
258 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
260 GNUNET_free(free_pos);
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "Calling daemons_stop\n");
271 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "daemons_stop finished\n");
276 if (dotOutFile != NULL)
278 fprintf(dotOutFile, "}");
287 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
289 struct TestMessageContext *pos = cls;
291 /* Disconnect from the respective cores */
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
296 if (pos->peer1handle != NULL)
297 GNUNET_CORE_disconnect(pos->peer1handle);
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
302 if (pos->peer2handle != NULL)
303 GNUNET_CORE_disconnect(pos->peer2handle);
304 /* Set handles to NULL so test case can be ended properly */
305 pos->peer1handle = NULL;
306 pos->peer2handle = NULL;
307 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
308 /* Decrement total connections so new can be established */
309 total_server_connections -= 2;
313 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
316 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
317 "End badly was called (%s)... stopping daemons.\n", msg);
318 struct TestMessageContext *pos;
319 struct TestMessageContext *free_pos;
320 struct PeerContext * peer_pos;
321 struct PeerContext * free_peer_pos;
323 peer_pos = all_peers;
324 while (peer_pos != NULL)
326 if (peer_pos->peer_handle != NULL)
327 GNUNET_CORE_disconnect(peer_pos->peer_handle);
328 free_peer_pos = peer_pos;
329 peer_pos = peer_pos->next;
330 GNUNET_free(free_peer_pos);
337 if (pos->peer1handle != NULL)
339 GNUNET_CORE_disconnect(pos->peer1handle);
340 pos->peer1handle = NULL;
342 if (pos->peer2handle != NULL)
344 GNUNET_CORE_disconnect(pos->peer2handle);
345 pos->peer2handle = NULL;
349 GNUNET_free(free_pos);
352 pos = other_test_messages;
355 if (pos->peer1handle != NULL)
357 GNUNET_CORE_disconnect(pos->peer1handle);
358 pos->peer1handle = NULL;
360 if (pos->peer2handle != NULL)
362 GNUNET_CORE_disconnect(pos->peer2handle);
363 pos->peer2handle = NULL;
367 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
369 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
371 GNUNET_free(free_pos);
376 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
377 ok = 7331; /* Opposite of leet */
380 ok = 401; /* Never got peers started */
382 if (dotOutFile != NULL)
384 fprintf(dotOutFile, "}");
390 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
393 process_mtype (void *cls,
394 const struct GNUNET_PeerIdentity *peer,
395 const struct GNUNET_MessageHeader *message,
396 struct GNUNET_TIME_Relative latency,
399 struct TestMessageContext *pos = cls;
400 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
401 if (pos->uid != ntohl(msg->uid))
404 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
405 if (total_other_expected_messages == 0)
407 total_messages_received++;
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
417 total_other_messages++;
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
420 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
422 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
426 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
428 GNUNET_SCHEDULER_cancel (sched, die_task);
429 die_task = GNUNET_SCHEDULER_add_delayed (sched,
431 &end_badly, "waiting for DV peers to connect!");
433 if ((num_peers == 3) && (total_other_expected_messages == 2))
435 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
439 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
442 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
444 GNUNET_SCHEDULER_cancel (sched, die_task);
445 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
449 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
456 transmit_ready (void *cls, size_t size, void *buf)
458 struct GNUNET_TestMessage *m;
459 struct TestMessageContext *pos = cls;
461 GNUNET_assert (buf != NULL);
462 m = (struct GNUNET_TestMessage *) buf;
463 m->header.type = htons (MTYPE);
464 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
465 m->uid = htonl(pos->uid);
466 transmit_ready_called++;
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "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);
471 return sizeof (struct GNUNET_TestMessage);
475 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
479 static struct GNUNET_CORE_MessageHandler handlers[] = {
480 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
485 init_notify_peer2 (void *cls,
486 struct GNUNET_CORE_Handle *server,
487 const struct GNUNET_PeerIdentity *my_identity,
488 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
490 struct TestMessageContext *pos = cls;
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
494 "Core connection to `%4s' established, scheduling message send\n",
495 GNUNET_i2s (my_identity));
497 total_server_connections++;
499 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
503 sizeof (struct GNUNET_TestMessage),
504 &transmit_ready, pos))
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
508 GNUNET_i2s (&pos->peer2->id));
509 transmit_ready_failed++;
513 transmit_ready_scheduled++;
519 init_notify_peer1 (void *cls,
520 struct GNUNET_CORE_Handle *server,
521 const struct GNUNET_PeerIdentity *my_identity,
522 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
524 struct TestMessageContext *pos = cls;
525 total_server_connections++;
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "Core connection to `%4s' established, setting up handles\n",
530 GNUNET_i2s (my_identity));
534 * Connect to the receiving peer
536 pos->peer2handle = GNUNET_CORE_connect (sched,
544 GNUNET_YES, NULL, GNUNET_YES, handlers);
550 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
552 struct TestMessageContext *pos = cls;
554 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
557 if (die_task == GNUNET_SCHEDULER_NO_TASK)
559 die_task = GNUNET_SCHEDULER_add_delayed (sched,
561 &end_badly, "from create topology (timeout)");
564 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
566 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
567 &send_test_messages, pos);
568 return; /* Otherwise we'll double schedule messages here! */
571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
574 * Connect to the sending peer
576 pos->peer1handle = GNUNET_CORE_connect (sched,
584 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
586 GNUNET_assert(pos->peer1handle != NULL);
588 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
590 GNUNET_SCHEDULER_add_now (sched,
591 &send_test_messages, pos->next);
595 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
596 &send_test_messages, pos->next);
601 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
603 struct TestMessageContext *pos;
604 struct TestMessageContext *free_pos;
605 struct PeerContext *peer_pos;
607 struct PeerContext *inner_peer_pos;
608 struct TestMessageContext *temp_context;
610 peer_pos = all_peers;
611 while (peer_pos != NULL)
613 if (peer_pos->peer_handle != NULL)
615 GNUNET_CORE_disconnect(peer_pos->peer_handle);
616 peer_pos->peer_handle = NULL;
619 inner_peer_pos = all_peers;
620 while (inner_peer_pos != NULL)
622 if (inner_peer_pos != peer_pos)
624 temp_total_other_messages++;
625 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
626 temp_context->peer1 = peer_pos->daemon;
627 temp_context->peer2 = inner_peer_pos->daemon;
628 temp_context->next = other_test_messages;
629 temp_context->uid = total_connections + temp_total_other_messages;
630 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
631 other_test_messages = temp_context;
633 inner_peer_pos = inner_peer_pos->next;
636 peer_pos = peer_pos->next;
643 if (pos->peer1handle != NULL)
645 GNUNET_CORE_disconnect(pos->peer1handle);
646 pos->peer1handle = NULL;
648 if (pos->peer2handle != NULL)
650 GNUNET_CORE_disconnect(pos->peer2handle);
651 pos->peer2handle = NULL;
655 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
657 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
659 GNUNET_free(free_pos);
661 test_messages = NULL;
663 total_other_expected_messages = temp_total_other_messages;
664 if (total_other_expected_messages == 0)
666 GNUNET_SCHEDULER_add_now (sched, &end_badly, "send_other_messages had 0 messages to send, no DV connections made!");
669 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
672 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
673 GNUNET_SCHEDULER_cancel(sched, die_task);
674 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
678 topology_callback (void *cls,
679 const struct GNUNET_PeerIdentity *first,
680 const struct GNUNET_PeerIdentity *second,
682 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
683 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
684 struct GNUNET_TESTING_Daemon *first_daemon,
685 struct GNUNET_TESTING_Daemon *second_daemon,
688 struct TestMessageContext *temp_context;
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
694 first_daemon->shortname,
695 second_daemon->shortname,
698 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
699 temp_context->peer1 = first_daemon;
700 temp_context->peer2 = second_daemon;
701 temp_context->next = test_messages;
702 temp_context->uid = total_connections;
703 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
704 test_messages = temp_context;
712 failed_connections++;
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
714 first_daemon->shortname,
715 second_daemon->shortname, emsg);
719 if (total_connections == expected_connections)
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Created %u total connections, which is our target number! Calling send messages.\n",
727 GNUNET_SCHEDULER_cancel (sched, die_task);
728 die_task = GNUNET_SCHEDULER_NO_TASK;
729 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
731 else if (total_connections + failed_connections == expected_connections)
733 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
735 GNUNET_SCHEDULER_cancel (sched, die_task);
736 die_task = GNUNET_SCHEDULER_NO_TASK;
737 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
741 GNUNET_SCHEDULER_cancel (sched, die_task);
742 die_task = GNUNET_SCHEDULER_add_now (sched,
743 &end_badly, "from topology_callback (too many failed connections)");
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
751 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
759 expected_connections = -1;
760 if ((pg != NULL) && (peers_left == 0))
762 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
765 "Have %d expected connections\n", expected_connections);
769 GNUNET_SCHEDULER_cancel (sched, die_task);
770 if (expected_connections == GNUNET_SYSERR)
772 die_task = GNUNET_SCHEDULER_add_now (sched,
773 &end_badly, "from connect topology (bad return)");
776 die_task = GNUNET_SCHEDULER_add_delayed (sched,
778 &end_badly, "from connect topology (timeout)");
784 peers_left = num_peers; /* Reset counter */
785 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 "Topology set up, now starting peers!\n");
791 GNUNET_TESTING_daemons_continue_startup(pg);
795 GNUNET_SCHEDULER_cancel (sched, die_task);
796 die_task = GNUNET_SCHEDULER_add_now (sched,
797 &end_badly, "from create topology (bad return)");
799 GNUNET_SCHEDULER_cancel (sched, die_task);
800 die_task = GNUNET_SCHEDULER_add_delayed (sched,
802 &end_badly, "from continue startup (timeout)");
806 * Method called whenever a given peer connects.
809 * @param peer peer identity this notification is about
810 * @param latency reported latency of the connection with 'other'
811 * @param distance reported distance (DV) to 'other'
813 static void all_connect_handler (void *cls,
815 GNUNET_PeerIdentity * peer,
816 struct GNUNET_TIME_Relative latency,
819 struct GNUNET_TESTING_Daemon *d = cls;
820 struct GNUNET_TESTING_Daemon *second_daemon;
821 char *second_shortname = strdup(GNUNET_i2s(peer));
823 struct TestMessageContext *temp_context;
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
832 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
834 if (second_daemon == NULL)
836 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
842 temp_total_other_messages++;
843 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
844 temp_context->peer1 = d;
845 temp_context->peer2 = second_daemon;
846 temp_context->next = other_test_messages;
847 temp_context->uid = total_connections + temp_total_other_messages;
848 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
849 other_test_messages = temp_context;
854 if (dotOutFile != NULL)
857 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
858 else if (distance == 2)
859 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
860 else if (distance == 3)
861 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
862 else if (distance == 4)
863 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
865 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
867 GNUNET_free(second_shortname);
869 if (temp_total_other_messages == num_additional_messages)
871 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
876 peers_started_callback (void *cls,
877 const struct GNUNET_PeerIdentity *id,
878 const struct GNUNET_CONFIGURATION_Handle *cfg,
879 struct GNUNET_TESTING_Daemon *d, const char *emsg)
881 struct PeerContext *new_peer;
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
888 GNUNET_assert (id != NULL);
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
891 (num_peers - peers_left) + 1, num_peers);
893 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
895 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
896 new_peer->peer_handle = GNUNET_CORE_connect(sched, cfg, GNUNET_TIME_UNIT_FOREVER_REL, d, NULL, &all_connect_handler, NULL, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
897 new_peer->daemon = d;
898 new_peer->next = all_peers;
899 all_peers = new_peer;
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
906 "All %d daemons started, now creating topology!\n",
909 GNUNET_SCHEDULER_cancel (sched, die_task);
910 /* Set up task in case topology creation doesn't finish
911 * within a reasonable amount of time */
912 die_task = GNUNET_SCHEDULER_add_delayed (sched,
913 GNUNET_TIME_relative_multiply
914 (GNUNET_TIME_UNIT_MINUTES, 5),
915 &end_badly, "from peers_started_callback");
923 * Callback indicating that the hostkey was created for a peer.
926 * @param id the peer identity
927 * @param d the daemon handle (pretty useless at this point, remove?)
928 * @param emsg non-null on failure
930 void hostkey_callback (void *cls,
931 const struct GNUNET_PeerIdentity *id,
932 struct GNUNET_TESTING_Daemon *d,
937 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
942 "Hostkey created for peer `%s'\n",
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "All %d hostkeys created, now creating topology!\n",
953 GNUNET_SCHEDULER_cancel (sched, die_task);
954 /* Set up task in case topology creation doesn't finish
955 * within a reasonable amount of time */
956 die_task = GNUNET_SCHEDULER_add_delayed (sched,
957 GNUNET_TIME_relative_multiply
958 (GNUNET_TIME_UNIT_MINUTES, 5),
959 &end_badly, "from hostkey_callback");
960 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
967 struct GNUNET_SCHEDULER_Handle *s,
969 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
972 char * connect_topology_str;
973 char * blacklist_topology_str;
974 char * connect_topology_option_str;
975 char * connect_topology_option_modifier_string;
979 dotOutFile = fopen (dotOutFileName, "w");
980 if (dotOutFile != NULL)
982 fprintf (dotOutFile, "strict graph G {\n");
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Starting daemons based on config file %s\n", cfgfile);
990 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
997 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
998 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
1000 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1001 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
1002 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1006 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
1007 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
1009 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1010 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1012 GNUNET_free_non_null(connect_topology_str);
1014 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
1015 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
1017 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1018 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
1019 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1021 GNUNET_free_non_null(connect_topology_option_str);
1023 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
1024 &connect_topology_option_modifier_string))
1026 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1028 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1029 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1030 connect_topology_option_modifier_string,
1031 "connect_topology_option_modifier",
1034 GNUNET_free (connect_topology_option_modifier_string);
1037 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1038 &blacklist_transports))
1039 blacklist_transports = NULL;
1042 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1043 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1045 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1046 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1048 GNUNET_free_non_null(topology_str);
1049 GNUNET_free_non_null(blacklist_topology_str);
1050 if (GNUNET_SYSERR ==
1051 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1053 num_peers = DEFAULT_NUM_PEERS;
1055 if (GNUNET_SYSERR ==
1056 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "additional_messages",
1057 &num_additional_messages))
1058 num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES;
1062 peers_left = num_peers;
1064 /* Set up a task to end testing if peer start fails */
1065 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1066 GNUNET_TIME_relative_multiply
1067 (GNUNET_TIME_UNIT_MINUTES, 5),
1068 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
1070 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
1071 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1072 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
1073 &topology_callback, NULL, NULL);
1081 char *const argv[] = {"test-transport-dv",
1083 "test_transport_dv_data.conf",
1089 struct GNUNET_GETOPT_CommandLineOption options[] = {
1090 GNUNET_GETOPT_OPTION_END
1092 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1093 argv, "test-transport-dv", "nohelp",
1094 options, &run, &ok);
1095 if (ret != GNUNET_OK)
1097 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret);
1103 main (int argc, char *argv[])
1107 GNUNET_log_setup ("test-transport-dv",
1116 * Need to remove base directory, subdirectories taken care
1117 * of by the testing framework.
1119 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1121 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1126 /* end of test_transport_api_dv.c */