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 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;
172 GNUNET_assert (pg != NULL);
173 struct PeerContext *peer_pos;
174 struct PeerContext *free_peer_pos;
175 struct TestMessageContext *pos;
176 struct TestMessageContext *free_pos;
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
181 "Called finish testing, stopping daemons.\n");
183 peer_pos = all_peers;
184 while (peer_pos != NULL)
186 if (peer_pos->peer_handle != NULL)
187 GNUNET_CORE_disconnect(peer_pos->peer_handle);
188 free_peer_pos = peer_pos;
189 peer_pos = peer_pos->next;
190 GNUNET_free(free_peer_pos);
198 if (pos->peer1handle != NULL)
200 GNUNET_CORE_disconnect(pos->peer1handle);
201 pos->peer1handle = NULL;
203 if (pos->peer2handle != NULL)
205 GNUNET_CORE_disconnect(pos->peer2handle);
206 pos->peer2handle = NULL;
210 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
212 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
214 GNUNET_free(free_pos);
217 pos = other_test_messages;
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 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Calling daemons_stop\n");
247 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "daemons_stop finished\n");
252 if (dotOutFile != NULL)
254 fprintf(dotOutFile, "}");
263 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
265 struct TestMessageContext *pos = cls;
267 /* Disconnect from the respective cores */
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
272 if (pos->peer1handle != NULL)
273 GNUNET_CORE_disconnect(pos->peer1handle);
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
276 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
278 if (pos->peer2handle != NULL)
279 GNUNET_CORE_disconnect(pos->peer2handle);
280 /* Set handles to NULL so test case can be ended properly */
281 pos->peer1handle = NULL;
282 pos->peer2handle = NULL;
283 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
284 /* Decrement total connections so new can be established */
285 total_server_connections -= 2;
289 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
292 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
293 "End badly was called (%s)... stopping daemons.\n", msg);
294 struct TestMessageContext *pos;
295 struct TestMessageContext *free_pos;
296 struct PeerContext * peer_pos;
297 struct PeerContext * free_peer_pos;
299 peer_pos = all_peers;
300 while (peer_pos != NULL)
302 if (peer_pos->peer_handle != NULL)
303 GNUNET_CORE_disconnect(peer_pos->peer_handle);
304 free_peer_pos = peer_pos;
305 peer_pos = peer_pos->next;
306 GNUNET_free(free_peer_pos);
313 if (pos->peer1handle != NULL)
315 GNUNET_CORE_disconnect(pos->peer1handle);
316 pos->peer1handle = NULL;
318 if (pos->peer2handle != NULL)
320 GNUNET_CORE_disconnect(pos->peer2handle);
321 pos->peer2handle = NULL;
325 GNUNET_free(free_pos);
328 pos = other_test_messages;
331 if (pos->peer1handle != NULL)
333 GNUNET_CORE_disconnect(pos->peer1handle);
334 pos->peer1handle = NULL;
336 if (pos->peer2handle != NULL)
338 GNUNET_CORE_disconnect(pos->peer2handle);
339 pos->peer2handle = NULL;
343 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
345 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
347 GNUNET_free(free_pos);
352 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
353 ok = 7331; /* Opposite of leet */
356 ok = 401; /* Never got peers started */
358 if (dotOutFile != NULL)
360 fprintf(dotOutFile, "}");
366 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
369 process_mtype (void *cls,
370 const struct GNUNET_PeerIdentity *peer,
371 const struct GNUNET_MessageHeader *message,
372 struct GNUNET_TIME_Relative latency,
375 struct TestMessageContext *pos = cls;
376 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
377 if (pos->uid != ntohl(msg->uid))
380 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
381 if (total_other_expected_messages == 0)
383 total_messages_received++;
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
388 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
393 total_other_messages++;
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
402 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
404 GNUNET_SCHEDULER_cancel (sched, die_task);
405 die_task = GNUNET_SCHEDULER_add_delayed (sched,
407 &end_badly, "waiting for DV peers to connect!");
409 if ((num_peers == 3) && (total_other_expected_messages == 2))
411 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
415 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
418 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
420 GNUNET_SCHEDULER_cancel (sched, die_task);
421 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
425 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
432 transmit_ready (void *cls, size_t size, void *buf)
434 struct GNUNET_TestMessage *m;
435 struct TestMessageContext *pos = cls;
437 GNUNET_assert (buf != NULL);
438 m = (struct GNUNET_TestMessage *) buf;
439 m->header.type = htons (MTYPE);
440 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
441 m->uid = htonl(pos->uid);
442 transmit_ready_called++;
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "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);
447 return sizeof (struct GNUNET_TestMessage);
451 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
455 static struct GNUNET_CORE_MessageHandler handlers[] = {
456 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
461 init_notify_peer2 (void *cls,
462 struct GNUNET_CORE_Handle *server,
463 const struct GNUNET_PeerIdentity *my_identity,
464 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
466 struct TestMessageContext *pos = cls;
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 "Core connection to `%4s' established, scheduling message send\n",
471 GNUNET_i2s (my_identity));
473 total_server_connections++;
475 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
479 sizeof (struct GNUNET_TestMessage),
480 &transmit_ready, pos))
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
484 GNUNET_i2s (&pos->peer2->id));
485 transmit_ready_failed++;
489 transmit_ready_scheduled++;
495 init_notify_peer1 (void *cls,
496 struct GNUNET_CORE_Handle *server,
497 const struct GNUNET_PeerIdentity *my_identity,
498 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
500 struct TestMessageContext *pos = cls;
501 total_server_connections++;
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Core connection to `%4s' established, setting up handles\n",
506 GNUNET_i2s (my_identity));
510 * Connect to the receiving peer
512 pos->peer2handle = GNUNET_CORE_connect (sched,
520 GNUNET_YES, NULL, GNUNET_YES, handlers);
526 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
528 struct TestMessageContext *pos = cls;
530 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
533 if (die_task == GNUNET_SCHEDULER_NO_TASK)
535 die_task = GNUNET_SCHEDULER_add_delayed (sched,
537 &end_badly, "from create topology (timeout)");
540 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
542 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
543 &send_test_messages, pos);
544 return; /* Otherwise we'll double schedule messages here! */
547 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
550 * Connect to the sending peer
552 pos->peer1handle = GNUNET_CORE_connect (sched,
560 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
562 GNUNET_assert(pos->peer1handle != NULL);
564 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
566 GNUNET_SCHEDULER_add_now (sched,
567 &send_test_messages, pos->next);
571 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
572 &send_test_messages, pos->next);
577 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
579 struct TestMessageContext *pos;
580 struct TestMessageContext *free_pos;
581 struct PeerContext *peer_pos;
583 struct PeerContext *inner_peer_pos;
584 struct TestMessageContext *temp_context;
586 peer_pos = all_peers;
587 while (peer_pos != NULL)
589 if (peer_pos->peer_handle != NULL)
591 GNUNET_CORE_disconnect(peer_pos->peer_handle);
592 peer_pos->peer_handle = NULL;
595 inner_peer_pos = all_peers;
596 while (inner_peer_pos != NULL)
598 if (inner_peer_pos != peer_pos)
600 temp_total_other_messages++;
601 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
602 temp_context->peer1 = peer_pos->daemon;
603 temp_context->peer2 = inner_peer_pos->daemon;
604 temp_context->next = other_test_messages;
605 temp_context->uid = total_connections + temp_total_other_messages;
606 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
607 other_test_messages = temp_context;
609 inner_peer_pos = inner_peer_pos->next;
612 peer_pos = peer_pos->next;
619 if (pos->peer1handle != NULL)
621 GNUNET_CORE_disconnect(pos->peer1handle);
622 pos->peer1handle = NULL;
624 if (pos->peer2handle != NULL)
626 GNUNET_CORE_disconnect(pos->peer2handle);
627 pos->peer2handle = NULL;
631 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
633 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
635 GNUNET_free(free_pos);
637 test_messages = NULL;
639 total_other_expected_messages = temp_total_other_messages;
640 if (total_other_expected_messages == 0)
642 GNUNET_SCHEDULER_add_now (sched, &end_badly, "send_other_messages had 0 messages to send, no DV connections made!");
645 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
648 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
649 GNUNET_SCHEDULER_cancel(sched, die_task);
650 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
654 topology_callback (void *cls,
655 const struct GNUNET_PeerIdentity *first,
656 const struct GNUNET_PeerIdentity *second,
658 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
659 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
660 struct GNUNET_TESTING_Daemon *first_daemon,
661 struct GNUNET_TESTING_Daemon *second_daemon,
664 struct TestMessageContext *temp_context;
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
670 first_daemon->shortname,
671 second_daemon->shortname,
674 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
675 temp_context->peer1 = first_daemon;
676 temp_context->peer2 = second_daemon;
677 temp_context->next = test_messages;
678 temp_context->uid = total_connections;
679 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
680 test_messages = temp_context;
688 failed_connections++;
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
690 first_daemon->shortname,
691 second_daemon->shortname, emsg);
695 if (total_connections == expected_connections)
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Created %d total connections, which is our target number! Calling send messages.\n",
703 GNUNET_SCHEDULER_cancel (sched, die_task);
704 die_task = GNUNET_SCHEDULER_NO_TASK;
705 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
707 else if (total_connections + failed_connections == expected_connections)
709 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
711 GNUNET_SCHEDULER_cancel (sched, die_task);
712 die_task = GNUNET_SCHEDULER_NO_TASK;
713 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
717 GNUNET_SCHEDULER_cancel (sched, die_task);
718 die_task = GNUNET_SCHEDULER_add_now (sched,
719 &end_badly, "from topology_callback (too many failed connections)");
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
727 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
735 expected_connections = -1;
736 if ((pg != NULL) && (peers_left == 0))
738 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 "Have %d expected connections\n", expected_connections);
745 GNUNET_SCHEDULER_cancel (sched, die_task);
746 if (expected_connections == GNUNET_SYSERR)
748 die_task = GNUNET_SCHEDULER_add_now (sched,
749 &end_badly, "from connect topology (bad return)");
752 die_task = GNUNET_SCHEDULER_add_delayed (sched,
754 &end_badly, "from connect topology (timeout)");
760 peers_left = num_peers; /* Reset counter */
761 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
765 "Topology set up, now starting peers!\n");
767 GNUNET_TESTING_daemons_continue_startup(pg);
771 GNUNET_SCHEDULER_cancel (sched, die_task);
772 die_task = GNUNET_SCHEDULER_add_now (sched,
773 &end_badly, "from create topology (bad return)");
775 GNUNET_SCHEDULER_cancel (sched, die_task);
776 die_task = GNUNET_SCHEDULER_add_delayed (sched,
778 &end_badly, "from continue startup (timeout)");
782 * Method called whenever a given peer connects.
785 * @param peer peer identity this notification is about
786 * @param latency reported latency of the connection with 'other'
787 * @param distance reported distance (DV) to 'other'
789 static void all_connect_handler (void *cls,
791 GNUNET_PeerIdentity * peer,
792 struct GNUNET_TIME_Relative latency,
795 struct GNUNET_TESTING_Daemon *d = cls;
796 struct GNUNET_TESTING_Daemon *second_daemon;
797 char *second_shortname = strdup(GNUNET_i2s(peer));
799 struct TestMessageContext *temp_context;
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
808 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
810 if (second_daemon == NULL)
812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
818 temp_total_other_messages++;
819 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
820 temp_context->peer1 = d;
821 temp_context->peer2 = second_daemon;
822 temp_context->next = other_test_messages;
823 temp_context->uid = total_connections + temp_total_other_messages;
824 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
825 other_test_messages = temp_context;
830 if (dotOutFile != NULL)
833 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
834 else if (distance == 2)
835 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
836 else if (distance == 3)
837 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
838 else if (distance == 4)
839 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
841 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
843 GNUNET_free(second_shortname);
845 if (temp_total_other_messages == num_additional_messages)
847 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
852 peers_started_callback (void *cls,
853 const struct GNUNET_PeerIdentity *id,
854 const struct GNUNET_CONFIGURATION_Handle *cfg,
855 struct GNUNET_TESTING_Daemon *d, const char *emsg)
857 struct PeerContext *new_peer;
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
864 GNUNET_assert (id != NULL);
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
867 (num_peers - peers_left) + 1, num_peers);
869 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
871 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
872 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);
873 new_peer->daemon = d;
874 new_peer->next = all_peers;
875 all_peers = new_peer;
881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 "All %d daemons started, now creating topology!\n",
885 GNUNET_SCHEDULER_cancel (sched, die_task);
886 /* Set up task in case topology creation doesn't finish
887 * within a reasonable amount of time */
888 die_task = GNUNET_SCHEDULER_add_delayed (sched,
889 GNUNET_TIME_relative_multiply
890 (GNUNET_TIME_UNIT_MINUTES, 5),
891 &end_badly, "from peers_started_callback");
899 * Callback indicating that the hostkey was created for a peer.
902 * @param id the peer identity
903 * @param d the daemon handle (pretty useless at this point, remove?)
904 * @param emsg non-null on failure
906 void hostkey_callback (void *cls,
907 const struct GNUNET_PeerIdentity *id,
908 struct GNUNET_TESTING_Daemon *d,
913 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 "Hostkey created for peer `%s'\n",
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "All %d hostkeys created, now creating topology!\n",
929 GNUNET_SCHEDULER_cancel (sched, die_task);
930 /* Set up task in case topology creation doesn't finish
931 * within a reasonable amount of time */
932 die_task = GNUNET_SCHEDULER_add_delayed (sched,
933 GNUNET_TIME_relative_multiply
934 (GNUNET_TIME_UNIT_MINUTES, 5),
935 &end_badly, "from hostkey_callback");
936 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
943 struct GNUNET_SCHEDULER_Handle *s,
945 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
948 char * connect_topology_str;
949 char * blacklist_topology_str;
950 char * connect_topology_option_str;
951 char * connect_topology_option_modifier_string;
955 dotOutFile = fopen (dotOutFileName, "w");
956 if (dotOutFile != NULL)
958 fprintf (dotOutFile, "strict graph G {\n");
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Starting daemons based on config file %s\n", cfgfile);
966 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
973 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
974 &topology_str)) && (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", topology_str, "TESTING", "TOPOLOGY");
978 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
982 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
983 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
985 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
986 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
988 GNUNET_free_non_null(connect_topology_str);
990 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
991 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
993 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
994 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
995 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
997 GNUNET_free_non_null(connect_topology_option_str);
999 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
1000 &connect_topology_option_modifier_string))
1002 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1004 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1005 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1006 connect_topology_option_modifier_string,
1007 "connect_topology_option_modifier",
1010 GNUNET_free (connect_topology_option_modifier_string);
1013 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1014 &blacklist_transports))
1015 blacklist_transports = NULL;
1018 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1019 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1021 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1022 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1024 GNUNET_free_non_null(topology_str);
1025 GNUNET_free_non_null(blacklist_topology_str);
1026 if (GNUNET_SYSERR ==
1027 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1029 num_peers = DEFAULT_NUM_PEERS;
1031 if (GNUNET_SYSERR ==
1032 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "additional_messages",
1033 &num_additional_messages))
1034 num_additional_messages = DEFAULT_ADDITIONAL_MESSAGES;
1038 peers_left = num_peers;
1040 /* Set up a task to end testing if peer start fails */
1041 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1042 GNUNET_TIME_relative_multiply
1043 (GNUNET_TIME_UNIT_MINUTES, 5),
1044 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
1046 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
1047 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1048 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
1049 &topology_callback, NULL, NULL);
1057 char *const argv[] = {"test-transport-dv",
1059 "test_transport_dv_data.conf",
1065 struct GNUNET_GETOPT_CommandLineOption options[] = {
1066 GNUNET_GETOPT_OPTION_END
1068 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1069 argv, "test-transport-dv", "nohelp",
1070 options, &run, &ok);
1071 if (ret != GNUNET_OK)
1073 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret);
1079 main (int argc, char *argv[])
1083 GNUNET_log_setup ("test-transport-dv",
1092 * Need to remove base directory, subdirectories taken care
1093 * of by the testing framework.
1095 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1097 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1102 /* end of test_testing_topology.c */