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.
27 * FIXME: Do churn, enable malicious peers!
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 #define DEFAULT_SECONDS_PER_PEER_START GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 45)
55 #define DEFAULT_TEST_DATA_SIZE 8
57 #define DEFAULT_MAX_OUTSTANDING_PUTS 10
59 #define DEFAULT_MAX_OUTSTANDING_GETS 10
61 #define DEFAULT_CONNECT_TIMEOUT 60
63 #define DEFAULT_TOPOLOGY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8)
66 * Default frequency for sending malicious get messages
68 #define DEFAULT_MALICIOUS_GET_FREQUENCY 1000 /* Number of milliseconds */
71 * Default frequency for sending malicious put messages
73 #define DEFAULT_MALICIOUS_PUT_FREQUENCY 1000 /* Default is in milliseconds */
77 struct MaliciousContext
80 * Handle to DHT service (via the API)
82 struct GNUNET_DHT_Handle *dht_handle;
85 * Handle to the peer daemon
87 struct GNUNET_TESTING_Daemon *daemon;
90 * Task for disconnecting DHT handles
92 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
95 * What type of malicious to set this peer to.
100 struct TestPutContext
102 /* This is a linked list */
103 struct TestPutContext *next;
106 * Handle to the first peers DHT service (via the API)
108 struct GNUNET_DHT_Handle *dht_handle;
111 * Handle to the PUT peer daemon
113 struct GNUNET_TESTING_Daemon *daemon;
116 * Identifier for this PUT
121 * Task for disconnecting DHT handles
123 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
126 struct TestGetContext
128 /* This is a linked list */
129 struct TestGetContext *next;
132 * Handle to the first peers DHT service (via the API)
134 struct GNUNET_DHT_Handle *dht_handle;
137 * Handle for the DHT get request
139 struct GNUNET_DHT_GetHandle *get_handle;
142 * Handle to the GET peer daemon
144 struct GNUNET_TESTING_Daemon *daemon;
147 * Identifier for this GET
152 * Task for disconnecting DHT handles (and stopping GET)
154 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
157 * Whether or not this request has been fulfilled already.
163 * Simple struct to keep track of progress, and print a
164 * nice little percentage meter for long running tasks.
174 unsigned int completed;
178 char *startup_string;
182 * Linked list of information for populating statistics
183 * before ending trial.
185 struct StatisticsIteratorContext
187 const struct GNUNET_PeerIdentity *peer;
188 unsigned int stat_routes;
189 unsigned int stat_route_forwards;
190 unsigned int stat_results;
191 unsigned int stat_results_to_client;
192 unsigned int stat_result_forwards;
193 unsigned int stat_gets;
194 unsigned int stat_puts;
195 unsigned int stat_puts_inserted;
196 unsigned int stat_find_peer;
197 unsigned int stat_find_peer_start;
198 unsigned int stat_get_start;
199 unsigned int stat_put_start;
200 unsigned int stat_find_peer_reply;
201 unsigned int stat_get_reply;
202 unsigned int stat_find_peer_answer;
203 unsigned int stat_get_response_start;
207 * Context for getting a topology, logging it, and continuing
208 * on with some next operation.
210 struct TopologyIteratorContext
212 unsigned int total_connections;
213 struct GNUNET_PeerIdentity *peer;
214 GNUNET_SCHEDULER_Task cont;
216 struct GNUNET_TIME_Relative timeout;
222 * Timeout to let all get requests happen.
224 static struct GNUNET_TIME_Relative all_get_timeout;
229 static struct GNUNET_TIME_Relative get_timeout;
231 static struct GNUNET_TIME_Relative get_delay;
233 static struct GNUNET_TIME_Relative put_delay;
235 static struct GNUNET_TIME_Relative seconds_per_peer_start;
237 static unsigned long long test_data_size = DEFAULT_TEST_DATA_SIZE;
239 static unsigned long long max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
241 static unsigned long long max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
243 static unsigned long long malicious_getters;
245 static unsigned long long malicious_putters;
247 static unsigned long long malicious_droppers;
249 static unsigned long long malicious_get_frequency;
251 static unsigned long long malicious_put_frequency;
253 static unsigned long long settle_time;
255 static struct GNUNET_DHTLOG_Handle *dhtlog_handle;
257 static unsigned long long trialuid;
260 * Hash map of stats contexts.
262 struct GNUNET_CONTAINER_MultiHashMap *stats_map;
265 * LL of malicious settings.
267 struct MaliciousContext *all_malicious;
270 * List of GETS to perform
272 struct TestGetContext *all_gets;
275 * List of PUTS to perform
277 struct TestPutContext *all_puts;
280 * Directory to store temporary data in, defined in config file
282 static char *test_directory;
285 * Variable used to store the number of connections we should wait for.
287 static unsigned int expected_connections;
290 * Variable used to keep track of how many peers aren't yet started.
292 static unsigned long long peers_left;
295 * Handle to the set of all peers run for this test.
297 static struct GNUNET_TESTING_PeerGroup *pg;
300 * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
302 static struct GNUNET_SCHEDULER_Handle *sched;
305 * Global config handle.
307 const struct GNUNET_CONFIGURATION_Handle *config;
310 * Total number of peers to run, set based on config file.
312 static unsigned long long num_peers;
315 * Total number of items to insert.
317 static unsigned long long num_puts;
320 * How many puts do we currently have in flight?
322 static unsigned long long outstanding_puts;
325 * How many puts are done?
327 static unsigned long long puts_completed;
330 * Total number of items to attempt to get.
332 static unsigned long long num_gets;
335 * How many puts do we currently have in flight?
337 static unsigned long long outstanding_gets;
340 * How many gets are done?
342 static unsigned long long gets_completed;
345 * How many gets failed?
347 static unsigned long long gets_failed;
350 * How many malicious control messages do
351 * we currently have in flight?
353 static unsigned long long outstanding_malicious;
356 * How many set malicious peers are done?
358 static unsigned long long malicious_completed;
361 * Global used to count how many connections we have currently
362 * been notified about (how many times has topology_callback been called
365 static unsigned int total_connections;
368 * Global used to count how many failed connections we have
369 * been notified about (how many times has topology_callback
370 * been called with failure?)
372 static unsigned int failed_connections;
374 /* Task handle to use to schedule shutdown if something goes wrong */
375 GNUNET_SCHEDULER_TaskIdentifier die_task;
377 static char *blacklist_transports;
379 static enum GNUNET_TESTING_Topology topology;
381 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
383 static enum GNUNET_TESTING_Topology connect_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
385 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
387 static double connect_topology_option_modifier = 0.0;
389 static struct ProgressMeter *hostkey_meter;
391 static struct ProgressMeter *peer_start_meter;
393 static struct ProgressMeter *peer_connect_meter;
395 static struct ProgressMeter *put_meter;
397 static struct ProgressMeter *get_meter;
399 /* Global return value (0 for success, anything else for failure) */
403 * Create a meter to keep track of the progress of some task.
405 * @param total the total number of items to complete
406 * @param start_string a string to prefix the meter with (if printing)
407 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
410 * @return the progress meter
412 static struct ProgressMeter *
413 create_meter(unsigned int total, char * start_string, int print)
415 struct ProgressMeter *ret;
416 ret = GNUNET_malloc(sizeof(struct ProgressMeter));
419 ret->modnum = total / 4;
420 ret->dotnum = (total / 50) + 1;
421 if (start_string != NULL)
422 ret->startup_string = GNUNET_strdup(start_string);
424 ret->startup_string = GNUNET_strdup("");
430 * Update progress meter (increment by one).
432 * @param meter the meter to update and print info for
434 * @return GNUNET_YES if called the total requested,
435 * GNUNET_NO if more items expected
438 update_meter(struct ProgressMeter *meter)
440 if (meter->print == GNUNET_YES)
442 if (meter->completed % meter->modnum == 0)
444 if (meter->completed == 0)
446 fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
449 fprintf(stdout, "%d%%", (int)(((float)meter->completed / meter->total) * 100));
451 else if (meter->completed % meter->dotnum == 0)
452 fprintf(stdout, ".");
454 if (meter->completed + 1 == meter->total)
455 fprintf(stdout, "%d%%]\n", 100);
460 if (meter->completed == meter->total)
466 * Release resources for meter
468 * @param meter the meter to free
471 free_meter(struct ProgressMeter *meter)
473 GNUNET_free_non_null(meter->startup_string);
474 GNUNET_free_non_null(meter);
478 * Check whether peers successfully shut down.
480 void shutdown_callback (void *cls,
491 * Task to release DHT handles for PUT
494 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
496 struct TestPutContext *test_put = cls;
497 test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
498 GNUNET_DHT_disconnect(test_put->dht_handle);
499 test_put->dht_handle = NULL;
503 * Function scheduled to be run on the successful completion of this
507 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n", (char *)cls);
510 GNUNET_assert (pg != NULL);
511 struct TestPutContext *test_put = all_puts;
512 struct TestGetContext *test_get = all_gets;
514 while (test_put != NULL)
516 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
517 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
518 if (test_put->dht_handle != NULL)
519 GNUNET_DHT_disconnect(test_put->dht_handle);
520 test_put = test_put->next;
523 while (test_get != NULL)
525 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
526 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
527 if (test_get->get_handle != NULL)
528 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
529 if (test_get->dht_handle != NULL)
530 GNUNET_DHT_disconnect(test_get->dht_handle);
531 test_get = test_get->next;
534 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
536 if (dhtlog_handle != NULL)
538 fprintf(stderr, "Update trial endtime\n");
539 dhtlog_handle->update_trial (trialuid, gets_completed);
540 GNUNET_DHTLOG_disconnect(dhtlog_handle);
541 dhtlog_handle = NULL;
544 if (hostkey_meter != NULL)
545 free_meter(hostkey_meter);
546 if (peer_start_meter != NULL)
547 free_meter(peer_start_meter);
548 if (peer_connect_meter != NULL)
549 free_meter(peer_connect_meter);
550 if (put_meter != NULL)
551 free_meter(put_meter);
552 if (get_meter != NULL)
553 free_meter(get_meter);
559 * Callback for iterating over all the peer connections of a peer group.
561 void log_topology_cb (void *cls,
562 const struct GNUNET_PeerIdentity *first,
563 const struct GNUNET_PeerIdentity *second,
564 struct GNUNET_TIME_Relative latency,
568 struct TopologyIteratorContext *topo_ctx = cls;
569 if ((first != NULL) && (second != NULL))
571 topo_ctx->total_connections++;
572 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging_extended"))
573 dhtlog_handle->insert_extended_topology(first, second);
577 GNUNET_assert(dhtlog_handle != NULL);
578 fprintf(stderr, "topology iteration finished (%u connections), scheduling continuation\n", topo_ctx->total_connections);
579 dhtlog_handle->update_topology(topo_ctx->total_connections);
580 if (topo_ctx->cont != NULL)
581 GNUNET_SCHEDULER_add_now (sched, topo_ctx->cont, topo_ctx->cls);
582 GNUNET_free(topo_ctx);
587 * Iterator over hash map entries.
589 * @param cls closure - always NULL
590 * @param key current key code
591 * @param value value in the hash map, a stats context
592 * @return GNUNET_YES if we should continue to
596 static int stats_iterate (void *cls,
597 const GNUNET_HashCode * key,
600 struct StatisticsIteratorContext *stats_ctx;
604 dhtlog_handle->insert_stat(stats_ctx->peer, stats_ctx->stat_routes, stats_ctx->stat_route_forwards, stats_ctx->stat_results,
605 stats_ctx->stat_results_to_client, stats_ctx->stat_result_forwards, stats_ctx->stat_gets,
606 stats_ctx->stat_puts, stats_ctx->stat_puts_inserted, stats_ctx->stat_find_peer,
607 stats_ctx->stat_find_peer_start, stats_ctx->stat_get_start, stats_ctx->stat_put_start,
608 stats_ctx->stat_find_peer_reply, stats_ctx->stat_get_reply, stats_ctx->stat_find_peer_answer,
609 stats_ctx->stat_get_response_start);
610 GNUNET_free(stats_ctx);
614 static void stats_finished (void *cls, int result)
616 fprintf(stderr, "Finished getting all peers statistics, iterating!\n");
617 GNUNET_CONTAINER_multihashmap_iterate(stats_map, &stats_iterate, NULL);
618 GNUNET_CONTAINER_multihashmap_destroy(stats_map);
619 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
623 * Callback function to process statistic values.
626 * @param peer the peer the statistics belong to
627 * @param subsystem name of subsystem that created the statistic
628 * @param name the name of the datum
629 * @param value the current value
630 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
631 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
633 static int stats_handle (void *cls,
634 const struct GNUNET_PeerIdentity *peer,
635 const char *subsystem,
640 struct StatisticsIteratorContext *stats_ctx;
642 if (dhtlog_handle != NULL)
643 dhtlog_handle->add_generic_stat(peer, name, subsystem, value);
644 if (GNUNET_CONTAINER_multihashmap_contains(stats_map, &peer->hashPubKey))
646 stats_ctx = GNUNET_CONTAINER_multihashmap_get(stats_map, &peer->hashPubKey);
650 stats_ctx = GNUNET_malloc(sizeof(struct StatisticsIteratorContext));
651 stats_ctx->peer = peer;
652 GNUNET_CONTAINER_multihashmap_put(stats_map, &peer->hashPubKey, stats_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
655 if (strcmp(name, STAT_ROUTES) == 0)
656 stats_ctx->stat_routes = value;
657 else if (strcmp(name, STAT_ROUTE_FORWARDS) == 0)
658 stats_ctx->stat_route_forwards = value;
659 else if (strcmp(name, STAT_RESULTS) == 0)
660 stats_ctx->stat_results = value;
661 else if (strcmp(name, STAT_RESULTS_TO_CLIENT) == 0)
662 stats_ctx->stat_results_to_client = value;
663 else if (strcmp(name, STAT_RESULT_FORWARDS) == 0)
664 stats_ctx->stat_result_forwards = value;
665 else if (strcmp(name, STAT_GETS) == 0)
666 stats_ctx->stat_gets = value;
667 else if (strcmp(name, STAT_PUTS) == 0)
668 stats_ctx->stat_puts = value;
669 else if (strcmp(name, STAT_PUTS_INSERTED) == 0)
670 stats_ctx->stat_puts_inserted = value;
671 else if (strcmp(name, STAT_FIND_PEER) == 0)
672 stats_ctx->stat_find_peer = value;
673 else if (strcmp(name, STAT_FIND_PEER_START) == 0)
674 stats_ctx->stat_find_peer_start = value;
675 else if (strcmp(name, STAT_GET_START) == 0)
676 stats_ctx->stat_get_start = value;
677 else if (strcmp(name, STAT_PUT_START) == 0)
678 stats_ctx->stat_put_start = value;
679 else if (strcmp(name, STAT_FIND_PEER_REPLY) == 0)
680 stats_ctx->stat_find_peer_reply = value;
681 else if (strcmp(name, STAT_GET_REPLY) == 0)
682 stats_ctx->stat_get_reply = value;
683 else if (strcmp(name, STAT_FIND_PEER_ANSWER) == 0)
684 stats_ctx->stat_find_peer_answer = value;
685 else if (strcmp(name, STAT_GET_RESPONSE_START) == 0)
686 stats_ctx->stat_get_response_start = value;
692 * Connect to statistics service for each peer and get the appropriate
693 * dht statistics for safe keeping.
696 log_dht_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
698 stats_map = GNUNET_CONTAINER_multihashmap_create(num_peers);
699 GNUNET_TESTING_get_statistics(pg, &stats_finished, &stats_handle, NULL);
704 * Connect to all peers in the peer group and iterate over their
708 capture_current_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
710 struct TopologyIteratorContext *topo_ctx = cls;
711 dhtlog_handle->insert_topology(0);
712 GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx);
717 * Check if the get_handle is being used, if so stop the request. Either
718 * way, schedule the end_badly_cont function which actually shuts down the
722 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
724 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n", (char *)cls);
726 struct TestPutContext *test_put = all_puts;
727 struct TestGetContext *test_get = all_gets;
729 while (test_put != NULL)
731 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
732 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
733 if (test_put->dht_handle != NULL)
734 GNUNET_DHT_disconnect(test_put->dht_handle);
735 test_put = test_put->next;
738 while (test_get != NULL)
740 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
741 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
742 if (test_get->get_handle != NULL)
743 GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
744 if (test_get->dht_handle != NULL)
745 GNUNET_DHT_disconnect(test_get->dht_handle);
746 test_get = test_get->next;
749 GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
751 if (dhtlog_handle != NULL)
753 fprintf(stderr, "Update trial endtime\n");
754 dhtlog_handle->update_trial (trialuid, gets_completed);
755 GNUNET_DHTLOG_disconnect(dhtlog_handle);
756 dhtlog_handle = NULL;
759 if (hostkey_meter != NULL)
760 free_meter(hostkey_meter);
761 if (peer_start_meter != NULL)
762 free_meter(peer_start_meter);
763 if (peer_connect_meter != NULL)
764 free_meter(peer_connect_meter);
765 if (put_meter != NULL)
766 free_meter(put_meter);
767 if (get_meter != NULL)
768 free_meter(get_meter);
774 * Task to release DHT handle associated with GET request.
777 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
779 struct TestGetContext *test_get = cls;
780 struct TopologyIteratorContext *topo_ctx;
781 outstanding_gets--; /* GET is really finished */
782 GNUNET_DHT_disconnect(test_get->dht_handle);
783 test_get->dht_handle = NULL;
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
788 update_meter(get_meter);
789 if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
791 GNUNET_SCHEDULER_cancel(sched, die_task);
792 //GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
793 if (dhtlog_handle != NULL)
795 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
796 topo_ctx->cont = &log_dht_statistics;
797 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
800 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
805 * Task to release get handle.
808 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
810 struct TestGetContext *test_get = cls;
812 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
814 GNUNET_assert(test_get->get_handle != NULL);
815 GNUNET_DHT_get_stop(test_get->get_handle, &get_stop_finished, test_get);
816 test_get->get_handle = NULL;
817 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
821 * Iterator called if the GET request initiated returns a response.
824 * @param exp when will this value expire
825 * @param key key of the result
826 * @param type type of the result
827 * @param size number of bytes in data
828 * @param data pointer to the result data
830 void get_result_iterator (void *cls,
831 struct GNUNET_TIME_Absolute exp,
832 const GNUNET_HashCode * key,
837 struct TestGetContext *test_get = cls;
838 GNUNET_HashCode search_key; /* Key stored under */
839 char original_data[test_data_size]; /* Made up data to store */
841 memset(original_data, test_get->uid, sizeof(original_data));
842 GNUNET_CRYPTO_hash(original_data, test_data_size, &search_key);
844 if (test_get->succeeded == GNUNET_YES)
845 return; /* Get has already been successful, probably ending now */
847 if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
854 test_get->succeeded = GNUNET_YES;
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
859 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
860 GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
864 * Continuation telling us GET request was sent.
867 get_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
869 // Is there something to be done here?
870 if (tc->reason != GNUNET_SCHEDULER_REASON_PREREQ_DONE)
875 * Set up some data, and call API PUT function
878 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
880 struct TestGetContext *test_get = cls;
881 GNUNET_HashCode key; /* Made up key to store data under */
882 char data[test_data_size]; /* Made up data to store */
886 GNUNET_SCHEDULER_cancel(sched, die_task);
887 GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
889 if (test_get == NULL)
890 return; /* End of the list */
892 memset(data, test_get->uid, sizeof(data));
893 GNUNET_CRYPTO_hash(data, test_data_size, &key);
895 if (outstanding_gets > max_outstanding_gets)
897 GNUNET_SCHEDULER_add_delayed (sched, get_delay, &do_get, test_get);
901 test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10);
902 /* Insert the data at the first peer */
903 GNUNET_assert(test_get->dht_handle != NULL);
905 test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
906 GNUNET_TIME_relative_get_forever(),
909 &get_result_iterator,
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
916 test_get->daemon->shortname);
918 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, get_timeout, &get_stop_task, test_get);
919 GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next);
923 * Called when the PUT request has been transmitted to the DHT service.
924 * Schedule the GET request for some time in the future.
927 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
929 struct TestPutContext *test_put = cls;
930 struct TopologyIteratorContext *topo_ctx;
934 if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
935 fprintf(stderr, "PUT Request failed!\n");
937 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
938 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put);
939 if (GNUNET_YES == update_meter(put_meter))
941 GNUNET_assert(outstanding_puts == 0);
942 GNUNET_SCHEDULER_cancel (sched, die_task);
943 if (dhtlog_handle != NULL)
945 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
946 topo_ctx->cont = &do_get;
947 topo_ctx->cls = all_gets;
948 topo_ctx->timeout = DEFAULT_GET_TIMEOUT;
949 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),
950 &end_badly, "from do gets");
951 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
955 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout),
956 &end_badly, "from do gets");
957 GNUNET_SCHEDULER_add_delayed(sched, DEFAULT_GET_TIMEOUT, &do_get, all_gets);
958 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
965 * Set up some data, and call API PUT function
968 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
970 struct TestPutContext *test_put = cls;
971 GNUNET_HashCode key; /* Made up key to store data under */
972 char data[test_data_size]; /* Made up data to store */
975 if (test_put == NULL)
976 return; /* End of list */
978 memset(data, test_put->uid, sizeof(data));
979 GNUNET_CRYPTO_hash(data, test_data_size, &key);
981 if (outstanding_puts > max_outstanding_puts)
983 GNUNET_SCHEDULER_add_delayed (sched, put_delay, &do_put, test_put);
988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
990 test_put->daemon->shortname);
992 test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10);
994 GNUNET_assert(test_put->dht_handle != NULL);
996 GNUNET_DHT_put(test_put->dht_handle,
1000 GNUNET_TIME_absolute_get_forever(),
1001 GNUNET_TIME_relative_get_forever(),
1002 &put_finished, test_put);
1003 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
1004 rand = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
1005 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, rand), &do_put, test_put->next);
1010 * Set up some all of the put and get operations we want
1011 * to do. Allocate data structure for each, add to list,
1012 * then call actual insert functions.
1015 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1018 uint32_t temp_daemon;
1019 struct TestPutContext *test_put;
1020 struct TestGetContext *test_get;
1021 int remember[num_puts][num_peers];
1023 memset(&remember, 0, sizeof(int) * num_puts * num_peers);
1024 for (i = 0; i < num_puts; i++)
1026 test_put = GNUNET_malloc(sizeof(struct TestPutContext));
1028 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1029 test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1030 test_put->next = all_puts;
1031 all_puts = test_put;
1034 for (i = 0; i < num_gets; i++)
1036 test_get = GNUNET_malloc(sizeof(struct TestGetContext));
1037 test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
1038 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1039 while (remember[test_get->uid][temp_daemon] == 1)
1040 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1041 test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1042 remember[test_get->uid][temp_daemon] = 1;
1043 test_get->next = all_gets;
1044 all_gets = test_get;
1047 /*GNUNET_SCHEDULER_cancel (sched, die_task);*/
1048 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
1049 &end_badly, "from do puts");
1050 GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts);
1054 * Set up some all of the put and get operations we want
1055 * to do. Allocate data structure for each, add to list,
1056 * then call actual insert functions.
1059 continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1063 struct TopologyIteratorContext *topo_ctx;
1064 if (dhtlog_handle != NULL)
1066 if (settle_time >= 60 * 2)
1067 max = (settle_time / 60) - 2;
1070 for (i = 1; i < max; i++)
1072 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1073 fprintf(stderr, "scheduled topology iteration in %d minutes\n", i);
1074 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, i), &capture_current_topology, topo_ctx);
1076 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1077 topo_ctx->cont = &setup_puts_and_gets;
1078 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &capture_current_topology, topo_ctx);
1081 GNUNET_SCHEDULER_add_now (sched, &setup_puts_and_gets, NULL);
1085 * Task to release DHT handles
1088 malicious_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1090 struct MaliciousContext *ctx = cls;
1091 outstanding_malicious--;
1092 malicious_completed++;
1093 ctx->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
1094 GNUNET_DHT_disconnect(ctx->dht_handle);
1095 ctx->dht_handle = NULL;
1098 if (malicious_completed == malicious_getters + malicious_putters + malicious_droppers)
1100 GNUNET_SCHEDULER_cancel(sched, die_task);
1101 fprintf(stderr, "Finished setting all malicious peers up, calling continuation!\n");
1102 if (dhtlog_handle != NULL)
1103 GNUNET_SCHEDULER_add_now (sched,
1104 &continue_puts_and_gets, NULL);
1106 GNUNET_SCHEDULER_add_delayed (sched,
1107 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1108 &continue_puts_and_gets, NULL);
1114 * Task to release DHT handles
1117 malicious_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1119 struct MaliciousContext *ctx = cls;
1120 GNUNET_SCHEDULER_cancel(sched, ctx->disconnect_task);
1121 GNUNET_SCHEDULER_add_now(sched, &malicious_disconnect_task, ctx);
1125 * Set up some data, and call API PUT function
1128 set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1130 struct MaliciousContext *ctx = cls;
1133 if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS)
1135 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1139 if (ctx->dht_handle == NULL)
1141 ctx->dht_handle = GNUNET_DHT_connect(sched, ctx->daemon->cfg, 1);
1142 outstanding_malicious++;
1145 GNUNET_assert(ctx->dht_handle != NULL);
1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting peer %s malicious type %d\n",
1150 ctx->daemon->shortname, ctx->malicious_type);
1154 switch (ctx->malicious_type)
1156 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
1157 ret = GNUNET_DHT_set_malicious_getter(ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx);
1159 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
1160 ret = GNUNET_DHT_set_malicious_putter(ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx);
1162 case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
1163 ret = GNUNET_DHT_set_malicious_dropper(ctx->dht_handle, &malicious_done_task, ctx);
1169 if (ret == GNUNET_NO)
1171 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx);
1174 ctx->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &malicious_disconnect_task, ctx);
1178 * Select randomly from set of known peers,
1179 * set the desired number of peers to the
1180 * proper malicious types.
1183 setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
1185 struct MaliciousContext *ctx;
1187 uint32_t temp_daemon;
1189 for (i = 0; i < malicious_getters; i++)
1191 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1192 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1193 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1194 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET;
1195 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1199 for (i = 0; i < malicious_putters; i++)
1201 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1202 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1203 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1204 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT;
1205 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1209 for (i = 0; i < malicious_droppers; i++)
1211 ctx = GNUNET_malloc(sizeof(struct MaliciousContext));
1212 temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
1213 ctx->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
1214 ctx->malicious_type = GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP;
1215 GNUNET_SCHEDULER_add_now (sched, &set_malicious, ctx);
1218 if (malicious_getters + malicious_putters + malicious_droppers > 0)
1219 die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, (malicious_getters + malicious_putters + malicious_droppers) * 2),
1220 &end_badly, "from set malicious");
1223 if (dhtlog_handle != NULL)
1224 GNUNET_SCHEDULER_add_now (sched,
1225 &continue_puts_and_gets, NULL);
1227 GNUNET_SCHEDULER_add_delayed (sched,
1228 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1229 &continue_puts_and_gets, NULL);
1235 * This function is called whenever a connection attempt is finished between two of
1236 * the started peers (started with GNUNET_TESTING_daemons_start). The total
1237 * number of times this function is called should equal the number returned
1238 * from the GNUNET_TESTING_connect_topology call.
1240 * The emsg variable is NULL on success (peers connected), and non-NULL on
1241 * failure (peers failed to connect).
1244 topology_callback (void *cls,
1245 const struct GNUNET_PeerIdentity *first,
1246 const struct GNUNET_PeerIdentity *second,
1248 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
1249 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
1250 struct GNUNET_TESTING_Daemon *first_daemon,
1251 struct GNUNET_TESTING_Daemon *second_daemon,
1254 struct TopologyIteratorContext *topo_ctx;
1257 total_connections++;
1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
1260 first_daemon->shortname,
1261 second_daemon->shortname,
1268 failed_connections++;
1269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
1270 first_daemon->shortname,
1271 second_daemon->shortname, emsg);
1274 GNUNET_assert(peer_connect_meter != NULL);
1275 if (GNUNET_YES == update_meter(peer_connect_meter))
1278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1279 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
1282 if (dhtlog_handle != NULL)
1284 dhtlog_handle->update_connections (trialuid, total_connections);
1285 dhtlog_handle->insert_topology(expected_connections);
1288 GNUNET_SCHEDULER_cancel (sched, die_task);
1289 /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT,
1290 &end_badly, "from setup puts/gets");*/
1291 if ((dhtlog_handle != NULL) && (settle_time > 0))
1293 topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
1294 topo_ctx->cont = &setup_malicious_peers;
1295 //topo_ctx->cont = &continue_puts_and_gets;
1296 GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx);
1300 GNUNET_SCHEDULER_add_now(sched, &setup_malicious_peers, NULL);
1301 /*GNUNET_SCHEDULER_add_delayed (sched,
1302 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
1303 &continue_puts_and_gets, NULL);*/
1306 else if (total_connections + failed_connections == expected_connections)
1308 GNUNET_SCHEDULER_cancel (sched, die_task);
1309 die_task = GNUNET_SCHEDULER_add_now (sched,
1310 &end_badly, "from topology_callback (too many failed connections)");
1315 peers_started_callback (void *cls,
1316 const struct GNUNET_PeerIdentity *id,
1317 const struct GNUNET_CONFIGURATION_Handle *cfg,
1318 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
1326 GNUNET_assert (id != NULL);
1329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
1330 (num_peers - peers_left) + 1, num_peers);
1335 if (GNUNET_YES == update_meter(peer_start_meter))
1338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1339 "All %d daemons started, now connecting peers!\n",
1342 GNUNET_SCHEDULER_cancel (sched, die_task);
1344 expected_connections = -1;
1345 if ((pg != NULL) && (peers_left == 0))
1347 expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier);
1349 peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES);
1350 fprintf(stderr, "Have %d expected connections\n", expected_connections);
1353 if (expected_connections == GNUNET_SYSERR)
1355 die_task = GNUNET_SCHEDULER_add_now (sched,
1356 &end_badly, "from connect topology (bad return)");
1359 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1360 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, DEFAULT_CONNECT_TIMEOUT * expected_connections),
1361 &end_badly, "from connect topology (timeout)");
1370 peers_left = num_peers; /* Reset counter */
1371 if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
1374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1375 "Topology set up, now starting peers!\n");
1377 GNUNET_TESTING_daemons_continue_startup(pg);
1381 GNUNET_SCHEDULER_cancel (sched, die_task);
1382 die_task = GNUNET_SCHEDULER_add_now (sched,
1383 &end_badly, "from create topology (bad return)");
1385 GNUNET_free_non_null(blacklist_transports);
1386 GNUNET_SCHEDULER_cancel (sched, die_task);
1387 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1388 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1389 &end_badly, "from continue startup (timeout)");
1393 * Callback indicating that the hostkey was created for a peer.
1396 * @param id the peer identity
1397 * @param d the daemon handle (pretty useless at this point, remove?)
1398 * @param emsg non-null on failure
1400 void hostkey_callback (void *cls,
1401 const struct GNUNET_PeerIdentity *id,
1402 struct GNUNET_TESTING_Daemon *d,
1407 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
1411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1412 "Hostkey (%d/%d) created for peer `%s'\n",
1413 num_peers - peers_left, num_peers, GNUNET_i2s(id));
1417 if (GNUNET_YES == update_meter(hostkey_meter))
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1421 "All %d hostkeys created, now creating topology!\n",
1424 GNUNET_SCHEDULER_cancel (sched, die_task);
1425 /* Set up task in case topology creation doesn't finish
1426 * within a reasonable amount of time */
1427 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1428 DEFAULT_TOPOLOGY_TIMEOUT,
1429 &end_badly, "from create_topology");
1430 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
1438 struct GNUNET_SCHEDULER_Handle *s,
1440 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1443 struct GNUNET_TESTING_Host *hosts;
1444 struct GNUNET_TESTING_Host *temphost;
1446 char *connect_topology_str;
1447 char *blacklist_topology_str;
1448 char *connect_topology_option_str;
1449 char *connect_topology_option_modifier_string;
1451 char *topology_percentage_str;
1452 float topology_percentage;
1453 char *topology_probability_str;
1455 float topology_probability;
1456 unsigned long long temp_config_number;
1459 int strict_kademlia;
1466 /* Get path from configuration file */
1467 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
1474 * Get DHT specific testing options.
1476 if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging")) ||
1477 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")))
1479 dhtlog_handle = GNUNET_DHTLOG_connect(cfg);
1480 if (dhtlog_handle == NULL)
1482 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1483 "Could not connect to mysql server for logging, will NOT log dht operations!");
1489 stop_closest = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_on_closest");
1490 if (stop_closest == GNUNET_SYSERR)
1491 stop_closest = GNUNET_NO;
1493 stop_found = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "stop_found");
1494 if (stop_found == GNUNET_SYSERR)
1495 stop_found = GNUNET_NO;
1497 strict_kademlia = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht", "strict_kademlia");
1498 if (strict_kademlia == GNUNET_SYSERR)
1499 strict_kademlia = GNUNET_NO;
1502 GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "comment",
1504 trialmessage = NULL;
1507 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
1512 if (hostfile != NULL)
1514 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
1515 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
1516 | GNUNET_DISK_PERM_USER_WRITE);
1517 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
1519 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1520 "Could not open file specified for host list, ending test!");
1522 GNUNET_free_non_null(trialmessage);
1523 GNUNET_free(hostfile);
1527 data = GNUNET_malloc_large (frstat.st_size);
1528 GNUNET_assert(data != NULL);
1529 if (frstat.st_size !=
1530 GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
1532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1533 "Could not read file %s specified for host list, ending test!", hostfile);
1534 GNUNET_free (hostfile);
1539 GNUNET_free_non_null(hostfile);
1543 while (count < frstat.st_size)
1546 if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))
1549 temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
1550 temphost->hostname = buf;
1551 temphost->next = hosts;
1553 buf = &data[count + 1];
1555 else if ((data[count] == '\n') || (data[count] == '\0'))
1556 buf = &data[count + 1];
1561 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_getters",
1562 &malicious_getters))
1563 malicious_getters = 0;
1566 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_putters",
1567 &malicious_putters))
1568 malicious_putters = 0;
1571 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_droppers",
1572 &malicious_droppers))
1573 malicious_droppers = 0;
1576 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "settle_time",
1580 if (GNUNET_SYSERR ==
1581 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
1583 num_puts = num_peers;
1585 if (GNUNET_SYSERR ==
1586 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
1588 num_gets = num_peers;
1591 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_timeout",
1592 &temp_config_number))
1593 get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1595 get_timeout = DEFAULT_GET_TIMEOUT;
1598 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_puts",
1599 &temp_config_number))
1600 max_outstanding_puts = temp_config_number;
1602 max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
1605 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_gets",
1606 &temp_config_number))
1607 max_outstanding_gets = temp_config_number;
1609 max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
1612 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "timeout",
1613 &temp_config_number))
1614 all_get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1616 all_get_timeout.value = get_timeout.value * ((num_gets / max_outstanding_gets) + 1);
1619 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay",
1620 &temp_config_number))
1621 get_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1623 get_delay = DEFAULT_GET_DELAY;
1626 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "put_delay",
1627 &temp_config_number))
1628 put_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1630 put_delay = DEFAULT_PUT_DELAY;
1633 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "peer_start_timeout",
1634 &temp_config_number))
1635 seconds_per_peer_start = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1637 seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START;
1640 GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "data_size",
1641 &temp_config_number))
1642 test_data_size = temp_config_number;
1644 test_data_size = DEFAULT_TEST_DATA_SIZE;
1647 * Get testing related options.
1650 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
1651 "MALICIOUS_GET_FREQUENCY",
1652 &malicious_get_frequency))
1653 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
1656 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING",
1657 "MALICIOUS_PUT_FREQUENCY",
1658 &malicious_put_frequency))
1659 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
1661 topology_str = NULL;
1663 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
1664 &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
1666 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1667 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
1668 topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1672 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
1673 &topology_percentage_str))
1674 topology_percentage = 0.5;
1677 topology_percentage = atof (topology_percentage_str);
1678 GNUNET_free(topology_percentage_str);
1682 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
1683 &topology_probability_str))
1684 topology_probability = 0.5;
1687 topology_probability = atof (topology_probability_str);
1688 GNUNET_free(topology_probability_str);
1692 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
1693 &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connect_topology, connect_topology_str)))
1695 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1696 "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1698 GNUNET_free_non_null(connect_topology_str);
1701 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
1702 &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
1704 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1705 "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
1706 connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1708 GNUNET_free_non_null(connect_topology_option_str);
1711 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
1712 &connect_topology_option_modifier_string))
1714 if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1716 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1717 _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1718 connect_topology_option_modifier_string,
1719 "connect_topology_option_modifier",
1722 GNUNET_free (connect_topology_option_modifier_string);
1725 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1726 &blacklist_transports))
1727 blacklist_transports = NULL;
1730 GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1731 &blacklist_topology_str)) &&
1732 (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1734 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1735 "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1737 GNUNET_free_non_null(topology_str);
1738 GNUNET_free_non_null(blacklist_topology_str);
1740 /* Get number of peers to start from configuration */
1741 if (GNUNET_SYSERR ==
1742 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1745 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1746 "Number of peers must be specified in section %s option %s\n", topology_str, "TESTING", "NUM_PEERS");
1749 /* Set peers_left so we know when all peers started */
1750 peers_left = num_peers;
1752 /* Set up a task to end testing if peer start fails */
1753 die_task = GNUNET_SCHEDULER_add_delayed (sched,
1754 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1755 &end_badly, "didn't generate all hostkeys within allowed startup time!");
1757 if (dhtlog_handle == NULL)
1758 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1759 "dhtlog_handle is NULL!");
1761 if ((trialmessage != NULL) && (dhtlog_handle != NULL))
1763 dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
1764 blacklist_topology, connect_topology,
1765 connect_topology_option,
1766 connect_topology_option_modifier, topology_percentage,
1767 topology_probability, num_puts, num_gets,
1768 max_outstanding_gets, settle_time, 1,
1769 malicious_getters, malicious_putters,
1770 malicious_droppers, malicious_get_frequency,
1771 malicious_put_frequency, stop_closest, stop_found,
1772 strict_kademlia, 0, trialmessage);
1774 else if (dhtlog_handle != NULL)
1776 dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
1777 blacklist_topology, connect_topology,
1778 connect_topology_option,
1779 connect_topology_option_modifier, topology_percentage,
1780 topology_probability, num_puts, num_gets,
1781 max_outstanding_gets, settle_time, 1,
1782 malicious_getters, malicious_putters,
1783 malicious_droppers, malicious_get_frequency,
1784 malicious_put_frequency, stop_closest, stop_found,
1785 strict_kademlia, 0, "");
1788 GNUNET_free_non_null(trialmessage);
1790 hostkey_meter = create_meter(peers_left, "Hostkeys created ", GNUNET_YES);
1791 peer_start_meter = create_meter(peers_left, "Peers started ", GNUNET_YES);
1793 put_meter = create_meter(num_puts, "Puts completed ", GNUNET_YES);
1794 get_meter = create_meter(num_gets, "Gets completed ", GNUNET_YES);
1795 pg = GNUNET_TESTING_daemons_start (sched, cfg,
1797 GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1798 &hostkey_callback, NULL,
1799 &peers_started_callback, NULL,
1800 &topology_callback, NULL,
1807 main (int argc, char *argv[])
1810 struct GNUNET_GETOPT_CommandLineOption options[] = {
1811 GNUNET_GETOPT_OPTION_END
1814 ret = GNUNET_PROGRAM_run (argc,
1815 argv, "gnunet-dht-driver", "nohelp",
1816 options, &run, &ok);
1818 if (ret != GNUNET_OK)
1820 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret);
1824 * Need to remove base directory, subdirectories taken care
1825 * of by the testing framework.
1827 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1829 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1834 /* end of test_dht_twopeer_put_get.c */