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/gnunet-dht-driver.c
22 * @brief Driver for setting up a group of gnunet peers and
23 * then issuing GETS and PUTS on the DHT. Coarse results
24 * are reported, fine grained results (if requested) are
25 * logged to a (mysql) database, or to file.
30 #include "gnunet_testing_lib.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_dht_service.h"
37 #define VERBOSE GNUNET_NO
39 /* Timeout for entire driver to run */
40 #define DEFAULT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
42 /* Timeout for waiting for (individual) replies to get requests */
43 #define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
45 #define DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
47 /* Timeout for waiting for gets to be sent to the service */
48 #define DEFAULT_GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
50 /* Timeout for waiting for puts to be sent to the service */
51 #define DEFAULT_PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
53 /* Time to allow a find peer request to take */
54 #define DEFAULT_FIND_PEER_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40)
56 #define DEFAULT_SECONDS_PER_PEER_START GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 45)
58 #define DEFAULT_TEST_DATA_SIZE 8
60 #define DEFAULT_BUCKET_SIZE 4
62 #define FIND_PEER_THRESHOLD DEFAULT_BUCKET_SIZE * 2
64 /* If more than this many peers are added, slow down sending */
65 #define MAX_FIND_PEER_CUTOFF 2500
67 /* If less than this many peers are added, speed up sending */
68 #define MIN_FIND_PEER_CUTOFF 500
70 #define DEFAULT_MAX_OUTSTANDING_PUTS 10
72 #define DEFAULT_MAX_OUTSTANDING_FIND_PEERS 64
74 #define DEFAULT_FIND_PEER_OFFSET GNUNET_TIME_relative_divide (DEFAULT_FIND_PEER_DELAY, DEFAULT_MAX_OUTSTANDING_FIND_PEERS)
76 #define DEFAULT_MAX_OUTSTANDING_GETS 10
78 #define DEFAULT_CONNECT_TIMEOUT 60
80 #define DEFAULT_TOPOLOGY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8)
83 * Default frequency for sending malicious get messages
85 #define DEFAULT_MALICIOUS_GET_FREQUENCY 1000 /* Number of milliseconds */
88 * Default frequency for sending malicious put messages
90 #define DEFAULT_MALICIOUS_PUT_FREQUENCY 1000 /* Default is in milliseconds */
94 struct MaliciousContext
97 * Handle to DHT service (via the API)
99 struct GNUNET_DHT_Handle *dht_handle;
102 * Handle to the peer daemon
104 struct GNUNET_TESTING_Daemon *daemon;
107 * Task for disconnecting DHT handles
109 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
112 * What type of malicious to set this peer to.
119 /* This is a linked list */
120 struct TestFindPeer *next;
122 /* Handle to the bigger context */
123 struct FindPeerContext *find_peer_context;
126 * Handle to the peer's DHT service (via the API)
128 struct GNUNET_DHT_Handle *dht_handle;
131 * Handle to the peer daemon
133 struct GNUNET_TESTING_Daemon *daemon;
136 * Task for disconnecting DHT handles
138 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
141 struct TestPutContext
143 /* This is a linked list */
144 struct TestPutContext *next;
147 * Handle to the first peers DHT service (via the API)
149 struct GNUNET_DHT_Handle *dht_handle;
152 * Handle to the PUT peer daemon
154 struct GNUNET_TESTING_Daemon *daemon;
157 * Identifier for this PUT
162 * Task for disconnecting DHT handles
164 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
167 struct TestGetContext
169 /* This is a linked list */
170 struct TestGetContext *next;
173 * Handle to the first peers DHT service (via the API)
175 struct GNUNET_DHT_Handle *dht_handle;
178 * Handle for the DHT get request
180 struct GNUNET_DHT_GetHandle *get_handle;
183 * Handle to the GET peer daemon
185 struct GNUNET_TESTING_Daemon *daemon;
188 * Identifier for this GET
193 * Task for disconnecting DHT handles (and stopping GET)
195 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
198 * Whether or not this request has been fulfilled already.
204 * Simple struct to keep track of progress, and print a
205 * nice little percentage meter for long running tasks.
215 unsigned int completed;
219 char *startup_string;
223 * Linked list of information for populating statistics
224 * before ending trial.
226 struct StatisticsIteratorContext
228 const struct GNUNET_PeerIdentity *peer;
229 unsigned int stat_routes;
230 unsigned int stat_route_forwards;
231 unsigned int stat_results;
232 unsigned int stat_results_to_client;
233 unsigned int stat_result_forwards;
234 unsigned int stat_gets;
235 unsigned int stat_puts;
236 unsigned int stat_puts_inserted;
237 unsigned int stat_find_peer;
238 unsigned int stat_find_peer_start;
239 unsigned int stat_get_start;
240 unsigned int stat_put_start;
241 unsigned int stat_find_peer_reply;
242 unsigned int stat_get_reply;
243 unsigned int stat_find_peer_answer;
244 unsigned int stat_get_response_start;
248 * Context for getting a topology, logging it, and continuing
249 * on with some next operation.
251 struct TopologyIteratorContext
253 unsigned int total_iterations;
254 unsigned int current_iteration;
255 unsigned int total_connections;
256 struct GNUNET_PeerIdentity *peer;
257 GNUNET_SCHEDULER_Task cont;
259 struct GNUNET_TIME_Relative timeout;
265 * Timeout to let all get requests happen.
267 static struct GNUNET_TIME_Relative all_get_timeout;
272 static struct GNUNET_TIME_Relative get_timeout;
274 static struct GNUNET_TIME_Relative get_delay;
276 static struct GNUNET_TIME_Relative put_delay;
278 static struct GNUNET_TIME_Relative find_peer_delay;
280 static struct GNUNET_TIME_Relative find_peer_offset;
282 static struct GNUNET_TIME_Relative seconds_per_peer_start;
284 static int do_find_peer;
286 static unsigned long long test_data_size = DEFAULT_TEST_DATA_SIZE;
288 static unsigned long long max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
290 static unsigned long long max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
292 static unsigned long long malicious_getters;
294 static unsigned long long max_outstanding_find_peers;
296 static unsigned long long malicious_putters;
298 static unsigned long long malicious_droppers;
300 static unsigned long long malicious_get_frequency;
302 static unsigned long long malicious_put_frequency;
304 static unsigned long long settle_time;
306 static unsigned long long trial_to_run;
308 static struct GNUNET_DHTLOG_Handle *dhtlog_handle;
310 static unsigned long long trialuid;
313 * Hash map of stats contexts.
315 struct GNUNET_CONTAINER_MultiHashMap *stats_map;
318 * LL of malicious settings.
320 struct MaliciousContext *all_malicious;
323 * List of GETS to perform
325 struct TestGetContext *all_gets;
328 * List of PUTS to perform
330 struct TestPutContext *all_puts;
333 * Directory to store temporary data in, defined in config file
335 static char *test_directory;
338 * Variable used to store the number of connections we should wait for.
340 static unsigned int expected_connections;
343 * Variable used to keep track of how many peers aren't yet started.
345 static unsigned long long peers_left;
348 * Handle to the set of all peers run for this test.
350 static struct GNUNET_TESTING_PeerGroup *pg;
353 * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
355 static struct GNUNET_SCHEDULER_Handle *sched;
358 * Global config handle.
360 const struct GNUNET_CONFIGURATION_Handle *config;
363 * Total number of peers to run, set based on config file.
365 static unsigned long long num_peers;
368 * Total number of items to insert.
370 static unsigned long long num_puts;
373 * How many puts do we currently have in flight?
375 static unsigned long long outstanding_puts;
378 * How many puts are done?
380 static unsigned long long puts_completed;
383 * Total number of items to attempt to get.
385 static unsigned long long num_gets;
388 * How many puts do we currently have in flight?
390 static unsigned long long outstanding_gets;
393 * How many gets are done?
395 static unsigned long long gets_completed;
398 * How many gets failed?
400 static unsigned long long gets_failed;
403 * How many malicious control messages do
404 * we currently have in flight?
406 static unsigned long long outstanding_malicious;
409 * How many set malicious peers are done?
411 static unsigned long long malicious_completed;
414 * Global used to count how many connections we have currently
415 * been notified about (how many times has topology_callback been called
418 static unsigned int total_connections;
421 * Global used to count how many failed connections we have
422 * been notified about (how many times has topology_callback
423 * been called with failure?)
425 static unsigned int failed_connections;
427 /* Task handle to use to schedule shutdown if something goes wrong */
428 GNUNET_SCHEDULER_TaskIdentifier die_task;
430 static char *blacklist_transports;
432 static enum GNUNET_TESTING_Topology topology;
434 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
436 static enum GNUNET_TESTING_Topology connect_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
438 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
440 static double connect_topology_option_modifier = 0.0;
442 static struct ProgressMeter *hostkey_meter;
444 static struct ProgressMeter *peer_start_meter;
446 static struct ProgressMeter *peer_connect_meter;
448 static struct ProgressMeter *put_meter;
450 static struct ProgressMeter *get_meter;
452 /* Global return value (0 for success, anything else for failure) */
456 * Create a meter to keep track of the progress of some task.
458 * @param total the total number of items to complete
459 * @param start_string a string to prefix the meter with (if printing)
460 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
463 * @return the progress meter
465 static struct ProgressMeter *
466 create_meter(unsigned int total, char * start_string, int print)
468 struct ProgressMeter *ret;
469 ret = GNUNET_malloc(sizeof(struct ProgressMeter));
472 ret->modnum = total / 4;
473 ret->dotnum = (total / 50) + 1;
474 if (start_string != NULL)
475 ret->startup_string = GNUNET_strdup(start_string);
477 ret->startup_string = GNUNET_strdup("");
483 * Update progress meter (increment by one).
485 * @param meter the meter to update and print info for
487 * @return GNUNET_YES if called the total requested,
488 * GNUNET_NO if more items expected
491 update_meter(struct ProgressMeter *meter)
493 if (meter->print == GNUNET_YES)
495 if (meter->completed % meter->modnum == 0)
497 if (meter->completed == 0)
499 fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
502 fprintf(stdout, "%d%%", (int)(((float)meter->completed / meter->total) * 100));
504 else if (meter->completed % meter->dotnum == 0)
505 fprintf(stdout, ".");
507 if (meter->completed + 1 == meter->total)
508 fprintf(stdout, "%d%%]\n", 100);
513 if (meter->completed == meter->total)
519 * Release resources for meter
521 * @param meter the meter to free
524 free_meter(struct ProgressMeter *meter)
526 GNUNET_free_non_null(meter->startup_string);
527 GNUNET_free_non_null(meter);
531 * Check whether peers successfully shut down.
533 void shutdown_callback (void *cls,
544 * Task to release DHT handles for PUT
547 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
549 struct TestPutContext *test_put = cls;
550 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
551 GNUNET_DHT_disconnect(test_put->dht_handle);
552 test_put->dht_handle = NULL;
556 * Function scheduled to be run on the successful completion of this
560 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
562 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n", (char *)cls);
563 GNUNET_assert (pg != NULL);
564 struct TestPutContext *test_put = all_puts;
565 struct TestGetContext *test_get = all_gets;
567 while (test_put != NULL)
569 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
570 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
571 if (test_put->dht_handle != NULL)
572 GNUNET_DHT_disconnect(test_put->dht_handle);
573 test_put = test_put->next;
576 while (test_get != NULL)
578 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
579 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
580 if (test_get->get_handle != NULL)
581 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
582 if (test_get->dht_handle != NULL)
583 GNUNET_DHT_disconnect(test_get->dht_handle);
584 test_get = test_get->next;
587 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
589 if (dhtlog_handle != NULL)
591 fprintf(stderr, "Update trial endtime\n");
592 dhtlog_handle->update_trial (trialuid, gets_completed);
593 GNUNET_DHTLOG_disconnect(dhtlog_handle);
594 dhtlog_handle = NULL;
597 if (hostkey_meter != NULL)
598 free_meter(hostkey_meter);
599 if (peer_start_meter != NULL)
600 free_meter(peer_start_meter);
601 if (peer_connect_meter != NULL)
602 free_meter(peer_connect_meter);
603 if (put_meter != NULL)
604 free_meter(put_meter);
605 if (get_meter != NULL)
606 free_meter(get_meter);
612 * Callback for iterating over all the peer connections of a peer group.
614 void log_topology_cb (void *cls,
615 const struct GNUNET_PeerIdentity *first,
616 const struct GNUNET_PeerIdentity *second,
617 struct GNUNET_TIME_Relative latency,
621 struct TopologyIteratorContext *topo_ctx = cls;
622 if ((first != NULL) && (second != NULL))
624 topo_ctx->total_connections++;
625 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging_extended"))
626 dhtlog_handle->insert_extended_topology(first, second);
630 GNUNET_assert(dhtlog_handle != NULL);
631 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Topology iteration (%u/%u) finished (%u connections)\n", topo_ctx->current_iteration, topo_ctx->total_iterations, topo_ctx->total_connections);
632 dhtlog_handle->update_topology(topo_ctx->total_connections);
633 if (topo_ctx->cont != NULL)
634 GNUNET_SCHEDULER_add_now (sched, topo_ctx->cont, topo_ctx->cls);
635 GNUNET_free(topo_ctx);
640 * Iterator over hash map entries.
642 * @param cls closure - always NULL
643 * @param key current key code
644 * @param value value in the hash map, a stats context
645 * @return GNUNET_YES if we should continue to
649 static int stats_iterate (void *cls,
650 const GNUNET_HashCode * key,
653 struct StatisticsIteratorContext *stats_ctx;
657 dhtlog_handle->insert_stat(stats_ctx->peer, stats_ctx->stat_routes, stats_ctx->stat_route_forwards, stats_ctx->stat_results,
658 stats_ctx->stat_results_to_client, stats_ctx->stat_result_forwards, stats_ctx->stat_gets,
659 stats_ctx->stat_puts, stats_ctx->stat_puts_inserted, stats_ctx->stat_find_peer,
660 stats_ctx->stat_find_peer_start, stats_ctx->stat_get_start, stats_ctx->stat_put_start,
661 stats_ctx->stat_find_peer_reply, stats_ctx->stat_get_reply, stats_ctx->stat_find_peer_answer,
662 stats_ctx->stat_get_response_start);
663 GNUNET_free(stats_ctx);
667 static void stats_finished (void *cls, int result)
669 fprintf(stderr, "Finished getting all peers statistics, iterating!\n");
670 GNUNET_CONTAINER_multihashmap_iterate(stats_map, &stats_iterate, NULL);
671 GNUNET_CONTAINER_multihashmap_destroy(stats_map);
672 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
676 * Callback function to process statistic values.
679 * @param peer the peer the statistics belong to
680 * @param subsystem name of subsystem that created the statistic
681 * @param name the name of the datum
682 * @param value the current value
683 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
684 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
686 static int stats_handle (void *cls,
687 const struct GNUNET_PeerIdentity *peer,
688 const char *subsystem,
693 struct StatisticsIteratorContext *stats_ctx;
695 if (dhtlog_handle != NULL)
696 dhtlog_handle->add_generic_stat(peer, name, subsystem, value);
697 if (GNUNET_CONTAINER_multihashmap_contains(stats_map, &peer->hashPubKey))
699 stats_ctx = GNUNET_CONTAINER_multihashmap_get(stats_map, &peer->hashPubKey);
703 stats_ctx = GNUNET_malloc(sizeof(struct StatisticsIteratorContext));
704 stats_ctx->peer = peer;
705 GNUNET_CONTAINER_multihashmap_put(stats_map, &peer->hashPubKey, stats_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
707 GNUNET_assert(stats_ctx != NULL);
709 if (strcmp(name, STAT_ROUTES) == 0)
710 stats_ctx->stat_routes = value;
711 else if (strcmp(name, STAT_ROUTE_FORWARDS) == 0)
712 stats_ctx->stat_route_forwards = value;
713 else if (strcmp(name, STAT_RESULTS) == 0)
714 stats_ctx->stat_results = value;
715 else if (strcmp(name, STAT_RESULTS_TO_CLIENT) == 0)
716 stats_ctx->stat_results_to_client = value;
717 else if (strcmp(name, STAT_RESULT_FORWARDS) == 0)
718 stats_ctx->stat_result_forwards = value;
719 else if (strcmp(name, STAT_GETS) == 0)
720 stats_ctx->stat_gets = value;
721 else if (strcmp(name, STAT_PUTS) == 0)
722 stats_ctx->stat_puts = value;
723 else if (strcmp(name, STAT_PUTS_INSERTED) == 0)
724 stats_ctx->stat_puts_inserted = value;
725 else if (strcmp(name, STAT_FIND_PEER) == 0)
726 stats_ctx->stat_find_peer = value;
727 else if (strcmp(name, STAT_FIND_PEER_START) == 0)
728 stats_ctx->stat_find_peer_start = value;
729 else if (strcmp(name, STAT_GET_START) == 0)
730 stats_ctx->stat_get_start = value;
731 else if (strcmp(name, STAT_PUT_START) == 0)
732 stats_ctx->stat_put_start = value;
733 else if (strcmp(name, STAT_FIND_PEER_REPLY) == 0)
734 stats_ctx->stat_find_peer_reply = value;
735 else if (strcmp(name, STAT_GET_REPLY) == 0)
736 stats_ctx->stat_get_reply = value;
737 else if (strcmp(name, STAT_FIND_PEER_ANSWER) == 0)
738 stats_ctx->stat_find_peer_answer = value;
739 else if (strcmp(name, STAT_GET_RESPONSE_START) == 0)
740 stats_ctx->stat_get_response_start = value;
746 * Connect to statistics service for each peer and get the appropriate
747 * dht statistics for safe keeping.
750 log_dht_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
752 stats_map = GNUNET_CONTAINER_multihashmap_create(num_peers);
753 fprintf(stderr, "Starting statistics logging\n");
754 GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_handle, NULL);
759 * Connect to all peers in the peer group and iterate over their
763 capture_current_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
765 struct TopologyIteratorContext *topo_ctx = cls;
766 dhtlog_handle->insert_topology(0);
767 GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx);
772 * Check if the get_handle is being used, if so stop the request. Either
773 * way, schedule the end_badly_cont function which actually shuts down the
777 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
779 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n", (char *)cls);
781 struct TestPutContext *test_put = all_puts;
782 struct TestGetContext *test_get = all_gets;
784 while (test_put != NULL)
786 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
787 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
788 if (test_put->dht_handle != NULL)
789 GNUNET_DHT_disconnect(test_put->dht_handle);
790 test_put = test_put->next;
793 while (test_get != NULL)
795 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
796 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
797 if (test_get->get_handle != NULL)
798 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
799 if (test_get->dht_handle != NULL)
800 GNUNET_DHT_disconnect(test_get->dht_handle);
801 test_get = test_get->next;
804 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
806 if (dhtlog_handle != NULL)
808 fprintf(stderr, "Update trial endtime\n");
809 dhtlog_handle->update_trial (trialuid, gets_completed);
810 GNUNET_DHTLOG_disconnect(dhtlog_handle);
811 dhtlog_handle = NULL;
814 if (hostkey_meter != NULL)
815 free_meter(hostkey_meter);
816 if (peer_start_meter != NULL)
817 free_meter(peer_start_meter);
818 if (peer_connect_meter != NULL)
819 free_meter(peer_connect_meter);
820 if (put_meter != NULL)
821 free_meter(put_meter);
822 if (get_meter != NULL)
823 free_meter(get_meter);
829 * Task to release DHT handle associated with GET request.
832 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
834 struct TestGetContext *test_get = cls;
835 struct TopologyIteratorContext *topo_ctx;
836 outstanding_gets--; /* GET is really finished */
837 GNUNET_DHT_disconnect(test_get->dht_handle);
838 test_get->dht_handle = NULL;
841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
843 update_meter(get_meter);
844 if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
846 GNUNET_SCHEDULER_cancel(sched, die_task);
847 //GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
848 if (dhtlog_handle != NULL)
850 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
851 topo_ctx->cont = &log_dht_statistics;
852 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
855 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
860 * Task to release get handle.
863 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
865 struct TestGetContext *test_get = cls;
867 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
869 GNUNET_assert(test_get->get_handle != NULL);
870 GNUNET_DHT_get_stop(test_get->get_handle, &get_stop_finished, test_get);
871 test_get->get_handle = NULL;
872 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
876 * Iterator called if the GET request initiated returns a response.
879 * @param exp when will this value expire
880 * @param key key of the result
881 * @param type type of the result
882 * @param size number of bytes in data
883 * @param data pointer to the result data
885 void get_result_iterator (void *cls,
886 struct GNUNET_TIME_Absolute exp,
887 const GNUNET_HashCode * key,
892 struct TestGetContext *test_get = cls;
893 GNUNET_HashCode search_key; /* Key stored under */
894 char original_data[test_data_size]; /* Made up data to store */
896 memset(original_data, test_get->uid, sizeof(original_data));
897 GNUNET_CRYPTO_hash(original_data, test_data_size, &search_key);
899 if (test_get->succeeded == GNUNET_YES)
900 return; /* Get has already been successful, probably ending now */
902 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
909 test_get->succeeded = GNUNET_YES;
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
914 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
915 GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
919 * Continuation telling us GET request was sent.
922 get_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
924 // Is there something to be done here?
925 if (tc->reason != GNUNET_SCHEDULER_REASON_PREREQ_DONE)
930 * Set up some data, and call API PUT function
933 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
935 struct TestGetContext *test_get = cls;
936 GNUNET_HashCode key; /* Made up key to store data under */
937 char data[test_data_size]; /* Made up data to store */
941 GNUNET_SCHEDULER_cancel(sched, die_task);
942 GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
944 if (test_get == NULL)
945 return; /* End of the list */
947 memset(data, test_get->uid, sizeof(data));
948 GNUNET_CRYPTO_hash(data, test_data_size, &key);
950 if (outstanding_gets > max_outstanding_gets)
952 GNUNET_SCHEDULER_add_delayed (sched, get_delay, &do_get, test_get);
956 test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10);
957 /* Insert the data at the first peer */
958 GNUNET_assert(test_get->dht_handle != NULL);
960 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
961 GNUNET_TIME_relative_get_forever(),
964 &get_result_iterator,
969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
971 test_get->daemon->shortname);
973 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, get_timeout, &get_stop_task, test_get);
974 GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next);
978 * Called when the PUT request has been transmitted to the DHT service.
979 * Schedule the GET request for some time in the future.
982 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
984 struct TestPutContext *test_put = cls;
985 struct TopologyIteratorContext *topo_ctx;
989 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
990 fprintf(stderr, "PUT Request failed!\n");
992 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
993 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put);
994 if (GNUNET_YES == update_meter(put_meter))
996 GNUNET_assert(outstanding_puts == 0);
997 GNUNET_SCHEDULER_cancel (sched, die_task);
998 if (dhtlog_handle != NULL)
1000 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1001 topo_ctx->cont = &do_get;
1002 topo_ctx->cls = all_gets;
1003 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1004 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout), DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT),
1005 &end_badly, "from do gets");
1006 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
1010 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout),
1011 &end_badly, "from do gets");
1012 GNUNET_SCHEDULER_add_delayed(sched, DEFAULT_GET_TIMEOUT, &do_get, all_gets);
1013 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
1020 * Set up some data, and call API PUT function
1023 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1025 struct TestPutContext *test_put = cls;
1026 GNUNET_HashCode key; /* Made up key to store data under */
1027 char data[test_data_size]; /* Made up data to store */
1030 if (test_put == NULL)
1031 return; /* End of list */
1033 memset(data, test_put->uid, sizeof(data));
1034 GNUNET_CRYPTO_hash(data, test_data_size, &key);
1036 if (outstanding_puts > max_outstanding_puts)
1038 GNUNET_SCHEDULER_add_delayed (sched, put_delay, &do_put, test_put);
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
1045 test_put->daemon->shortname);
1047 test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10);
1049 GNUNET_assert(test_put->dht_handle != NULL);
1051 GNUNET_DHT_put(test_put->dht_handle,
1055 GNUNET_TIME_absolute_get_forever(),
1056 GNUNET_TIME_relative_get_forever(),
1057 &put_finished, test_put);
1058 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
1059 rand = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
1060 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, rand), &do_put, test_put->next);
1064 * Context for sending out find peer requests.
1066 struct FindPeerContext
1069 * How long to send find peer requests, once the settle time
1070 * is over don't send any more out!
1072 * TODO: Add option for settle time and find peer sending time?
1074 struct GNUNET_TIME_Absolute endtime;
1077 * Number of connections in the current topology
1078 * (after this round of find peer requests has ended).
1080 unsigned int current_peers;
1083 * Number of connections in the current topology
1084 * (before this round of find peer requests started).
1086 unsigned int previous_peers;
1089 * Number of find peer requests we have currently
1092 unsigned int outstanding;
1095 * Number of find peer requests to send in this round.
1100 * Number of find peer requests sent last time around.
1102 unsigned int last_sent;
1105 * Hashmap of peers in the current topology, value
1106 * is a PeerCount, with the number of connections
1109 struct GNUNET_CONTAINER_MultiHashMap *peer_hash;
1112 * Min heap which orders values in the peer_hash for
1115 struct GNUNET_CONTAINER_Heap *peer_min_heap;
1119 schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
1122 * Given a number of total peers and a bucket size, estimate the number of
1123 * connections in a perfect kademlia topology.
1125 static unsigned int connection_estimate(unsigned int peer_count, unsigned int bucket_size)
1128 unsigned int filled;
1132 while (i >= bucket_size)
1137 filled++; /* Add one filled bucket to account for one "half full" and some miscellaneous */
1138 return filled * bucket_size * peer_count;
1144 /** Node in the heap */
1145 struct GNUNET_CONTAINER_HeapNode *heap_node;
1147 /** Peer the count refers to */
1148 struct GNUNET_PeerIdentity peer_id;
1150 /** Count of connections this peer has */
1156 * Add a connection to the find_peer_context given. This may
1157 * be complete overkill, but allows us to choose the peers with
1158 * the least connections to initiate find peer requests from.
1160 static void add_new_connection(struct FindPeerContext *find_peer_context,
1161 const struct GNUNET_PeerIdentity *first,
1162 const struct GNUNET_PeerIdentity *second)
1164 struct PeerCount *first_count;
1165 struct PeerCount *second_count;
1167 if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &first->hashPubKey))
1169 first_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &first->hashPubKey);
1170 first_count->count++;
1171 GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, first_count->heap_node, first_count->count);
1175 first_count = GNUNET_malloc(sizeof(struct PeerCount));
1176 first_count->count = 1;
1177 memcpy(&first_count->peer_id, first, sizeof(struct GNUNET_PeerIdentity));
1178 first_count->heap_node = GNUNET_CONTAINER_heap_insert(find_peer_context->peer_min_heap, first_count, first_count->count);
1179 GNUNET_CONTAINER_multihashmap_put(find_peer_context->peer_hash, &first->hashPubKey, first_count, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1182 if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &second->hashPubKey))
1184 second_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &second->hashPubKey);
1185 second_count->count++;
1186 GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, second_count->heap_node, second_count->count);
1190 second_count = GNUNET_malloc(sizeof(struct PeerCount));
1191 second_count->count = 1;
1192 memcpy(&second_count->peer_id, second, sizeof(struct GNUNET_PeerIdentity));
1193 second_count->heap_node = GNUNET_CONTAINER_heap_insert(find_peer_context->peer_min_heap, second_count, second_count->count);
1194 GNUNET_CONTAINER_multihashmap_put(find_peer_context->peer_hash, &second->hashPubKey, second_count, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1199 * Callback for iterating over all the peer connections of a peer group.
1201 void count_peers_cb (void *cls,
1202 const struct GNUNET_PeerIdentity *first,
1203 const struct GNUNET_PeerIdentity *second,
1204 struct GNUNET_TIME_Relative latency,
1208 struct FindPeerContext *find_peer_context = cls;
1209 if ((first != NULL) && (second != NULL))
1211 add_new_connection(find_peer_context, first, second);
1212 find_peer_context->current_peers++;
1216 GNUNET_assert(dhtlog_handle != NULL);
1217 /*GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peer count finished (%u connections), %u new peers, connection estimate %u\n", find_peer_context->current_peers, find_peer_context->current_peers - find_peer_context->previous_peers, connection_estimate(num_peers, DEFAULT_BUCKET_SIZE));*/
1218 if ((find_peer_context->current_peers - find_peer_context->previous_peers > FIND_PEER_THRESHOLD) &&
1219 (find_peer_context->current_peers < connection_estimate(num_peers, DEFAULT_BUCKET_SIZE)) &&
1220 (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0))
1222 GNUNET_SCHEDULER_add_now(sched, &schedule_find_peer_requests, find_peer_context);
1226 fprintf(stderr, "Not sending any more find peer requests.\n");
1232 * Connect to all peers in the peer group and iterate over their
1236 count_new_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1238 struct FindPeerContext *find_peer_context = cls;
1239 find_peer_context->previous_peers = find_peer_context->current_peers;
1240 find_peer_context->current_peers = 0;
1241 GNUNET_TESTING_get_topology (pg, &count_peers_cb, find_peer_context);
1246 decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1248 struct TestFindPeer *test_find_peer = cls;
1249 GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0);
1250 test_find_peer->find_peer_context->outstanding--;
1251 test_find_peer->find_peer_context->total--;
1252 if ((0 == test_find_peer->find_peer_context->total) &&
1253 (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value > 0))
1255 GNUNET_SCHEDULER_add_now(sched, &count_new_peers, test_find_peer->find_peer_context);
1257 GNUNET_free(test_find_peer);
1261 * A find peer request has been sent to the server, now we will schedule a task
1262 * to wait the appropriate time to allow the request to go out and back.
1264 * @param cls closure - a TestFindPeer struct
1265 * @param tc context the task is being called with
1268 handle_find_peer_sent (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1270 struct TestFindPeer *test_find_peer = cls;
1272 GNUNET_DHT_disconnect(test_find_peer->dht_handle);
1273 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_divide(find_peer_delay, 2), &decrement_find_peers, test_find_peer);
1277 send_find_peer_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1279 struct TestFindPeer *test_find_peer = cls;
1281 if (test_find_peer->find_peer_context->outstanding > max_outstanding_find_peers)
1283 GNUNET_SCHEDULER_add_delayed(sched, find_peer_offset, &send_find_peer_request, test_find_peer);
1287 test_find_peer->find_peer_context->outstanding++;
1288 if (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value == 0)
1290 GNUNET_SCHEDULER_add_now(sched, &decrement_find_peers, test_find_peer);
1294 test_find_peer->dht_handle = GNUNET_DHT_connect(sched, test_find_peer->daemon->cfg, 1);
1295 GNUNET_assert(test_find_peer->dht_handle != NULL);
1296 GNUNET_DHT_find_peers (test_find_peer->dht_handle,
1297 &handle_find_peer_sent, test_find_peer);
1301 * Iterator over hash map entries.
1303 * @param cls closure
1304 * @param key current key code
1305 * @param value value in the hash map
1306 * @return GNUNET_YES if we should continue to
1310 static int remove_peer_count (void *cls,
1311 const GNUNET_HashCode * key,
1314 struct FindPeerContext *find_peer_ctx = cls;
1315 struct PeerCount *peer_count = value;
1316 GNUNET_CONTAINER_heap_remove_node(find_peer_ctx->peer_min_heap, peer_count->heap_node);
1317 GNUNET_free(peer_count);
1324 * Set up a single find peer request for each peer in the topology. Do this
1325 * until the settle time is over, limited by the number of outstanding requests
1326 * and the time allowed for each one!
1329 schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1331 struct FindPeerContext *find_peer_ctx = cls;
1332 struct TestFindPeer *test_find_peer;
1333 struct PeerCount *peer_count;
1337 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
1338 find_peer_ctx->total = 1;
1339 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
1340 find_peer_ctx->total = find_peer_ctx->last_sent - (find_peer_ctx->last_sent / 8);
1342 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers < MIN_FIND_PEER_CUTOFF)
1343 find_peer_ctx->total = find_peer_ctx->last_sent * 2; /* FIXME: always multiply by two (unless above max?) */
1345 find_peer_ctx->total = find_peer_ctx->last_sent;
1348 find_peer_ctx->total = find_peer_ctx->last_sent * 2;
1351 if (find_peer_ctx->total > max_outstanding_find_peers)
1352 find_peer_ctx->total = max_outstanding_find_peers;
1354 find_peer_ctx->last_sent = find_peer_ctx->total;
1355 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending %u find peer messages (goal %u connections)\n", find_peer_ctx->total, connection_estimate(num_peers, DEFAULT_BUCKET_SIZE));
1357 find_peer_offset = GNUNET_TIME_relative_divide(find_peer_delay, find_peer_ctx->total);
1358 for (i = 0; i < find_peer_ctx->total; i++)
1360 test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer));
1361 if (find_peer_ctx->previous_peers == 0) /* If we haven't sent any requests, yet choose random peers */
1364 * Attempt to spread find peer requests across even sections of the peer address
1365 * space. Choose basically 1 peer in every num_peers / max_outstanding_requests
1366 * each time, then offset it by a randomish value.
1368 * For instance, if num_peers is 100 and max_outstanding is 10, first chosen peer
1369 * will be between 0 - 10, second between 10 - 20, etc.
1371 random = (num_peers / find_peer_ctx->total) * i;
1372 random = random + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (num_peers / find_peer_ctx->total));
1373 if (random >= num_peers)
1375 random = random - num_peers;
1378 random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1380 test_find_peer->daemon = GNUNET_TESTING_daemon_get(pg, random);
1382 else /* If we have sent requests, choose peers with a low number of connections to send requests from */
1384 peer_count = GNUNET_CONTAINER_heap_remove_root(find_peer_ctx->peer_min_heap);
1385 GNUNET_CONTAINER_multihashmap_remove(find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey, peer_count);
1386 test_find_peer->daemon = GNUNET_TESTING_daemon_get_by_id(pg, &peer_count->peer_id);
1387 GNUNET_assert(test_find_peer->daemon != NULL);
1390 test_find_peer->find_peer_context = find_peer_ctx;
1391 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(find_peer_offset, i), &send_find_peer_request, test_find_peer);
1394 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap == NULL))
1396 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create(num_peers);
1397 find_peer_ctx->peer_min_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1401 GNUNET_CONTAINER_multihashmap_iterate(find_peer_ctx->peer_hash, &remove_peer_count, find_peer_ctx);
1402 GNUNET_CONTAINER_multihashmap_destroy(find_peer_ctx->peer_hash);
1403 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create(num_peers);
1406 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash));
1407 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap));
1412 * Set up some all of the put and get operations we want
1413 * to do. Allocate data structure for each, add to list,
1414 * then call actual insert functions.
1417 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1420 uint32_t temp_daemon;
1421 struct TestPutContext *test_put;
1422 struct TestGetContext *test_get;
1423 int remember[num_puts][num_peers];
1425 memset(&remember, 0, sizeof(int) * num_puts * num_peers);
1426 for (i = 0; i < num_puts; i++)
1428 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
1430 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1431 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1432 test_put->next = all_puts;
1433 all_puts = test_put;
1436 for (i = 0; i < num_gets; i++)
1438 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
1439 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
1440 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1441 while (remember[test_get->uid][temp_daemon] == 1)
1442 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1443 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1444 remember[test_get->uid][temp_daemon] = 1;
1445 test_get->next = all_gets;
1446 all_gets = test_get;
1449 /*GNUNET_SCHEDULER_cancel (sched, die_task);*/
1450 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
1451 &end_badly, "from do puts");
1452 GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts);
1456 * Set up some all of the put and get operations we want
1457 * to do. Allocate data structure for each, add to list,
1458 * then call actual insert functions.
1461 continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1465 struct TopologyIteratorContext *topo_ctx;
1466 struct FindPeerContext *find_peer_context;
1467 if (dhtlog_handle != NULL)
1469 if (settle_time >= 180 * 2)
1470 max = (settle_time / 180) - 2;
1473 for (i = 1; i < max; i++)
1475 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1476 topo_ctx->current_iteration = i;
1477 topo_ctx->total_iterations = max;
1478 //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
1479 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, i * 3), &capture_current_topology, topo_ctx);
1481 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1482 topo_ctx->cont = &setup_puts_and_gets;
1483 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &capture_current_topology, topo_ctx);
1486 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &setup_puts_and_gets, NULL);
1488 if (GNUNET_YES == do_find_peer)
1490 find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext));
1491 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time));
1492 GNUNET_SCHEDULER_add_now(sched, &schedule_find_peer_requests, find_peer_context);
1497 * Task to release DHT handles
1500 malicious_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1502 struct MaliciousContext *ctx = cls;
1503 outstanding_malicious--;
1504 malicious_completed++;
1505 ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
1506 GNUNET_DHT_disconnect(ctx->dht_handle);
1507 ctx->dht_handle = NULL;
1510 if (malicious_completed == malicious_getters + malicious_putters + malicious_droppers)
1512 GNUNET_SCHEDULER_cancel(sched, die_task);
1513 fprintf(stderr, "Finished setting all malicious peers up, calling continuation!\n");
1514 if (dhtlog_handle != NULL)
1515 GNUNET_SCHEDULER_add_now (sched,
1516 &continue_puts_and_gets, NULL);
1518 GNUNET_SCHEDULER_add_delayed (sched,
1519 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1520 &continue_puts_and_gets, NULL);
1526 * Task to release DHT handles
1529 malicious_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1531 struct MaliciousContext *ctx = cls;
1532 GNUNET_SCHEDULER_cancel(sched, ctx->disconnect_task);
1533 GNUNET_SCHEDULER_add_now(sched, &malicious_disconnect_task, ctx);
1537 * Set up some data, and call API PUT function
1540 set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1542 struct MaliciousContext *ctx = cls;
1545 if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
1547 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1551 if (ctx->dht_handle == NULL)
1553 ctx->dht_handle = GNUNET_DHT_connect(sched, ctx->daemon->cfg, 1);
1554 outstanding_malicious++;
1557 GNUNET_assert(ctx->dht_handle != NULL);
1561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
1562 ctx->daemon->shortname, ctx->malicious_type);
1566 switch (ctx->malicious_type)
1568 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
1569 ret = GNUNET_DHT_set_malicious_getter(ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx);
1571 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
1572 ret = GNUNET_DHT_set_malicious_putter(ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx);
1574 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
1575 ret = GNUNET_DHT_set_malicious_dropper(ctx->dht_handle, &malicious_done_task, ctx);
1581 if (ret == GNUNET_NO)
1583 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1586 ctx->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &malicious_disconnect_task, ctx);
1590 * Select randomly from set of known peers,
1591 * set the desired number of peers to the
1592 * proper malicious types.
1595 setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1597 struct MaliciousContext *ctx;
1599 uint32_t temp_daemon;
1601 for (i = 0; i < malicious_getters; i++)
1603 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1604 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1605 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1606 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
1607 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1611 for (i = 0; i < malicious_putters; i++)
1613 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1614 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1615 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1616 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
1617 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1621 for (i = 0; i < malicious_droppers; i++)
1623 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1624 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1625 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1626 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
1627 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1630 if (malicious_getters + malicious_putters + malicious_droppers > 0)
1631 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (malicious_getters + malicious_putters + malicious_droppers) * 2),
1632 &end_badly, "from set malicious");
1635 if (dhtlog_handle != NULL)
1636 GNUNET_SCHEDULER_add_now (sched,
1637 &continue_puts_and_gets, NULL);
1639 GNUNET_SCHEDULER_add_delayed (sched,
1640 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1641 &continue_puts_and_gets, NULL);
1647 * This function is called whenever a connection attempt is finished between two of
1648 * the started peers (started with GNUNET_TESTING_daemons_start). The total
1649 * number of times this function is called should equal the number returned
1650 * from the GNUNET_TESTING_connect_topology call.
1652 * The emsg variable is NULL on success (peers connected), and non-NULL on
1653 * failure (peers failed to connect).
1656 topology_callback (void *cls,
1657 const struct GNUNET_PeerIdentity *first,
1658 const struct GNUNET_PeerIdentity *second,
1660 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
1661 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
1662 struct GNUNET_TESTING_Daemon *first_daemon,
1663 struct GNUNET_TESTING_Daemon *second_daemon,
1666 struct TopologyIteratorContext *topo_ctx;
1669 total_connections++;
1671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
1672 first_daemon->shortname,
1673 second_daemon->shortname,
1680 failed_connections++;
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
1682 first_daemon->shortname,
1683 second_daemon->shortname, emsg);
1686 GNUNET_assert(peer_connect_meter != NULL);
1687 if (GNUNET_YES == update_meter(peer_connect_meter))
1690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1691 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
1694 if (dhtlog_handle != NULL)
1696 dhtlog_handle->update_connections (trialuid, total_connections);
1697 dhtlog_handle->insert_topology(expected_connections);
1700 GNUNET_SCHEDULER_cancel (sched, die_task);
1701 /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT,
1702 &end_badly, "from setup puts/gets");*/
1703 if ((dhtlog_handle != NULL) && (settle_time > 0))
1705 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1706 topo_ctx->cont = &setup_malicious_peers;
1707 //topo_ctx->cont = &continue_puts_and_gets;
1708 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
1712 GNUNET_SCHEDULER_add_now(sched, &setup_malicious_peers, NULL);
1713 /*GNUNET_SCHEDULER_add_delayed (sched,
1714 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1715 &continue_puts_and_gets, NULL);*/
1718 else if (total_connections + failed_connections == expected_connections)
1720 GNUNET_SCHEDULER_cancel (sched, die_task);
1721 die_task = GNUNET_SCHEDULER_add_now (sched,
1722 &end_badly, "from topology_callback (too many failed connections)");
1727 peers_started_callback (void *cls,
1728 const struct GNUNET_PeerIdentity *id,
1729 const struct GNUNET_CONFIGURATION_Handle *cfg,
1730 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
1738 GNUNET_assert (id != NULL);
1741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
1742 (num_peers - peers_left) + 1, num_peers);
1747 if (GNUNET_YES == update_meter(peer_start_meter))
1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1751 "All %d daemons started, now connecting peers!\n",
1754 GNUNET_SCHEDULER_cancel (sched, die_task);
1756 expected_connections = -1;
1757 if ((pg != NULL) && (peers_left == 0))
1759 expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier);
1761 peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES);
1762 fprintf(stderr, "Have %d expected connections\n", expected_connections);
1765 if (expected_connections == GNUNET_SYSERR)
1767 die_task = GNUNET_SCHEDULER_add_now (sched,
1768 &end_badly, "from connect topology (bad return)");
1771 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1772 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, DEFAULT_CONNECT_TIMEOUT * expected_connections),
1773 &end_badly, "from connect topology (timeout)");
1782 peers_left = num_peers; /* Reset counter */
1783 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
1786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1787 "Topology set up, now starting peers!\n");
1789 GNUNET_TESTING_daemons_continue_startup(pg);
1793 GNUNET_SCHEDULER_cancel (sched, die_task);
1794 die_task = GNUNET_SCHEDULER_add_now (sched,
1795 &end_badly, "from create topology (bad return)");
1797 GNUNET_free_non_null(blacklist_transports);
1798 GNUNET_SCHEDULER_cancel (sched, die_task);
1799 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1800 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1801 &end_badly, "from continue startup (timeout)");
1805 * Callback indicating that the hostkey was created for a peer.
1808 * @param id the peer identity
1809 * @param d the daemon handle (pretty useless at this point, remove?)
1810 * @param emsg non-null on failure
1812 void hostkey_callback (void *cls,
1813 const struct GNUNET_PeerIdentity *id,
1814 struct GNUNET_TESTING_Daemon *d,
1819 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
1823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1824 "Hostkey (%d/%d) created for peer `%s'\n",
1825 num_peers - peers_left, num_peers, GNUNET_i2s(id));
1829 if (GNUNET_YES == update_meter(hostkey_meter))
1832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1833 "All %d hostkeys created, now creating topology!\n",
1836 GNUNET_SCHEDULER_cancel (sched, die_task);
1837 /* Set up task in case topology creation doesn't finish
1838 * within a reasonable amount of time */
1839 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1840 DEFAULT_TOPOLOGY_TIMEOUT,
1841 &end_badly, "from create_topology");
1842 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
1850 struct GNUNET_SCHEDULER_Handle *s,
1852 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1855 struct GNUNET_TESTING_Host *hosts;
1856 struct GNUNET_TESTING_Host *temphost;
1858 char *connect_topology_str;
1859 char *blacklist_topology_str;
1860 char *connect_topology_option_str;
1861 char *connect_topology_option_modifier_string;
1863 char *topology_percentage_str;
1864 float topology_percentage;
1865 char *topology_probability_str;
1867 float topology_probability;
1868 unsigned long long temp_config_number;
1871 int strict_kademlia;
1878 /* Get path from configuration file */
1879 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
1886 * Get DHT specific testing options.
1888 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging")) ||
1889 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")))
1891 dhtlog_handle = GNUNET_DHTLOG_connect(cfg);
1892 if (dhtlog_handle == NULL)
1894 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1895 "Could not connect to mysql server for logging, will NOT log dht operations!");
1901 stop_closest = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_on_closest");
1902 if (stop_closest == GNUNET_SYSERR)
1903 stop_closest = GNUNET_NO;
1905 stop_found = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_found");
1906 if (stop_found == GNUNET_SYSERR)
1907 stop_found = GNUNET_NO;
1909 strict_kademlia = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "strict_kademlia");
1910 if (strict_kademlia == GNUNET_SYSERR)
1911 strict_kademlia = GNUNET_NO;
1914 GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "comment",
1916 trialmessage = NULL;
1919 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
1925 if (hostfile != NULL)
1927 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
1928 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
1929 | GNUNET_DISK_PERM_USER_WRITE);
1930 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
1932 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1933 "Could not open file specified for host list, ending test!");
1935 GNUNET_free_non_null(trialmessage);
1936 GNUNET_free(hostfile);
1940 data = GNUNET_malloc_large (frstat.st_size);
1941 GNUNET_assert(data != NULL);
1942 if (frstat.st_size !=
1943 GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
1945 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1946 "Could not read file %s specified for host list, ending test!", hostfile);
1947 GNUNET_free (hostfile);
1949 GNUNET_free_non_null(trialmessage);
1953 GNUNET_free_non_null(hostfile);
1957 while (count < frstat.st_size)
1960 if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))
1963 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
1964 temphost->hostname = buf;
1965 temphost->next = hosts;
1967 buf = &data[count + 1];
1969 else if ((data[count] == '\n') || (data[count] == '\0'))
1970 buf = &data[count + 1];
1975 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_getters",
1976 &malicious_getters))
1977 malicious_getters = 0;
1980 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_putters",
1981 &malicious_putters))
1982 malicious_putters = 0;
1985 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_droppers",
1986 &malicious_droppers))
1987 malicious_droppers = 0;
1990 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "settle_time",
1994 if (GNUNET_SYSERR ==
1995 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
1997 num_puts = num_peers;
1999 if (GNUNET_SYSERR ==
2000 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
2002 num_gets = num_peers;
2005 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "find_peer_delay",
2006 &temp_config_number))
2007 find_peer_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2009 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
2012 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_find_peers",
2013 &temp_config_number))
2014 max_outstanding_find_peers = temp_config_number;
2016 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
2019 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_timeout",
2020 &temp_config_number))
2021 get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2023 get_timeout = DEFAULT_GET_TIMEOUT;
2026 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_puts",
2027 &temp_config_number))
2028 max_outstanding_puts = temp_config_number;
2030 max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
2033 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_gets",
2034 &temp_config_number))
2035 max_outstanding_gets = temp_config_number;
2037 max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
2040 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "timeout",
2041 &temp_config_number))
2042 all_get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2044 all_get_timeout.value = get_timeout.value * ((num_gets / max_outstanding_gets) + 1);
2047 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay",
2048 &temp_config_number))
2049 get_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2051 get_delay = DEFAULT_GET_DELAY;
2054 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "put_delay",
2055 &temp_config_number))
2056 put_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2058 put_delay = DEFAULT_PUT_DELAY;
2061 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "peer_start_timeout",
2062 &temp_config_number))
2063 seconds_per_peer_start = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2065 seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START;
2068 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "data_size",
2069 &temp_config_number))
2070 test_data_size = temp_config_number;
2072 test_data_size = DEFAULT_TEST_DATA_SIZE;
2075 * Get testing related options.
2078 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2079 "MALICIOUS_GET_FREQUENCY",
2080 &malicious_get_frequency))
2081 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
2084 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2085 "MALICIOUS_PUT_FREQUENCY",
2086 &malicious_put_frequency))
2087 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
2090 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
2093 do_find_peer = GNUNET_NO;
2096 do_find_peer = GNUNET_YES;
2098 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2105 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2107 &temp_config_number))
2109 find_peer_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2112 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
2114 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2115 "OUTSTANDING_FIND_PEERS",
2116 &max_outstanding_find_peers))
2117 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
2119 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "strict_kademlia"))
2120 max_outstanding_find_peers = max_outstanding_find_peers * 1;
2122 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, max_outstanding_find_peers);
2124 topology_str = NULL;
2126 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
2127 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
2129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2130 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
2131 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
2135 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
2136 &topology_percentage_str))
2137 topology_percentage = 0.5;
2140 topology_percentage = atof (topology_percentage_str);
2141 GNUNET_free(topology_percentage_str);
2145 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
2146 &topology_probability_str))
2147 topology_probability = 0.5;
2150 topology_probability = atof (topology_probability_str);
2151 GNUNET_free(topology_probability_str);
2155 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
2156 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connect_topology, connect_topology_str)))
2158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2159 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
2161 GNUNET_free_non_null(connect_topology_str);
2164 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
2165 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
2167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2168 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
2169 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
2171 GNUNET_free_non_null(connect_topology_option_str);
2174 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
2175 &connect_topology_option_modifier_string))
2177 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
2179 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2180 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
2181 connect_topology_option_modifier_string,
2182 "connect_topology_option_modifier",
2185 GNUNET_free (connect_topology_option_modifier_string);
2188 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
2189 &blacklist_transports))
2190 blacklist_transports = NULL;
2193 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
2194 &blacklist_topology_str)) &&
2195 (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
2197 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2198 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
2200 GNUNET_free_non_null(topology_str);
2201 GNUNET_free_non_null(blacklist_topology_str);
2203 /* Get number of peers to start from configuration */
2204 if (GNUNET_SYSERR ==
2205 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
2208 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2209 "Number of peers must be specified in section %s option %s\n", topology_str, "TESTING", "NUM_PEERS");
2211 GNUNET_assert(num_peers > 0 && num_peers < (unsigned long long)-1);
2212 /* Set peers_left so we know when all peers started */
2213 peers_left = num_peers;
2215 /* Set up a task to end testing if peer start fails */
2216 die_task = GNUNET_SCHEDULER_add_delayed (sched,
2217 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
2218 &end_badly, "didn't generate all hostkeys within allowed startup time!");
2220 if (dhtlog_handle == NULL)
2221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2222 "dhtlog_handle is NULL!");
2224 if ((trialmessage != NULL) && (dhtlog_handle != NULL))
2226 dhtlog_handle->insert_trial (&trialuid, (unsigned int)trial_to_run, peers_left, topology,
2227 blacklist_topology, connect_topology,
2228 connect_topology_option,
2229 connect_topology_option_modifier, topology_percentage,
2230 topology_probability, num_puts, num_gets,
2231 max_outstanding_gets, settle_time, 1,
2232 malicious_getters, malicious_putters,
2233 malicious_droppers, malicious_get_frequency,
2234 malicious_put_frequency, stop_closest, stop_found,
2235 strict_kademlia, 0, trialmessage);
2237 else if (dhtlog_handle != NULL)
2239 dhtlog_handle->insert_trial (&trialuid, (unsigned int)trial_to_run, peers_left, topology,
2240 blacklist_topology, connect_topology,
2241 connect_topology_option,
2242 connect_topology_option_modifier, topology_percentage,
2243 topology_probability, num_puts, num_gets,
2244 max_outstanding_gets, settle_time, 1,
2245 malicious_getters, malicious_putters,
2246 malicious_droppers, malicious_get_frequency,
2247 malicious_put_frequency, stop_closest, stop_found,
2248 strict_kademlia, 0, "");
2251 GNUNET_free_non_null(trialmessage);
2253 hostkey_meter = create_meter(peers_left, "Hostkeys created ", GNUNET_YES);
2254 peer_start_meter = create_meter(peers_left, "Peers started ", GNUNET_YES);
2256 put_meter = create_meter(num_puts, "Puts completed ", GNUNET_YES);
2257 get_meter = create_meter(num_gets, "Gets completed ", GNUNET_YES);
2258 pg = GNUNET_TESTING_daemons_start (sched, cfg,
2260 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
2261 &hostkey_callback, NULL,
2262 &peers_started_callback, NULL,
2263 &topology_callback, NULL,
2266 GNUNET_free_non_null(temphost);
2271 main (int argc, char *argv[])
2274 struct GNUNET_GETOPT_CommandLineOption options[] = {
2275 GNUNET_GETOPT_OPTION_END
2278 ret = GNUNET_PROGRAM_run (argc,
2279 argv, "gnunet-dht-driver", "nohelp",
2280 options, &run, &ok);
2282 if (ret != GNUNET_OK)
2284 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret);
2288 * Need to remove base directory, subdirectories taken care
2289 * of by the testing framework.
2291 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
2293 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
2298 /* end of gnunet-dht-driver.c */