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;
89 * Context for a peer which actively does DHT PUT/GET
94 * The linked peer context
99 * Handler to the DHT service
101 struct GNUNET_DHT_Handle *dht;
104 * The data used for do a PUT. Will be NULL if a PUT hasn't been performed yet
109 * The active context used for our DHT GET
111 struct ActiveContext *get_ac;
116 struct GNUNET_DHT_PutHandle *dht_put;
121 struct GNUNET_DHT_GetHandle *dht_get;
124 * The hash of the @e put_data
126 struct GNUNET_HashCode hash;
131 GNUNET_SCHEDULER_TaskIdentifier delay_task;
134 * The size of the @e put_data
136 uint16_t put_data_size;
139 * The number of peers currently doing GET on our data
146 * An array of contexts. The size of this array should be equal to @a num_peers
148 static struct Context *a_ctx;
151 * Array of active peers
153 static struct ActiveContext *a_ac;
156 * The delay between starting to do PUTS and GETS
158 static struct GNUNET_TIME_Relative delay;
161 * The timeout for GET and PUT
163 static struct GNUNET_TIME_Relative timeout;
168 static unsigned int num_peers;
172 * Number or malicious peers.
174 static unsigned int n_malicious;
178 * Number of active peers
180 static unsigned int n_active;
183 * Number of DHT service connections we currently have
185 static unsigned int n_dht;
188 * Number of DHT PUTs made
190 static unsigned int n_puts;
193 * Number of DHT PUTs succeeded
195 static unsigned int n_puts_ok;
198 * Number of DHT PUTs failed
200 static unsigned int n_puts_fail;
203 * Number of DHT GETs made
205 static unsigned int n_gets;
208 * Number of DHT GETs succeeded
210 static unsigned int n_gets_ok;
213 * Number of DHT GETs succeeded
215 static unsigned int n_gets_fail;
220 static unsigned int replication;
223 * Number of times we try to find the successor circle formation
225 static unsigned int max_searches;
228 * Testbed Operation (to get stats).
230 static struct GNUNET_TESTBED_Operation *bandwidth_stats_op;
233 * To get successor stats.
235 static struct GNUNET_TESTBED_Operation *successor_stats_op;
238 * Testbed peer handles.
240 static struct GNUNET_TESTBED_Peer **testbed_handles;
243 * Total number of messages sent by peer.
245 static uint64_t outgoing_bandwidth;
248 * Total number of messages received by peer.
250 static uint64_t incoming_bandwidth;
253 * Average number of hops taken to do put.
255 static unsigned int average_put_path_length;
258 * Average number of hops taken to do get.
260 static unsigned int average_get_path_length;
263 * Total put path length across all peers.
265 static unsigned int total_put_path_length;
268 * Total get path length across all peers.
270 static unsigned int total_get_path_length;
273 * Hashmap to store pair of peer and its corresponding successor.
275 static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap;
278 * Key to start the lookup on successor_peer_hashmap.
280 static struct GNUNET_HashCode *start_key;
283 * Flag used to get the start_key.
288 * Task to collect peer and its current successor statistics.
290 static GNUNET_SCHEDULER_TaskIdentifier successor_stats_task;
293 * Closure for successor_stats_task.
295 struct Collect_Stat_Context
298 * Current Peer Context.
300 struct Context *service_connect_ctx;
303 * Testbed operation acting on this peer
305 struct GNUNET_TESTBED_Operation *op;
309 * List of all the peers contexts.
311 struct Context **peer_contexts = NULL;
314 * Counter to keep track of peers added to peer_context lists.
316 static int peers_started = 0;
319 * Task that collects successor statistics from all the peers.
324 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
328 * Shutdown task. Cleanup all resources and operations.
331 * @param tc scheduler task context
334 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
336 struct ActiveContext *ac;
341 for (cnt=0; cnt < num_peers; cnt++)
343 if (NULL != a_ctx[cnt].op)
344 GNUNET_TESTBED_operation_done (a_ctx[cnt].op);
346 /* Cleanup active context if this peer is an active peer */
350 if (GNUNET_SCHEDULER_NO_TASK != ac->delay_task)
351 GNUNET_SCHEDULER_cancel (ac->delay_task);
352 if (NULL != ac->put_data)
353 GNUNET_free (ac->put_data);
354 if (NULL != ac->dht_put)
355 GNUNET_DHT_put_cancel (ac->dht_put);
356 if (NULL != ac->dht_get)
357 GNUNET_DHT_get_stop (ac->dht_get);
362 if(NULL != bandwidth_stats_op)
363 GNUNET_TESTBED_operation_done (bandwidth_stats_op);
364 bandwidth_stats_op = NULL;
365 GNUNET_free_non_null (a_ac);
370 * Stats callback. Finish the stats testbed operation and when all stats have
371 * been iterated, shutdown the test.
374 * @param op the operation that has been finished
375 * @param emsg error message in case the operation has failed; will be NULL if
376 * operation has executed successfully.
379 bandwidth_stats_cont (void *cls,
380 struct GNUNET_TESTBED_Operation *op,
383 INFO ("# Outgoing bandwidth: %u\n", outgoing_bandwidth);
384 INFO ("# Incoming bandwidth: %u\n", incoming_bandwidth);
385 GNUNET_SCHEDULER_shutdown ();
390 * Process statistic values.
393 * @param peer the peer the statistic belong to
394 * @param subsystem name of subsystem that created the statistic
395 * @param name the name of the datum
396 * @param value the current value
397 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
398 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
401 bandwidth_stats_iterator (void *cls,
402 const struct GNUNET_TESTBED_Peer *peer,
403 const char *subsystem,
408 static const char *s_sent = "# Bytes transmitted to other peers";
409 static const char *s_recv = "# Bytes received from other peers";
411 if (0 == strncmp (s_sent, name, strlen (s_sent)))
412 outgoing_bandwidth = outgoing_bandwidth + value;
413 else if (0 == strncmp(s_recv, name, strlen (s_recv)))
414 incoming_bandwidth = incoming_bandwidth + value;
417 DEBUG ("Bandwith - Out: %lu; In: %lu\n",
418 (unsigned long) outgoing_bandwidth,
419 (unsigned long) incoming_bandwidth);
427 INFO ("# PUTS made: %u\n", n_puts);
428 INFO ("# PUTS succeeded: %u\n", n_puts_ok);
429 INFO ("# PUTS failed: %u\n", n_puts_fail);
430 INFO ("# GETS made: %u\n", n_gets);
431 INFO ("# GETS succeeded: %u\n", n_gets_ok);
432 INFO ("# GETS failed: %u\n", n_gets_fail);
433 INFO ("# average_put_path_length: %u\n", average_put_path_length);
434 INFO ("# average_get_path_length: %u\n", average_get_path_length);
436 if (NULL == testbed_handles)
438 INFO ("No peers found\n");
442 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles,
444 bandwidth_stats_iterator,
445 bandwidth_stats_cont, NULL);
450 * Task to cancel DHT GET.
453 * @param tc scheduler task context
456 cancel_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
458 struct ActiveContext *ac = cls;
460 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
461 GNUNET_assert (NULL != ac->dht_get);
462 GNUNET_DHT_get_stop (ac->dht_get);
466 /* If profiling is complete, summarize */
467 if (n_active == n_gets_fail + n_gets_ok)
474 * Iterator called on each result obtained for a DHT
475 * operation that expects a reply
478 * @param exp when will this value expire
479 * @param key key of the result
480 * @param get_path peers on reply path (or NULL if not recorded)
481 * [0] = datastore's first neighbor, [length - 1] = local peer
482 * @param get_path_length number of entries in @a get_path
483 * @param put_path peers on the PUT path (or NULL if not recorded)
484 * [0] = origin, [length - 1] = datastore
485 * @param put_path_length number of entries in @a put_path
486 * @param type type of the result
487 * @param size number of bytes in @a data
488 * @param data pointer to the result data
492 struct GNUNET_TIME_Absolute exp,
493 const struct GNUNET_HashCode *key,
494 const struct GNUNET_PeerIdentity *get_path,
495 unsigned int get_path_length,
496 const struct GNUNET_PeerIdentity *put_path,
497 unsigned int put_path_length,
498 enum GNUNET_BLOCK_Type type,
499 size_t size, const void *data)
501 struct ActiveContext *ac = cls;
502 struct ActiveContext *get_ac = ac->get_ac;
504 /* Check the keys of put and get match or not. */
505 GNUNET_assert (0 == memcmp (key, &get_ac->hash, sizeof (struct GNUNET_HashCode)));
506 /* we found the data we are looking for */
507 DEBUG ("We found a GET request; %u remaining\n", n_gets - (n_gets_fail + n_gets_ok));
510 GNUNET_DHT_get_stop (ac->dht_get);
512 GNUNET_SCHEDULER_cancel (ac->delay_task);
513 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
515 total_put_path_length = total_put_path_length + put_path_length;
516 total_get_path_length = total_get_path_length + get_path_length;
518 /* Summarize if profiling is complete */
519 if (n_active == n_gets_fail + n_gets_ok)
521 average_put_path_length = total_put_path_length/n_active;
522 average_get_path_length = total_get_path_length/n_active;
529 * Task to do DHT GETs
531 * @param cls the active context
532 * @param tc the scheduler task context
535 delayed_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
537 struct ActiveContext *ac = cls;
538 struct ActiveContext *get_ac;
541 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
545 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_active);
547 if (NULL != get_ac->put_data)
552 DEBUG ("Doing a DHT GET for data of size %u\n", get_ac->put_data_size);
553 ac->dht_get = GNUNET_DHT_get_start (ac->dht,
554 GNUNET_BLOCK_TYPE_TEST,
556 1, /* replication level */
558 NULL, 0, /* extended query and size */
559 get_iter, ac); /* GET iterator and closure
563 /* schedule the timeout task for GET */
564 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, &cancel_get, ac);
569 * Queue up a delayed task for doing DHT GET
571 * @param cls the active context
572 * @param success #GNUNET_OK if the PUT was transmitted,
573 * #GNUNET_NO on timeout,
574 * #GNUNET_SYSERR on disconnect from service
575 * after the PUT message was transmitted
576 * (so we don't know if it was received or not)
579 put_cont (void *cls, int success)
581 struct ActiveContext *ac = cls;
588 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_get, ac);
593 * Task to do DHT PUTS
595 * @param cls the active context
596 * @param tc the scheduler task context
599 delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
601 struct ActiveContext *ac = cls;
603 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
604 /* Generate and DHT PUT some random data */
605 ac->put_data_size = 16; /* minimum */
606 ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
608 ac->put_data = GNUNET_malloc (ac->put_data_size);
609 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
610 ac->put_data, ac->put_data_size);
611 GNUNET_CRYPTO_hash (ac->put_data, ac->put_data_size, &ac->hash);
612 DEBUG ("Doing a DHT PUT with data of size %u\n", ac->put_data_size);
613 ac->dht_put = GNUNET_DHT_put (ac->dht, &ac->hash,
616 GNUNET_BLOCK_TYPE_TEST,
619 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
620 timeout, /* PUT timeout */
621 put_cont, ac); /* continuation and its closure */
627 * Connection to DHT has been established. Call the delay task.
629 * @param cls the active context
630 * @param op the operation that has been finished
631 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
632 * @param emsg error message in case the operation has failed; will be NULL if
633 * operation has executed successfully.
636 dht_connected (void *cls,
637 struct GNUNET_TESTBED_Operation *op,
641 struct ActiveContext *ac = cls;
642 struct Context *ctx = ac->ctx;
644 GNUNET_assert (NULL != ctx);
645 GNUNET_assert (NULL != ctx->op);
646 GNUNET_assert (ctx->op == op);
647 ac->dht = (struct GNUNET_DHT_Handle *) ca_result;
650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
651 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */
656 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac);
661 * Connect to DHT service and return the DHT client handler
663 * @param cls the active context
664 * @param cfg configuration of the peer to connect to; will be available until
665 * GNUNET_TESTBED_operation_done() is called on the operation returned
666 * from GNUNET_TESTBED_service_connect()
667 * @return service handle to return in 'op_result', NULL on error
670 dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
673 return GNUNET_DHT_connect (cfg, 10);
678 * Adapter function called to destroy a connection to
681 * @param cls the active context
682 * @param op_result service handle returned from the connect adapter
685 dht_disconnect (void *cls, void *op_result)
687 struct ActiveContext *ac = cls;
689 GNUNET_assert (NULL != ac->dht);
690 GNUNET_assert (ac->dht == op_result);
691 GNUNET_DHT_disconnect (ac->dht);
694 GNUNET_SCHEDULER_shutdown ();
699 * FIXME:Verify where is n_active used. Should this service be started only
700 * for n_active peers?
701 * Start testbed service for all the peers.
704 start_testbed_service_on_all_peers()
707 for(i = 0; i < peers_started; i++)
709 struct Context *ctx = peer_contexts[i];
710 DEBUG("GNUNET_TESTBED_service_connect \n");
712 GNUNET_TESTBED_service_connect (ctx,
715 &dht_connected, ctx->ac,
723 static unsigned int tries;
726 * Stats callback. Iterate over the hashmap and check if all th peers form
727 * a virtual ring topology.
730 * @param op the operation that has been finished
731 * @param emsg error message in case the operation has failed; will be NULL if
732 * operation has executed successfully.
735 successor_stats_cont (void *cls,
736 struct GNUNET_TESTBED_Operation *op,
739 struct GNUNET_HashCode *val;
740 struct GNUNET_HashCode *start_val;
742 struct GNUNET_HashCode *key;
744 start_val =(struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
747 val = GNUNET_new(struct GNUNET_HashCode);
749 while (count < num_peers)
751 key = GNUNET_new(struct GNUNET_HashCode);
753 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
755 GNUNET_assert(NULL != val);
759 if (start_val == val)
761 DEBUG("CIRCLE COMPLETED after %u tries", tries);
762 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
764 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
765 //FIXME: free hashmap.
767 successor_stats_op = NULL;
769 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
771 start_testbed_service_on_all_peers();
778 if (max_searches == ++tries)
780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
781 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
782 " cirle formation. Exiting\n",
784 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
786 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
787 //FIXME: free hashmap
789 successor_stats_op = NULL;
791 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
793 start_testbed_service_on_all_peers();
799 //FIXME: change delay use exponential back off.
800 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay, &collect_stats, cls);
806 * Process successor statistic values.
809 * @param peer the peer the statistic belong to
810 * @param subsystem name of subsystem that created the statistic
811 * @param name the name of the datum
812 * @param value the current value
813 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
814 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
817 successor_stats_iterator (void *cls,
818 const struct GNUNET_TESTBED_Peer *peer,
819 const char *subsystem,
824 static const char *key_string = "XDHT";
825 if (0 == strncmp (key_string, name, strlen (key_string)))
828 char successor_str[13];
829 char truncated_my_id_str[13];
830 char truncated_successor_str[13];
831 struct GNUNET_HashCode *my_id_key;
832 struct GNUNET_HashCode *succ_key;
834 strtok((char *)name,":");
835 my_id_str = strtok(NULL,":");
837 strncpy(truncated_my_id_str, my_id_str, 12);
838 truncated_my_id_str[12] = '\0';
839 my_id_key = GNUNET_new(struct GNUNET_HashCode);
840 GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key);
841 GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
842 strncpy(truncated_successor_str, successor_str, 12);
843 truncated_successor_str[12] ='\0';
845 succ_key = GNUNET_new(struct GNUNET_HashCode);
846 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
850 start_key = my_id_key;
853 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
854 my_id_key, (void *)succ_key,
855 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
862 * Task that collects peer and its corresponding successors.
864 * @param cls Closure (NULL).
865 * @param tc Task Context.
868 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
870 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
873 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
874 DEBUG("num_peers = %d", num_peers);
875 GNUNET_assert(NULL != testbed_handles);
878 /* Check for successor pointer, don't start put till the virtual ring topology
881 GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
883 successor_stats_iterator,
884 successor_stats_cont, cls);
886 GNUNET_assert(successor_stats_op);
890 * Callback called when DHT service on the peer is started
892 * @param cls the context
893 * @param op the operation that has been finished
894 * @param emsg error message in case the operation has failed; will be NULL if
895 * operation has executed successfully.
898 service_started (void *cls,
899 struct GNUNET_TESTBED_Operation *op,
902 struct Context *ctx = cls;
904 GNUNET_assert (NULL != ctx);
905 GNUNET_assert (NULL != ctx->op);
906 GNUNET_TESTBED_operation_done (ctx->op);
911 if (NULL == peer_contexts)
913 peer_contexts = GNUNET_malloc(num_peers * sizeof(struct Context *));
916 peer_contexts[peers_started] = ctx;
918 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
920 if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers)
922 DEBUG("successor_stats_task \n");
923 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context);
924 collect_stat_cls->service_connect_ctx = cls;
925 collect_stat_cls->op = op;
927 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
929 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay,
937 * Signature of a main function for a testcase.
940 * @param h the run handle
941 * @param num_peers number of peers in 'peers'
942 * @param peers handle to peers run in the testbed
943 * @param links_succeeded the number of overlay link connection attempts that
945 * @param links_failed the number of overlay link
949 struct GNUNET_TESTBED_RunHandle *h,
950 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
951 unsigned int links_succeeded,
952 unsigned int links_failed)
957 testbed_handles = peers;
963 INFO ("%u peers started\n", num_peers);
964 a_ctx = GNUNET_malloc (sizeof (struct Context) * num_peers);
966 /* select the peers which actively participate in profiling */
967 n_active = num_peers * PUT_PROBABILITY / 100;
970 GNUNET_SCHEDULER_shutdown ();
977 if(PUT_PROBABILITY + MALICIOUS_PEERS > 100)
979 DEBUG ("Reduce either number of malicious peer or active peers. ");
980 GNUNET_SCHEDULER_shutdown ();
985 /* Select the peers which should act maliciously. */
986 n_malicious = num_peers * MALICIOUS_PEERS / 100;
988 /* Select n_malicious peers and ensure that those are not active peers.
989 keep all malicious peer at one place, and call act malicious for all
994 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
996 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
998 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1001 a_ctx[cnt].ac = &a_ac[ac_cnt];
1002 a_ac[ac_cnt].ctx = &a_ctx[cnt];
1006 a_ac = GNUNET_realloc (a_ac, n_active * sizeof (struct ActiveContext));
1007 INFO ("Active peers: %u\n", n_active);
1009 /* start DHT service on all peers */
1010 for (cnt = 0; cnt < num_peers; cnt++)
1012 a_ctx[cnt].peer = peers[cnt];
1013 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt],
1024 * Main function that will be run by the scheduler.
1026 * @param cls closure
1027 * @param args remaining command-line arguments
1028 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1029 * @param config configuration
1032 run (void *cls, char *const *args, const char *cfgfile,
1033 const struct GNUNET_CONFIGURATION_Handle *config)
1035 uint64_t event_mask;
1039 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
1043 cfg = GNUNET_CONFIGURATION_dup (config);
1045 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
1046 NULL, &test_run, NULL);
1047 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
1055 * @return 0 on success
1058 main (int argc, char *const *argv)
1062 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1063 {'n', "peers", "COUNT",
1064 gettext_noop ("number of peers to start"),
1065 1, &GNUNET_GETOPT_set_uint, &num_peers},
1066 {'s', "searches", "COUNT",
1067 gettext_noop ("maximum number of times we try to search for successor circle formation (default is 1)"),
1068 1, &GNUNET_GETOPT_set_uint, &max_searches},
1069 {'H', "hosts", "FILENAME",
1070 gettext_noop ("name of the file with the login information for the testbed"),
1071 1, &GNUNET_GETOPT_set_string, &hosts_file},
1072 {'d', "delay", "DELAY",
1073 gettext_noop ("delay for starting DHT PUT and GET"),
1074 1, &GNUNET_GETOPT_set_relative_time, &delay},
1075 {'r', "replication", "DEGREE",
1076 gettext_noop ("replication degree for DHT PUTs"),
1077 1, &GNUNET_GETOPT_set_uint, &replication},
1078 {'t', "timeout", "TIMEOUT",
1079 gettext_noop ("timeout for DHT PUT and GET requests"),
1080 1, &GNUNET_GETOPT_set_relative_time, &timeout},
1081 GNUNET_GETOPT_OPTION_END
1085 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1087 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /* default delay */
1088 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default timeout */
1089 replication = 1; /* default replication */
1092 GNUNET_PROGRAM_run (argc, argv, "dht-profiler",
1094 ("Measure quality and performance of the DHT service."),
1095 options, &run, NULL))