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,
453 &get_result_iterator,
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
458 test_get->daemon->shortname);
460 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, &get_stop_task, test_get);
461 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
465 * Called when the PUT request has been transmitted to the DHT service.
466 * Schedule the GET request for some time in the future.
469 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
471 struct TestPutContext *test_put = cls;
475 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
476 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task, test_put);
477 if (puts_completed == num_puts)
479 GNUNET_assert(outstanding_puts == 0);
480 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets);
486 * Set up some data, and call API PUT function
489 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
491 struct TestPutContext *test_put = cls;
492 GNUNET_HashCode key; /* Made up key to store data under */
493 char data[TEST_DATA_SIZE]; /* Made up data to store */
495 if (test_put == NULL)
496 return; /* End of list */
498 memset(data, test_put->uid, sizeof(data));
499 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
501 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
503 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
510 test_put->daemon->shortname);
512 test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10);
514 GNUNET_assert(test_put->dht_handle != NULL);
516 GNUNET_DHT_put(test_put->dht_handle,
519 GNUNET_BLOCK_TYPE_TEST,
521 GNUNET_TIME_UNIT_FOREVER_ABS,
522 GNUNET_TIME_UNIT_FOREVER_REL,
523 &put_finished, test_put);
524 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
525 GNUNET_SCHEDULER_add_now(&do_put, test_put->next);
530 * Set up some all of the put and get operations we want
531 * to do. Allocate data structure for each, add to list,
532 * then call actual insert functions.
535 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
538 uint32_t temp_daemon;
539 struct TestPutContext *test_put;
540 struct TestGetContext *test_get;
541 int remember[num_puts][num_peers];
543 for (i = 0; i < num_puts; i++)
545 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
547 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
548 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
549 test_put->next = all_puts;
553 for (i = 0; i < num_gets; i++)
555 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
556 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
557 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
558 while (remember[test_get->uid][temp_daemon] == 1)
559 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
560 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
561 remember[test_get->uid][temp_daemon] = 1;
562 test_get->next = all_gets;
566 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
571 * This function is called whenever a connection attempt is finished between two of
572 * the started peers (started with GNUNET_TESTING_daemons_start). The total
573 * number of times this function is called should equal the number returned
574 * from the GNUNET_TESTING_connect_topology call.
576 * The emsg variable is NULL on success (peers connected), and non-NULL on
577 * failure (peers failed to connect).
580 topology_callback (void *cls,
581 const struct GNUNET_PeerIdentity *first,
582 const struct GNUNET_PeerIdentity *second,
584 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
585 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
586 struct GNUNET_TESTING_Daemon *first_daemon,
587 struct GNUNET_TESTING_Daemon *second_daemon,
594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
595 first_daemon->shortname,
596 second_daemon->shortname,
603 failed_connections++;
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
605 first_daemon->shortname,
606 second_daemon->shortname, emsg);
610 if (total_connections == expected_connections)
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
617 GNUNET_SCHEDULER_cancel (die_task);
618 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
619 &end_badly, "from setup puts/gets");
621 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL);
623 else if (total_connections + failed_connections == expected_connections)
625 GNUNET_SCHEDULER_cancel (die_task);
626 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
631 peers_started_callback (void *cls,
632 const struct GNUNET_PeerIdentity *id,
633 const struct GNUNET_CONFIGURATION_Handle *cfg,
634 struct GNUNET_TESTING_Daemon *d, const char *emsg)
638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
642 GNUNET_assert (id != NULL);
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
646 (num_peers - peers_left) + 1, num_peers);
654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 "All %d daemons started, now connecting peers!\n",
658 GNUNET_SCHEDULER_cancel (die_task);
660 expected_connections = -1;
661 if ((pg != NULL) && (peers_left == 0))
663 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
666 "Have %d expected connections\n", expected_connections);
670 if (expected_connections == GNUNET_SYSERR)
672 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
675 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
676 &end_badly, "from connect topology (timeout)");
685 peers_left = num_peers; /* Reset counter */
686 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "Topology set up, now starting peers!\n");
692 GNUNET_TESTING_daemons_continue_startup(pg);
696 GNUNET_SCHEDULER_cancel (die_task);
697 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)");
699 GNUNET_SCHEDULER_cancel (die_task);
700 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
701 &end_badly, "from continue startup (timeout)");
705 * Callback indicating that the hostkey was created for a peer.
708 * @param id the peer identity
709 * @param d the daemon handle (pretty useless at this point, remove?)
710 * @param emsg non-null on failure
712 void hostkey_callback (void *cls,
713 const struct GNUNET_PeerIdentity *id,
714 struct GNUNET_TESTING_Daemon *d,
719 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Hostkey (%d/%d) created for peer `%s'\n",
725 num_peers - peers_left, num_peers, GNUNET_i2s(id));
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "All %d hostkeys created, now creating topology!\n",
737 GNUNET_SCHEDULER_cancel (die_task);
738 /* Set up task in case topology creation doesn't finish
739 * within a reasonable amount of time */
740 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
741 &end_badly, "from create_topology");
742 GNUNET_SCHEDULER_add_now(&create_topology, NULL);
751 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
754 char * connect_topology_str;
755 char * blacklist_topology_str;
756 char * connect_topology_option_str;
757 char * connect_topology_option_modifier_string;
759 /* Get path from configuration file */
760 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
767 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
768 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
770 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
771 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
772 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
776 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
777 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
779 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
780 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
782 GNUNET_free_non_null(connect_topology_str);
784 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
785 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
787 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
788 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
789 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
791 GNUNET_free_non_null(connect_topology_option_str);
793 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
794 &connect_topology_option_modifier_string))
796 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
799 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
800 connect_topology_option_modifier_string,
801 "connect_topology_option_modifier",
804 GNUNET_free (connect_topology_option_modifier_string);
807 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
808 &blacklist_transports))
809 blacklist_transports = NULL;
812 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
813 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
815 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
816 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
818 GNUNET_free_non_null(topology_str);
819 GNUNET_free_non_null(blacklist_topology_str);
821 /* Get number of peers to start from configuration */
823 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
825 num_peers = DEFAULT_NUM_PEERS;
828 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
830 num_puts = DEFAULT_NUM_PEERS;
833 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
835 num_gets = DEFAULT_NUM_PEERS;
837 /* Set peers_left so we know when all peers started */
838 peers_left = num_peers;
840 /* Set up a task to end testing if peer start fails */
841 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
842 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
844 pg = GNUNET_TESTING_daemons_start (cfg,
845 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
846 &topology_callback, NULL, NULL);
854 /* Arguments for GNUNET_PROGRAM_run */
855 char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */
857 "test_dht_multipeer_data.conf", /* Config file to use */
863 struct GNUNET_GETOPT_CommandLineOption options[] = {
864 GNUNET_GETOPT_OPTION_END
866 /* Run the run function as a new program */
867 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
868 argv, "test-dht-multipeer", "nohelp",
870 if (ret != GNUNET_OK)
872 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with error code %d\n", ret);
878 main (int argc, char *argv[])
882 GNUNET_log_setup ("test-dht-multipeer",
891 * Need to remove base directory, subdirectories taken care
892 * of by the testing framework.
894 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
896 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
901 /* end of test_dht_twopeer_put_get.c */