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_YES
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 * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
158 static struct GNUNET_SCHEDULER_Handle *sched;
161 * Total number of peers to run, set based on config file.
163 static unsigned long long num_peers;
166 * Total number of items to insert.
168 static unsigned long long num_puts;
171 * Total number of items to attempt to get.
173 static unsigned long long num_gets;
176 * How many puts do we currently have in flight?
178 static unsigned long long outstanding_puts;
181 * How many puts are done?
183 static unsigned long long puts_completed;
186 * How many puts do we currently have in flight?
188 static unsigned long long outstanding_gets;
191 * How many gets are done?
193 static unsigned long long gets_completed;
196 * How many gets failed?
198 static unsigned long long gets_failed;
201 * Global used to count how many connections we have currently
202 * been notified about (how many times has topology_callback been called
205 static unsigned int total_connections;
208 * Global used to count how many failed connections we have
209 * been notified about (how many times has topology_callback
210 * been called with failure?)
212 static unsigned int failed_connections;
214 /* Task handle to use to schedule test failure */
215 GNUNET_SCHEDULER_TaskIdentifier die_task;
217 static char *blacklist_transports;
219 static enum GNUNET_TESTING_Topology topology;
221 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
223 static enum GNUNET_TESTING_Topology connection_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
225 static enum GNUNET_TESTING_TopologyOption connect_topology_option = 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) */
234 * Check whether peers successfully shut down.
236 void shutdown_callback (void *cls,
247 * Task to release DHT handles for PUT
250 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
252 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(sched, 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(sched, 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", (char *)cls);
304 struct TestPutContext *test_put = all_puts;
305 struct TestGetContext *test_get = all_gets;
307 while (test_put != NULL)
309 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
310 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
311 if (test_put->dht_handle != NULL)
312 GNUNET_DHT_disconnect(test_put->dht_handle);
313 test_put = test_put->next;
316 while (test_get != NULL)
318 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
319 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
320 if (test_get->get_handle != NULL)
321 GNUNET_DHT_get_stop(test_get->get_handle);
322 if (test_get->dht_handle != NULL)
323 GNUNET_DHT_disconnect(test_get->dht_handle);
324 test_get = test_get->next;
327 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
332 * Task to release DHT handle associated with GET request.
335 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
337 struct TestGetContext *test_get = cls;
338 outstanding_gets--; /* GET is really finished */
339 GNUNET_DHT_disconnect(test_get->dht_handle);
340 test_get->dht_handle = NULL;
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
343 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */
345 GNUNET_SCHEDULER_cancel (sched, die_task);
346 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
347 GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
349 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
351 GNUNET_SCHEDULER_cancel(sched, die_task);
352 GNUNET_SCHEDULER_add_now(sched, &end_badly, "not all gets succeeded!\n");
357 * Task to release get handle.
360 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
362 struct TestGetContext *test_get = cls;
363 GNUNET_HashCode search_key; /* Key stored under */
364 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
366 memset(original_data, test_get->uid, sizeof(original_data));
367 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
369 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get from peer %s for key %s failed!\n", test_get->daemon->shortname, GNUNET_h2s(&search_key));
374 GNUNET_assert(test_get->get_handle != NULL);
375 GNUNET_DHT_get_stop(test_get->get_handle);
376 GNUNET_SCHEDULER_add_now (sched, &get_stop_finished, test_get);
377 test_get->get_handle = NULL;
378 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
382 * Iterator called if the GET request initiated returns a response.
385 * @param exp when will this value expire
386 * @param key key of the result
387 * @param type type of the result
388 * @param size number of bytes in data
389 * @param data pointer to the result data
391 void get_result_iterator (void *cls,
392 struct GNUNET_TIME_Absolute exp,
393 const GNUNET_HashCode * key,
394 const struct GNUNET_PeerIdentity * const *get_path,
395 const struct GNUNET_PeerIdentity * const *put_path,
396 enum GNUNET_BLOCK_Type type,
400 struct TestGetContext *test_get = cls;
401 GNUNET_HashCode search_key; /* Key stored under */
402 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
404 memset(original_data, test_get->uid, sizeof(original_data));
405 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
407 if (test_get->succeeded == GNUNET_YES)
408 return; /* Get has already been successful, probably ending now */
410 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
417 test_get->succeeded = GNUNET_YES;
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
421 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
422 GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
427 * Set up some data, and call API PUT function
430 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
432 struct TestGetContext *test_get = cls;
433 GNUNET_HashCode key; /* Made up key to store data under */
434 char data[TEST_DATA_SIZE]; /* Made up data to store */
436 if (test_get == NULL)
437 return; /* End of the list */
438 memset(data, test_get->uid, sizeof(data));
439 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
441 if (outstanding_gets > MAX_OUTSTANDING_GETS)
443 GNUNET_SCHEDULER_add_delayed (sched, GET_DELAY, &do_get, test_get);
447 test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10);
448 /* Insert the data at the first peer */
449 GNUNET_assert(test_get->dht_handle != NULL);
451 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
452 GNUNET_TIME_UNIT_FOREVER_REL,
453 GNUNET_BLOCK_TYPE_TEST,
458 &get_result_iterator,
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
463 test_get->daemon->shortname);
465 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GET_TIMEOUT, &get_stop_task, test_get);
466 GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next);
470 * Called when the PUT request has been transmitted to the DHT service.
471 * Schedule the GET request for some time in the future.
474 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
476 struct TestPutContext *test_put = cls;
480 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
481 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put);
482 if (puts_completed == num_puts)
484 GNUNET_assert(outstanding_puts == 0);
485 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets);
491 * Set up some data, and call API PUT function
494 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
496 struct TestPutContext *test_put = cls;
497 GNUNET_HashCode key; /* Made up key to store data under */
498 char data[TEST_DATA_SIZE]; /* Made up data to store */
500 if (test_put == NULL)
501 return; /* End of list */
503 memset(data, test_put->uid, sizeof(data));
504 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
506 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
508 GNUNET_SCHEDULER_add_delayed (sched, PUT_DELAY, &do_put, test_put);
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
515 test_put->daemon->shortname);
517 test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10);
519 GNUNET_assert(test_put->dht_handle != NULL);
521 GNUNET_DHT_put(test_put->dht_handle,
524 GNUNET_BLOCK_TYPE_TEST,
526 GNUNET_TIME_UNIT_FOREVER_ABS,
527 GNUNET_TIME_UNIT_FOREVER_REL,
528 &put_finished, test_put);
529 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
530 GNUNET_SCHEDULER_add_now(sched, &do_put, test_put->next);
535 * Set up some all of the put and get operations we want
536 * to do. Allocate data structure for each, add to list,
537 * then call actual insert functions.
540 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
543 uint32_t temp_daemon;
544 struct TestPutContext *test_put;
545 struct TestGetContext *test_get;
546 int remember[num_puts][num_peers];
548 for (i = 0; i < num_puts; i++)
550 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
552 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
553 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
554 test_put->next = all_puts;
558 for (i = 0; i < num_gets; i++)
560 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
561 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
562 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
563 while (remember[test_get->uid][temp_daemon] == 1)
564 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
565 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
566 remember[test_get->uid][temp_daemon] = 1;
567 test_get->next = all_gets;
571 GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts);
576 * This function is called whenever a connection attempt is finished between two of
577 * the started peers (started with GNUNET_TESTING_daemons_start). The total
578 * number of times this function is called should equal the number returned
579 * from the GNUNET_TESTING_connect_topology call.
581 * The emsg variable is NULL on success (peers connected), and non-NULL on
582 * failure (peers failed to connect).
585 topology_callback (void *cls,
586 const struct GNUNET_PeerIdentity *first,
587 const struct GNUNET_PeerIdentity *second,
589 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
590 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
591 struct GNUNET_TESTING_Daemon *first_daemon,
592 struct GNUNET_TESTING_Daemon *second_daemon,
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
600 first_daemon->shortname,
601 second_daemon->shortname,
608 failed_connections++;
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
610 first_daemon->shortname,
611 second_daemon->shortname, emsg);
615 if (total_connections == expected_connections)
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
622 GNUNET_SCHEDULER_cancel (sched, die_task);
623 die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT,
624 &end_badly, "from setup puts/gets");
626 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL);
628 else if (total_connections + failed_connections == expected_connections)
630 GNUNET_SCHEDULER_cancel (sched, die_task);
631 die_task = GNUNET_SCHEDULER_add_now (sched,
632 &end_badly, "from topology_callback (too many failed connections)");
637 peers_started_callback (void *cls,
638 const struct GNUNET_PeerIdentity *id,
639 const struct GNUNET_CONFIGURATION_Handle *cfg,
640 struct GNUNET_TESTING_Daemon *d, const char *emsg)
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
648 GNUNET_assert (id != NULL);
651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
652 (num_peers - peers_left) + 1, num_peers);
660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
661 "All %d daemons started, now connecting peers!\n",
664 GNUNET_SCHEDULER_cancel (sched, die_task);
666 expected_connections = -1;
667 if ((pg != NULL) && (peers_left == 0))
669 expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier);
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Have %d expected connections\n", expected_connections);
676 if (expected_connections == GNUNET_SYSERR)
678 die_task = GNUNET_SCHEDULER_add_now (sched,
679 &end_badly, "from connect topology (bad return)");
682 die_task = GNUNET_SCHEDULER_add_delayed (sched,
684 &end_badly, "from connect topology (timeout)");
693 peers_left = num_peers; /* Reset counter */
694 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
698 "Topology set up, now starting peers!\n");
700 GNUNET_TESTING_daemons_continue_startup(pg);
704 GNUNET_SCHEDULER_cancel (sched, die_task);
705 die_task = GNUNET_SCHEDULER_add_now (sched,
706 &end_badly, "from create topology (bad return)");
708 GNUNET_SCHEDULER_cancel (sched, die_task);
709 die_task = GNUNET_SCHEDULER_add_delayed (sched,
711 &end_badly, "from continue startup (timeout)");
715 * Callback indicating that the hostkey was created for a peer.
718 * @param id the peer identity
719 * @param d the daemon handle (pretty useless at this point, remove?)
720 * @param emsg non-null on failure
722 void hostkey_callback (void *cls,
723 const struct GNUNET_PeerIdentity *id,
724 struct GNUNET_TESTING_Daemon *d,
729 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Hostkey (%d/%d) created for peer `%s'\n",
735 num_peers - peers_left, num_peers, GNUNET_i2s(id));
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
744 "All %d hostkeys created, now creating topology!\n",
747 GNUNET_SCHEDULER_cancel (sched, die_task);
748 /* Set up task in case topology creation doesn't finish
749 * within a reasonable amount of time */
750 die_task = GNUNET_SCHEDULER_add_delayed (sched,
752 &end_badly, "from create_topology");
753 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
761 struct GNUNET_SCHEDULER_Handle *s,
763 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
766 char * connect_topology_str;
767 char * blacklist_topology_str;
768 char * connect_topology_option_str;
769 char * connect_topology_option_modifier_string;
772 /* Get path from configuration file */
773 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
780 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
781 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
783 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
784 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
785 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
789 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
790 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
792 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
793 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
795 GNUNET_free_non_null(connect_topology_str);
797 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
798 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
800 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
801 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
802 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
804 GNUNET_free_non_null(connect_topology_option_str);
806 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
807 &connect_topology_option_modifier_string))
809 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
811 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
812 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
813 connect_topology_option_modifier_string,
814 "connect_topology_option_modifier",
817 GNUNET_free (connect_topology_option_modifier_string);
820 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
821 &blacklist_transports))
822 blacklist_transports = NULL;
825 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
826 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
828 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
829 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
831 GNUNET_free_non_null(topology_str);
832 GNUNET_free_non_null(blacklist_topology_str);
834 /* Get number of peers to start from configuration */
836 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
838 num_peers = DEFAULT_NUM_PEERS;
841 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
843 num_puts = DEFAULT_NUM_PEERS;
846 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
848 num_gets = DEFAULT_NUM_PEERS;
850 /* Set peers_left so we know when all peers started */
851 peers_left = num_peers;
853 /* Set up a task to end testing if peer start fails */
854 die_task = GNUNET_SCHEDULER_add_delayed (sched,
855 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
856 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
858 pg = GNUNET_TESTING_daemons_start (sched, cfg,
859 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
860 &topology_callback, NULL, NULL);
868 /* Arguments for GNUNET_PROGRAM_run */
869 char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */
871 "test_dht_multipeer_data.conf", /* Config file to use */
877 struct GNUNET_GETOPT_CommandLineOption options[] = {
878 GNUNET_GETOPT_OPTION_END
880 /* Run the run function as a new program */
881 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
882 argv, "test-dht-multipeer", "nohelp",
884 if (ret != GNUNET_OK)
886 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with error code %d\n", ret);
892 main (int argc, char *argv[])
896 GNUNET_log_setup ("test-dht-multipeer",
905 * Need to remove base directory, subdirectories taken care
906 * of by the testing framework.
908 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
910 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
915 /* end of test_dht_twopeer_put_get.c */