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;
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
204 "Called finish testing, stopping daemons.\n");
206 peer_pos = all_peers;
207 while (peer_pos != NULL)
209 if (peer_pos->peer_handle != NULL)
210 GNUNET_CORE_disconnect(peer_pos->peer_handle);
211 free_peer_pos = peer_pos;
212 peer_pos = peer_pos->next;
213 GNUNET_free(free_peer_pos);
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(sched, free_pos->disconnect_task);
236 GNUNET_free(free_pos);
239 pos = other_test_messages;
242 if (pos->peer1handle != NULL)
244 GNUNET_CORE_disconnect(pos->peer1handle);
245 pos->peer1handle = NULL;
247 if (pos->peer2handle != NULL)
249 GNUNET_CORE_disconnect(pos->peer2handle);
250 pos->peer2handle = NULL;
254 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
256 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
258 GNUNET_free(free_pos);
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
267 "Calling daemons_stop\n");
269 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "daemons_stop finished\n");
274 if (dotOutFile != NULL)
276 fprintf(dotOutFile, "}");
285 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
287 struct TestMessageContext *pos = cls;
289 /* Disconnect from the respective cores */
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
294 if (pos->peer1handle != NULL)
295 GNUNET_CORE_disconnect(pos->peer1handle);
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
300 if (pos->peer2handle != NULL)
301 GNUNET_CORE_disconnect(pos->peer2handle);
302 /* Set handles to NULL so test case can be ended properly */
303 pos->peer1handle = NULL;
304 pos->peer2handle = NULL;
305 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
306 /* Decrement total connections so new can be established */
307 total_server_connections -= 2;
311 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
315 "End badly was called (%s)... stopping daemons.\n", msg);
316 struct TestMessageContext *pos;
317 struct TestMessageContext *free_pos;
318 struct PeerContext * peer_pos;
319 struct PeerContext * free_peer_pos;
321 peer_pos = all_peers;
322 while (peer_pos != NULL)
324 if (peer_pos->peer_handle != NULL)
325 GNUNET_CORE_disconnect(peer_pos->peer_handle);
326 free_peer_pos = peer_pos;
327 peer_pos = peer_pos->next;
328 GNUNET_free(free_peer_pos);
335 if (pos->peer1handle != NULL)
337 GNUNET_CORE_disconnect(pos->peer1handle);
338 pos->peer1handle = NULL;
340 if (pos->peer2handle != NULL)
342 GNUNET_CORE_disconnect(pos->peer2handle);
343 pos->peer2handle = NULL;
347 GNUNET_free(free_pos);
350 pos = other_test_messages;
353 if (pos->peer1handle != NULL)
355 GNUNET_CORE_disconnect(pos->peer1handle);
356 pos->peer1handle = NULL;
358 if (pos->peer2handle != NULL)
360 GNUNET_CORE_disconnect(pos->peer2handle);
361 pos->peer2handle = NULL;
365 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
367 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
369 GNUNET_free(free_pos);
374 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
375 ok = 7331; /* Opposite of leet */
378 ok = 401; /* Never got peers started */
380 if (dotOutFile != NULL)
382 fprintf(dotOutFile, "}");
388 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
391 process_mtype (void *cls,
392 const struct GNUNET_PeerIdentity *peer,
393 const struct GNUNET_MessageHeader *message,
394 struct GNUNET_TIME_Relative latency,
397 struct TestMessageContext *pos = cls;
398 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
399 if (pos->uid != ntohl(msg->uid))
402 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
403 if (total_other_expected_messages == 0)
405 total_messages_received++;
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
415 total_other_messages++;
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
420 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
424 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
426 GNUNET_SCHEDULER_cancel (sched, die_task);
427 die_task = GNUNET_SCHEDULER_add_delayed (sched,
429 &end_badly, "waiting for DV peers to connect!");
431 if ((num_peers == 3) && (total_other_expected_messages == 2))
433 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
437 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
440 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
442 GNUNET_SCHEDULER_cancel (sched, die_task);
443 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
447 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
454 transmit_ready (void *cls, size_t size, void *buf)
456 struct GNUNET_TestMessage *m;
457 struct TestMessageContext *pos = cls;
459 GNUNET_assert (buf != NULL);
460 m = (struct GNUNET_TestMessage *) buf;
461 m->header.type = htons (MTYPE);
462 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
463 m->uid = htonl(pos->uid);
464 transmit_ready_called++;
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "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);
469 return sizeof (struct GNUNET_TestMessage);
473 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
477 static struct GNUNET_CORE_MessageHandler handlers[] = {
478 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
483 init_notify_peer2 (void *cls,
484 struct GNUNET_CORE_Handle *server,
485 const struct GNUNET_PeerIdentity *my_identity,
486 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
488 struct TestMessageContext *pos = cls;
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 "Core connection to `%4s' established, scheduling message send\n",
493 GNUNET_i2s (my_identity));
495 total_server_connections++;
497 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
501 sizeof (struct GNUNET_TestMessage),
502 &transmit_ready, pos))
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
506 GNUNET_i2s (&pos->peer2->id));
507 transmit_ready_failed++;
511 transmit_ready_scheduled++;
517 init_notify_peer1 (void *cls,
518 struct GNUNET_CORE_Handle *server,
519 const struct GNUNET_PeerIdentity *my_identity,
520 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
522 struct TestMessageContext *pos = cls;
523 total_server_connections++;
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Core connection to `%4s' established, setting up handles\n",
528 GNUNET_i2s (my_identity));
532 * Connect to the receiving peer
534 pos->peer2handle = GNUNET_CORE_connect (sched,
542 GNUNET_YES, NULL, GNUNET_YES, handlers);
548 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
550 struct TestMessageContext *pos = cls;
552 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
555 if (die_task == GNUNET_SCHEDULER_NO_TASK)
557 die_task = GNUNET_SCHEDULER_add_delayed (sched,
559 &end_badly, "from create topology (timeout)");
562 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
564 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
565 &send_test_messages, pos);
566 return; /* Otherwise we'll double schedule messages here! */
569 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
572 * Connect to the sending peer
574 pos->peer1handle = GNUNET_CORE_connect (sched,
582 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
584 GNUNET_assert(pos->peer1handle != NULL);
586 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
588 GNUNET_SCHEDULER_add_now (sched,
589 &send_test_messages, pos->next);
593 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
594 &send_test_messages, pos->next);
599 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
601 struct TestMessageContext *pos;
602 struct TestMessageContext *free_pos;
603 struct PeerContext *peer_pos;
605 struct PeerContext *inner_peer_pos;
606 struct TestMessageContext *temp_context;
608 peer_pos = all_peers;
609 while (peer_pos != NULL)
611 if (peer_pos->peer_handle != NULL)
613 GNUNET_CORE_disconnect(peer_pos->peer_handle);
614 peer_pos->peer_handle = NULL;
617 inner_peer_pos = all_peers;
618 while (inner_peer_pos != NULL)
620 if (inner_peer_pos != peer_pos)
622 temp_total_other_messages++;
623 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
624 temp_context->peer1 = peer_pos->daemon;
625 temp_context->peer2 = inner_peer_pos->daemon;
626 temp_context->next = other_test_messages;
627 temp_context->uid = total_connections + temp_total_other_messages;
628 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
629 other_test_messages = temp_context;
631 inner_peer_pos = inner_peer_pos->next;
634 peer_pos = peer_pos->next;
641 if (pos->peer1handle != NULL)
643 GNUNET_CORE_disconnect(pos->peer1handle);
644 pos->peer1handle = NULL;
646 if (pos->peer2handle != NULL)
648 GNUNET_CORE_disconnect(pos->peer2handle);
649 pos->peer2handle = NULL;
653 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
655 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
657 GNUNET_free(free_pos);
659 test_messages = NULL;
661 total_other_expected_messages = temp_total_other_messages;
662 if (total_other_expected_messages == 0)
664 GNUNET_SCHEDULER_add_now (sched, &end_badly, "send_other_messages had 0 messages to send, no DV connections made!");
667 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
670 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
671 GNUNET_SCHEDULER_cancel(sched, die_task);
672 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
676 topology_callback (void *cls,
677 const struct GNUNET_PeerIdentity *first,
678 const struct GNUNET_PeerIdentity *second,
680 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
681 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
682 struct GNUNET_TESTING_Daemon *first_daemon,
683 struct GNUNET_TESTING_Daemon *second_daemon,
686 struct TestMessageContext *temp_context;
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
692 first_daemon->shortname,
693 second_daemon->shortname,
696 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
697 temp_context->peer1 = first_daemon;
698 temp_context->peer2 = second_daemon;
699 temp_context->next = test_messages;
700 temp_context->uid = total_connections;
701 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
702 test_messages = temp_context;
710 failed_connections++;
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
712 first_daemon->shortname,
713 second_daemon->shortname, emsg);
717 if (total_connections == expected_connections)
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
721 "Created %u total connections, which is our target number! Calling send messages.\n",
725 GNUNET_SCHEDULER_cancel (sched, die_task);
726 die_task = GNUNET_SCHEDULER_NO_TASK;
727 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
729 else if (total_connections + failed_connections == expected_connections)
731 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
733 GNUNET_SCHEDULER_cancel (sched, die_task);
734 die_task = GNUNET_SCHEDULER_NO_TASK;
735 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
739 GNUNET_SCHEDULER_cancel (sched, die_task);
740 die_task = GNUNET_SCHEDULER_add_now (sched,
741 &end_badly, "from topology_callback (too many failed connections)");
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
749 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
757 expected_connections = -1;
758 if ((pg != NULL) && (peers_left == 0))
760 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "Have %d expected connections\n", expected_connections);
767 GNUNET_SCHEDULER_cancel (sched, die_task);
768 if (expected_connections == GNUNET_SYSERR)
770 die_task = GNUNET_SCHEDULER_add_now (sched,
771 &end_badly, "from connect topology (bad return)");
774 die_task = GNUNET_SCHEDULER_add_delayed (sched,
776 &end_badly, "from connect topology (timeout)");
782 peers_left = num_peers; /* Reset counter */
783 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "Topology set up, now starting peers!\n");
789 GNUNET_TESTING_daemons_continue_startup(pg);
793 GNUNET_SCHEDULER_cancel (sched, die_task);
794 die_task = GNUNET_SCHEDULER_add_now (sched,
795 &end_badly, "from create topology (bad return)");
797 GNUNET_SCHEDULER_cancel (sched, die_task);
798 die_task = GNUNET_SCHEDULER_add_delayed (sched,
800 &end_badly, "from continue startup (timeout)");
804 * Method called whenever a given peer connects.
807 * @param peer peer identity this notification is about
808 * @param latency reported latency of the connection with 'other'
809 * @param distance reported distance (DV) to 'other'
811 static void all_connect_handler (void *cls,
813 GNUNET_PeerIdentity * peer,
814 struct GNUNET_TIME_Relative latency,
817 struct GNUNET_TESTING_Daemon *d = cls;
818 struct GNUNET_TESTING_Daemon *second_daemon;
819 char *second_shortname = strdup(GNUNET_i2s(peer));
821 struct TestMessageContext *temp_context;
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
830 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
832 if (second_daemon == NULL)
834 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
835 GNUNET_free(second_shortname);
841 temp_total_other_messages++;
842 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
843 temp_context->peer1 = d;
844 temp_context->peer2 = second_daemon;
845 temp_context->next = other_test_messages;
846 temp_context->uid = total_connections + temp_total_other_messages;
847 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
848 other_test_messages = temp_context;
853 if (dotOutFile != NULL)
856 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
857 else if (distance == 2)
858 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
859 else if (distance == 3)
860 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
861 else if (distance == 4)
862 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
864 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
866 GNUNET_free(second_shortname);
868 if (temp_total_other_messages == num_additional_messages)
870 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
875 peers_started_callback (void *cls,
876 const struct GNUNET_PeerIdentity *id,
877 const struct GNUNET_CONFIGURATION_Handle *cfg,
878 struct GNUNET_TESTING_Daemon *d, const char *emsg)
880 struct PeerContext *new_peer;
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
887 GNUNET_assert (id != NULL);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
890 (num_peers - peers_left) + 1, num_peers);
892 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
894 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
895 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);
896 new_peer->daemon = d;
897 new_peer->next = all_peers;
898 all_peers = new_peer;
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
905 "All %d daemons started, now creating topology!\n",
908 GNUNET_SCHEDULER_cancel (sched, die_task);
909 /* Set up task in case topology creation doesn't finish
910 * within a reasonable amount of time */
911 die_task = GNUNET_SCHEDULER_add_delayed (sched,
912 GNUNET_TIME_relative_multiply
913 (GNUNET_TIME_UNIT_MINUTES, 5),
914 &end_badly, "from peers_started_callback");
922 * Callback indicating that the hostkey was created for a peer.
925 * @param id the peer identity
926 * @param d the daemon handle (pretty useless at this point, remove?)
927 * @param emsg non-null on failure
929 void hostkey_callback (void *cls,
930 const struct GNUNET_PeerIdentity *id,
931 struct GNUNET_TESTING_Daemon *d,
936 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
941 "Hostkey created for peer `%s'\n",
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
949 "All %d hostkeys created, now creating topology!\n",
952 GNUNET_SCHEDULER_cancel (sched, die_task);
953 /* Set up task in case topology creation doesn't finish
954 * within a reasonable amount of time */
955 die_task = GNUNET_SCHEDULER_add_delayed (sched,
956 GNUNET_TIME_relative_multiply
957 (GNUNET_TIME_UNIT_MINUTES, 5),
958 &end_badly, "from hostkey_callback");
959 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
966 struct GNUNET_SCHEDULER_Handle *s,
968 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
971 char * connect_topology_str;
972 char * blacklist_topology_str;
973 char * connect_topology_option_str;
974 char * connect_topology_option_modifier_string;
978 dotOutFile = fopen (dotOutFileName, "w");
979 if (dotOutFile != NULL)
981 fprintf (dotOutFile, "strict graph G {\n");
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986 "Starting daemons based on config file %s\n", cfgfile);
989 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
996 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
997 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
999 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1000 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
1001 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1005 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
1006 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
1008 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1009 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1011 GNUNET_free_non_null(connect_topology_str);
1013 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
1014 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
1016 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1017 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
1018 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1020 GNUNET_free_non_null(connect_topology_option_str);
1022 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
1023 &connect_topology_option_modifier_string))
1025 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1027 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1028 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1029 connect_topology_option_modifier_string,
1030 "connect_topology_option_modifier",
1033 GNUNET_free (connect_topology_option_modifier_string);
1036 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1037 &blacklist_transports))
1038 blacklist_transports = NULL;
1041 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1042 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1044 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1045 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1047 GNUNET_free_non_null(topology_str);
1048 GNUNET_free_non_null(blacklist_topology_str);
1049 if (GNUNET_SYSERR ==
1050 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1052 num_peers = DEFAULT_NUM_PEERS;
1054 if (GNUNET_SYSERR ==
1055 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "additional_messages",
1056 &num_additional_messages))
1057 num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES;
1061 GNUNET_assert(num_peers > 0 && num_peers < (unsigned int)-1);
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 */