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 struct GNUNET_DHTLOG_Handle *dhtlog_handle;
308 static unsigned long long trialuid;
311 * Hash map of stats contexts.
313 struct GNUNET_CONTAINER_MultiHashMap *stats_map;
316 * LL of malicious settings.
318 struct MaliciousContext *all_malicious;
321 * List of GETS to perform
323 struct TestGetContext *all_gets;
326 * List of PUTS to perform
328 struct TestPutContext *all_puts;
331 * Directory to store temporary data in, defined in config file
333 static char *test_directory;
336 * Variable used to store the number of connections we should wait for.
338 static unsigned int expected_connections;
341 * Variable used to keep track of how many peers aren't yet started.
343 static unsigned long long peers_left;
346 * Handle to the set of all peers run for this test.
348 static struct GNUNET_TESTING_PeerGroup *pg;
351 * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
353 static struct GNUNET_SCHEDULER_Handle *sched;
356 * Global config handle.
358 const struct GNUNET_CONFIGURATION_Handle *config;
361 * Total number of peers to run, set based on config file.
363 static unsigned long long num_peers;
366 * Total number of items to insert.
368 static unsigned long long num_puts;
371 * How many puts do we currently have in flight?
373 static unsigned long long outstanding_puts;
376 * How many puts are done?
378 static unsigned long long puts_completed;
381 * Total number of items to attempt to get.
383 static unsigned long long num_gets;
386 * How many puts do we currently have in flight?
388 static unsigned long long outstanding_gets;
391 * How many gets are done?
393 static unsigned long long gets_completed;
396 * How many gets failed?
398 static unsigned long long gets_failed;
401 * How many malicious control messages do
402 * we currently have in flight?
404 static unsigned long long outstanding_malicious;
407 * How many set malicious peers are done?
409 static unsigned long long malicious_completed;
412 * Global used to count how many connections we have currently
413 * been notified about (how many times has topology_callback been called
416 static unsigned int total_connections;
419 * Global used to count how many failed connections we have
420 * been notified about (how many times has topology_callback
421 * been called with failure?)
423 static unsigned int failed_connections;
425 /* Task handle to use to schedule shutdown if something goes wrong */
426 GNUNET_SCHEDULER_TaskIdentifier die_task;
428 static char *blacklist_transports;
430 static enum GNUNET_TESTING_Topology topology;
432 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
434 static enum GNUNET_TESTING_Topology connect_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
436 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
438 static double connect_topology_option_modifier = 0.0;
440 static struct ProgressMeter *hostkey_meter;
442 static struct ProgressMeter *peer_start_meter;
444 static struct ProgressMeter *peer_connect_meter;
446 static struct ProgressMeter *put_meter;
448 static struct ProgressMeter *get_meter;
450 /* Global return value (0 for success, anything else for failure) */
454 * Create a meter to keep track of the progress of some task.
456 * @param total the total number of items to complete
457 * @param start_string a string to prefix the meter with (if printing)
458 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
461 * @return the progress meter
463 static struct ProgressMeter *
464 create_meter(unsigned int total, char * start_string, int print)
466 struct ProgressMeter *ret;
467 ret = GNUNET_malloc(sizeof(struct ProgressMeter));
470 ret->modnum = total / 4;
471 ret->dotnum = (total / 50) + 1;
472 if (start_string != NULL)
473 ret->startup_string = GNUNET_strdup(start_string);
475 ret->startup_string = GNUNET_strdup("");
481 * Update progress meter (increment by one).
483 * @param meter the meter to update and print info for
485 * @return GNUNET_YES if called the total requested,
486 * GNUNET_NO if more items expected
489 update_meter(struct ProgressMeter *meter)
491 if (meter->print == GNUNET_YES)
493 if (meter->completed % meter->modnum == 0)
495 if (meter->completed == 0)
497 fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
500 fprintf(stdout, "%d%%", (int)(((float)meter->completed / meter->total) * 100));
502 else if (meter->completed % meter->dotnum == 0)
503 fprintf(stdout, ".");
505 if (meter->completed + 1 == meter->total)
506 fprintf(stdout, "%d%%]\n", 100);
511 if (meter->completed == meter->total)
517 * Release resources for meter
519 * @param meter the meter to free
522 free_meter(struct ProgressMeter *meter)
524 GNUNET_free_non_null(meter->startup_string);
525 GNUNET_free_non_null(meter);
529 * Check whether peers successfully shut down.
531 void shutdown_callback (void *cls,
542 * Task to release DHT handles for PUT
545 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
547 struct TestPutContext *test_put = cls;
548 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
549 GNUNET_DHT_disconnect(test_put->dht_handle);
550 test_put->dht_handle = NULL;
554 * Function scheduled to be run on the successful completion of this
558 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
560 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n", (char *)cls);
561 GNUNET_assert (pg != NULL);
562 struct TestPutContext *test_put = all_puts;
563 struct TestGetContext *test_get = all_gets;
565 while (test_put != NULL)
567 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
568 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
569 if (test_put->dht_handle != NULL)
570 GNUNET_DHT_disconnect(test_put->dht_handle);
571 test_put = test_put->next;
574 while (test_get != NULL)
576 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
577 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
578 if (test_get->get_handle != NULL)
579 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
580 if (test_get->dht_handle != NULL)
581 GNUNET_DHT_disconnect(test_get->dht_handle);
582 test_get = test_get->next;
585 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
587 if (dhtlog_handle != NULL)
589 fprintf(stderr, "Update trial endtime\n");
590 dhtlog_handle->update_trial (trialuid, gets_completed);
591 GNUNET_DHTLOG_disconnect(dhtlog_handle);
592 dhtlog_handle = NULL;
595 if (hostkey_meter != NULL)
596 free_meter(hostkey_meter);
597 if (peer_start_meter != NULL)
598 free_meter(peer_start_meter);
599 if (peer_connect_meter != NULL)
600 free_meter(peer_connect_meter);
601 if (put_meter != NULL)
602 free_meter(put_meter);
603 if (get_meter != NULL)
604 free_meter(get_meter);
610 * Callback for iterating over all the peer connections of a peer group.
612 void log_topology_cb (void *cls,
613 const struct GNUNET_PeerIdentity *first,
614 const struct GNUNET_PeerIdentity *second,
615 struct GNUNET_TIME_Relative latency,
619 struct TopologyIteratorContext *topo_ctx = cls;
620 if ((first != NULL) && (second != NULL))
622 topo_ctx->total_connections++;
623 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging_extended"))
624 dhtlog_handle->insert_extended_topology(first, second);
628 GNUNET_assert(dhtlog_handle != NULL);
629 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);
630 dhtlog_handle->update_topology(topo_ctx->total_connections);
631 if (topo_ctx->cont != NULL)
632 GNUNET_SCHEDULER_add_now (sched, topo_ctx->cont, topo_ctx->cls);
633 GNUNET_free(topo_ctx);
638 * Iterator over hash map entries.
640 * @param cls closure - always NULL
641 * @param key current key code
642 * @param value value in the hash map, a stats context
643 * @return GNUNET_YES if we should continue to
647 static int stats_iterate (void *cls,
648 const GNUNET_HashCode * key,
651 struct StatisticsIteratorContext *stats_ctx;
655 dhtlog_handle->insert_stat(stats_ctx->peer, stats_ctx->stat_routes, stats_ctx->stat_route_forwards, stats_ctx->stat_results,
656 stats_ctx->stat_results_to_client, stats_ctx->stat_result_forwards, stats_ctx->stat_gets,
657 stats_ctx->stat_puts, stats_ctx->stat_puts_inserted, stats_ctx->stat_find_peer,
658 stats_ctx->stat_find_peer_start, stats_ctx->stat_get_start, stats_ctx->stat_put_start,
659 stats_ctx->stat_find_peer_reply, stats_ctx->stat_get_reply, stats_ctx->stat_find_peer_answer,
660 stats_ctx->stat_get_response_start);
661 GNUNET_free(stats_ctx);
665 static void stats_finished (void *cls, int result)
667 fprintf(stderr, "Finished getting all peers statistics, iterating!\n");
668 GNUNET_CONTAINER_multihashmap_iterate(stats_map, &stats_iterate, NULL);
669 GNUNET_CONTAINER_multihashmap_destroy(stats_map);
670 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
674 * Callback function to process statistic values.
677 * @param peer the peer the statistics belong to
678 * @param subsystem name of subsystem that created the statistic
679 * @param name the name of the datum
680 * @param value the current value
681 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
682 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
684 static int stats_handle (void *cls,
685 const struct GNUNET_PeerIdentity *peer,
686 const char *subsystem,
691 struct StatisticsIteratorContext *stats_ctx;
693 if (dhtlog_handle != NULL)
694 dhtlog_handle->add_generic_stat(peer, name, subsystem, value);
695 if (GNUNET_CONTAINER_multihashmap_contains(stats_map, &peer->hashPubKey))
697 stats_ctx = GNUNET_CONTAINER_multihashmap_get(stats_map, &peer->hashPubKey);
701 stats_ctx = GNUNET_malloc(sizeof(struct StatisticsIteratorContext));
702 stats_ctx->peer = peer;
703 GNUNET_CONTAINER_multihashmap_put(stats_map, &peer->hashPubKey, stats_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
705 GNUNET_assert(stats_ctx != NULL);
707 if (strcmp(name, STAT_ROUTES) == 0)
708 stats_ctx->stat_routes = value;
709 else if (strcmp(name, STAT_ROUTE_FORWARDS) == 0)
710 stats_ctx->stat_route_forwards = value;
711 else if (strcmp(name, STAT_RESULTS) == 0)
712 stats_ctx->stat_results = value;
713 else if (strcmp(name, STAT_RESULTS_TO_CLIENT) == 0)
714 stats_ctx->stat_results_to_client = value;
715 else if (strcmp(name, STAT_RESULT_FORWARDS) == 0)
716 stats_ctx->stat_result_forwards = value;
717 else if (strcmp(name, STAT_GETS) == 0)
718 stats_ctx->stat_gets = value;
719 else if (strcmp(name, STAT_PUTS) == 0)
720 stats_ctx->stat_puts = value;
721 else if (strcmp(name, STAT_PUTS_INSERTED) == 0)
722 stats_ctx->stat_puts_inserted = value;
723 else if (strcmp(name, STAT_FIND_PEER) == 0)
724 stats_ctx->stat_find_peer = value;
725 else if (strcmp(name, STAT_FIND_PEER_START) == 0)
726 stats_ctx->stat_find_peer_start = value;
727 else if (strcmp(name, STAT_GET_START) == 0)
728 stats_ctx->stat_get_start = value;
729 else if (strcmp(name, STAT_PUT_START) == 0)
730 stats_ctx->stat_put_start = value;
731 else if (strcmp(name, STAT_FIND_PEER_REPLY) == 0)
732 stats_ctx->stat_find_peer_reply = value;
733 else if (strcmp(name, STAT_GET_REPLY) == 0)
734 stats_ctx->stat_get_reply = value;
735 else if (strcmp(name, STAT_FIND_PEER_ANSWER) == 0)
736 stats_ctx->stat_find_peer_answer = value;
737 else if (strcmp(name, STAT_GET_RESPONSE_START) == 0)
738 stats_ctx->stat_get_response_start = value;
744 * Connect to statistics service for each peer and get the appropriate
745 * dht statistics for safe keeping.
748 log_dht_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
750 stats_map = GNUNET_CONTAINER_multihashmap_create(num_peers);
751 fprintf(stderr, "Starting statistics logging\n");
752 GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_handle, NULL);
757 * Connect to all peers in the peer group and iterate over their
761 capture_current_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
763 struct TopologyIteratorContext *topo_ctx = cls;
764 dhtlog_handle->insert_topology(0);
765 GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx);
770 * Check if the get_handle is being used, if so stop the request. Either
771 * way, schedule the end_badly_cont function which actually shuts down the
775 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
777 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n", (char *)cls);
779 struct TestPutContext *test_put = all_puts;
780 struct TestGetContext *test_get = all_gets;
782 while (test_put != NULL)
784 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
785 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
786 if (test_put->dht_handle != NULL)
787 GNUNET_DHT_disconnect(test_put->dht_handle);
788 test_put = test_put->next;
791 while (test_get != NULL)
793 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
794 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
795 if (test_get->get_handle != NULL)
796 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
797 if (test_get->dht_handle != NULL)
798 GNUNET_DHT_disconnect(test_get->dht_handle);
799 test_get = test_get->next;
802 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
804 if (dhtlog_handle != NULL)
806 fprintf(stderr, "Update trial endtime\n");
807 dhtlog_handle->update_trial (trialuid, gets_completed);
808 GNUNET_DHTLOG_disconnect(dhtlog_handle);
809 dhtlog_handle = NULL;
812 if (hostkey_meter != NULL)
813 free_meter(hostkey_meter);
814 if (peer_start_meter != NULL)
815 free_meter(peer_start_meter);
816 if (peer_connect_meter != NULL)
817 free_meter(peer_connect_meter);
818 if (put_meter != NULL)
819 free_meter(put_meter);
820 if (get_meter != NULL)
821 free_meter(get_meter);
827 * Task to release DHT handle associated with GET request.
830 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
832 struct TestGetContext *test_get = cls;
833 struct TopologyIteratorContext *topo_ctx;
834 outstanding_gets--; /* GET is really finished */
835 GNUNET_DHT_disconnect(test_get->dht_handle);
836 test_get->dht_handle = NULL;
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
841 update_meter(get_meter);
842 if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
844 GNUNET_SCHEDULER_cancel(sched, die_task);
845 //GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
846 if (dhtlog_handle != NULL)
848 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
849 topo_ctx->cont = &log_dht_statistics;
850 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
853 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
858 * Task to release get handle.
861 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
863 struct TestGetContext *test_get = cls;
865 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
867 GNUNET_assert(test_get->get_handle != NULL);
868 GNUNET_DHT_get_stop(test_get->get_handle, &get_stop_finished, test_get);
869 test_get->get_handle = NULL;
870 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
874 * Iterator called if the GET request initiated returns a response.
877 * @param exp when will this value expire
878 * @param key key of the result
879 * @param type type of the result
880 * @param size number of bytes in data
881 * @param data pointer to the result data
883 void get_result_iterator (void *cls,
884 struct GNUNET_TIME_Absolute exp,
885 const GNUNET_HashCode * key,
890 struct TestGetContext *test_get = cls;
891 GNUNET_HashCode search_key; /* Key stored under */
892 char original_data[test_data_size]; /* Made up data to store */
894 memset(original_data, test_get->uid, sizeof(original_data));
895 GNUNET_CRYPTO_hash(original_data, test_data_size, &search_key);
897 if (test_get->succeeded == GNUNET_YES)
898 return; /* Get has already been successful, probably ending now */
900 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
907 test_get->succeeded = GNUNET_YES;
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
912 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
913 GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
917 * Continuation telling us GET request was sent.
920 get_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
922 // Is there something to be done here?
923 if (tc->reason != GNUNET_SCHEDULER_REASON_PREREQ_DONE)
928 * Set up some data, and call API PUT function
931 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
933 struct TestGetContext *test_get = cls;
934 GNUNET_HashCode key; /* Made up key to store data under */
935 char data[test_data_size]; /* Made up data to store */
939 GNUNET_SCHEDULER_cancel(sched, die_task);
940 GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
942 if (test_get == NULL)
943 return; /* End of the list */
945 memset(data, test_get->uid, sizeof(data));
946 GNUNET_CRYPTO_hash(data, test_data_size, &key);
948 if (outstanding_gets > max_outstanding_gets)
950 GNUNET_SCHEDULER_add_delayed (sched, get_delay, &do_get, test_get);
954 test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10);
955 /* Insert the data at the first peer */
956 GNUNET_assert(test_get->dht_handle != NULL);
958 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
959 GNUNET_TIME_relative_get_forever(),
962 &get_result_iterator,
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
969 test_get->daemon->shortname);
971 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, get_timeout, &get_stop_task, test_get);
972 GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next);
976 * Called when the PUT request has been transmitted to the DHT service.
977 * Schedule the GET request for some time in the future.
980 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
982 struct TestPutContext *test_put = cls;
983 struct TopologyIteratorContext *topo_ctx;
987 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
988 fprintf(stderr, "PUT Request failed!\n");
990 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
991 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put);
992 if (GNUNET_YES == update_meter(put_meter))
994 GNUNET_assert(outstanding_puts == 0);
995 GNUNET_SCHEDULER_cancel (sched, die_task);
996 if (dhtlog_handle != NULL)
998 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
999 topo_ctx->cont = &do_get;
1000 topo_ctx->cls = all_gets;
1001 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
1002 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),
1003 &end_badly, "from do gets");
1004 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
1008 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout),
1009 &end_badly, "from do gets");
1010 GNUNET_SCHEDULER_add_delayed(sched, DEFAULT_GET_TIMEOUT, &do_get, all_gets);
1011 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
1018 * Set up some data, and call API PUT function
1021 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1023 struct TestPutContext *test_put = cls;
1024 GNUNET_HashCode key; /* Made up key to store data under */
1025 char data[test_data_size]; /* Made up data to store */
1028 if (test_put == NULL)
1029 return; /* End of list */
1031 memset(data, test_put->uid, sizeof(data));
1032 GNUNET_CRYPTO_hash(data, test_data_size, &key);
1034 if (outstanding_puts > max_outstanding_puts)
1036 GNUNET_SCHEDULER_add_delayed (sched, put_delay, &do_put, test_put);
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
1043 test_put->daemon->shortname);
1045 test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10);
1047 GNUNET_assert(test_put->dht_handle != NULL);
1049 GNUNET_DHT_put(test_put->dht_handle,
1053 GNUNET_TIME_absolute_get_forever(),
1054 GNUNET_TIME_relative_get_forever(),
1055 &put_finished, test_put);
1056 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
1057 rand = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
1058 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, rand), &do_put, test_put->next);
1062 * Context for sending out find peer requests.
1064 struct FindPeerContext
1067 * How long to send find peer requests, once the settle time
1068 * is over don't send any more out!
1070 * TODO: Add option for settle time and find peer sending time?
1072 struct GNUNET_TIME_Absolute endtime;
1075 * Number of connections in the current topology
1076 * (after this round of find peer requests has ended).
1078 unsigned int current_peers;
1081 * Number of connections in the current topology
1082 * (before this round of find peer requests started).
1084 unsigned int previous_peers;
1087 * Number of find peer requests we have currently
1090 unsigned int outstanding;
1093 * Number of find peer requests to send in this round.
1098 * Number of find peer requests sent last time around.
1100 unsigned int last_sent;
1103 * Hashmap of peers in the current topology, value
1104 * is a PeerCount, with the number of connections
1107 struct GNUNET_CONTAINER_MultiHashMap *peer_hash;
1110 * Min heap which orders values in the peer_hash for
1113 struct GNUNET_CONTAINER_Heap *peer_min_heap;
1117 schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
1120 * Given a number of total peers and a bucket size, estimate the number of
1121 * connections in a perfect kademlia topology.
1123 static unsigned int connection_estimate(unsigned int peer_count, unsigned int bucket_size)
1126 unsigned int filled;
1130 while (i >= bucket_size)
1135 filled++; /* Add one filled bucket to account for one "half full" and some miscellaneous */
1136 return filled * bucket_size * peer_count;
1142 /** Node in the heap */
1143 struct GNUNET_CONTAINER_HeapNode *heap_node;
1145 /** Peer the count refers to */
1146 struct GNUNET_PeerIdentity peer_id;
1148 /** Count of connections this peer has */
1154 * Add a connection to the find_peer_context given. This may
1155 * be complete overkill, but allows us to choose the peers with
1156 * the least connections to initiate find peer requests from.
1158 static void add_new_connection(struct FindPeerContext *find_peer_context,
1159 const struct GNUNET_PeerIdentity *first,
1160 const struct GNUNET_PeerIdentity *second)
1162 struct PeerCount *first_count;
1163 struct PeerCount *second_count;
1165 if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &first->hashPubKey))
1167 first_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &first->hashPubKey);
1168 first_count->count++;
1169 GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, first_count->heap_node, first_count->count);
1173 first_count = GNUNET_malloc(sizeof(struct PeerCount));
1174 first_count->count = 1;
1175 memcpy(&first_count->peer_id, first, sizeof(struct GNUNET_PeerIdentity));
1176 first_count->heap_node = GNUNET_CONTAINER_heap_insert(find_peer_context->peer_min_heap, first_count, first_count->count);
1177 GNUNET_CONTAINER_multihashmap_put(find_peer_context->peer_hash, &first->hashPubKey, first_count, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1180 if (GNUNET_CONTAINER_multihashmap_contains(find_peer_context->peer_hash, &second->hashPubKey))
1182 second_count = GNUNET_CONTAINER_multihashmap_get(find_peer_context->peer_hash, &second->hashPubKey);
1183 second_count->count++;
1184 GNUNET_CONTAINER_heap_update_cost(find_peer_context->peer_min_heap, second_count->heap_node, second_count->count);
1188 second_count = GNUNET_malloc(sizeof(struct PeerCount));
1189 second_count->count = 1;
1190 memcpy(&second_count->peer_id, second, sizeof(struct GNUNET_PeerIdentity));
1191 second_count->heap_node = GNUNET_CONTAINER_heap_insert(find_peer_context->peer_min_heap, second_count, second_count->count);
1192 GNUNET_CONTAINER_multihashmap_put(find_peer_context->peer_hash, &second->hashPubKey, second_count, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1197 * Callback for iterating over all the peer connections of a peer group.
1199 void count_peers_cb (void *cls,
1200 const struct GNUNET_PeerIdentity *first,
1201 const struct GNUNET_PeerIdentity *second,
1202 struct GNUNET_TIME_Relative latency,
1206 struct FindPeerContext *find_peer_context = cls;
1207 if ((first != NULL) && (second != NULL))
1209 add_new_connection(find_peer_context, first, second);
1210 find_peer_context->current_peers++;
1214 GNUNET_assert(dhtlog_handle != NULL);
1215 /*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));*/
1216 if ((find_peer_context->current_peers - find_peer_context->previous_peers > FIND_PEER_THRESHOLD) &&
1217 (find_peer_context->current_peers < connection_estimate(num_peers, DEFAULT_BUCKET_SIZE)) &&
1218 (GNUNET_TIME_absolute_get_remaining(find_peer_context->endtime).value > 0))
1220 GNUNET_SCHEDULER_add_now(sched, &schedule_find_peer_requests, find_peer_context);
1224 fprintf(stderr, "Not sending any more find peer requests.\n");
1230 * Connect to all peers in the peer group and iterate over their
1234 count_new_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1236 struct FindPeerContext *find_peer_context = cls;
1237 find_peer_context->previous_peers = find_peer_context->current_peers;
1238 find_peer_context->current_peers = 0;
1239 GNUNET_TESTING_get_topology (pg, &count_peers_cb, find_peer_context);
1244 decrement_find_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1246 struct TestFindPeer *test_find_peer = cls;
1247 GNUNET_assert(test_find_peer->find_peer_context->outstanding > 0);
1248 test_find_peer->find_peer_context->outstanding--;
1249 test_find_peer->find_peer_context->total--;
1250 if ((0 == test_find_peer->find_peer_context->total) &&
1251 (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value > 0))
1253 GNUNET_SCHEDULER_add_now(sched, &count_new_peers, test_find_peer->find_peer_context);
1255 GNUNET_free(test_find_peer);
1259 * A find peer request has been sent to the server, now we will schedule a task
1260 * to wait the appropriate time to allow the request to go out and back.
1262 * @param cls closure - a TestFindPeer struct
1263 * @param tc context the task is being called with
1266 handle_find_peer_sent (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1268 struct TestFindPeer *test_find_peer = cls;
1270 GNUNET_DHT_disconnect(test_find_peer->dht_handle);
1271 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_divide(find_peer_delay, 2), &decrement_find_peers, test_find_peer);
1275 send_find_peer_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1277 struct TestFindPeer *test_find_peer = cls;
1279 if (test_find_peer->find_peer_context->outstanding > max_outstanding_find_peers)
1281 GNUNET_SCHEDULER_add_delayed(sched, find_peer_offset, &send_find_peer_request, test_find_peer);
1285 test_find_peer->find_peer_context->outstanding++;
1286 if (GNUNET_TIME_absolute_get_remaining(test_find_peer->find_peer_context->endtime).value == 0)
1288 GNUNET_SCHEDULER_add_now(sched, &decrement_find_peers, test_find_peer);
1292 test_find_peer->dht_handle = GNUNET_DHT_connect(sched, test_find_peer->daemon->cfg, 1);
1293 GNUNET_assert(test_find_peer->dht_handle != NULL);
1294 GNUNET_DHT_find_peers (test_find_peer->dht_handle,
1295 &handle_find_peer_sent, test_find_peer);
1299 * Iterator over hash map entries.
1301 * @param cls closure
1302 * @param key current key code
1303 * @param value value in the hash map
1304 * @return GNUNET_YES if we should continue to
1308 static int remove_peer_count (void *cls,
1309 const GNUNET_HashCode * key,
1312 struct FindPeerContext *find_peer_ctx = cls;
1313 struct PeerCount *peer_count = value;
1314 GNUNET_CONTAINER_heap_remove_node(find_peer_ctx->peer_min_heap, peer_count->heap_node);
1315 GNUNET_free(peer_count);
1322 * Set up a single find peer request for each peer in the topology. Do this
1323 * until the settle time is over, limited by the number of outstanding requests
1324 * and the time allowed for each one!
1327 schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1329 struct FindPeerContext *find_peer_ctx = cls;
1330 struct TestFindPeer *test_find_peer;
1331 struct PeerCount *peer_count;
1335 if (find_peer_ctx->previous_peers == 0) /* First time, go slowly */
1336 find_peer_ctx->total = 1;
1337 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers > MAX_FIND_PEER_CUTOFF) /* Found LOTS of peers, still go slowly */
1338 find_peer_ctx->total = find_peer_ctx->last_sent / 2;
1340 else if (find_peer_ctx->current_peers - find_peer_ctx->previous_peers < MIN_FIND_PEER_CUTOFF)
1341 find_peer_ctx->total = find_peer_ctx->last_sent * 2; /* FIXME: always multiply by two (unless above max?) */
1343 find_peer_ctx->total = find_peer_ctx->last_sent;
1346 find_peer_ctx->total = find_peer_ctx->last_sent * 2;
1349 if (find_peer_ctx->total > max_outstanding_find_peers)
1350 find_peer_ctx->total = max_outstanding_find_peers;
1352 find_peer_ctx->last_sent = find_peer_ctx->total;
1353 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));
1355 find_peer_offset = GNUNET_TIME_relative_divide(find_peer_delay, find_peer_ctx->total);
1356 for (i = 0; i < find_peer_ctx->total; i++)
1358 test_find_peer = GNUNET_malloc(sizeof(struct TestFindPeer));
1359 if (find_peer_ctx->previous_peers == 0) /* If we haven't sent any requests, yet choose random peers */
1362 * Attempt to spread find peer requests across even sections of the peer address
1363 * space. Choose basically 1 peer in every num_peers / max_outstanding_requests
1364 * each time, then offset it by a randomish value.
1366 * For instance, if num_peers is 100 and max_outstanding is 10, first chosen peer
1367 * will be between 0 - 10, second between 10 - 20, etc.
1369 random = (num_peers / find_peer_ctx->total) * i;
1370 random = random + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (num_peers / find_peer_ctx->total));
1371 if (random >= num_peers)
1373 random = random - num_peers;
1376 random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1378 test_find_peer->daemon = GNUNET_TESTING_daemon_get(pg, random);
1380 else /* If we have sent requests, choose peers with a low number of connections to send requests from */
1382 peer_count = GNUNET_CONTAINER_heap_remove_root(find_peer_ctx->peer_min_heap);
1383 GNUNET_CONTAINER_multihashmap_remove(find_peer_ctx->peer_hash, &peer_count->peer_id.hashPubKey, peer_count);
1384 test_find_peer->daemon = GNUNET_TESTING_daemon_get_by_id(pg, &peer_count->peer_id);
1385 GNUNET_assert(test_find_peer->daemon != NULL);
1388 test_find_peer->find_peer_context = find_peer_ctx;
1389 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(find_peer_offset, i), &send_find_peer_request, test_find_peer);
1392 if ((find_peer_ctx->peer_hash == NULL) && (find_peer_ctx->peer_min_heap == NULL))
1394 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create(num_peers);
1395 find_peer_ctx->peer_min_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1399 GNUNET_CONTAINER_multihashmap_iterate(find_peer_ctx->peer_hash, &remove_peer_count, find_peer_ctx);
1400 GNUNET_CONTAINER_multihashmap_destroy(find_peer_ctx->peer_hash);
1401 find_peer_ctx->peer_hash = GNUNET_CONTAINER_multihashmap_create(num_peers);
1404 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(find_peer_ctx->peer_hash));
1405 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(find_peer_ctx->peer_min_heap));
1410 * Set up some all of the put and get operations we want
1411 * to do. Allocate data structure for each, add to list,
1412 * then call actual insert functions.
1415 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1418 uint32_t temp_daemon;
1419 struct TestPutContext *test_put;
1420 struct TestGetContext *test_get;
1421 int remember[num_puts][num_peers];
1423 memset(&remember, 0, sizeof(int) * num_puts * num_peers);
1424 for (i = 0; i < num_puts; i++)
1426 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
1428 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1429 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1430 test_put->next = all_puts;
1431 all_puts = test_put;
1434 for (i = 0; i < num_gets; i++)
1436 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
1437 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
1438 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1439 while (remember[test_get->uid][temp_daemon] == 1)
1440 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1441 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1442 remember[test_get->uid][temp_daemon] = 1;
1443 test_get->next = all_gets;
1444 all_gets = test_get;
1447 /*GNUNET_SCHEDULER_cancel (sched, die_task);*/
1448 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
1449 &end_badly, "from do puts");
1450 GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts);
1454 * Set up some all of the put and get operations we want
1455 * to do. Allocate data structure for each, add to list,
1456 * then call actual insert functions.
1459 continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1463 struct TopologyIteratorContext *topo_ctx;
1464 struct FindPeerContext *find_peer_context;
1465 if (dhtlog_handle != NULL)
1467 if (settle_time >= 60 * 2)
1468 max = (settle_time / 60) - 2;
1471 for (i = 1; i < max; i++)
1473 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1474 topo_ctx->current_iteration = i;
1475 topo_ctx->total_iterations = max;
1476 //fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
1477 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, i), &capture_current_topology, topo_ctx);
1479 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1480 topo_ctx->cont = &setup_puts_and_gets;
1481 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &capture_current_topology, topo_ctx);
1484 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &setup_puts_and_gets, NULL);
1486 if (GNUNET_YES == do_find_peer)
1488 find_peer_context = GNUNET_malloc(sizeof(struct FindPeerContext));
1489 find_peer_context->endtime = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time));
1490 GNUNET_SCHEDULER_add_now(sched, &schedule_find_peer_requests, find_peer_context);
1495 * Task to release DHT handles
1498 malicious_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1500 struct MaliciousContext *ctx = cls;
1501 outstanding_malicious--;
1502 malicious_completed++;
1503 ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
1504 GNUNET_DHT_disconnect(ctx->dht_handle);
1505 ctx->dht_handle = NULL;
1508 if (malicious_completed == malicious_getters + malicious_putters + malicious_droppers)
1510 GNUNET_SCHEDULER_cancel(sched, die_task);
1511 fprintf(stderr, "Finished setting all malicious peers up, calling continuation!\n");
1512 if (dhtlog_handle != NULL)
1513 GNUNET_SCHEDULER_add_now (sched,
1514 &continue_puts_and_gets, NULL);
1516 GNUNET_SCHEDULER_add_delayed (sched,
1517 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1518 &continue_puts_and_gets, NULL);
1524 * Task to release DHT handles
1527 malicious_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1529 struct MaliciousContext *ctx = cls;
1530 GNUNET_SCHEDULER_cancel(sched, ctx->disconnect_task);
1531 GNUNET_SCHEDULER_add_now(sched, &malicious_disconnect_task, ctx);
1535 * Set up some data, and call API PUT function
1538 set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1540 struct MaliciousContext *ctx = cls;
1543 if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
1545 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1549 if (ctx->dht_handle == NULL)
1551 ctx->dht_handle = GNUNET_DHT_connect(sched, ctx->daemon->cfg, 1);
1552 outstanding_malicious++;
1555 GNUNET_assert(ctx->dht_handle != NULL);
1559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
1560 ctx->daemon->shortname, ctx->malicious_type);
1564 switch (ctx->malicious_type)
1566 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
1567 ret = GNUNET_DHT_set_malicious_getter(ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx);
1569 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
1570 ret = GNUNET_DHT_set_malicious_putter(ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx);
1572 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
1573 ret = GNUNET_DHT_set_malicious_dropper(ctx->dht_handle, &malicious_done_task, ctx);
1579 if (ret == GNUNET_NO)
1581 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1584 ctx->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &malicious_disconnect_task, ctx);
1588 * Select randomly from set of known peers,
1589 * set the desired number of peers to the
1590 * proper malicious types.
1593 setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1595 struct MaliciousContext *ctx;
1597 uint32_t temp_daemon;
1599 for (i = 0; i < malicious_getters; i++)
1601 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1602 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1603 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1604 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
1605 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1609 for (i = 0; i < malicious_putters; i++)
1611 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1612 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1613 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1614 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
1615 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1619 for (i = 0; i < malicious_droppers; i++)
1621 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1622 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1623 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1624 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
1625 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1628 if (malicious_getters + malicious_putters + malicious_droppers > 0)
1629 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (malicious_getters + malicious_putters + malicious_droppers) * 2),
1630 &end_badly, "from set malicious");
1633 if (dhtlog_handle != NULL)
1634 GNUNET_SCHEDULER_add_now (sched,
1635 &continue_puts_and_gets, NULL);
1637 GNUNET_SCHEDULER_add_delayed (sched,
1638 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1639 &continue_puts_and_gets, NULL);
1645 * This function is called whenever a connection attempt is finished between two of
1646 * the started peers (started with GNUNET_TESTING_daemons_start). The total
1647 * number of times this function is called should equal the number returned
1648 * from the GNUNET_TESTING_connect_topology call.
1650 * The emsg variable is NULL on success (peers connected), and non-NULL on
1651 * failure (peers failed to connect).
1654 topology_callback (void *cls,
1655 const struct GNUNET_PeerIdentity *first,
1656 const struct GNUNET_PeerIdentity *second,
1658 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
1659 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
1660 struct GNUNET_TESTING_Daemon *first_daemon,
1661 struct GNUNET_TESTING_Daemon *second_daemon,
1664 struct TopologyIteratorContext *topo_ctx;
1667 total_connections++;
1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
1670 first_daemon->shortname,
1671 second_daemon->shortname,
1678 failed_connections++;
1679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
1680 first_daemon->shortname,
1681 second_daemon->shortname, emsg);
1684 GNUNET_assert(peer_connect_meter != NULL);
1685 if (GNUNET_YES == update_meter(peer_connect_meter))
1688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1689 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
1692 if (dhtlog_handle != NULL)
1694 dhtlog_handle->update_connections (trialuid, total_connections);
1695 dhtlog_handle->insert_topology(expected_connections);
1698 GNUNET_SCHEDULER_cancel (sched, die_task);
1699 /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT,
1700 &end_badly, "from setup puts/gets");*/
1701 if ((dhtlog_handle != NULL) && (settle_time > 0))
1703 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1704 topo_ctx->cont = &setup_malicious_peers;
1705 //topo_ctx->cont = &continue_puts_and_gets;
1706 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
1710 GNUNET_SCHEDULER_add_now(sched, &setup_malicious_peers, NULL);
1711 /*GNUNET_SCHEDULER_add_delayed (sched,
1712 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1713 &continue_puts_and_gets, NULL);*/
1716 else if (total_connections + failed_connections == expected_connections)
1718 GNUNET_SCHEDULER_cancel (sched, die_task);
1719 die_task = GNUNET_SCHEDULER_add_now (sched,
1720 &end_badly, "from topology_callback (too many failed connections)");
1725 peers_started_callback (void *cls,
1726 const struct GNUNET_PeerIdentity *id,
1727 const struct GNUNET_CONFIGURATION_Handle *cfg,
1728 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
1736 GNUNET_assert (id != NULL);
1739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
1740 (num_peers - peers_left) + 1, num_peers);
1745 if (GNUNET_YES == update_meter(peer_start_meter))
1748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1749 "All %d daemons started, now connecting peers!\n",
1752 GNUNET_SCHEDULER_cancel (sched, die_task);
1754 expected_connections = -1;
1755 if ((pg != NULL) && (peers_left == 0))
1757 expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier);
1759 peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES);
1760 fprintf(stderr, "Have %d expected connections\n", expected_connections);
1763 if (expected_connections == GNUNET_SYSERR)
1765 die_task = GNUNET_SCHEDULER_add_now (sched,
1766 &end_badly, "from connect topology (bad return)");
1769 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1770 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, DEFAULT_CONNECT_TIMEOUT * expected_connections),
1771 &end_badly, "from connect topology (timeout)");
1780 peers_left = num_peers; /* Reset counter */
1781 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1785 "Topology set up, now starting peers!\n");
1787 GNUNET_TESTING_daemons_continue_startup(pg);
1791 GNUNET_SCHEDULER_cancel (sched, die_task);
1792 die_task = GNUNET_SCHEDULER_add_now (sched,
1793 &end_badly, "from create topology (bad return)");
1795 GNUNET_free_non_null(blacklist_transports);
1796 GNUNET_SCHEDULER_cancel (sched, die_task);
1797 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1798 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1799 &end_badly, "from continue startup (timeout)");
1803 * Callback indicating that the hostkey was created for a peer.
1806 * @param id the peer identity
1807 * @param d the daemon handle (pretty useless at this point, remove?)
1808 * @param emsg non-null on failure
1810 void hostkey_callback (void *cls,
1811 const struct GNUNET_PeerIdentity *id,
1812 struct GNUNET_TESTING_Daemon *d,
1817 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
1821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1822 "Hostkey (%d/%d) created for peer `%s'\n",
1823 num_peers - peers_left, num_peers, GNUNET_i2s(id));
1827 if (GNUNET_YES == update_meter(hostkey_meter))
1830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1831 "All %d hostkeys created, now creating topology!\n",
1834 GNUNET_SCHEDULER_cancel (sched, die_task);
1835 /* Set up task in case topology creation doesn't finish
1836 * within a reasonable amount of time */
1837 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1838 DEFAULT_TOPOLOGY_TIMEOUT,
1839 &end_badly, "from create_topology");
1840 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
1848 struct GNUNET_SCHEDULER_Handle *s,
1850 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1853 struct GNUNET_TESTING_Host *hosts;
1854 struct GNUNET_TESTING_Host *temphost;
1856 char *connect_topology_str;
1857 char *blacklist_topology_str;
1858 char *connect_topology_option_str;
1859 char *connect_topology_option_modifier_string;
1861 char *topology_percentage_str;
1862 float topology_percentage;
1863 char *topology_probability_str;
1865 float topology_probability;
1866 unsigned long long temp_config_number;
1869 int strict_kademlia;
1876 /* Get path from configuration file */
1877 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
1884 * Get DHT specific testing options.
1886 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging")) ||
1887 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")))
1889 dhtlog_handle = GNUNET_DHTLOG_connect(cfg);
1890 if (dhtlog_handle == NULL)
1892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1893 "Could not connect to mysql server for logging, will NOT log dht operations!");
1899 stop_closest = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_on_closest");
1900 if (stop_closest == GNUNET_SYSERR)
1901 stop_closest = GNUNET_NO;
1903 stop_found = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_found");
1904 if (stop_found == GNUNET_SYSERR)
1905 stop_found = GNUNET_NO;
1907 strict_kademlia = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "strict_kademlia");
1908 if (strict_kademlia == GNUNET_SYSERR)
1909 strict_kademlia = GNUNET_NO;
1912 GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "comment",
1914 trialmessage = NULL;
1917 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
1923 if (hostfile != NULL)
1925 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
1926 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
1927 | GNUNET_DISK_PERM_USER_WRITE);
1928 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
1930 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1931 "Could not open file specified for host list, ending test!");
1933 GNUNET_free_non_null(trialmessage);
1934 GNUNET_free(hostfile);
1938 data = GNUNET_malloc_large (frstat.st_size);
1939 GNUNET_assert(data != NULL);
1940 if (frstat.st_size !=
1941 GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
1943 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1944 "Could not read file %s specified for host list, ending test!", hostfile);
1945 GNUNET_free (hostfile);
1947 GNUNET_free_non_null(trialmessage);
1951 GNUNET_free_non_null(hostfile);
1955 while (count < frstat.st_size)
1958 if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))
1961 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
1962 temphost->hostname = buf;
1963 temphost->next = hosts;
1965 buf = &data[count + 1];
1967 else if ((data[count] == '\n') || (data[count] == '\0'))
1968 buf = &data[count + 1];
1973 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_getters",
1974 &malicious_getters))
1975 malicious_getters = 0;
1978 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_putters",
1979 &malicious_putters))
1980 malicious_putters = 0;
1983 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_droppers",
1984 &malicious_droppers))
1985 malicious_droppers = 0;
1988 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "settle_time",
1992 if (GNUNET_SYSERR ==
1993 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
1995 num_puts = num_peers;
1997 if (GNUNET_SYSERR ==
1998 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
2000 num_gets = num_peers;
2003 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "find_peer_delay",
2004 &temp_config_number))
2005 find_peer_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2007 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
2010 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_find_peers",
2011 &temp_config_number))
2012 max_outstanding_find_peers = temp_config_number;
2014 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
2017 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_timeout",
2018 &temp_config_number))
2019 get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2021 get_timeout = DEFAULT_GET_TIMEOUT;
2024 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_puts",
2025 &temp_config_number))
2026 max_outstanding_puts = temp_config_number;
2028 max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
2031 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_gets",
2032 &temp_config_number))
2033 max_outstanding_gets = temp_config_number;
2035 max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
2038 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "timeout",
2039 &temp_config_number))
2040 all_get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2042 all_get_timeout.value = get_timeout.value * ((num_gets / max_outstanding_gets) + 1);
2045 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay",
2046 &temp_config_number))
2047 get_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2049 get_delay = DEFAULT_GET_DELAY;
2052 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "put_delay",
2053 &temp_config_number))
2054 put_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2056 put_delay = DEFAULT_PUT_DELAY;
2059 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "peer_start_timeout",
2060 &temp_config_number))
2061 seconds_per_peer_start = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2063 seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START;
2066 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "data_size",
2067 &temp_config_number))
2068 test_data_size = temp_config_number;
2070 test_data_size = DEFAULT_TEST_DATA_SIZE;
2073 * Get testing related options.
2076 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2077 "MALICIOUS_GET_FREQUENCY",
2078 &malicious_get_frequency))
2079 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
2082 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2083 "MALICIOUS_PUT_FREQUENCY",
2084 &malicious_put_frequency))
2085 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
2088 GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht",
2091 do_find_peer = GNUNET_NO;
2094 do_find_peer = GNUNET_YES;
2096 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2098 &temp_config_number))
2100 find_peer_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
2103 find_peer_delay = DEFAULT_FIND_PEER_DELAY;
2105 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
2106 "OUTSTANDING_FIND_PEERS",
2107 &max_outstanding_find_peers))
2108 max_outstanding_find_peers = DEFAULT_MAX_OUTSTANDING_FIND_PEERS;
2110 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "strict_kademlia"))
2111 max_outstanding_find_peers = max_outstanding_find_peers * 1;
2113 find_peer_offset = GNUNET_TIME_relative_divide (find_peer_delay, max_outstanding_find_peers);
2115 topology_str = NULL;
2117 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
2118 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
2120 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2121 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
2122 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
2126 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
2127 &topology_percentage_str))
2128 topology_percentage = 0.5;
2131 topology_percentage = atof (topology_percentage_str);
2132 GNUNET_free(topology_percentage_str);
2136 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
2137 &topology_probability_str))
2138 topology_probability = 0.5;
2141 topology_probability = atof (topology_probability_str);
2142 GNUNET_free(topology_probability_str);
2146 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
2147 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connect_topology, connect_topology_str)))
2149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2150 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
2152 GNUNET_free_non_null(connect_topology_str);
2155 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
2156 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
2158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2159 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
2160 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
2162 GNUNET_free_non_null(connect_topology_option_str);
2165 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
2166 &connect_topology_option_modifier_string))
2168 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
2170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2171 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
2172 connect_topology_option_modifier_string,
2173 "connect_topology_option_modifier",
2176 GNUNET_free (connect_topology_option_modifier_string);
2179 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
2180 &blacklist_transports))
2181 blacklist_transports = NULL;
2184 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
2185 &blacklist_topology_str)) &&
2186 (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
2188 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2189 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
2191 GNUNET_free_non_null(topology_str);
2192 GNUNET_free_non_null(blacklist_topology_str);
2194 /* Get number of peers to start from configuration */
2195 if (GNUNET_SYSERR ==
2196 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
2199 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2200 "Number of peers must be specified in section %s option %s\n", topology_str, "TESTING", "NUM_PEERS");
2202 GNUNET_assert(num_peers > 0 && num_peers < (unsigned long long)-1);
2203 /* Set peers_left so we know when all peers started */
2204 peers_left = num_peers;
2206 /* Set up a task to end testing if peer start fails */
2207 die_task = GNUNET_SCHEDULER_add_delayed (sched,
2208 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
2209 &end_badly, "didn't generate all hostkeys within allowed startup time!");
2211 if (dhtlog_handle == NULL)
2212 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2213 "dhtlog_handle is NULL!");
2215 if ((trialmessage != NULL) && (dhtlog_handle != NULL))
2217 dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
2218 blacklist_topology, connect_topology,
2219 connect_topology_option,
2220 connect_topology_option_modifier, topology_percentage,
2221 topology_probability, num_puts, num_gets,
2222 max_outstanding_gets, settle_time, 1,
2223 malicious_getters, malicious_putters,
2224 malicious_droppers, malicious_get_frequency,
2225 malicious_put_frequency, stop_closest, stop_found,
2226 strict_kademlia, 0, trialmessage);
2228 else if (dhtlog_handle != NULL)
2230 dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
2231 blacklist_topology, connect_topology,
2232 connect_topology_option,
2233 connect_topology_option_modifier, topology_percentage,
2234 topology_probability, num_puts, num_gets,
2235 max_outstanding_gets, settle_time, 1,
2236 malicious_getters, malicious_putters,
2237 malicious_droppers, malicious_get_frequency,
2238 malicious_put_frequency, stop_closest, stop_found,
2239 strict_kademlia, 0, "");
2242 GNUNET_free_non_null(trialmessage);
2244 hostkey_meter = create_meter(peers_left, "Hostkeys created ", GNUNET_YES);
2245 peer_start_meter = create_meter(peers_left, "Peers started ", GNUNET_YES);
2247 put_meter = create_meter(num_puts, "Puts completed ", GNUNET_YES);
2248 get_meter = create_meter(num_gets, "Gets completed ", GNUNET_YES);
2249 pg = GNUNET_TESTING_daemons_start (sched, cfg,
2251 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
2252 &hostkey_callback, NULL,
2253 &peers_started_callback, NULL,
2254 &topology_callback, NULL,
2257 GNUNET_free_non_null(temphost);
2262 main (int argc, char *argv[])
2265 struct GNUNET_GETOPT_CommandLineOption options[] = {
2266 GNUNET_GETOPT_OPTION_END
2269 ret = GNUNET_PROGRAM_run (argc,
2270 argv, "gnunet-dht-driver", "nohelp",
2271 options, &run, &ok);
2273 if (ret != GNUNET_OK)
2275 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret);
2279 * Need to remove base directory, subdirectories taken care
2280 * of by the testing framework.
2282 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
2284 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
2289 /* end of test_dht_twopeer_put_get.c */