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
61 * This is a linked list
63 struct TestPutContext *next;
66 * Handle to the first peers DHT service (via the API)
68 struct GNUNET_DHT_Handle *dht_handle;
71 * Handle to the PUT peer daemon
73 struct GNUNET_TESTING_Daemon *daemon;
76 * Identifier for this PUT
81 * Task for disconnecting DHT handles
83 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
88 /* This is a linked list */
89 struct TestGetContext *next;
92 * Handle to the first peers DHT service (via the API)
94 struct GNUNET_DHT_Handle *dht_handle;
97 * Handle for the DHT get request
99 struct GNUNET_DHT_GetHandle *get_handle;
102 * Handle to the GET peer daemon
104 struct GNUNET_TESTING_Daemon *daemon;
107 * Identifier for this GET
112 * Task for disconnecting DHT handles (and stopping GET)
114 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
117 * Whether or not this request has been fulfilled already.
125 * List of GETS to perform
127 struct TestGetContext *all_gets;
130 * List of PUTS to perform
132 struct TestPutContext *all_puts;
135 * Directory to store temp data in, defined in config file
137 static char *test_directory;
140 * Variable used to store the number of connections we should wait for.
142 static unsigned int expected_connections;
145 * Variable used to keep track of how many peers aren't yet started.
147 static unsigned long long peers_left;
150 * Handle to the set of all peers run for this test.
152 static struct GNUNET_TESTING_PeerGroup *pg;
156 * Total number of peers to run, set based on config file.
158 static unsigned long long num_peers;
161 * Total number of items to insert.
163 static unsigned long long num_puts;
166 * Total number of items to attempt to get.
168 static unsigned long long num_gets;
171 * How many puts do we currently have in flight?
173 static unsigned long long outstanding_puts;
176 * How many puts are done?
178 static unsigned long long puts_completed;
181 * How many puts do we currently have in flight?
183 static unsigned long long outstanding_gets;
186 * How many gets are done?
188 static unsigned long long gets_completed;
191 * How many gets failed?
193 static unsigned long long gets_failed;
196 * Global used to count how many connections we have currently
197 * been notified about (how many times has topology_callback been called
200 static unsigned int total_connections;
203 * Global used to count how many failed connections we have
204 * been notified about (how many times has topology_callback
205 * been called with failure?)
207 static unsigned int failed_connections;
209 /* Task handle to use to schedule test failure */
210 GNUNET_SCHEDULER_TaskIdentifier die_task;
212 static char *blacklist_transports;
214 static enum GNUNET_TESTING_Topology topology;
216 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
218 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
220 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
222 static double connect_topology_option_modifier = 0.0;
224 /* Global return value (0 for success, anything else for failure) */
229 * Check whether peers successfully shut down.
231 void shutdown_callback (void *cls,
242 * Task to release DHT handles for PUT
245 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
247 struct TestPutContext *test_put = cls;
248 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
249 GNUNET_DHT_disconnect(test_put->dht_handle);
250 test_put->dht_handle = NULL;
254 * Function scheduled to be run on the successful completion of this
258 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
260 GNUNET_assert (pg != NULL);
261 struct TestPutContext *test_put = all_puts;
262 struct TestGetContext *test_get = all_gets;
264 while (test_put != NULL)
266 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
267 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
268 if (test_put->dht_handle != NULL)
269 GNUNET_DHT_disconnect(test_put->dht_handle);
270 test_put = test_put->next;
273 while (test_get != NULL)
275 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
276 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
277 if (test_get->get_handle != NULL)
278 GNUNET_DHT_get_stop(test_get->get_handle);
279 if (test_get->dht_handle != NULL)
280 GNUNET_DHT_disconnect(test_get->dht_handle);
281 test_get = test_get->next;
284 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
290 * Check if the get_handle is being used, if so stop the request. Either
291 * way, schedule the end_badly_cont function which actually shuts down the
295 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls);
299 struct TestPutContext *test_put = all_puts;
300 struct TestGetContext *test_get = all_gets;
302 while (test_put != NULL)
304 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
305 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
306 if (test_put->dht_handle != NULL)
307 GNUNET_DHT_disconnect(test_put->dht_handle);
308 test_put = test_put->next;
311 while (test_get != NULL)
313 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
314 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
315 if (test_get->get_handle != NULL)
316 GNUNET_DHT_get_stop(test_get->get_handle);
317 if (test_get->dht_handle != NULL)
318 GNUNET_DHT_disconnect(test_get->dht_handle);
319 test_get = test_get->next;
322 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
327 * Task to release DHT handle associated with GET request.
330 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
332 struct TestGetContext *test_get = cls;
333 outstanding_gets--; /* GET is really finished */
334 GNUNET_DHT_disconnect(test_get->dht_handle);
335 test_get->dht_handle = NULL;
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
338 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */
340 GNUNET_SCHEDULER_cancel (die_task);
341 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
342 GNUNET_SCHEDULER_add_now(&finish_testing, NULL);
344 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
346 GNUNET_SCHEDULER_cancel(die_task);
347 GNUNET_SCHEDULER_add_now(&end_badly, "not all gets succeeded!\n");
352 * Task to release get handle.
355 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
357 struct TestGetContext *test_get = cls;
358 GNUNET_HashCode search_key; /* Key stored under */
359 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
361 memset(original_data, test_get->uid, sizeof(original_data));
362 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
364 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get from peer %s for key %s failed!\n", test_get->daemon->shortname, GNUNET_h2s(&search_key));
369 GNUNET_assert(test_get->get_handle != NULL);
370 GNUNET_DHT_get_stop(test_get->get_handle);
371 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
372 test_get->get_handle = NULL;
373 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
377 * Iterator called if the GET request initiated returns a response.
380 * @param exp when will this value expire
381 * @param key key of the result
382 * @param type type of the result
383 * @param size number of bytes in data
384 * @param data pointer to the result data
386 void get_result_iterator (void *cls,
387 struct GNUNET_TIME_Absolute exp,
388 const GNUNET_HashCode * key,
389 const struct GNUNET_PeerIdentity * const *get_path,
390 const struct GNUNET_PeerIdentity * const *put_path,
391 enum GNUNET_BLOCK_Type type,
395 struct TestGetContext *test_get = cls;
396 GNUNET_HashCode search_key; /* Key stored under */
397 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
399 memset(original_data, test_get->uid, sizeof(original_data));
400 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
402 if (test_get->succeeded == GNUNET_YES)
403 return; /* Get has already been successful, probably ending now */
405 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
412 test_get->succeeded = GNUNET_YES;
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
416 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
417 GNUNET_SCHEDULER_add_continuation(&get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
422 * Set up some data, and call API PUT function
425 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
427 struct TestGetContext *test_get = cls;
428 GNUNET_HashCode key; /* Made up key to store data under */
429 char data[TEST_DATA_SIZE]; /* Made up data to store */
431 if (test_get == NULL)
432 return; /* End of the list */
433 memset(data, test_get->uid, sizeof(data));
434 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
436 if (outstanding_gets > MAX_OUTSTANDING_GETS)
438 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
442 test_get->dht_handle = GNUNET_DHT_connect(test_get->daemon->cfg, 10);
443 /* Insert the data at the first peer */
444 GNUNET_assert(test_get->dht_handle != NULL);
446 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
447 GNUNET_TIME_UNIT_FOREVER_REL,
448 GNUNET_BLOCK_TYPE_TEST,
450 DEFAULT_GET_REPLICATION,
454 &get_result_iterator,
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
459 test_get->daemon->shortname);
461 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, &get_stop_task, test_get);
462 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
466 * Called when the PUT request has been transmitted to the DHT service.
467 * Schedule the GET request for some time in the future.
470 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
472 struct TestPutContext *test_put = cls;
476 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
477 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task, test_put);
478 if (puts_completed == num_puts)
480 GNUNET_assert(outstanding_puts == 0);
481 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets);
487 * Set up some data, and call API PUT function
490 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
492 struct TestPutContext *test_put = cls;
493 GNUNET_HashCode key; /* Made up key to store data under */
494 char data[TEST_DATA_SIZE]; /* Made up data to store */
496 if (test_put == NULL)
497 return; /* End of list */
499 memset(data, test_put->uid, sizeof(data));
500 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
502 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
504 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
511 test_put->daemon->shortname);
513 test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10);
515 GNUNET_assert(test_put->dht_handle != NULL);
517 GNUNET_DHT_put(test_put->dht_handle,
519 DEFAULT_PUT_REPLICATION,
521 GNUNET_BLOCK_TYPE_TEST,
523 GNUNET_TIME_UNIT_FOREVER_ABS,
524 GNUNET_TIME_UNIT_FOREVER_REL,
525 &put_finished, test_put);
526 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
527 GNUNET_SCHEDULER_add_now(&do_put, test_put->next);
532 * Set up some all of the put and get operations we want
533 * to do. Allocate data structure for each, add to list,
534 * then call actual insert functions.
537 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
540 uint32_t temp_daemon;
541 struct TestPutContext *test_put;
542 struct TestGetContext *test_get;
543 int remember[num_puts][num_peers];
545 for (i = 0; i < num_puts; i++)
547 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
549 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
550 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
551 test_put->next = all_puts;
555 for (i = 0; i < num_gets; i++)
557 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
558 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
559 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
560 while (remember[test_get->uid][temp_daemon] == 1)
561 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
562 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
563 remember[test_get->uid][temp_daemon] = 1;
564 test_get->next = all_gets;
568 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
573 * This function is called whenever a connection attempt is finished between two of
574 * the started peers (started with GNUNET_TESTING_daemons_start). The total
575 * number of times this function is called should equal the number returned
576 * from the GNUNET_TESTING_connect_topology call.
578 * The emsg variable is NULL on success (peers connected), and non-NULL on
579 * failure (peers failed to connect).
582 topology_callback (void *cls,
583 const struct GNUNET_PeerIdentity *first,
584 const struct GNUNET_PeerIdentity *second,
586 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
587 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
588 struct GNUNET_TESTING_Daemon *first_daemon,
589 struct GNUNET_TESTING_Daemon *second_daemon,
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
597 first_daemon->shortname,
598 second_daemon->shortname,
605 failed_connections++;
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
607 first_daemon->shortname,
608 second_daemon->shortname, emsg);
612 if (total_connections == expected_connections)
615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
616 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
619 GNUNET_SCHEDULER_cancel (die_task);
620 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
621 &end_badly, "from setup puts/gets");
623 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL);
625 else if (total_connections + failed_connections == expected_connections)
627 GNUNET_SCHEDULER_cancel (die_task);
628 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
633 peers_started_callback (void *cls,
634 const struct GNUNET_PeerIdentity *id,
635 const struct GNUNET_CONFIGURATION_Handle *cfg,
636 struct GNUNET_TESTING_Daemon *d, const char *emsg)
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
644 GNUNET_assert (id != NULL);
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
648 (num_peers - peers_left) + 1, num_peers);
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "All %d daemons started, now connecting peers!\n",
660 GNUNET_SCHEDULER_cancel (die_task);
662 expected_connections = -1;
663 if ((pg != NULL) && (peers_left == 0))
665 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
668 "Have %d expected connections\n", expected_connections);
672 if (expected_connections == GNUNET_SYSERR)
674 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
677 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
678 &end_badly, "from connect topology (timeout)");
687 peers_left = num_peers; /* Reset counter */
688 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
692 "Topology set up, now starting peers!\n");
694 GNUNET_TESTING_daemons_continue_startup(pg);
698 GNUNET_SCHEDULER_cancel (die_task);
699 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)");
701 GNUNET_SCHEDULER_cancel (die_task);
702 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
703 &end_badly, "from continue startup (timeout)");
707 * Callback indicating that the hostkey was created for a peer.
710 * @param id the peer identity
711 * @param d the daemon handle (pretty useless at this point, remove?)
712 * @param emsg non-null on failure
714 void hostkey_callback (void *cls,
715 const struct GNUNET_PeerIdentity *id,
716 struct GNUNET_TESTING_Daemon *d,
721 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Hostkey (%d/%d) created for peer `%s'\n",
727 num_peers - peers_left, num_peers, GNUNET_i2s(id));
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "All %d hostkeys created, now creating topology!\n",
739 GNUNET_SCHEDULER_cancel (die_task);
740 /* Set up task in case topology creation doesn't finish
741 * within a reasonable amount of time */
742 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
743 &end_badly, "from create_topology");
744 GNUNET_SCHEDULER_add_now(&create_topology, NULL);
753 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
756 char * connect_topology_str;
757 char * blacklist_topology_str;
758 char * connect_topology_option_str;
759 char * connect_topology_option_modifier_string;
761 /* Get path from configuration file */
762 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
769 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
770 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
772 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
773 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
774 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
778 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
779 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
781 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
782 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
784 GNUNET_free_non_null(connect_topology_str);
786 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
787 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
789 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
790 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
791 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
793 GNUNET_free_non_null(connect_topology_option_str);
795 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
796 &connect_topology_option_modifier_string))
798 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
800 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
801 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
802 connect_topology_option_modifier_string,
803 "connect_topology_option_modifier",
806 GNUNET_free (connect_topology_option_modifier_string);
809 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
810 &blacklist_transports))
811 blacklist_transports = NULL;
814 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
815 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
818 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
820 GNUNET_free_non_null(topology_str);
821 GNUNET_free_non_null(blacklist_topology_str);
823 /* Get number of peers to start from configuration */
825 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
827 num_peers = DEFAULT_NUM_PEERS;
830 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
832 num_puts = DEFAULT_NUM_PEERS;
835 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
837 num_gets = DEFAULT_NUM_PEERS;
839 /* Set peers_left so we know when all peers started */
840 peers_left = num_peers;
842 /* Set up a task to end testing if peer start fails */
843 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
844 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
846 pg = GNUNET_TESTING_daemons_start (cfg,
847 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
848 &topology_callback, NULL, NULL);
856 /* Arguments for GNUNET_PROGRAM_run */
857 char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */
859 "test_dht_multipeer_data.conf", /* Config file to use */
865 struct GNUNET_GETOPT_CommandLineOption options[] = {
866 GNUNET_GETOPT_OPTION_END
868 /* Run the run function as a new program */
869 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
870 argv, "test-dht-multipeer", "nohelp",
872 if (ret != GNUNET_OK)
874 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with error code %d\n", ret);
880 main (int argc, char *argv[])
884 GNUNET_log_setup ("test-dht-multipeer",
893 * Need to remove base directory, subdirectories taken care
894 * of by the testing framework.
896 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
898 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
903 /* end of test_dht_twopeer_put_get.c */