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 dht/test_dht_multipeer.c
22 * @brief testcase for testing DHT service with
26 #include "gnunet_testing_lib.h"
27 #include "gnunet_core_service.h"
28 #include "gnunet_dht_service.h"
31 #define VERBOSE GNUNET_NO
33 /* Timeout for entire testcase */
34 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
36 /* Timeout for waiting for replies to get requests */
37 #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
39 /* Timeout for waiting for gets to complete */
40 #define GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
42 /* Timeout for waiting for puts to complete */
43 #define PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
45 #define SECONDS_PER_PEER_START 45
47 /* If number of peers not in config file, use this number */
48 #define DEFAULT_NUM_PEERS 5
50 #define TEST_DATA_SIZE 8
52 #define MAX_OUTSTANDING_PUTS 10
54 #define MAX_OUTSTANDING_GETS 10
56 #define PATH_TRACKING GNUNET_YES
63 * This is a linked list
65 struct TestPutContext *next;
68 * Handle to the first peers DHT service (via the API)
70 struct GNUNET_DHT_Handle *dht_handle;
73 * Handle to the PUT peer daemon
75 struct GNUNET_TESTING_Daemon *daemon;
78 * Identifier for this PUT
83 * Task for disconnecting DHT handles
85 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
90 /* This is a linked list */
91 struct TestGetContext *next;
94 * Handle to the first peers DHT service (via the API)
96 struct GNUNET_DHT_Handle *dht_handle;
99 * Handle for the DHT get request
101 struct GNUNET_DHT_GetHandle *get_handle;
104 * Handle to the GET peer daemon
106 struct GNUNET_TESTING_Daemon *daemon;
109 * Identifier for this GET
114 * Task for disconnecting DHT handles (and stopping GET)
116 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
119 * Whether or not this request has been fulfilled already.
127 * List of GETS to perform
129 struct TestGetContext *all_gets;
132 * List of PUTS to perform
134 struct TestPutContext *all_puts;
137 * Directory to store temp data in, defined in config file
139 static char *test_directory;
142 * Variable used to store the number of connections we should wait for.
144 static unsigned int expected_connections;
147 * Variable used to keep track of how many peers aren't yet started.
149 static unsigned long long peers_left;
152 * Handle to the set of all peers run for this test.
154 static struct GNUNET_TESTING_PeerGroup *pg;
158 * Total number of peers to run, set based on config file.
160 static unsigned long long num_peers;
163 * Total number of items to insert.
165 static unsigned long long num_puts;
168 * Total number of items to attempt to get.
170 static unsigned long long num_gets;
173 * How many puts do we currently have in flight?
175 static unsigned long long outstanding_puts;
178 * How many puts are done?
180 static unsigned long long puts_completed;
183 * How many puts do we currently have in flight?
185 static unsigned long long outstanding_gets;
188 * How many gets are done?
190 static unsigned long long gets_completed;
193 * How many gets failed?
195 static unsigned long long gets_failed;
198 * Global used to count how many connections we have currently
199 * been notified about (how many times has topology_callback been called
202 static unsigned int total_connections;
205 * Global used to count how many failed connections we have
206 * been notified about (how many times has topology_callback
207 * been called with failure?)
209 static unsigned int failed_connections;
211 enum GNUNET_DHT_RouteOption route_option;
213 /* Task handle to use to schedule test failure */
214 static GNUNET_SCHEDULER_TaskIdentifier die_task;
216 static char *blacklist_transports;
218 static enum GNUNET_TESTING_Topology topology;
220 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
222 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
224 static enum GNUNET_TESTING_TopologyOption connect_topology_option =
225 GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
227 static double connect_topology_option_modifier = 0.0;
229 /* Global return value (0 for success, anything else for failure) */
233 * Check whether peers successfully shut down.
236 shutdown_callback (void *cls, const char *emsg)
246 * Task to release DHT handles for PUT
249 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 struct TestPutContext *test_put = cls;
253 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
254 GNUNET_DHT_disconnect (test_put->dht_handle);
255 test_put->dht_handle = NULL;
259 * Function scheduled to be run on the successful completion of this
263 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
265 GNUNET_assert (pg != NULL);
266 struct TestPutContext *test_put = all_puts;
267 struct TestGetContext *test_get = all_gets;
269 while (test_put != NULL)
271 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
272 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
273 if (test_put->dht_handle != NULL)
274 GNUNET_DHT_disconnect (test_put->dht_handle);
275 test_put = test_put->next;
278 while (test_get != NULL)
280 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
281 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
282 if (test_get->get_handle != NULL)
283 GNUNET_DHT_get_stop (test_get->get_handle);
284 if (test_get->dht_handle != NULL)
285 GNUNET_DHT_disconnect (test_get->dht_handle);
286 test_get = test_get->next;
289 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
295 * Check if the get_handle is being used, if so stop the request. Either
296 * way, schedule the end_badly_cont function which actually shuts down the
300 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
305 struct TestPutContext *test_put = all_puts;
306 struct TestGetContext *test_get = all_gets;
308 while (test_put != NULL)
310 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
311 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
312 if (test_put->dht_handle != NULL)
313 GNUNET_DHT_disconnect (test_put->dht_handle);
314 test_put = test_put->next;
317 while (test_get != NULL)
319 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
320 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
321 if (test_get->get_handle != NULL)
322 GNUNET_DHT_get_stop (test_get->get_handle);
323 if (test_get->dht_handle != NULL)
324 GNUNET_DHT_disconnect (test_get->dht_handle);
325 test_get = test_get->next;
328 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
333 * Task to release DHT handle associated with GET request.
336 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
338 struct TestGetContext *test_get = cls;
340 outstanding_gets--; /* GET is really finished */
341 GNUNET_DHT_disconnect (test_get->dht_handle);
342 test_get->dht_handle = NULL;
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n",
345 gets_completed, gets_failed);
346 if ((gets_completed == num_gets) && (outstanding_gets == 0)) /* All gets successful */
348 GNUNET_SCHEDULER_cancel (die_task);
349 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
350 die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
352 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
354 GNUNET_SCHEDULER_cancel (die_task);
356 GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded!\n");
361 * Task to release get handle.
364 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
366 struct TestGetContext *test_get = cls;
367 GNUNET_HashCode search_key; /* Key stored under */
368 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
370 memset (original_data, test_get->uid, sizeof (original_data));
371 GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
373 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
377 "Get from peer %s for key %s failed!\n",
378 test_get->daemon->shortname, GNUNET_h2s (&search_key));
380 GNUNET_assert (test_get->get_handle != NULL);
381 GNUNET_DHT_get_stop (test_get->get_handle);
382 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
383 test_get->get_handle = NULL;
384 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
388 * Iterator called if the GET request initiated returns a response.
391 * @param exp when will this value expire
392 * @param key key of the result
393 * @param type type of the result
394 * @param size number of bytes in data
395 * @param data pointer to the result data
398 get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
399 const GNUNET_HashCode * key,
400 const struct GNUNET_PeerIdentity *get_path,
401 unsigned int get_path_length,
402 const struct GNUNET_PeerIdentity *put_path,
403 unsigned int put_path_length,
404 enum GNUNET_BLOCK_Type type, size_t size, const void *data)
406 struct TestGetContext *test_get = cls;
407 GNUNET_HashCode search_key; /* Key stored under */
408 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
411 memset (original_data, test_get->uid, sizeof (original_data));
412 GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key);
414 if (test_get->succeeded == GNUNET_YES)
415 return; /* Get has already been successful, probably ending now */
418 if (put_path != NULL)
420 fprintf (stderr, "PUT Path: ");
421 for (i = 0; i<put_path_length; i++)
422 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
423 fprintf (stderr, "\n");
425 if (get_path != NULL)
427 fprintf (stderr, "GET Path: ");
428 for (i = 0; i < get_path_length; i++)
429 fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
430 fprintf (stderr, "\n");
434 if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) ||
435 (0 != memcmp (original_data, data, sizeof (original_data))))
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
438 "Key or data is not the same as was inserted!\n");
443 test_get->succeeded = GNUNET_YES;
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
447 GNUNET_SCHEDULER_cancel (test_get->disconnect_task);
448 GNUNET_SCHEDULER_add_continuation (&get_stop_task, test_get,
449 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
454 * Set up some data, and call API PUT function
457 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
459 struct TestGetContext *test_get = cls;
460 GNUNET_HashCode key; /* Made up key to store data under */
461 char data[TEST_DATA_SIZE]; /* Made up data to store */
463 if (test_get == NULL)
464 return; /* End of the list */
465 memset (data, test_get->uid, sizeof (data));
466 GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
468 if (outstanding_gets > MAX_OUTSTANDING_GETS)
470 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
474 test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10);
475 /* Insert the data at the first peer */
476 GNUNET_assert (test_get->dht_handle != NULL);
478 test_get->get_handle =
479 GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
480 GNUNET_BLOCK_TYPE_TEST, &key,
481 1, route_option, NULL, 0,
482 &get_result_iterator, test_get);
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
485 test_get->uid, test_get->daemon->shortname);
487 test_get->disconnect_task =
488 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get);
489 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
493 * Called when the PUT request has been transmitted to the DHT service.
494 * Schedule the GET request for some time in the future.
497 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
499 struct TestPutContext *test_put = cls;
504 GNUNET_SCHEDULER_cancel (test_put->disconnect_task);
505 test_put->disconnect_task =
506 GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put);
507 if (puts_completed == num_puts)
509 GNUNET_assert (outstanding_puts == 0);
510 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
511 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get,
518 * Set up some data, and call API PUT function
521 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
523 struct TestPutContext *test_put = cls;
524 GNUNET_HashCode key; /* Made up key to store data under */
525 char data[TEST_DATA_SIZE]; /* Made up data to store */
527 if (test_put == NULL)
528 return; /* End of list */
530 memset (data, test_put->uid, sizeof (data));
531 GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key);
533 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
535 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
541 test_put->uid, test_put->daemon->shortname);
543 test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10);
545 GNUNET_assert (test_put->dht_handle != NULL);
547 GNUNET_DHT_put (test_put->dht_handle, &key, 1,
548 route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
549 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
550 &put_finished, test_put);
551 test_put->disconnect_task =
552 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
553 &put_disconnect_task, test_put);
554 GNUNET_SCHEDULER_add_now (&do_put, test_put->next);
559 * Set up some all of the put and get operations we want
560 * to do. Allocate data structure for each, add to list,
561 * then call actual insert functions.
564 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
567 uint32_t temp_daemon;
568 struct TestPutContext *test_put;
569 struct TestGetContext *test_get;
570 int remember[num_puts][num_peers];
572 for (i = 0; i < num_puts; i++)
574 test_put = GNUNET_malloc (sizeof (struct TestPutContext));
577 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
578 test_put->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
579 test_put->next = all_puts;
583 for (i = 0; i < num_gets; i++)
585 test_get = GNUNET_malloc (sizeof (struct TestGetContext));
587 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
589 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
590 while (remember[test_get->uid][temp_daemon] == 1)
592 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
593 test_get->daemon = GNUNET_TESTING_daemon_get (pg, temp_daemon);
594 remember[test_get->uid][temp_daemon] = 1;
595 test_get->next = all_gets;
599 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
604 * This function is called whenever a connection attempt is finished between two of
605 * the started peers (started with GNUNET_TESTING_daemons_start). The total
606 * number of times this function is called should equal the number returned
607 * from the GNUNET_TESTING_connect_topology call.
609 * The emsg variable is NULL on success (peers connected), and non-NULL on
610 * failure (peers failed to connect).
613 topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
614 const struct GNUNET_PeerIdentity *second, uint32_t distance,
615 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
616 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
617 struct GNUNET_TESTING_Daemon *first_daemon,
618 struct GNUNET_TESTING_Daemon *second_daemon,
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
626 "connected peer %s to peer %s, distance %u\n",
627 first_daemon->shortname, second_daemon->shortname, distance);
633 failed_connections++;
634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
635 "Failed to connect peer %s to peer %s with error :\n%s\n",
636 first_daemon->shortname, second_daemon->shortname, emsg);
640 if (total_connections == expected_connections)
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
647 GNUNET_SCHEDULER_cancel (die_task);
649 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
650 "from setup puts/gets");
651 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
652 (GNUNET_TIME_UNIT_SECONDS, 2),
653 &setup_puts_and_gets, NULL);
655 else if (total_connections + failed_connections == expected_connections)
657 GNUNET_SCHEDULER_cancel (die_task);
659 GNUNET_SCHEDULER_add_now (&end_badly,
660 "from topology_callback (too many failed connections)");
665 peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
666 const struct GNUNET_CONFIGURATION_Handle *cfg,
667 struct GNUNET_TESTING_Daemon *d, const char *emsg)
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Failed to start daemon with error: `%s'\n", emsg);
675 GNUNET_assert (id != NULL);
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
679 (num_peers - peers_left) + 1, num_peers);
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688 "All %d daemons started, now connecting peers!\n", num_peers);
691 expected_connections = -1;
692 if ((pg != NULL) && (peers_left == 0))
694 expected_connections =
695 GNUNET_TESTING_connect_topology (pg, connection_topology,
696 connect_topology_option,
697 connect_topology_option_modifier,
698 TIMEOUT, num_peers, NULL, NULL);
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
701 expected_connections);
705 GNUNET_SCHEDULER_cancel (die_task);
706 if (expected_connections == GNUNET_SYSERR)
709 GNUNET_SCHEDULER_add_now (&end_badly,
710 "from connect topology (bad return)");
715 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
716 "from connect topology (timeout)");
725 peers_left = num_peers; /* Reset counter */
726 GNUNET_SCHEDULER_cancel (die_task);
727 if (GNUNET_TESTING_create_topology
728 (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Topology set up, now starting peers!\n");
734 GNUNET_TESTING_daemons_continue_startup (pg);
736 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
737 "from continue startup (timeout)");
742 GNUNET_SCHEDULER_add_now (&end_badly,
743 "from create topology (bad return)");
748 * Callback indicating that the hostkey was created for a peer.
751 * @param id the peer identity
752 * @param d the daemon handle (pretty useless at this point, remove?)
753 * @param emsg non-null on failure
756 hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
757 struct GNUNET_TESTING_Daemon *d, const char *emsg)
761 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
762 "Hostkey callback received error: %s\n", emsg);
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left,
768 num_peers, GNUNET_i2s (id));
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
777 "All %d hostkeys created, now creating topology!\n", num_peers);
779 GNUNET_SCHEDULER_cancel (die_task);
780 /* Set up task in case topology creation doesn't finish
781 * within a reasonable amount of time */
783 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
784 "from create_topology");
785 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
792 run (void *cls, char *const *args, const char *cfgfile,
793 const struct GNUNET_CONFIGURATION_Handle *cfg)
796 char *connect_topology_str;
797 char *blacklist_topology_str;
798 char *connect_topology_option_str;
799 char *connect_topology_option_modifier_string;
802 route_option = GNUNET_DHT_RO_RECORD_ROUTE;
804 route_option = GNUNET_DHT_RO_NONE;
807 /* Get path from configuration file */
809 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
817 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "topology",
819 (GNUNET_NO == GNUNET_TESTING_topology_get (&topology, topology_str)))
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
822 "Invalid topology `%s' given for section %s option %s\n",
823 topology_str, "TESTING", "TOPOLOGY");
824 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
828 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
830 &connect_topology_str)) &&
832 GNUNET_TESTING_topology_get (&connection_topology,
833 connect_topology_str)))
835 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
836 "Invalid connect topology `%s' given for section %s option %s\n",
837 connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
839 GNUNET_free_non_null (connect_topology_str);
841 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
842 "connect_topology_option",
843 &connect_topology_option_str)) &&
845 GNUNET_TESTING_topology_option_get (&connect_topology_option,
846 connect_topology_option_str)))
848 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
849 "Invalid connect topology option `%s' given for section %s option %s\n",
850 connect_topology_option_str, "TESTING",
851 "CONNECT_TOPOLOGY_OPTION");
852 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
854 GNUNET_free_non_null (connect_topology_option_str);
856 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
857 "connect_topology_option_modifier",
858 &connect_topology_option_modifier_string))
861 (connect_topology_option_modifier_string, "%lf",
862 &connect_topology_option_modifier) != 1)
864 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
866 ("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
867 connect_topology_option_modifier_string,
868 "connect_topology_option_modifier", "TESTING");
870 GNUNET_free (connect_topology_option_modifier_string);
874 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
875 "blacklist_transports",
876 &blacklist_transports))
877 blacklist_transports = NULL;
880 GNUNET_CONFIGURATION_get_value_string (cfg, "testing",
881 "blacklist_topology",
882 &blacklist_topology_str)) &&
884 GNUNET_TESTING_topology_get (&blacklist_topology,
885 blacklist_topology_str)))
887 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
888 "Invalid topology `%s' given for section %s option %s\n",
889 topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
891 GNUNET_free_non_null (topology_str);
892 GNUNET_free_non_null (blacklist_topology_str);
894 /* Get number of peers to start from configuration */
896 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
898 num_peers = DEFAULT_NUM_PEERS;
901 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
903 num_puts = DEFAULT_NUM_PEERS;
906 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
908 num_gets = DEFAULT_NUM_PEERS;
910 /* Set peers_left so we know when all peers started */
911 peers_left = num_peers;
913 /* Set up a task to end testing if peer start fails */
915 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
916 (GNUNET_TIME_UNIT_SECONDS,
917 SECONDS_PER_PEER_START * num_peers),
919 "didn't generate all hostkeys within a reasonable amount of time!!!");
921 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
922 peers_left, /* Number of outstanding connections */
923 peers_left, /* Number of parallel ssh connections, or peers being started at once */
924 GNUNET_TIME_relative_multiply
925 (GNUNET_TIME_UNIT_SECONDS,
926 SECONDS_PER_PEER_START * num_peers),
927 &hostkey_callback, NULL,
928 &peers_started_callback, NULL,
929 &topology_callback, NULL, NULL);
938 /* Arguments for GNUNET_PROGRAM_run */
939 char *const argv[] = { "test-dht-multipeer", /* Name to give running binary */
941 "test_dht_multipeer_data.conf", /* Config file to use */
947 struct GNUNET_GETOPT_CommandLineOption options[] = {
948 GNUNET_GETOPT_OPTION_END
950 /* Run the run function as a new program */
952 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
953 "test-dht-multipeer", "nohelp", options, &run, &ok);
954 if (ret != GNUNET_OK)
956 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
957 "`test-dht-multipeer': Failed with error code %d\n", ret);
963 main (int argc, char *argv[])
967 GNUNET_log_setup ("test-dht-multipeer",
976 * Need to remove base directory, subdirectories taken care
977 * of by the testing framework.
979 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
981 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
982 "Failed to remove testing directory %s\n", test_directory);
987 /* end of test_dht_multipeer.c */