2 This file is part of GNUnet.
3 (C) 2014 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.
22 * @file dht/gnunet_dht_profiler.c
23 * @brief Profiler for GNUnet DHT
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_dht_service.h"
33 GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__)
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
39 * Number of peers which should perform a PUT out of 100 peers
41 #define PUT_PROBABILITY 100
44 * Percentage of peers that should act maliciously.
45 * These peers will never start PUT/GET request.
46 * n_active and n_malicious should not intersect.
48 #define MALICIOUS_PEERS 0
53 static struct GNUNET_CONFIGURATION_Handle *cfg;
56 * Name of the file with the hosts to run the test over
58 static char *hosts_file;
61 * Context for a peer which actively does DHT PUT/GET
66 * Context to hold data of peer
72 * The testbed peer this context belongs to
74 struct GNUNET_TESTBED_Peer *peer;
77 * Testbed operation acting on this peer
79 struct GNUNET_TESTBED_Operation *op;
82 * Active context; NULL if this peer is not an active peer
84 struct ActiveContext *ac;
90 * Context for a peer which should act maliciously.
92 struct MaliciousContext
95 * The linked peer context
100 * Handler to the DHT service
102 struct GNUNET_DHT_Handle *dht;
106 * List of all the malicious peers contexts.
108 struct Context **malicious_peer_contexts = NULL;
113 * Context for a peer which actively does DHT PUT/GET
118 * The linked peer context
123 * Handler to the DHT service
125 struct GNUNET_DHT_Handle *dht;
128 * The data used for do a PUT. Will be NULL if a PUT hasn't been performed yet
133 * The active context used for our DHT GET
135 struct ActiveContext *get_ac;
140 struct GNUNET_DHT_PutHandle *dht_put;
145 struct GNUNET_DHT_GetHandle *dht_get;
148 * The hash of the @e put_data
150 struct GNUNET_HashCode hash;
155 GNUNET_SCHEDULER_TaskIdentifier delay_task;
158 * The size of the @e put_data
160 uint16_t put_data_size;
163 * The number of peers currently doing GET on our data
170 * An array of contexts. The size of this array should be equal to @a num_peers
172 static struct Context *a_ctx;
175 * Array of active peers
177 static struct ActiveContext *a_ac;
180 * The delay between starting to do PUTS and GETS
182 static struct GNUNET_TIME_Relative delay;
185 * The timeout for GET and PUT
187 static struct GNUNET_TIME_Relative timeout;
192 static unsigned int num_peers;
196 * Number or malicious peers.
198 static unsigned int n_malicious;
202 * Number of active peers
204 static unsigned int n_active;
207 * Number of DHT service connections we currently have
209 static unsigned int n_dht;
212 * Number of DHT PUTs made
214 static unsigned int n_puts;
217 * Number of DHT PUTs succeeded
219 static unsigned int n_puts_ok;
222 * Number of DHT PUTs failed
224 static unsigned int n_puts_fail;
227 * Number of DHT GETs made
229 static unsigned int n_gets;
232 * Number of DHT GETs succeeded
234 static unsigned int n_gets_ok;
237 * Number of DHT GETs succeeded
239 static unsigned int n_gets_fail;
244 static unsigned int replication;
247 * Number of times we try to find the successor circle formation
249 static unsigned int max_searches;
252 * Testbed Operation (to get stats).
254 static struct GNUNET_TESTBED_Operation *bandwidth_stats_op;
257 * To get successor stats.
259 static struct GNUNET_TESTBED_Operation *successor_stats_op;
262 * Testbed peer handles.
264 static struct GNUNET_TESTBED_Peer **testbed_handles;
267 * Total number of messages sent by peer.
269 static uint64_t outgoing_bandwidth;
272 * Total number of messages received by peer.
274 static uint64_t incoming_bandwidth;
277 * Average number of hops taken to do put.
279 static double average_put_path_length;
282 * Average number of hops taken to do get.
284 static double average_get_path_length;
287 * Total put path length across all peers.
289 static unsigned int total_put_path_length;
292 * Total get path length across all peers.
294 static unsigned int total_get_path_length;
297 * Hashmap to store pair of peer and its corresponding successor.
299 static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap;
302 * Key to start the lookup on successor_peer_hashmap.
304 static struct GNUNET_HashCode *start_key;
307 * Flag used to get the start_key.
312 * Task to collect peer and its current successor statistics.
314 static GNUNET_SCHEDULER_TaskIdentifier successor_stats_task;
317 * Closure for successor_stats_task.
319 struct Collect_Stat_Context
322 * Current Peer Context.
324 struct Context *service_connect_ctx;
327 * Testbed operation acting on this peer
329 struct GNUNET_TESTBED_Operation *op;
333 * List of all the peers contexts.
335 struct Context **peer_contexts = NULL;
338 * Counter to keep track of peers added to peer_context lists.
340 static int peers_started = 0;
343 * Task that collects successor statistics from all the peers.
348 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
352 * Shutdown task. Cleanup all resources and operations.
355 * @param tc scheduler task context
358 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
360 struct ActiveContext *ac;
365 for (cnt=0; cnt < num_peers; cnt++)
367 if (NULL != a_ctx[cnt].op)
368 GNUNET_TESTBED_operation_done (a_ctx[cnt].op);
370 /* Cleanup active context if this peer is an active peer */
374 if (GNUNET_SCHEDULER_NO_TASK != ac->delay_task)
375 GNUNET_SCHEDULER_cancel (ac->delay_task);
376 if (NULL != ac->put_data)
377 GNUNET_free (ac->put_data);
378 if (NULL != ac->dht_put)
379 GNUNET_DHT_put_cancel (ac->dht_put);
380 if (NULL != ac->dht_get)
381 GNUNET_DHT_get_stop (ac->dht_get);
386 if(NULL != bandwidth_stats_op)
387 GNUNET_TESTBED_operation_done (bandwidth_stats_op);
388 bandwidth_stats_op = NULL;
389 GNUNET_free_non_null (a_ac);
394 * Stats callback. Finish the stats testbed operation and when all stats have
395 * been iterated, shutdown the test.
398 * @param op the operation that has been finished
399 * @param emsg error message in case the operation has failed; will be NULL if
400 * operation has executed successfully.
403 bandwidth_stats_cont (void *cls,
404 struct GNUNET_TESTBED_Operation *op,
407 INFO ("# Outgoing bandwidth: %u\n", outgoing_bandwidth);
408 INFO ("# Incoming bandwidth: %u\n", incoming_bandwidth);
409 GNUNET_SCHEDULER_shutdown ();
414 * Process statistic values.
417 * @param peer the peer the statistic belong to
418 * @param subsystem name of subsystem that created the statistic
419 * @param name the name of the datum
420 * @param value the current value
421 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
422 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
425 bandwidth_stats_iterator (void *cls,
426 const struct GNUNET_TESTBED_Peer *peer,
427 const char *subsystem,
432 static const char *s_sent = "# Bytes transmitted to other peers";
433 static const char *s_recv = "# Bytes received from other peers";
435 if (0 == strncmp (s_sent, name, strlen (s_sent)))
436 outgoing_bandwidth = outgoing_bandwidth + value;
437 else if (0 == strncmp(s_recv, name, strlen (s_recv)))
438 incoming_bandwidth = incoming_bandwidth + value;
441 DEBUG ("Bandwith - Out: %lu; In: %lu\n",
442 (unsigned long) outgoing_bandwidth,
443 (unsigned long) incoming_bandwidth);
451 INFO ("# PUTS made: %u\n", n_puts);
452 INFO ("# PUTS succeeded: %u\n", n_puts_ok);
453 INFO ("# PUTS failed: %u\n", n_puts_fail);
454 INFO ("# GETS made: %u\n", n_gets);
455 INFO ("# GETS succeeded: %u\n", n_gets_ok);
456 INFO ("# GETS failed: %u\n", n_gets_fail);
457 INFO ("# average_put_path_length: %f\n", average_put_path_length);
458 INFO ("# average_get_path_length: %f\n", average_get_path_length);
460 if (NULL == testbed_handles)
462 INFO ("No peers found\n");
466 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles,
468 bandwidth_stats_iterator,
469 bandwidth_stats_cont, NULL);
474 * Task to cancel DHT GET.
477 * @param tc scheduler task context
480 cancel_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
482 struct ActiveContext *ac = cls;
483 struct Context *ctx = ac->ctx;
485 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
486 GNUNET_assert (NULL != ac->dht_get);
487 GNUNET_DHT_get_stop (ac->dht_get);
490 GNUNET_assert (NULL != ctx->op);
491 GNUNET_TESTBED_operation_done (ctx->op);
494 /* If profiling is complete, summarize */
495 if (n_active == n_gets_fail + n_gets_ok)
502 * Iterator called on each result obtained for a DHT
503 * operation that expects a reply
506 * @param exp when will this value expire
507 * @param key key of the result
508 * @param get_path peers on reply path (or NULL if not recorded)
509 * [0] = datastore's first neighbor, [length - 1] = local peer
510 * @param get_path_length number of entries in @a get_path
511 * @param put_path peers on the PUT path (or NULL if not recorded)
512 * [0] = origin, [length - 1] = datastore
513 * @param put_path_length number of entries in @a put_path
514 * @param type type of the result
515 * @param size number of bytes in @a data
516 * @param data pointer to the result data
520 struct GNUNET_TIME_Absolute exp,
521 const struct GNUNET_HashCode *key,
522 const struct GNUNET_PeerIdentity *get_path,
523 unsigned int get_path_length,
524 const struct GNUNET_PeerIdentity *put_path,
525 unsigned int put_path_length,
526 enum GNUNET_BLOCK_Type type,
527 size_t size, const void *data)
529 struct ActiveContext *ac = cls;
530 struct ActiveContext *get_ac = ac->get_ac;
531 struct Context *ctx = ac->ctx;
533 /* Check the keys of put and get match or not. */
534 GNUNET_assert (0 == memcmp (key, &get_ac->hash, sizeof (struct GNUNET_HashCode)));
535 /* we found the data we are looking for */
536 DEBUG ("We found a GET request; %u remaining\n", n_gets - (n_gets_fail + n_gets_ok));
539 GNUNET_DHT_get_stop (ac->dht_get);
541 GNUNET_SCHEDULER_cancel (ac->delay_task);
542 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
543 GNUNET_assert (NULL != ctx->op);
544 GNUNET_TESTBED_operation_done (ctx->op);
547 total_put_path_length = total_put_path_length + put_path_length;
548 total_get_path_length = total_get_path_length + get_path_length;
550 /* Summarize if profiling is complete */
551 if (n_active == n_gets_fail + n_gets_ok)
553 average_put_path_length = (double)total_put_path_length/(double)n_active;
554 average_get_path_length = (double)total_get_path_length/(double )n_active;
561 * Task to do DHT GETs
563 * @param cls the active context
564 * @param tc the scheduler task context
567 delayed_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
569 struct ActiveContext *ac = cls;
570 struct ActiveContext *get_ac;
573 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
577 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_active);
579 if (NULL != get_ac->put_data)
584 DEBUG ("Doing a DHT GET for data of size %u\n", get_ac->put_data_size);
585 ac->dht_get = GNUNET_DHT_get_start (ac->dht,
586 GNUNET_BLOCK_TYPE_TEST,
588 1, /* replication level */
590 NULL, 0, /* extended query and size */
591 get_iter, ac); /* GET iterator and closure
595 /* schedule the timeout task for GET */
596 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, &cancel_get, ac);
601 * Queue up a delayed task for doing DHT GET
603 * @param cls the active context
604 * @param success #GNUNET_OK if the PUT was transmitted,
605 * #GNUNET_NO on timeout,
606 * #GNUNET_SYSERR on disconnect from service
607 * after the PUT message was transmitted
608 * (so we don't know if it was received or not)
611 put_cont (void *cls, int success)
613 struct ActiveContext *ac = cls;
620 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_get, ac);
625 * Task to do DHT PUTS
627 * @param cls the active context
628 * @param tc the scheduler task context
631 delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
633 struct ActiveContext *ac = cls;
635 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
636 /* Generate and DHT PUT some random data */
637 ac->put_data_size = 16; /* minimum */
638 ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
640 ac->put_data = GNUNET_malloc (ac->put_data_size);
641 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
642 ac->put_data, ac->put_data_size);
643 GNUNET_CRYPTO_hash (ac->put_data, ac->put_data_size, &ac->hash);
644 DEBUG ("Doing a DHT PUT with data of size %u\n", ac->put_data_size);
645 ac->dht_put = GNUNET_DHT_put (ac->dht, &ac->hash,
648 GNUNET_BLOCK_TYPE_TEST,
651 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
652 timeout, /* PUT timeout */
653 put_cont, ac); /* continuation and its closure */
659 * Connection to DHT has been established. Call the delay task.
661 * @param cls the active context
662 * @param op the operation that has been finished
663 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
664 * @param emsg error message in case the operation has failed; will be NULL if
665 * operation has executed successfully.
668 dht_connected (void *cls,
669 struct GNUNET_TESTBED_Operation *op,
673 struct ActiveContext *ac = cls;
674 struct Context *ctx = ac->ctx;
676 GNUNET_assert (NULL != ctx);
677 GNUNET_assert (NULL != ctx->op);
678 GNUNET_assert (ctx->op == op);
679 ac->dht = (struct GNUNET_DHT_Handle *) ca_result;
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
683 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */
688 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac);
693 * Connect to DHT service and return the DHT client handler
695 * @param cls the active context
696 * @param cfg configuration of the peer to connect to; will be available until
697 * GNUNET_TESTBED_operation_done() is called on the operation returned
698 * from GNUNET_TESTBED_service_connect()
699 * @return service handle to return in 'op_result', NULL on error
702 dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
705 return GNUNET_DHT_connect (cfg, 10);
710 * Adapter function called to destroy a connection to
713 * @param cls the active context
714 * @param op_result service handle returned from the connect adapter
717 dht_disconnect (void *cls, void *op_result)
719 struct ActiveContext *ac = cls;
721 GNUNET_assert (NULL != ac->dht);
722 GNUNET_assert (ac->dht == op_result);
723 GNUNET_DHT_disconnect (ac->dht);
726 GNUNET_SCHEDULER_shutdown ();
731 * FIXME:Verify where is n_active used. Should this service be started only
732 * for n_active peers?
733 * Start testbed service for all the peers.
736 start_testbed_service_on_all_peers()
739 DEBUG("GNUNET_TESTBED_service_connect \n");
740 for(i = 0; i < n_active; i++)
742 struct ActiveContext *ac = &a_ac[i];
744 GNUNET_TESTBED_service_connect (ac->ctx,
754 static unsigned int tries;
757 * Stats callback. Iterate over the hashmap and check if all th peers form
758 * a virtual ring topology.
761 * @param op the operation that has been finished
762 * @param emsg error message in case the operation has failed; will be NULL if
763 * operation has executed successfully.
766 successor_stats_cont (void *cls,
767 struct GNUNET_TESTBED_Operation *op,
770 struct GNUNET_HashCode *val;
771 struct GNUNET_HashCode *start_val;
773 struct GNUNET_HashCode *key;
775 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
776 GNUNET_TESTBED_operation_done (successor_stats_op);
777 successor_stats_op = NULL;
778 start_val =(struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
781 val = GNUNET_new(struct GNUNET_HashCode);
783 while (count < num_peers)
785 key = GNUNET_new(struct GNUNET_HashCode);
787 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
789 GNUNET_assert(NULL != val);
793 if (start_val == val)
795 DEBUG("CIRCLE COMPLETED after %u tries", tries);
797 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
799 start_testbed_service_on_all_peers();
806 if (max_searches == ++tries)
808 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
809 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
810 " cirle formation. Exiting\n",
812 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
814 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
815 //FIXME: free hashmap
818 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
820 start_testbed_service_on_all_peers();
826 //FIXME: change delay use exponential back off.
827 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay, &collect_stats, cls);
833 * Process successor statistic values.
836 * @param peer the peer the statistic belong to
837 * @param subsystem name of subsystem that created the statistic
838 * @param name the name of the datum
839 * @param value the current value
840 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
841 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
844 successor_stats_iterator (void *cls,
845 const struct GNUNET_TESTBED_Peer *peer,
846 const char *subsystem,
851 static const char *key_string = "XDHT";
852 if (0 == strncmp (key_string, name, strlen (key_string)))
855 char successor_str[13];
856 char truncated_my_id_str[13];
857 char truncated_successor_str[13];
858 struct GNUNET_HashCode *my_id_key;
859 struct GNUNET_HashCode *succ_key;
861 strtok((char *)name,":");
862 my_id_str = strtok(NULL,":");
864 strncpy(truncated_my_id_str, my_id_str, 12);
865 truncated_my_id_str[12] = '\0';
866 my_id_key = GNUNET_new(struct GNUNET_HashCode);
867 GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key);
868 GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
869 strncpy(truncated_successor_str, successor_str, 12);
870 truncated_successor_str[12] ='\0';
872 succ_key = GNUNET_new(struct GNUNET_HashCode);
873 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
877 start_key = my_id_key;
880 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
881 my_id_key, (void *)succ_key,
882 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
889 * Task that collects peer and its corresponding successors.
891 * @param cls Closure (NULL).
892 * @param tc Task Context.
895 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
897 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
900 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
901 DEBUG("num_peers = %d", num_peers);
902 GNUNET_assert(NULL != testbed_handles);
905 /* Check for successor pointer, don't start put till the virtual ring topology
908 GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
910 successor_stats_iterator,
911 successor_stats_cont, cls);
913 GNUNET_assert(NULL != successor_stats_op);
917 * Callback called when DHT service on the peer is started
919 * @param cls the context
920 * @param op the operation that has been finished
921 * @param emsg error message in case the operation has failed; will be NULL if
922 * operation has executed successfully.
925 service_started (void *cls,
926 struct GNUNET_TESTBED_Operation *op,
929 struct Context *ctx = cls;
931 GNUNET_assert (NULL != ctx);
932 GNUNET_assert (NULL != ctx->op);
933 GNUNET_TESTBED_operation_done (ctx->op);
935 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
936 if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers)
938 DEBUG("successor_stats_task \n");
939 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context);
940 collect_stat_cls->service_connect_ctx = cls;
941 collect_stat_cls->op = op;
942 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
944 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay,
952 * Signature of a main function for a testcase.
955 * @param h the run handle
956 * @param num_peers number of peers in 'peers'
957 * @param peers handle to peers run in the testbed
958 * @param links_succeeded the number of overlay link connection attempts that
960 * @param links_failed the number of overlay link
964 struct GNUNET_TESTBED_RunHandle *h,
965 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
966 unsigned int links_succeeded,
967 unsigned int links_failed)
972 testbed_handles = peers;
978 INFO ("%u peers started\n", num_peers);
979 a_ctx = GNUNET_malloc (sizeof (struct Context) * num_peers);
981 /* select the peers which actively participate in profiling */
982 n_active = num_peers * PUT_PROBABILITY / 100;
985 GNUNET_SCHEDULER_shutdown ();
992 if(PUT_PROBABILITY + MALICIOUS_PEERS > 100)
994 DEBUG ("Reduce either number of malicious peer or active peers. ");
995 GNUNET_SCHEDULER_shutdown ();
1000 /* Select the peers which should act maliciously. */
1001 n_malicious = num_peers * MALICIOUS_PEERS / 100;
1003 /* Select n_malicious peers and ensure that those are not active peers.
1004 keep all malicious peer at one place, and call act malicious for all
1009 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
1011 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
1013 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1016 a_ctx[cnt].ac = &a_ac[ac_cnt];
1017 a_ac[ac_cnt].ctx = &a_ctx[cnt];
1021 a_ac = GNUNET_realloc (a_ac, n_active * sizeof (struct ActiveContext));
1022 INFO ("Active peers: %u\n", n_active);
1024 /* start DHT service on all peers */
1025 for (cnt = 0; cnt < num_peers; cnt++)
1027 a_ctx[cnt].peer = peers[cnt];
1028 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt],
1039 * Main function that will be run by the scheduler.
1041 * @param cls closure
1042 * @param args remaining command-line arguments
1043 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1044 * @param config configuration
1047 run (void *cls, char *const *args, const char *cfgfile,
1048 const struct GNUNET_CONFIGURATION_Handle *config)
1050 uint64_t event_mask;
1054 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
1058 cfg = GNUNET_CONFIGURATION_dup (config);
1060 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
1061 NULL, &test_run, NULL);
1062 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
1070 * @return 0 on success
1073 main (int argc, char *const *argv)
1077 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1078 {'n', "peers", "COUNT",
1079 gettext_noop ("number of peers to start"),
1080 1, &GNUNET_GETOPT_set_uint, &num_peers},
1081 {'s', "searches", "COUNT",
1082 gettext_noop ("maximum number of times we try to search for successor circle formation (default is 1)"),
1083 1, &GNUNET_GETOPT_set_uint, &max_searches},
1084 {'H', "hosts", "FILENAME",
1085 gettext_noop ("name of the file with the login information for the testbed"),
1086 1, &GNUNET_GETOPT_set_string, &hosts_file},
1087 {'d', "delay", "DELAY",
1088 gettext_noop ("delay for starting DHT PUT and GET"),
1089 1, &GNUNET_GETOPT_set_relative_time, &delay},
1090 {'r', "replication", "DEGREE",
1091 gettext_noop ("replication degree for DHT PUTs"),
1092 1, &GNUNET_GETOPT_set_uint, &replication},
1093 {'t', "timeout", "TIMEOUT",
1094 gettext_noop ("timeout for DHT PUT and GET requests"),
1095 1, &GNUNET_GETOPT_set_relative_time, &timeout},
1096 GNUNET_GETOPT_OPTION_END
1100 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1102 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /* default delay */
1103 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default timeout */
1104 replication = 1; /* default replication */
1107 GNUNET_PROGRAM_run (argc, argv, "dht-profiler",
1109 ("Measure quality and performance of the DHT service."),
1110 options, &run, NULL))