2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file dv/test_transport_api_dv.c
22 * @brief base testcase for testing distance vector transport
25 #include "gnunet_testing_lib.h"
26 #include "gnunet_core_service.h"
28 #define VERBOSE GNUNET_YES
30 #define TEST_ALL GNUNET_NO
33 * How long until we fail the whole testcase?
35 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
38 * How long until we give up on starting the peers?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 500)
42 #define DEFAULT_NUM_PEERS 4
44 #define MAX_OUTSTANDING_CONNECTIONS 100
46 static float fail_percentage = 0.00;
50 static unsigned long long num_peers;
52 static unsigned int total_connections;
54 static unsigned int failed_connections;
56 static unsigned int total_server_connections;
58 static unsigned int total_messages_received;
60 static unsigned int total_other_expected_messages;
62 static unsigned int temp_total_other_messages;
64 static unsigned int total_other_messages;
66 static unsigned int expected_messages;
68 static unsigned int expected_connections;
70 static unsigned long long peers_left;
72 static struct GNUNET_TESTING_PeerGroup *pg;
74 static struct GNUNET_SCHEDULER_Handle *sched;
76 const struct GNUNET_CONFIGURATION_Handle *main_cfg;
78 GNUNET_SCHEDULER_TaskIdentifier die_task;
80 static char *dotOutFileName = "topology.dot";
82 static FILE *dotOutFile;
84 static char *blacklist_transports;
86 static int transmit_ready_scheduled;
88 static int transmit_ready_failed;
90 static int transmit_ready_called;
92 static enum GNUNET_TESTING_Topology topology;
94 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
96 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
98 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
100 static double connect_topology_option_modifier = 0.0;
102 static char *test_directory;
104 struct GNUNET_CONTAINER_MultiHashMap *peer_daemon_hash;
108 struct GNUNET_TestMessage
111 * Header of the message
113 struct GNUNET_MessageHeader header;
116 * Unique identifier for this message.
123 /* This is a linked list */
124 struct PeerContext *next;
127 * Handle to the daemon
129 struct GNUNET_TESTING_Daemon *daemon;
131 /* Handle to the peer core */
132 struct GNUNET_CORE_Handle *peer_handle;
135 static struct PeerContext *all_peers;
137 struct TestMessageContext
139 /* This is a linked list */
140 struct TestMessageContext *next;
142 /* Handle to the sending peer core */
143 struct GNUNET_CORE_Handle *peer1handle;
145 /* Handle to the receiving peer core */
146 struct GNUNET_CORE_Handle *peer2handle;
148 /* Handle to the sending peer daemon */
149 struct GNUNET_TESTING_Daemon *peer1;
151 /* Handle to the receiving peer daemon */
152 struct GNUNET_TESTING_Daemon *peer2;
154 /* Identifier for this message, so we don't disconnect other peers! */
157 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
158 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
161 static struct TestMessageContext *test_messages;
163 static struct TestMessageContext *other_test_messages;
168 GNUNET_assert (pg != NULL);
169 struct PeerContext *peer_pos;
170 struct PeerContext *free_peer_pos;
171 struct TestMessageContext *pos;
172 struct TestMessageContext *free_pos;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Called finish testing, stopping daemons.\n");
179 peer_pos = all_peers;
180 while (peer_pos != NULL)
182 if (peer_pos->peer_handle != NULL)
183 GNUNET_CORE_disconnect(peer_pos->peer_handle);
184 free_peer_pos = peer_pos;
185 peer_pos = peer_pos->next;
186 GNUNET_free(free_peer_pos);
194 if (pos->peer1handle != NULL)
196 GNUNET_CORE_disconnect(pos->peer1handle);
197 pos->peer1handle = NULL;
199 if (pos->peer2handle != NULL)
201 GNUNET_CORE_disconnect(pos->peer2handle);
202 pos->peer2handle = NULL;
206 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
208 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
210 GNUNET_free(free_pos);
213 pos = other_test_messages;
216 if (pos->peer1handle != NULL)
218 GNUNET_CORE_disconnect(pos->peer1handle);
219 pos->peer1handle = NULL;
221 if (pos->peer2handle != NULL)
223 GNUNET_CORE_disconnect(pos->peer2handle);
224 pos->peer2handle = NULL;
228 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
230 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
232 GNUNET_free(free_pos);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "Calling daemons_stop\n");
243 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "daemons_stop finished\n");
248 if (dotOutFile != NULL)
250 fprintf(dotOutFile, "}");
259 disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
261 struct TestMessageContext *pos = cls;
263 /* Disconnect from the respective cores */
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
266 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
268 if (pos->peer1handle != NULL)
269 GNUNET_CORE_disconnect(pos->peer1handle);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
274 if (pos->peer2handle != NULL)
275 GNUNET_CORE_disconnect(pos->peer2handle);
276 /* Set handles to NULL so test case can be ended properly */
277 pos->peer1handle = NULL;
278 pos->peer2handle = NULL;
279 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
280 /* Decrement total connections so new can be established */
281 total_server_connections -= 2;
285 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
288 process_mtype (void *cls,
289 const struct GNUNET_PeerIdentity *peer,
290 const struct GNUNET_MessageHeader *message,
291 struct GNUNET_TIME_Relative latency,
294 struct TestMessageContext *pos = cls;
295 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
296 if (pos->uid != ntohl(msg->uid))
299 GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
300 if (total_other_expected_messages == 0)
302 total_messages_received++;
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
307 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
312 total_other_messages++;
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
315 "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance);
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
317 "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages);
321 if ((total_messages_received == expected_messages) && (total_other_messages == 0))
323 GNUNET_SCHEDULER_cancel (sched, die_task);
325 if ((num_peers == 3) && (total_other_expected_messages == 2))
327 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
331 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL);
334 else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages))
336 GNUNET_SCHEDULER_cancel (sched, die_task);
337 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
341 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
348 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
352 "End badly was called (%s)... stopping daemons.\n", msg);
353 struct TestMessageContext *pos;
354 struct TestMessageContext *free_pos;
355 struct PeerContext * peer_pos;
356 struct PeerContext * free_peer_pos;
358 peer_pos = all_peers;
359 while (peer_pos != NULL)
361 if (peer_pos->peer_handle != NULL)
362 GNUNET_CORE_disconnect(peer_pos->peer_handle);
363 free_peer_pos = peer_pos;
364 peer_pos = peer_pos->next;
365 GNUNET_free(free_peer_pos);
372 if (pos->peer1handle != NULL)
374 GNUNET_CORE_disconnect(pos->peer1handle);
375 pos->peer1handle = NULL;
377 if (pos->peer2handle != NULL)
379 GNUNET_CORE_disconnect(pos->peer2handle);
380 pos->peer2handle = NULL;
384 GNUNET_free(free_pos);
387 pos = other_test_messages;
390 if (pos->peer1handle != NULL)
392 GNUNET_CORE_disconnect(pos->peer1handle);
393 pos->peer1handle = NULL;
395 if (pos->peer2handle != NULL)
397 GNUNET_CORE_disconnect(pos->peer2handle);
398 pos->peer2handle = NULL;
402 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
404 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
406 GNUNET_free(free_pos);
411 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
412 ok = 7331; /* Opposite of leet */
415 ok = 401; /* Never got peers started */
417 if (dotOutFile != NULL)
419 fprintf(dotOutFile, "}");
425 transmit_ready (void *cls, size_t size, void *buf)
427 struct GNUNET_TestMessage *m;
428 struct TestMessageContext *pos = cls;
430 GNUNET_assert (buf != NULL);
431 m = (struct GNUNET_TestMessage *) buf;
432 m->header.type = htons (MTYPE);
433 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
434 m->uid = htonl(pos->uid);
435 transmit_ready_called++;
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
438 "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);
440 return sizeof (struct GNUNET_TestMessage);
444 static struct GNUNET_CORE_MessageHandler no_handlers[] = {
448 static struct GNUNET_CORE_MessageHandler handlers[] = {
449 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
454 init_notify_peer2 (void *cls,
455 struct GNUNET_CORE_Handle *server,
456 const struct GNUNET_PeerIdentity *my_identity,
457 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
459 struct TestMessageContext *pos = cls;
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Core connection to `%4s' established, scheduling message send\n",
464 GNUNET_i2s (my_identity));
466 total_server_connections++;
468 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
472 sizeof (struct GNUNET_TestMessage),
473 &transmit_ready, pos))
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
477 GNUNET_i2s (&pos->peer2->id));
478 transmit_ready_failed++;
482 transmit_ready_scheduled++;
488 init_notify_peer1 (void *cls,
489 struct GNUNET_CORE_Handle *server,
490 const struct GNUNET_PeerIdentity *my_identity,
491 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
493 struct TestMessageContext *pos = cls;
494 total_server_connections++;
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
498 "Core connection to `%4s' established, setting up handles\n",
499 GNUNET_i2s (my_identity));
503 * Connect to the receiving peer
505 pos->peer2handle = GNUNET_CORE_connect (sched,
513 GNUNET_YES, NULL, GNUNET_YES, handlers);
519 send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
521 struct TestMessageContext *pos = cls;
523 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
526 if (die_task == GNUNET_SCHEDULER_NO_TASK)
528 die_task = GNUNET_SCHEDULER_add_delayed (sched,
530 &end_badly, "from create topology (timeout)");
533 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
535 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
536 &send_test_messages, pos);
537 return; /* Otherwise we'll double schedule messages here! */
540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname);
543 * Connect to the sending peer
545 pos->peer1handle = GNUNET_CORE_connect (sched,
553 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
555 GNUNET_assert(pos->peer1handle != NULL);
557 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
559 GNUNET_SCHEDULER_add_now (sched,
560 &send_test_messages, pos->next);
564 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
565 &send_test_messages, pos->next);
570 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
572 struct TestMessageContext *pos;
573 struct TestMessageContext *free_pos;
574 struct PeerContext *peer_pos;
576 struct PeerContext *inner_peer_pos;
577 struct TestMessageContext *temp_context;
579 peer_pos = all_peers;
580 while (peer_pos != NULL)
582 if (peer_pos->peer_handle != NULL)
584 GNUNET_CORE_disconnect(peer_pos->peer_handle);
585 peer_pos->peer_handle = NULL;
588 inner_peer_pos = all_peers;
589 while (inner_peer_pos != NULL)
591 if (inner_peer_pos != peer_pos)
593 temp_total_other_messages++;
594 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
595 temp_context->peer1 = peer_pos->daemon;
596 temp_context->peer2 = inner_peer_pos->daemon;
597 temp_context->next = other_test_messages;
598 temp_context->uid = total_connections + temp_total_other_messages;
599 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
600 other_test_messages = temp_context;
602 inner_peer_pos = inner_peer_pos->next;
605 peer_pos = peer_pos->next;
612 if (pos->peer1handle != NULL)
614 GNUNET_CORE_disconnect(pos->peer1handle);
615 pos->peer1handle = NULL;
617 if (pos->peer2handle != NULL)
619 GNUNET_CORE_disconnect(pos->peer2handle);
620 pos->peer2handle = NULL;
624 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
626 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
628 GNUNET_free(free_pos);
630 test_messages = NULL;
632 total_other_expected_messages = temp_total_other_messages;
633 if (total_other_expected_messages == 0)
635 GNUNET_SCHEDULER_add_now (sched, &end_badly, "send_other_messages had 0 messages to send, no DV connections made!");
638 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Preparing to send %d other test messages\n", total_other_expected_messages);
641 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages);
642 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages");
646 topology_callback (void *cls,
647 const struct GNUNET_PeerIdentity *first,
648 const struct GNUNET_PeerIdentity *second,
650 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
651 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
652 struct GNUNET_TESTING_Daemon *first_daemon,
653 struct GNUNET_TESTING_Daemon *second_daemon,
656 struct TestMessageContext *temp_context;
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
662 first_daemon->shortname,
663 second_daemon->shortname,
666 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
667 temp_context->peer1 = first_daemon;
668 temp_context->peer2 = second_daemon;
669 temp_context->next = test_messages;
670 temp_context->uid = total_connections;
671 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
672 test_messages = temp_context;
680 failed_connections++;
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
682 first_daemon->shortname,
683 second_daemon->shortname, emsg);
687 if (total_connections == expected_connections)
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "Created %d total connections, which is our target number! Calling send messages.\n",
695 GNUNET_SCHEDULER_cancel (sched, die_task);
696 die_task = GNUNET_SCHEDULER_NO_TASK;
697 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
698 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
700 else if (total_connections + failed_connections == expected_connections)
702 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
704 GNUNET_SCHEDULER_cancel (sched, die_task);
705 die_task = GNUNET_SCHEDULER_NO_TASK;
706 GNUNET_SCHEDULER_add_now (sched, &send_test_messages, test_messages);
707 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
711 GNUNET_SCHEDULER_cancel (sched, die_task);
712 die_task = GNUNET_SCHEDULER_add_now (sched,
713 &end_badly, "from topology_callback (too many failed connections)");
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
720 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
721 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
729 expected_connections = -1;
730 if ((pg != NULL) && (peers_left == 0))
732 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
735 "Have %d expected connections\n", expected_connections);
739 GNUNET_SCHEDULER_cancel (sched, die_task);
740 if (expected_connections == GNUNET_SYSERR)
742 die_task = GNUNET_SCHEDULER_add_now (sched,
743 &end_badly, "from connect topology (bad return)");
746 die_task = GNUNET_SCHEDULER_add_delayed (sched,
748 &end_badly, "from connect topology (timeout)");
754 peers_left = num_peers; /* Reset counter */
755 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
759 "Topology set up, now starting peers!\n");
761 GNUNET_TESTING_daemons_continue_startup(pg);
765 GNUNET_SCHEDULER_cancel (sched, die_task);
766 die_task = GNUNET_SCHEDULER_add_now (sched,
767 &end_badly, "from create topology (bad return)");
769 GNUNET_SCHEDULER_cancel (sched, die_task);
770 die_task = GNUNET_SCHEDULER_add_delayed (sched,
772 &end_badly, "from continue startup (timeout)");
776 * Method called whenever a given peer connects.
779 * @param peer peer identity this notification is about
780 * @param latency reported latency of the connection with 'other'
781 * @param distance reported distance (DV) to 'other'
783 static void all_connect_handler (void *cls,
785 GNUNET_PeerIdentity * peer,
786 struct GNUNET_TIME_Relative latency,
789 struct GNUNET_TESTING_Daemon *d = cls;
790 struct GNUNET_TESTING_Daemon *second_daemon;
791 char *second_shortname = strdup(GNUNET_i2s(peer));
793 struct TestMessageContext *temp_context;
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
802 second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
804 if (second_daemon == NULL)
806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
812 temp_total_other_messages++;
813 temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
814 temp_context->peer1 = d;
815 temp_context->peer2 = second_daemon;
816 temp_context->next = other_test_messages;
817 temp_context->uid = total_connections + temp_total_other_messages;
818 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
819 other_test_messages = temp_context;
824 if (dotOutFile != NULL)
827 fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
828 else if (distance == 2)
829 fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
830 else if (distance == 3)
831 fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
832 else if (distance == 4)
833 fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
835 fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
837 GNUNET_free(second_shortname);
839 if ((num_peers == 3) && (temp_total_other_messages == 2))
841 /*GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30), &send_other_messages, NULL);*/
842 GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL);
847 peers_started_callback (void *cls,
848 const struct GNUNET_PeerIdentity *id,
849 const struct GNUNET_CONFIGURATION_Handle *cfg,
850 struct GNUNET_TESTING_Daemon *d, const char *emsg)
852 struct PeerContext *new_peer;
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
859 GNUNET_assert (id != NULL);
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
862 (num_peers - peers_left) + 1, num_peers);
864 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
866 new_peer = GNUNET_malloc(sizeof(struct PeerContext));
867 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);
868 new_peer->daemon = d;
869 new_peer->next = all_peers;
870 all_peers = new_peer;
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
877 "All %d daemons started, now creating topology!\n",
880 GNUNET_SCHEDULER_cancel (sched, die_task);
881 /* Set up task in case topology creation doesn't finish
882 * within a reasonable amount of time */
883 die_task = GNUNET_SCHEDULER_add_delayed (sched,
884 GNUNET_TIME_relative_multiply
885 (GNUNET_TIME_UNIT_MINUTES, 5),
886 &end_badly, "from peers_started_callback");
894 * Callback indicating that the hostkey was created for a peer.
897 * @param id the peer identity
898 * @param d the daemon handle (pretty useless at this point, remove?)
899 * @param emsg non-null on failure
901 void hostkey_callback (void *cls,
902 const struct GNUNET_PeerIdentity *id,
903 struct GNUNET_TESTING_Daemon *d,
908 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
913 "Hostkey created for peer `%s'\n",
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 "All %d hostkeys created, now creating topology!\n",
924 GNUNET_SCHEDULER_cancel (sched, die_task);
925 /* Set up task in case topology creation doesn't finish
926 * within a reasonable amount of time */
927 die_task = GNUNET_SCHEDULER_add_delayed (sched,
928 GNUNET_TIME_relative_multiply
929 (GNUNET_TIME_UNIT_MINUTES, 5),
930 &end_badly, "from hostkey_callback");
931 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
938 struct GNUNET_SCHEDULER_Handle *s,
940 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
943 char * connect_topology_str;
944 char * blacklist_topology_str;
945 char * connect_topology_option_str;
946 char * connect_topology_option_modifier_string;
950 dotOutFile = fopen (dotOutFileName, "w");
951 if (dotOutFile != NULL)
953 fprintf (dotOutFile, "strict graph G {\n");
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Starting daemons based on config file %s\n", cfgfile);
961 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
968 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
969 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
971 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
972 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
973 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
977 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
978 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
980 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
981 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
983 GNUNET_free_non_null(connect_topology_str);
985 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
986 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
988 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
989 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
990 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
992 GNUNET_free_non_null(connect_topology_option_str);
994 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
995 &connect_topology_option_modifier_string))
997 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
999 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1000 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1001 connect_topology_option_modifier_string,
1002 "connect_topology_option_modifier",
1005 GNUNET_free (connect_topology_option_modifier_string);
1008 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1009 &blacklist_transports))
1010 blacklist_transports = NULL;
1013 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1014 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1016 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1017 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1019 GNUNET_free_non_null(topology_str);
1020 GNUNET_free_non_null(blacklist_topology_str);
1021 if (GNUNET_SYSERR ==
1022 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1024 num_peers = DEFAULT_NUM_PEERS;
1028 peers_left = num_peers;
1030 /* Set up a task to end testing if peer start fails */
1031 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1032 GNUNET_TIME_relative_multiply
1033 (GNUNET_TIME_UNIT_MINUTES, 5),
1034 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
1036 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
1037 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1038 peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
1039 &topology_callback, NULL, NULL);
1047 char *const argv[] = {"test-transport-dv",
1049 "test_transport_dv_data.conf",
1055 struct GNUNET_GETOPT_CommandLineOption options[] = {
1056 GNUNET_GETOPT_OPTION_END
1058 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
1059 argv, "test-transport-dv", "nohelp",
1060 options, &run, &ok);
1061 if (ret != GNUNET_OK)
1063 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-transport-dv': Failed with error code %d\n", ret);
1069 main (int argc, char *argv[])
1073 GNUNET_log_setup ("test-transport-dv",
1082 * Need to remove base directory, subdirectories taken care
1083 * of by the testing framework.
1085 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1087 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1092 /* end of test_testing_topology.c */