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 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 = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
226 static double connect_topology_option_modifier = 0.0;
228 /* Global return value (0 for success, anything else for failure) */
232 * Check whether peers successfully shut down.
234 void shutdown_callback (void *cls,
245 * Task to release DHT handles for PUT
248 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
250 struct TestPutContext *test_put = cls;
251 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
252 GNUNET_DHT_disconnect(test_put->dht_handle);
253 test_put->dht_handle = NULL;
257 * Function scheduled to be run on the successful completion of this
261 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
263 GNUNET_assert (pg != NULL);
264 struct TestPutContext *test_put = all_puts;
265 struct TestGetContext *test_get = all_gets;
267 while (test_put != NULL)
269 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
270 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
271 if (test_put->dht_handle != NULL)
272 GNUNET_DHT_disconnect(test_put->dht_handle);
273 test_put = test_put->next;
276 while (test_get != NULL)
278 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
279 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
280 if (test_get->get_handle != NULL)
281 GNUNET_DHT_get_stop(test_get->get_handle);
282 if (test_get->dht_handle != NULL)
283 GNUNET_DHT_disconnect(test_get->dht_handle);
284 test_get = test_get->next;
287 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
293 * Check if the get_handle is being used, if so stop the request. Either
294 * way, schedule the end_badly_cont function which actually shuts down the
298 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls);
302 struct TestPutContext *test_put = all_puts;
303 struct TestGetContext *test_get = all_gets;
305 while (test_put != NULL)
307 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
308 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
309 if (test_put->dht_handle != NULL)
310 GNUNET_DHT_disconnect(test_put->dht_handle);
311 test_put = test_put->next;
314 while (test_get != NULL)
316 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
317 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
318 if (test_get->get_handle != NULL)
319 GNUNET_DHT_get_stop(test_get->get_handle);
320 if (test_get->dht_handle != NULL)
321 GNUNET_DHT_disconnect(test_get->dht_handle);
322 test_get = test_get->next;
325 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
330 * Task to release DHT handle associated with GET request.
333 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
335 struct TestGetContext *test_get = cls;
336 outstanding_gets--; /* GET is really finished */
337 GNUNET_DHT_disconnect(test_get->dht_handle);
338 test_get->dht_handle = NULL;
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
341 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */
343 GNUNET_SCHEDULER_cancel (die_task);
344 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
345 GNUNET_SCHEDULER_add_now(&finish_testing, NULL);
347 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
349 GNUNET_SCHEDULER_cancel(die_task);
350 GNUNET_SCHEDULER_add_now(&end_badly, "not all gets succeeded!\n");
355 * Task to release get handle.
358 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
360 struct TestGetContext *test_get = cls;
361 GNUNET_HashCode search_key; /* Key stored under */
362 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
364 memset(original_data, test_get->uid, sizeof(original_data));
365 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
367 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get from peer %s for key %s failed!\n", test_get->daemon->shortname, GNUNET_h2s(&search_key));
372 GNUNET_assert(test_get->get_handle != NULL);
373 GNUNET_DHT_get_stop(test_get->get_handle);
374 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
375 test_get->get_handle = NULL;
376 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
380 * Iterator called if the GET request initiated returns a response.
383 * @param exp when will this value expire
384 * @param key key of the result
385 * @param type type of the result
386 * @param size number of bytes in data
387 * @param data pointer to the result data
389 void get_result_iterator (void *cls,
390 struct GNUNET_TIME_Absolute exp,
391 const GNUNET_HashCode * key,
392 const struct GNUNET_PeerIdentity * const *get_path,
393 const struct GNUNET_PeerIdentity * const *put_path,
394 enum GNUNET_BLOCK_Type type,
398 struct TestGetContext *test_get = cls;
399 GNUNET_HashCode search_key; /* Key stored under */
400 char original_data[TEST_DATA_SIZE]; /* Made up data to store */
402 memset(original_data, test_get->uid, sizeof(original_data));
403 GNUNET_CRYPTO_hash(original_data, TEST_DATA_SIZE, &search_key);
405 if (test_get->succeeded == GNUNET_YES)
406 return; /* Get has already been successful, probably ending now */
409 if (put_path != NULL)
411 fprintf(stderr, "PUT Path: ");
412 for (i = 0; put_path[i] != NULL; i++)
413 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(put_path[i]));
414 fprintf(stderr, "\n");
416 if (get_path != NULL)
418 fprintf(stderr, "GET Path: ");
419 for (i = 0; get_path[i] != NULL; i++)
420 fprintf(stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s(get_path[i]));
421 fprintf(stderr, "\n");
425 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
432 test_get->succeeded = GNUNET_YES;
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
436 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
437 GNUNET_SCHEDULER_add_continuation(&get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
442 * Set up some data, and call API PUT function
445 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
447 struct TestGetContext *test_get = cls;
448 GNUNET_HashCode key; /* Made up key to store data under */
449 char data[TEST_DATA_SIZE]; /* Made up data to store */
451 if (test_get == NULL)
452 return; /* End of the list */
453 memset(data, test_get->uid, sizeof(data));
454 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
456 if (outstanding_gets > MAX_OUTSTANDING_GETS)
458 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
462 test_get->dht_handle = GNUNET_DHT_connect(test_get->daemon->cfg, 10);
463 /* Insert the data at the first peer */
464 GNUNET_assert(test_get->dht_handle != NULL);
466 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
467 GNUNET_TIME_UNIT_FOREVER_REL,
468 GNUNET_BLOCK_TYPE_TEST,
470 DEFAULT_GET_REPLICATION,
474 &get_result_iterator,
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
479 test_get->daemon->shortname);
481 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, &get_stop_task, test_get);
482 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
486 * Called when the PUT request has been transmitted to the DHT service.
487 * Schedule the GET request for some time in the future.
490 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
492 struct TestPutContext *test_put = cls;
496 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
497 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task, test_put);
498 if (puts_completed == num_puts)
500 GNUNET_assert(outstanding_puts == 0);
501 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets);
507 * Set up some data, and call API PUT function
510 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
512 struct TestPutContext *test_put = cls;
513 GNUNET_HashCode key; /* Made up key to store data under */
514 char data[TEST_DATA_SIZE]; /* Made up data to store */
516 if (test_put == NULL)
517 return; /* End of list */
519 memset(data, test_put->uid, sizeof(data));
520 GNUNET_CRYPTO_hash(data, TEST_DATA_SIZE, &key);
522 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
524 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
531 test_put->daemon->shortname);
533 test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10);
535 GNUNET_assert(test_put->dht_handle != NULL);
537 GNUNET_DHT_put(test_put->dht_handle,
539 DEFAULT_PUT_REPLICATION,
541 GNUNET_BLOCK_TYPE_TEST,
543 GNUNET_TIME_UNIT_FOREVER_ABS,
544 GNUNET_TIME_UNIT_FOREVER_REL,
545 &put_finished, test_put);
546 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
547 GNUNET_SCHEDULER_add_now(&do_put, test_put->next);
552 * Set up some all of the put and get operations we want
553 * to do. Allocate data structure for each, add to list,
554 * then call actual insert functions.
557 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
560 uint32_t temp_daemon;
561 struct TestPutContext *test_put;
562 struct TestGetContext *test_get;
563 int remember[num_puts][num_peers];
565 for (i = 0; i < num_puts; i++)
567 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
569 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
570 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
571 test_put->next = all_puts;
575 for (i = 0; i < num_gets; i++)
577 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
578 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
579 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
580 while (remember[test_get->uid][temp_daemon] == 1)
581 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
582 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
583 remember[test_get->uid][temp_daemon] = 1;
584 test_get->next = all_gets;
588 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
593 * This function is called whenever a connection attempt is finished between two of
594 * the started peers (started with GNUNET_TESTING_daemons_start). The total
595 * number of times this function is called should equal the number returned
596 * from the GNUNET_TESTING_connect_topology call.
598 * The emsg variable is NULL on success (peers connected), and non-NULL on
599 * failure (peers failed to connect).
602 topology_callback (void *cls,
603 const struct GNUNET_PeerIdentity *first,
604 const struct GNUNET_PeerIdentity *second,
606 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
607 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
608 struct GNUNET_TESTING_Daemon *first_daemon,
609 struct GNUNET_TESTING_Daemon *second_daemon,
616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
617 first_daemon->shortname,
618 second_daemon->shortname,
625 failed_connections++;
626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
627 first_daemon->shortname,
628 second_daemon->shortname, emsg);
632 if (total_connections == expected_connections)
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
639 GNUNET_SCHEDULER_cancel (die_task);
640 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
641 &end_badly, "from setup puts/gets");
643 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL);
645 else if (total_connections + failed_connections == expected_connections)
647 GNUNET_SCHEDULER_cancel (die_task);
648 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
653 peers_started_callback (void *cls,
654 const struct GNUNET_PeerIdentity *id,
655 const struct GNUNET_CONFIGURATION_Handle *cfg,
656 struct GNUNET_TESTING_Daemon *d, const char *emsg)
660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
664 GNUNET_assert (id != NULL);
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
668 (num_peers - peers_left) + 1, num_peers);
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
677 "All %d daemons started, now connecting peers!\n",
680 GNUNET_SCHEDULER_cancel (die_task);
682 expected_connections = -1;
683 if ((pg != NULL) && (peers_left == 0))
685 expected_connections = GNUNET_TESTING_connect_topology (pg,
687 connect_topology_option,
688 connect_topology_option_modifier,
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "Have %d expected connections\n", expected_connections);
698 if (expected_connections == GNUNET_SYSERR)
700 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
703 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
704 &end_badly, "from connect topology (timeout)");
713 peers_left = num_peers; /* Reset counter */
714 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
718 "Topology set up, now starting peers!\n");
720 GNUNET_TESTING_daemons_continue_startup(pg);
724 GNUNET_SCHEDULER_cancel (die_task);
725 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)");
727 GNUNET_SCHEDULER_cancel (die_task);
728 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
729 &end_badly, "from continue startup (timeout)");
733 * Callback indicating that the hostkey was created for a peer.
736 * @param id the peer identity
737 * @param d the daemon handle (pretty useless at this point, remove?)
738 * @param emsg non-null on failure
740 void hostkey_callback (void *cls,
741 const struct GNUNET_PeerIdentity *id,
742 struct GNUNET_TESTING_Daemon *d,
747 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Hostkey (%d/%d) created for peer `%s'\n",
753 num_peers - peers_left, num_peers, GNUNET_i2s(id));
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "All %d hostkeys created, now creating topology!\n",
765 GNUNET_SCHEDULER_cancel (die_task);
766 /* Set up task in case topology creation doesn't finish
767 * within a reasonable amount of time */
768 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
769 &end_badly, "from create_topology");
770 GNUNET_SCHEDULER_add_now(&create_topology, NULL);
779 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
782 char * connect_topology_str;
783 char * blacklist_topology_str;
784 char * connect_topology_option_str;
785 char * connect_topology_option_modifier_string;
788 route_option = GNUNET_DHT_RO_RECORD_ROUTE;
790 route_option = GNUNET_DHT_RO_NONE;
793 /* Get path from configuration file */
794 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
801 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
802 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
804 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
805 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
806 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
810 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
811 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connection_topology, connect_topology_str)))
813 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
814 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
816 GNUNET_free_non_null(connect_topology_str);
818 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
819 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
822 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
823 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
825 GNUNET_free_non_null(connect_topology_option_str);
827 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
828 &connect_topology_option_modifier_string))
830 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
832 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
833 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
834 connect_topology_option_modifier_string,
835 "connect_topology_option_modifier",
838 GNUNET_free (connect_topology_option_modifier_string);
841 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
842 &blacklist_transports))
843 blacklist_transports = NULL;
846 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
847 &blacklist_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
850 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
852 GNUNET_free_non_null(topology_str);
853 GNUNET_free_non_null(blacklist_topology_str);
855 /* Get number of peers to start from configuration */
857 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
859 num_peers = DEFAULT_NUM_PEERS;
862 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
864 num_puts = DEFAULT_NUM_PEERS;
867 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
869 num_gets = DEFAULT_NUM_PEERS;
871 /* Set peers_left so we know when all peers started */
872 peers_left = num_peers;
874 /* Set up a task to end testing if peer start fails */
875 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
876 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
878 pg = GNUNET_TESTING_daemons_start (cfg,
879 peers_left, /* Total number of peers */
880 peers_left, /* Number of outstanding connections */
881 peers_left, /* Number of parallel ssh connections, or peers being started at once */
882 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
885 &peers_started_callback,
897 /* Arguments for GNUNET_PROGRAM_run */
898 char *const argv[] = {"test-dht-multipeer", /* Name to give running binary */
900 "test_dht_multipeer_data.conf", /* Config file to use */
906 struct GNUNET_GETOPT_CommandLineOption options[] = {
907 GNUNET_GETOPT_OPTION_END
909 /* Run the run function as a new program */
910 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
911 argv, "test-dht-multipeer", "nohelp",
913 if (ret != GNUNET_OK)
915 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-multipeer': Failed with error code %d\n", ret);
921 main (int argc, char *argv[])
925 GNUNET_log_setup ("test-dht-multipeer",
934 * Need to remove base directory, subdirectories taken care
935 * of by the testing framework.
937 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
939 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
944 /* end of test_dht_twopeer_put_get.c */