2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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 50
46 static struct GNUNET_CONFIGURATION_Handle *cfg;
49 * Name of the file with the hosts to run the test over
51 static char *hosts_file;
54 * Context for a peer which actively does DHT PUT/GET
59 * Context to hold data of peer
64 * The testbed peer this context belongs to
66 struct GNUNET_TESTBED_Peer *peer;
69 * Testbed operation acting on this peer
71 struct GNUNET_TESTBED_Operation *op;
74 * Active context; NULL if this peer is not an active peer
76 struct ActiveContext *ac;
82 * Context for a peer which actively does DHT PUT/GET
87 * The linked peer context
92 * Handler to the DHT service
94 struct GNUNET_DHT_Handle *dht;
97 * The data used for do a PUT. Will be NULL if a PUT hasn't been performed yet
102 * The active context used for our DHT GET
104 struct ActiveContext *get_ac;
109 struct GNUNET_DHT_PutHandle *dht_put;
114 struct GNUNET_DHT_GetHandle *dht_get;
117 * The hash of the @e put_data
119 struct GNUNET_HashCode hash;
124 struct GNUNET_SCHEDULER_Task * delay_task;
127 * The size of the @e put_data
129 uint16_t put_data_size;
132 * The number of peers currently doing GET on our data
139 * An array of contexts. The size of this array should be equal to @a num_peers
141 static struct Context *a_ctx;
144 * Array of active peers
146 static struct ActiveContext *a_ac;
149 * The delay between rounds for collecting statistics
151 static struct GNUNET_TIME_Relative delay_stats;
154 * The delay to start puts.
156 static struct GNUNET_TIME_Relative delay_put;
159 * The delay to start puts.
161 static struct GNUNET_TIME_Relative delay_get;
164 * The timeout for GET and PUT
166 static struct GNUNET_TIME_Relative timeout;
171 static unsigned int num_peers;
174 * Number of active peers
176 static unsigned int n_active;
179 * Number of DHT service connections we currently have
181 static unsigned int n_dht;
184 * Number of DHT PUTs made
186 static unsigned int n_puts;
189 * Number of DHT PUTs succeeded
191 static unsigned int n_puts_ok;
194 * Number of DHT PUTs failed
196 static unsigned int n_puts_fail;
199 * Number of DHT GETs made
201 static unsigned int n_gets;
204 * Number of DHT GETs succeeded
206 static unsigned int n_gets_ok;
209 * Number of DHT GETs succeeded
211 static unsigned int n_gets_fail;
216 static unsigned int replication;
219 * Number of times we try to find the successor circle formation
221 static unsigned int max_searches;
224 * Testbed Operation (to get stats).
226 static struct GNUNET_TESTBED_Operation *bandwidth_stats_op;
229 * To get successor stats.
231 static struct GNUNET_TESTBED_Operation *successor_stats_op;
234 * Testbed peer handles.
236 static struct GNUNET_TESTBED_Peer **testbed_handles;
239 * Total number of messages sent by peer.
241 static uint64_t outgoing_bandwidth;
244 * Total number of messages received by peer.
246 static uint64_t incoming_bandwidth;
249 * Average number of hops taken to do put.
251 static double average_put_path_length;
254 * Average number of hops taken to do get.
256 static double average_get_path_length;
259 * Total put path length across all peers.
261 static unsigned int total_put_path_length;
264 * Total get path length across all peers.
266 static unsigned int total_get_path_length;
269 * Hashmap to store pair of peer and its corresponding successor.
271 static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap;
274 * Key to start the lookup on successor_peer_hashmap.
276 static struct GNUNET_HashCode *start_key;
279 * Flag used to get the start_key.
284 * Task to collect peer and its current successor statistics.
286 static struct GNUNET_SCHEDULER_Task * successor_stats_task;
289 * Closure for successor_stats_task.
291 struct Collect_Stat_Context
294 * Current Peer Context.
296 struct Context *service_connect_ctx;
299 * Testbed operation acting on this peer
301 struct GNUNET_TESTBED_Operation *op;
305 * List of all the peers contexts.
307 struct Context **peer_contexts = NULL;
310 * Counter to keep track of peers added to peer_context lists.
312 static int peers_started = 0;
315 * Should we do a PUT (mode = 0) or GET (mode = 1);
326 * Are we shutting down
328 static int in_shutdown = 0;
331 * Total number of times to check if circle is formed or not.
333 static unsigned int tries;
337 * Task that collects successor statistics from all the peers.
342 collect_stats (void *cls);
346 * Connect to DHT services of active peers
349 start_profiling (void);
353 * Shutdown task. Cleanup all resources and operations.
358 do_shutdown (void *cls)
360 struct ActiveContext *ac;
363 in_shutdown = GNUNET_YES;
366 for (cnt=0; cnt < num_peers; cnt++)
368 /* Cleanup active context if this peer is an active peer */
372 if (NULL != ac->delay_task)
373 GNUNET_SCHEDULER_cancel (ac->delay_task);
374 if (NULL != ac->put_data)
375 GNUNET_free (ac->put_data);
376 if (NULL != ac->dht_put)
377 GNUNET_DHT_put_cancel (ac->dht_put);
378 if (NULL != ac->dht_get)
379 GNUNET_DHT_get_stop (ac->dht_get);
381 /* Cleanup testbed operation handle at the last as this operation may
382 contain service connection to DHT */
383 if (NULL != a_ctx[cnt].op)
384 GNUNET_TESTBED_operation_done (a_ctx[cnt].op);
389 //FIXME: Should we collect stats only for put/get not for other messages.
390 if (NULL != bandwidth_stats_op)
392 GNUNET_TESTBED_operation_done (bandwidth_stats_op);
393 bandwidth_stats_op = NULL;
395 if (NULL != successor_stats_op)
397 GNUNET_TESTBED_operation_done (successor_stats_op);
398 successor_stats_op = NULL;
400 if (NULL != successor_stats_task)
402 GNUNET_SCHEDULER_cancel (successor_stats_task);
403 successor_stats_task = NULL;
405 GNUNET_free_non_null (a_ac);
410 * Stats callback. Finish the stats testbed operation and when all stats have
411 * been iterated, shutdown the test.
414 * @param op the operation that has been finished
415 * @param emsg error message in case the operation has failed; will be NULL if
416 * operation has executed successfully.
419 bandwidth_stats_cont (void *cls,
420 struct GNUNET_TESTBED_Operation *op,
423 INFO ("# Outgoing bandwidth: %llu\n",
424 (unsigned long long) outgoing_bandwidth);
425 INFO ("# Incoming bandwidth: %llu\n",
426 (unsigned long long) incoming_bandwidth);
427 GNUNET_SCHEDULER_shutdown ();
432 * Process statistic values.
435 * @param peer the peer the statistic belong to
436 * @param subsystem name of subsystem that created the statistic
437 * @param name the name of the datum
438 * @param value the current value
439 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
440 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
443 bandwidth_stats_iterator (void *cls,
444 const struct GNUNET_TESTBED_Peer *peer,
445 const char *subsystem,
450 static const char *s_sent = "# Bytes transmitted to other peers";
451 static const char *s_recv = "# Bytes received from other peers";
453 if (0 == strncmp (s_sent, name, strlen (s_sent)))
454 outgoing_bandwidth = outgoing_bandwidth + value;
455 else if (0 == strncmp(s_recv, name, strlen (s_recv)))
456 incoming_bandwidth = incoming_bandwidth + value;
465 INFO ("# PUTS made: %u\n", n_puts);
466 INFO ("# PUTS succeeded: %u\n", n_puts_ok);
467 INFO ("# PUTS failed: %u\n", n_puts_fail);
468 INFO ("# GETS made: %u\n", n_gets);
469 INFO ("# GETS succeeded: %u\n", n_gets_ok);
470 INFO ("# GETS failed: %u\n", n_gets_fail);
471 INFO ("# average_put_path_length: %f\n", average_put_path_length);
472 INFO ("# average_get_path_length: %f\n", average_get_path_length);
474 if (NULL == testbed_handles)
476 INFO ("No peers found\n");
480 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles,
482 bandwidth_stats_iterator,
483 bandwidth_stats_cont, NULL);
488 * Task to cancel DHT GET.
493 cancel_get (void *cls)
495 struct ActiveContext *ac = cls;
496 struct Context *ctx = ac->ctx;
498 ac->delay_task = NULL;
499 GNUNET_assert (NULL != ac->dht_get);
500 GNUNET_DHT_get_stop (ac->dht_get);
503 GNUNET_assert (NULL != ctx->op);
504 GNUNET_TESTBED_operation_done (ctx->op);
507 /* If profiling is complete, summarize */
508 if (n_active == n_gets_fail + n_gets_ok)
510 average_put_path_length = (double)total_put_path_length/(double)n_active;
511 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok;
518 * Iterator called on each result obtained for a DHT
519 * operation that expects a reply
522 * @param exp when will this value expire
523 * @param key key of the result
524 * @param get_path peers on reply path (or NULL if not recorded)
525 * [0] = datastore's first neighbor, [length - 1] = local peer
526 * @param get_path_length number of entries in @a get_path
527 * @param put_path peers on the PUT path (or NULL if not recorded)
528 * [0] = origin, [length - 1] = datastore
529 * @param put_path_length number of entries in @a put_path
530 * @param type type of the result
531 * @param size number of bytes in @a data
532 * @param data pointer to the result data
536 struct GNUNET_TIME_Absolute exp,
537 const struct GNUNET_HashCode *key,
538 const struct GNUNET_PeerIdentity *get_path,
539 unsigned int get_path_length,
540 const struct GNUNET_PeerIdentity *put_path,
541 unsigned int put_path_length,
542 enum GNUNET_BLOCK_Type type,
543 size_t size, const void *data)
545 struct ActiveContext *ac = cls;
546 struct ActiveContext *get_ac = ac->get_ac;
547 struct Context *ctx = ac->ctx;
549 /* Check the keys of put and get match or not. */
550 GNUNET_assert (0 == memcmp (key, &get_ac->hash, sizeof (struct GNUNET_HashCode)));
551 /* we found the data we are looking for */
552 DEBUG ("We found a GET request; %u remaining\n", n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1.
555 GNUNET_DHT_get_stop (ac->dht_get);
557 if (ac->delay_task != NULL)
558 GNUNET_SCHEDULER_cancel (ac->delay_task);
559 ac->delay_task = NULL;
560 GNUNET_assert (NULL != ctx->op);
561 GNUNET_TESTBED_operation_done (ctx->op);
564 total_put_path_length = total_put_path_length + (double)put_path_length;
565 total_get_path_length = total_get_path_length + (double)get_path_length;
566 DEBUG ("total_put_path_length = %u,put_path \n",
567 total_put_path_length);
568 /* Summarize if profiling is complete */
569 if (n_active == n_gets_fail + n_gets_ok)
571 average_put_path_length = (double)total_put_path_length/(double)n_active;
572 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok;
579 * Task to do DHT GETs
581 * @param cls the active context
584 delayed_get (void *cls)
586 struct ActiveContext *ac = cls;
587 struct ActiveContext *get_ac;
590 ac->delay_task = NULL;
594 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_active);
596 if (NULL != get_ac->put_data)
601 DEBUG ("GET_REQUEST_START key %s \n", GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data));
602 ac->dht_get = GNUNET_DHT_get_start (ac->dht,
603 GNUNET_BLOCK_TYPE_TEST,
605 1, /* replication level */
607 NULL, 0, /* extended query and size */
608 get_iter, ac); /* GET iterator and closure
612 /* schedule the timeout task for GET */
613 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, &cancel_get, ac);
618 * Task to teardown the dht connection. We do it as a task because calling
619 * GNUNET_DHT_disconnect() from put_continutation_callback seems illegal (the
620 * put_continuation_callback() is getting called again synchronously). Also,
621 * only free the operation when we are not shutting down; the shutdown task will
622 * clear the operation during shutdown.
624 * @param cls the context
627 teardown_dht_connection (void *cls)
629 struct Context *ctx = cls;
630 struct GNUNET_TESTBED_Operation *op;
632 GNUNET_assert (NULL != ctx);
633 GNUNET_assert (NULL != (op = ctx->op));
635 GNUNET_TESTBED_operation_done (op);
640 * Queue up a delayed task for doing DHT GET
642 * @param cls the active context
643 * @param success #GNUNET_OK if the PUT was transmitted,
644 * #GNUNET_NO on timeout,
645 * #GNUNET_SYSERR on disconnect from service
646 * after the PUT message was transmitted
647 * (so we don't know if it was received or not)
650 put_cont (void *cls, int success)
652 struct ActiveContext *ac = cls;
653 struct Context *ctx = ac->ctx;
660 GNUNET_assert (NULL != ctx);
661 (void) GNUNET_SCHEDULER_add_now (&teardown_dht_connection, ctx);
666 * Task to do DHT PUTs
668 * @param cls the active context
671 delayed_put (void *cls)
673 struct ActiveContext *ac = cls;
675 ac->delay_task = NULL;
676 /* Generate and DHT PUT some random data */
677 ac->put_data_size = 16; /* minimum */
678 ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
680 ac->put_data = GNUNET_malloc (ac->put_data_size);
681 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
682 ac->put_data, ac->put_data_size);
683 GNUNET_CRYPTO_hash (ac->put_data, ac->put_data_size, &ac->hash);
684 DEBUG ("PUT_REQUEST_START key %s\n",
685 GNUNET_h2s((struct GNUNET_HashCode *)ac->put_data));
686 ac->dht_put = GNUNET_DHT_put (ac->dht,
689 GNUNET_DHT_RO_RECORD_ROUTE,
690 GNUNET_BLOCK_TYPE_TEST,
693 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
694 &put_cont, ac); /* continuation and its closure */
700 * Connection to DHT has been established. Call the delay task.
702 * @param cls the active context
703 * @param op the operation that has been finished
704 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
705 * @param emsg error message in case the operation has failed; will be NULL if
706 * operation has executed successfully.
709 dht_connected (void *cls,
710 struct GNUNET_TESTBED_Operation *op,
714 struct ActiveContext *ac = cls;
715 struct Context *ctx = ac->ctx;
717 GNUNET_assert (NULL != ctx); //FIXME: Fails
718 GNUNET_assert (NULL != ctx->op);
719 GNUNET_assert (ctx->op == op);
720 ac->dht = (struct GNUNET_DHT_Handle *) ca_result;
723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
724 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */
732 struct GNUNET_TIME_Relative peer_delay_put;
733 peer_delay_put.rel_value_us =
734 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
735 delay_put.rel_value_us);
736 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, &delayed_put, ac);
741 struct GNUNET_TIME_Relative peer_delay_get;
742 peer_delay_get.rel_value_us =
743 delay_get.rel_value_us +
744 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
745 delay_get.rel_value_us);
746 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get, &delayed_get, ac);
754 * Connect to DHT service and return the DHT client handler
756 * @param cls the active context
757 * @param cfg configuration of the peer to connect to; will be available until
758 * GNUNET_TESTBED_operation_done() is called on the operation returned
759 * from GNUNET_TESTBED_service_connect()
760 * @return service handle to return in 'op_result', NULL on error
763 dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
766 return GNUNET_DHT_connect (cfg, 10);
771 * Adapter function called to destroy a connection to
774 * @param cls the active context
775 * @param op_result service handle returned from the connect adapter
778 dht_disconnect (void *cls, void *op_result)
780 struct ActiveContext *ac = cls;
782 GNUNET_assert (NULL != ac->dht);
783 GNUNET_assert (ac->dht == op_result);
784 GNUNET_DHT_disconnect (ac->dht);
789 if (GNUNET_YES == in_shutdown)
794 if ((n_puts_ok + n_puts_fail) != n_active)
796 /* Start GETs if all PUTs have been made */
798 //(void) GNUNET_SCHEDULER_add_now (&call_start_profiling, NULL);
802 if ((n_gets_ok + n_gets_fail) != n_active)
809 * Connect to DHT services of active peers
817 DEBUG("GNUNET_TESTBED_service_connect \n");
818 GNUNET_break (GNUNET_YES != in_shutdown);
819 for(i = 0; i < n_active; i++)
821 struct ActiveContext *ac = &a_ac[i];
822 GNUNET_assert (NULL != (ctx = ac->ctx));
823 GNUNET_assert (NULL == ctx->op);
825 GNUNET_TESTBED_service_connect (ctx,
836 * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first
837 * set the malicious peers. If not, then start with PUT operation on active
848 * Remove entry from successor peer hashmap.
850 * @param key current public key
851 * @param value value in the hash map
852 * @return #GNUNET_YES if we should continue to iterate,
856 hashmap_iterate_remove(void *cls,
857 const struct GNUNET_HashCode *key,
860 GNUNET_assert (GNUNET_YES ==
861 GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value));
867 * Stats callback. Iterate over the hashmap and check if all th peers form
868 * a virtual ring topology.
871 * @param op the operation that has been finished
872 * @param emsg error message in case the operation has failed; will be NULL if
873 * operation has executed successfully.
876 successor_stats_cont (void *cls,
877 struct GNUNET_TESTBED_Operation *op,
880 struct GNUNET_HashCode *val;
881 struct GNUNET_HashCode *start_val;
882 struct GNUNET_HashCode *key;
885 /* Don't schedule the task till we are looking for circle here. */
886 successor_stats_task = NULL;
887 GNUNET_TESTBED_operation_done (successor_stats_op);
888 successor_stats_op = NULL;
889 if (0 == max_searches)
895 GNUNET_assert (NULL != start_key);
896 start_val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
898 GNUNET_assert (NULL != start_val);
900 for (count = 0; count < num_peers; count++)
903 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
907 /* Remove the entry from hashmap. This is done to take care of loop. */
909 GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap,
912 DEBUG ("Failed to remove entry from hashmap\n");
915 /* If a peer has its own identity as its successor. */
916 if (0 == memcmp(key, val, sizeof (struct GNUNET_HashCode)))
920 GNUNET_assert (GNUNET_SYSERR !=
921 GNUNET_CONTAINER_multihashmap_iterate (successor_peer_hashmap,
922 &hashmap_iterate_remove,
925 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
927 if ((start_val == val) && (count == num_peers))
929 DEBUG ("CIRCLE COMPLETED after %u tries", tries);
930 if(NULL == successor_stats_task)
936 if (max_searches == ++tries)
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
940 " circle formation. Exiting\n",
947 = GNUNET_SCHEDULER_add_delayed (delay_stats,
954 * Process successor statistic values.
957 * @param peer the peer the statistic belong to
958 * @param subsystem name of subsystem that created the statistic
959 * @param name the name of the datum
960 * @param value the current value
961 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
962 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
965 successor_stats_iterator (void *cls,
966 const struct GNUNET_TESTBED_Peer *peer,
967 const char *subsystem,
972 static const char *key_string = "XDHT";
973 if (0 == max_searches)
976 if (0 == strncmp (key_string, name, strlen (key_string)))
979 char successor_str[13];
980 char truncated_my_id_str[13];
981 char truncated_successor_str[13];
982 struct GNUNET_HashCode *my_id_key;
983 struct GNUNET_HashCode *succ_key;
985 strtok((char *)name,":");
986 my_id_str = strtok(NULL,":");
988 strncpy(truncated_my_id_str, my_id_str, 12);
989 truncated_my_id_str[12] = '\0';
990 my_id_key = GNUNET_new(struct GNUNET_HashCode);
991 GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key);
992 GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
993 strncpy(truncated_successor_str, successor_str, 12);
994 truncated_successor_str[12] ='\0';
996 succ_key = GNUNET_new(struct GNUNET_HashCode);
997 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
1001 GNUNET_assert(NULL != my_id_key);
1002 start_key = my_id_key;
1003 GNUNET_assert(NULL != start_key);
1006 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
1007 my_id_key, (void *)succ_key,
1008 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1016 * Task that collects peer and its corresponding successors.
1018 * @param cls Closure (NULL).
1021 collect_stats (void *cls)
1023 successor_stats_task = NULL;
1024 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1025 "Start collecting statistics...\n");
1026 GNUNET_assert(NULL != testbed_handles);
1028 if (0 != max_searches)
1029 successor_peer_hashmap
1030 = GNUNET_CONTAINER_multihashmap_create (num_peers,
1033 = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
1035 successor_stats_iterator,
1036 successor_stats_cont, cls);
1037 GNUNET_assert (NULL != successor_stats_op);
1042 * Callback called when DHT service on the peer is started
1044 * @param cls the context
1045 * @param op the operation that has been finished
1046 * @param emsg error message in case the operation has failed; will be NULL if
1047 * operation has executed successfully.
1050 service_started (void *cls,
1051 struct GNUNET_TESTBED_Operation *op,
1054 struct Context *ctx = cls;
1056 GNUNET_assert (NULL != ctx);
1057 GNUNET_assert (NULL != ctx->op);
1058 GNUNET_TESTBED_operation_done (ctx->op);
1061 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
1062 if (NULL == successor_stats_task && peers_started == num_peers)
1064 DEBUG("successor_stats_task \n");
1065 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context);
1066 collect_stat_cls->service_connect_ctx = cls;
1067 collect_stat_cls->op = op;
1069 successor_stats_task
1070 = GNUNET_SCHEDULER_add_delayed (delay_stats,
1078 * Signature of a main function for a testcase.
1080 * @param cls closure
1081 * @param h the run handle
1082 * @param num_peers number of peers in 'peers'
1083 * @param peers handle to peers run in the testbed
1084 * @param links_succeeded the number of overlay link connection attempts that
1086 * @param links_failed the number of overlay link
1089 test_run (void *cls,
1090 struct GNUNET_TESTBED_RunHandle *h,
1091 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
1092 unsigned int links_succeeded,
1093 unsigned int links_failed)
1096 unsigned int ac_cnt;
1097 testbed_handles = peers;
1103 INFO ("%u peers started\n", num_peers);
1104 a_ctx = GNUNET_malloc (sizeof (struct Context) * num_peers);
1106 /* select the peers which actively participate in profiling */
1107 n_active = num_peers * PUT_PROBABILITY / 100;
1110 GNUNET_SCHEDULER_shutdown ();
1111 GNUNET_free (a_ctx);
1115 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
1117 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
1119 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1123 a_ctx[cnt].ac = &a_ac[ac_cnt];
1124 a_ac[ac_cnt].ctx = &a_ctx[cnt];
1128 INFO ("Active peers: %u\n", n_active);
1130 /* start DHT service on all peers */
1131 for (cnt = 0; cnt < num_peers; cnt++)
1133 a_ctx[cnt].peer = peers[cnt];
1134 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt],
1145 * Main function that will be run by the scheduler.
1147 * @param cls closure
1148 * @param args remaining command-line arguments
1149 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1150 * @param config configuration
1153 run (void *cls, char *const *args, const char *cfgfile,
1154 const struct GNUNET_CONFIGURATION_Handle *config)
1156 uint64_t event_mask;
1160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1161 _("Exiting as the number of peers is %u\n"),
1165 cfg = GNUNET_CONFIGURATION_dup (config);
1167 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
1168 NULL, &test_run, NULL);
1169 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1177 * @return 0 on success
1180 main (int argc, char *const *argv)
1184 struct GNUNET_GETOPT_CommandLineOption options[] = {
1185 GNUNET_GETOPT_option_uint ('n',
1188 gettext_noop ("number of peers to start"),
1191 GNUNET_GETOPT_option_uint ('s',
1194 gettext_noop ("maximum number of times we try to search for successor circle formation (0 for R5N)"),
1197 GNUNET_GETOPT_option_string ('H',
1200 gettext_noop ("name of the file with the login information for the testbed"),
1203 GNUNET_GETOPT_option_relative_time ('D',
1206 gettext_noop ("delay between rounds for collecting statistics (default: 30 sec)"),
1209 GNUNET_GETOPT_option_relative_time ('P',
1212 gettext_noop ("delay to start doing PUTs (default: 1 sec)"),
1215 GNUNET_GETOPT_option_relative_time ('G',
1218 gettext_noop ("delay to start doing GETs (default: 5 min)"),
1220 GNUNET_GETOPT_option_uint ('r',
1223 gettext_noop ("replication degree for DHT PUTs"),
1227 GNUNET_GETOPT_option_relative_time ('t',
1230 gettext_noop ("timeout for DHT PUT and GET requests (default: 1 min)"),
1232 GNUNET_GETOPT_OPTION_END
1236 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1238 /* set default delays */
1239 delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1240 delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1241 delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1242 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1243 replication = 1; /* default replication */
1246 GNUNET_PROGRAM_run (argc, argv, "dht-profiler",
1248 ("Measure quality and performance of the DHT service."),
1249 options, &run, NULL))