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 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
289 "End badly was called (%s)... stopping daemons.\n", msg);
290 struct TestMessageContext *pos;
291 struct TestMessageContext *free_pos;
292 struct PeerContext * peer_pos;
293 struct PeerContext * free_peer_pos;
295 peer_pos = all_peers;
296 while (peer_pos != NULL)
298 if (peer_pos->peer_handle != NULL)
299 GNUNET_CORE_disconnect(peer_pos->peer_handle);
300 free_peer_pos = peer_pos;
301 peer_pos = peer_pos->next;
302 GNUNET_free(free_peer_pos);
309 if (pos->peer1handle != NULL)
311 GNUNET_CORE_disconnect(pos->peer1handle);
312 pos->peer1handle = NULL;
314 if (pos->peer2handle != NULL)
316 GNUNET_CORE_disconnect(pos->peer2handle);
317 pos->peer2handle = NULL;
321 GNUNET_free(free_pos);
324 pos = other_test_messages;
327 if (pos->peer1handle != NULL)
329 GNUNET_CORE_disconnect(pos->peer1handle);
330 pos->peer1handle = NULL;
332 if (pos->peer2handle != NULL)
334 GNUNET_CORE_disconnect(pos->peer2handle);
335 pos->peer2handle = NULL;
339 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
341 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
343 GNUNET_free(free_pos);
348 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
349 ok = 7331; /* Opposite of leet */
352 ok = 401; /* Never got peers started */
354 if (dotOutFile != NULL)
356 fprintf(dotOutFile, "}");
362 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
365 process_mtype (void *cls,
366 const struct GNUNET_PeerIdentity *peer,
367 const struct GNUNET_MessageHeader *message,
368 struct GNUNET_TIME_Relative latency,
371 struct TestMessageContext *pos = cls;
372 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
373 if (pos->uid != ntohl(msg->uid))
376 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
377 if (total_other_expected_messages == 0)
379 total_messages_received++;
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
384 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
389 total_other_messages++;
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
398 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
400 GNUNET_SCHEDULER_cancel (sched, die_task);
401 die_task = GNUNET_SCHEDULER_add_delayed (sched,
403 &end_badly, "waiting for DV peers to connect!");
405 if ((num_peers == 3) && (total_other_expected_messages == 2))
407 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
411 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
414 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
416 GNUNET_SCHEDULER_cancel (sched, die_task);
417 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
421 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
428 transmit_ready (void *cls, size_t size, void *buf)
430 struct GNUNET_TestMessage *m;
431 struct TestMessageContext *pos = cls;
433 GNUNET_assert (buf != NULL);
434 m = (struct GNUNET_TestMessage *) buf;
435 m->header.type = htons (MTYPE);
436 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
437 m->uid = htonl(pos->uid);
438 transmit_ready_called++;
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "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);
443 return sizeof (struct GNUNET_TestMessage);
447 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
451 static struct GNUNET_CORE_MessageHandler handlers[] = {
452 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
457 init_notify_peer2 (void *cls,
458 struct GNUNET_CORE_Handle *server,
459 const struct GNUNET_PeerIdentity *my_identity,
460 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
462 struct TestMessageContext *pos = cls;
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "Core connection to `%4s' established, scheduling message send\n",
467 GNUNET_i2s (my_identity));
469 total_server_connections++;
471 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
475 sizeof (struct GNUNET_TestMessage),
476 &transmit_ready, pos))
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
480 GNUNET_i2s (&pos->peer2->id));
481 transmit_ready_failed++;
485 transmit_ready_scheduled++;
491 init_notify_peer1 (void *cls,
492 struct GNUNET_CORE_Handle *server,
493 const struct GNUNET_PeerIdentity *my_identity,
494 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
496 struct TestMessageContext *pos = cls;
497 total_server_connections++;
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 "Core connection to `%4s' established, setting up handles\n",
502 GNUNET_i2s (my_identity));
506 * Connect to the receiving peer
508 pos->peer2handle = GNUNET_CORE_connect (sched,
516 GNUNET_YES, NULL, GNUNET_YES, handlers);
522 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
524 struct TestMessageContext *pos = cls;
526 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
529 if (die_task == GNUNET_SCHEDULER_NO_TASK)
531 die_task = GNUNET_SCHEDULER_add_delayed (sched,
533 &end_badly, "from create topology (timeout)");
536 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
538 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
539 &send_test_messages, pos);
540 return; /* Otherwise we'll double schedule messages here! */
543 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
546 * Connect to the sending peer
548 pos->peer1handle = GNUNET_CORE_connect (sched,
556 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
558 GNUNET_assert(pos->peer1handle != NULL);
560 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
562 GNUNET_SCHEDULER_add_now (sched,
563 &send_test_messages, pos->next);
567 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
568 &send_test_messages, pos->next);
573 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
575 struct TestMessageContext *pos;
576 struct TestMessageContext *free_pos;
577 struct PeerContext *peer_pos;
579 struct PeerContext *inner_peer_pos;
580 struct TestMessageContext *temp_context;
582 peer_pos = all_peers;
583 while (peer_pos != NULL)
585 if (peer_pos->peer_handle != NULL)
587 GNUNET_CORE_disconnect(peer_pos->peer_handle);
588 peer_pos->peer_handle = NULL;
591 inner_peer_pos = all_peers;
592 while (inner_peer_pos != NULL)
594 if (inner_peer_pos != peer_pos)
596 temp_total_other_messages++;
597 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
598 temp_context->peer1 = peer_pos->daemon;
599 temp_context->peer2 = inner_peer_pos->daemon;
600 temp_context->next = other_test_messages;
601 temp_context->uid = total_connections + temp_total_other_messages;
602 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
603 other_test_messages = temp_context;
605 inner_peer_pos = inner_peer_pos->next;
608 peer_pos = peer_pos->next;
615 if (pos->peer1handle != NULL)
617 GNUNET_CORE_disconnect(pos->peer1handle);
618 pos->peer1handle = NULL;
620 if (pos->peer2handle != NULL)
622 GNUNET_CORE_disconnect(pos->peer2handle);
623 pos->peer2handle = NULL;
627 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
629 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
631 GNUNET_free(free_pos);
633 test_messages = NULL;
635 total_other_expected_messages = temp_total_other_messages;
636 if (total_other_expected_messages == 0)
638 GNUNET_SCHEDULER_add_now (sched, &end_badly, "send_other_messages had 0 messages to send, no DV connections made!");
641 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
644 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
645 GNUNET_SCHEDULER_cancel(sched, die_task);
646 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
650 topology_callback (void *cls,
651 const struct GNUNET_PeerIdentity *first,
652 const struct GNUNET_PeerIdentity *second,
654 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
655 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
656 struct GNUNET_TESTING_Daemon *first_daemon,
657 struct GNUNET_TESTING_Daemon *second_daemon,
660 struct TestMessageContext *temp_context;
665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
666 first_daemon->shortname,
667 second_daemon->shortname,
670 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
671 temp_context->peer1 = first_daemon;
672 temp_context->peer2 = second_daemon;
673 temp_context->next = test_messages;
674 temp_context->uid = total_connections;
675 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
676 test_messages = temp_context;
684 failed_connections++;
685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
686 first_daemon->shortname,
687 second_daemon->shortname, emsg);
691 if (total_connections == expected_connections)
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "Created %d total connections, which is our target number! Calling send messages.\n",
699 GNUNET_SCHEDULER_cancel (sched, die_task);
700 die_task = GNUNET_SCHEDULER_NO_TASK;
701 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
702 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
704 else if (total_connections + failed_connections == expected_connections)
706 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
708 GNUNET_SCHEDULER_cancel (sched, die_task);
709 die_task = GNUNET_SCHEDULER_NO_TASK;
710 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
711 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
715 GNUNET_SCHEDULER_cancel (sched, die_task);
716 die_task = GNUNET_SCHEDULER_add_now (sched,
717 &end_badly, "from topology_callback (too many failed connections)");
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
725 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
733 expected_connections = -1;
734 if ((pg != NULL) && (peers_left == 0))
736 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 "Have %d expected connections\n", expected_connections);
743 GNUNET_SCHEDULER_cancel (sched, die_task);
744 if (expected_connections == GNUNET_SYSERR)
746 die_task = GNUNET_SCHEDULER_add_now (sched,
747 &end_badly, "from connect topology (bad return)");
750 die_task = GNUNET_SCHEDULER_add_delayed (sched,
752 &end_badly, "from connect topology (timeout)");
758 peers_left = num_peers; /* Reset counter */
759 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "Topology set up, now starting peers!\n");
765 GNUNET_TESTING_daemons_continue_startup(pg);
769 GNUNET_SCHEDULER_cancel (sched, die_task);
770 die_task = GNUNET_SCHEDULER_add_now (sched,
771 &end_badly, "from create topology (bad return)");
773 GNUNET_SCHEDULER_cancel (sched, die_task);
774 die_task = GNUNET_SCHEDULER_add_delayed (sched,
776 &end_badly, "from continue startup (timeout)");
780 * Method called whenever a given peer connects.
783 * @param peer peer identity this notification is about
784 * @param latency reported latency of the connection with 'other'
785 * @param distance reported distance (DV) to 'other'
787 static void all_connect_handler (void *cls,
789 GNUNET_PeerIdentity * peer,
790 struct GNUNET_TIME_Relative latency,
793 struct GNUNET_TESTING_Daemon *d = cls;
794 struct GNUNET_TESTING_Daemon *second_daemon;
795 char *second_shortname = strdup(GNUNET_i2s(peer));
797 struct TestMessageContext *temp_context;
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
806 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
808 if (second_daemon == NULL)
810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
816 temp_total_other_messages++;
817 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
818 temp_context->peer1 = d;
819 temp_context->peer2 = second_daemon;
820 temp_context->next = other_test_messages;
821 temp_context->uid = total_connections + temp_total_other_messages;
822 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
823 other_test_messages = temp_context;
828 if (dotOutFile != NULL)
831 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
832 else if (distance == 2)
833 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
834 else if (distance == 3)
835 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
836 else if (distance == 4)
837 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
839 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
841 GNUNET_free(second_shortname);
843 if ((num_peers == 3) && (temp_total_other_messages == 2))
845 /*GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30), &send_other_messages, NULL);*/
846 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
851 peers_started_callback (void *cls,
852 const struct GNUNET_PeerIdentity *id,
853 const struct GNUNET_CONFIGURATION_Handle *cfg,
854 struct GNUNET_TESTING_Daemon *d, const char *emsg)
856 struct PeerContext *new_peer;
859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
863 GNUNET_assert (id != NULL);
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
866 (num_peers - peers_left) + 1, num_peers);
868 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
870 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
871 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);
872 new_peer->daemon = d;
873 new_peer->next = all_peers;
874 all_peers = new_peer;
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "All %d daemons started, now creating topology!\n",
884 GNUNET_SCHEDULER_cancel (sched, die_task);
885 /* Set up task in case topology creation doesn't finish
886 * within a reasonable amount of time */
887 die_task = GNUNET_SCHEDULER_add_delayed (sched,
888 GNUNET_TIME_relative_multiply
889 (GNUNET_TIME_UNIT_MINUTES, 5),
890 &end_badly, "from peers_started_callback");
898 * Callback indicating that the hostkey was created for a peer.
901 * @param id the peer identity
902 * @param d the daemon handle (pretty useless at this point, remove?)
903 * @param emsg non-null on failure
905 void hostkey_callback (void *cls,
906 const struct GNUNET_PeerIdentity *id,
907 struct GNUNET_TESTING_Daemon *d,
912 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "Hostkey created for peer `%s'\n",
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
925 "All %d hostkeys created, now creating topology!\n",
928 GNUNET_SCHEDULER_cancel (sched, die_task);
929 /* Set up task in case topology creation doesn't finish
930 * within a reasonable amount of time */
931 die_task = GNUNET_SCHEDULER_add_delayed (sched,
932 GNUNET_TIME_relative_multiply
933 (GNUNET_TIME_UNIT_MINUTES, 5),
934 &end_badly, "from hostkey_callback");
935 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
942 struct GNUNET_SCHEDULER_Handle *s,
944 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
947 char * connect_topology_str;
948 char * blacklist_topology_str;
949 char * connect_topology_option_str;
950 char * connect_topology_option_modifier_string;
954 dotOutFile = fopen (dotOutFileName, "w");
955 if (dotOutFile != NULL)
957 fprintf (dotOutFile, "strict graph G {\n");
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "Starting daemons based on config file %s\n", cfgfile);
965 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
972 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
973 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
975 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
976 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
977 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
981 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
982 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
984 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
985 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
987 GNUNET_free_non_null(connect_topology_str);
989 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
990 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
992 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
993 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
994 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
996 GNUNET_free_non_null(connect_topology_option_str);
998 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
999 &connect_topology_option_modifier_string))
1001 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1003 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1004 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1005 connect_topology_option_modifier_string,
1006 "connect_topology_option_modifier",
1009 GNUNET_free (connect_topology_option_modifier_string);
1012 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1013 &blacklist_transports))
1014 blacklist_transports = NULL;
1017 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1018 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1021 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1023 GNUNET_free_non_null(topology_str);
1024 GNUNET_free_non_null(blacklist_topology_str);
1025 if (GNUNET_SYSERR ==
1026 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1028 num_peers = DEFAULT_NUM_PEERS;
1032 peers_left = num_peers;
1034 /* Set up a task to end testing if peer start fails */
1035 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1036 GNUNET_TIME_relative_multiply
1037 (GNUNET_TIME_UNIT_MINUTES, 5),
1038 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
1040 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
1041 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1042 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
1043 &topology_callback, NULL, NULL);
1051 char *const argv[] = {"test-transport-dv",
1053 "test_transport_dv_data.conf",
1059 struct GNUNET_GETOPT_CommandLineOption options[] = {
1060 GNUNET_GETOPT_OPTION_END
1062 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1063 argv, "test-transport-dv", "nohelp",
1064 options, &run, &ok);
1065 if (ret != GNUNET_OK)
1067 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret);
1073 main (int argc, char *argv[])
1077 GNUNET_log_setup ("test-transport-dv",
1086 * Need to remove base directory, subdirectories taken care
1087 * of by the testing framework.
1089 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1091 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1096 /* end of test_testing_topology.c */