X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fdht%2Fgnunet_dht_profiler.c;h=60c78c2805a0d2c85f6b56e2c9533c6014477ec2;hb=1b49510e7736620d7e10a33326076e2d75c86943;hp=0380a82b471338f5b3dc72f00791bb948a64836c;hpb=1a021fccfa0554a6396f1114f11ef509c49712fc;p=oweals%2Fgnunet.git diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 0380a82b4..60c78c280 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2014 Christian Grothoff (and other contributing authors) + Copyright (C) 2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -47,7 +47,7 @@ #define MALICIOUS_PROBABILITY 20 /** - * Context for a peer which should act maliciously. + * Context for a peer which should act maliciously. */ struct MaliciousContext; #endif @@ -87,10 +87,10 @@ struct Context * Active context; NULL if this peer is not an active peer */ struct ActiveContext *ac; - + #if ENABLE_MALICIOUS /** - * Malicious context; NULL if this peer is NOT malicious. + * Malicious context; NULL if this peer is NOT malicious. */ struct MaliciousContext *mc; #endif @@ -112,7 +112,7 @@ struct MaliciousContext * Handler to the DHT service */ struct GNUNET_DHT_Handle *dht; - + /** * Handler to malicious api */ @@ -195,7 +195,7 @@ struct ActiveContext /** * Delay task */ - GNUNET_SCHEDULER_TaskIdentifier delay_task; + struct GNUNET_SCHEDULER_Task * delay_task; /** * The size of the @e put_data @@ -310,7 +310,7 @@ static struct GNUNET_TESTBED_Operation *successor_stats_op; static struct GNUNET_TESTBED_Peer **testbed_handles; /** - * Total number of messages sent by peer. + * Total number of messages sent by peer. */ static uint64_t outgoing_bandwidth; @@ -325,27 +325,27 @@ static uint64_t incoming_bandwidth; static double average_put_path_length; /** - * Average number of hops taken to do get. + * Average number of hops taken to do get. */ static double average_get_path_length; /** - * Total put path length across all peers. + * Total put path length across all peers. */ static unsigned int total_put_path_length; /** - * Total get path length across all peers. + * Total get path length across all peers. */ static unsigned int total_get_path_length; /** - * Hashmap to store pair of peer and its corresponding successor. + * Hashmap to store pair of peer and its corresponding successor. */ static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap; /** - * Key to start the lookup on successor_peer_hashmap. + * Key to start the lookup on successor_peer_hashmap. */ static struct GNUNET_HashCode *start_key; @@ -357,7 +357,7 @@ static int flag = 0; /** * Task to collect peer and its current successor statistics. */ -static GNUNET_SCHEDULER_TaskIdentifier successor_stats_task; +static struct GNUNET_SCHEDULER_Task * successor_stats_task; /** * Closure for successor_stats_task. @@ -365,10 +365,10 @@ static GNUNET_SCHEDULER_TaskIdentifier successor_stats_task; struct Collect_Stat_Context { /** - * Current Peer Context. + * Current Peer Context. */ struct Context *service_connect_ctx; - + /** * Testbed operation acting on this peer */ @@ -381,7 +381,7 @@ struct Collect_Stat_Context struct Context **peer_contexts = NULL; /** - * Counter to keep track of peers added to peer_context lists. + * Counter to keep track of peers added to peer_context lists. */ static int peers_started = 0; @@ -407,7 +407,7 @@ static int in_shutdown = 0; static unsigned int tries; /** - * Task that collects successor statistics from all the peers. + * Task that collects successor statistics from all the peers. * @param cls * @param tc */ @@ -441,7 +441,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ac = a_ctx[cnt].ac; if (NULL != ac) { - if (GNUNET_SCHEDULER_NO_TASK != ac->delay_task) + if (NULL != ac->delay_task) GNUNET_SCHEDULER_cancel (ac->delay_task); if (NULL != ac->put_data) GNUNET_free (ac->put_data); @@ -476,8 +476,8 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * operation has executed successfully. */ static void -bandwidth_stats_cont (void *cls, - struct GNUNET_TESTBED_Operation *op, +bandwidth_stats_cont (void *cls, + struct GNUNET_TESTBED_Operation *op, const char *emsg) { INFO ("# Outgoing bandwidth: %u\n", outgoing_bandwidth); @@ -498,11 +498,11 @@ bandwidth_stats_cont (void *cls, * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -bandwidth_stats_iterator (void *cls, +bandwidth_stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, - const char *subsystem, + const char *subsystem, const char *name, - uint64_t value, + uint64_t value, int is_persistent) { static const char *s_sent = "# Bytes transmitted to other peers"; @@ -512,7 +512,7 @@ bandwidth_stats_iterator (void *cls, outgoing_bandwidth = outgoing_bandwidth + value; else if (0 == strncmp(s_recv, name, strlen (s_recv))) incoming_bandwidth = incoming_bandwidth + value; - + return GNUNET_OK; } @@ -528,7 +528,7 @@ summarize () INFO ("# GETS failed: %u\n", n_gets_fail); INFO ("# average_put_path_length: %f\n", average_put_path_length); INFO ("# average_get_path_length: %f\n", average_get_path_length); - + if (NULL == testbed_handles) { INFO ("No peers found\n"); @@ -537,7 +537,7 @@ summarize () /* Collect Stats*/ bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles, "dht", NULL, - bandwidth_stats_iterator, + bandwidth_stats_iterator, bandwidth_stats_cont, NULL); } @@ -554,7 +554,7 @@ cancel_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct ActiveContext *ac = cls; struct Context *ctx = ac->ctx; - ac->delay_task = GNUNET_SCHEDULER_NO_TASK; + ac->delay_task = NULL; GNUNET_assert (NULL != ac->dht_get); GNUNET_DHT_get_stop (ac->dht_get); ac->dht_get = NULL; @@ -613,13 +613,13 @@ get_iter (void *cls, get_ac->nrefs--; GNUNET_DHT_get_stop (ac->dht_get); ac->dht_get = NULL; - if (ac->delay_task != GNUNET_SCHEDULER_NO_TASK) + if (ac->delay_task != NULL) GNUNET_SCHEDULER_cancel (ac->delay_task); - ac->delay_task = GNUNET_SCHEDULER_NO_TASK; + ac->delay_task = NULL; GNUNET_assert (NULL != ctx->op); GNUNET_TESTBED_operation_done (ctx->op); ctx->op = NULL; - + total_put_path_length = total_put_path_length + (double)put_path_length; total_get_path_length = total_get_path_length + (double)get_path_length; DEBUG ("total_put_path_length = %f,put_path \n",total_put_path_length); @@ -646,7 +646,7 @@ delayed_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct ActiveContext *get_ac; unsigned int r; - ac->delay_task = GNUNET_SCHEDULER_NO_TASK; + ac->delay_task = NULL; get_ac = NULL; while (1) { @@ -735,7 +735,7 @@ delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ActiveContext *ac = cls; - ac->delay_task = GNUNET_SCHEDULER_NO_TASK; + ac->delay_task = NULL; /* Generate and DHT PUT some random data */ ac->put_data_size = 16; /* minimum */ ac->put_data_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, @@ -825,7 +825,6 @@ static void * dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { n_dht++; - DEBUG("\n Inside dht_connect , n_dht = %u",n_dht); return GNUNET_DHT_connect (cfg, 10); } @@ -876,7 +875,7 @@ start_profiling() { struct Context *ctx; unsigned int i; - + DEBUG("GNUNET_TESTBED_service_connect \n"); GNUNET_break (GNUNET_YES != in_shutdown); for(i = 0; i < n_active; i++) @@ -915,7 +914,7 @@ act_malicious_cont (void *cls, int success) { struct MaliciousContext *mc = cls; struct Context *ctx = mc->ctx; - + GNUNET_TESTBED_operation_done (ctx->op); ctx->op = NULL; return; @@ -930,7 +929,7 @@ act_malicious_cont (void *cls, int success) * @param emsg error message in case the operation has failed; will be NULL if * operation has executed successfully. */ -void +static void dht_set_malicious(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, @@ -975,7 +974,7 @@ dht_disconnect_malicious (void *cls, void *op_result) if (0 != n_dht) return; - + if(n_malicious == count_malicious) { DEBUG("\n Call start_profiling()"); @@ -991,11 +990,11 @@ static void set_malicious() { unsigned int i; - DEBUG ("Setting %u peers malicious",n_malicious); - + + DEBUG ("Setting %u peers malicious", + n_malicious); for(i = 0; i < n_malicious; i++) { - DEBUG("\n Inside loop , i = %u",i); struct MaliciousContext *mc = &a_mc[i]; mc->ctx->op = GNUNET_TESTBED_service_connect (mc->ctx, @@ -1021,9 +1020,9 @@ start_func() { #if ENABLE_MALICIOUS set_malicious(); - return; -#endif +#else start_profiling(); +#endif } @@ -1035,12 +1034,12 @@ start_func() * @return #GNUNET_YES if we should continue to iterate, * #GNUNET_NO if not. */ -static int -hashmap_iterate_remove(void *cls, - const struct GNUNET_HashCode *key, +static int +hashmap_iterate_remove(void *cls, + const struct GNUNET_HashCode *key, void *value) { - GNUNET_assert (GNUNET_YES == + GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value)); return GNUNET_YES; } @@ -1056,66 +1055,61 @@ hashmap_iterate_remove(void *cls, * operation has executed successfully. */ static void -successor_stats_cont (void *cls, - struct GNUNET_TESTBED_Operation *op, +successor_stats_cont (void *cls, + struct GNUNET_TESTBED_Operation *op, const char *emsg) { struct GNUNET_HashCode *val; struct GNUNET_HashCode *start_val; struct GNUNET_HashCode *key; int count; - + /* Don't schedule the task till we are looking for circle here. */ - successor_stats_task = GNUNET_SCHEDULER_NO_TASK; + successor_stats_task = NULL; GNUNET_TESTBED_operation_done (successor_stats_op); successor_stats_op = NULL; if (0 == max_searches) { - start_func(); + start_func(); return; } GNUNET_assert (NULL != start_key); - start_val = - (struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap, - start_key); - + start_val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap, + start_key); + GNUNET_assert (NULL != start_val); val = start_val; for (count = 0; count < num_peers; count++) { key = val; val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap, key); - if(NULL == val) - { + if (NULL == val) break; - } /* Remove the entry from hashmap. This is done to take care of loop. */ - if (GNUNET_NO == - GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap, - key, val)) + if (GNUNET_NO == + GNUNET_CONTAINER_multihashmap_remove (successor_peer_hashmap, + key, val)) { DEBUG ("Failed to remove entry from hashmap\n"); break; } /* If a peer has its own identity as its successor. */ if (0 == memcmp(key, val, sizeof (struct GNUNET_HashCode))) - { break; - } } - - GNUNET_assert(GNUNET_SYSERR != - GNUNET_CONTAINER_multihashmap_iterate (successor_peer_hashmap, - hashmap_iterate_remove, - NULL)); - - successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, + + GNUNET_assert (GNUNET_SYSERR != + GNUNET_CONTAINER_multihashmap_iterate (successor_peer_hashmap, + &hashmap_iterate_remove, + NULL)); + + successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, GNUNET_NO); if ((start_val == val) && (count == num_peers)) { DEBUG("CIRCLE COMPLETED after %u tries", tries); - if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) + if(NULL == successor_stats_task) { start_func(); } @@ -1129,23 +1123,24 @@ successor_stats_cont (void *cls, "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" " circle formation. Exiting\n", max_searches,tries); - if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) + if (NULL != successor_stats_task) { - successor_stats_task = GNUNET_SCHEDULER_NO_TASK; + successor_stats_task = NULL; } - if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) + if(NULL == successor_stats_task) { start_func(); } - + return; } else { flag = 0; - successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, &collect_stats, cls); + successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, + &collect_stats, cls); } - } + } } @@ -1161,11 +1156,11 @@ successor_stats_cont (void *cls, * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ static int -successor_stats_iterator (void *cls, +successor_stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, - const char *subsystem, + const char *subsystem, const char *name, - uint64_t value, + uint64_t value, int is_persistent) { static const char *key_string = "XDHT"; @@ -1180,10 +1175,10 @@ successor_stats_iterator (void *cls, char truncated_successor_str[13]; struct GNUNET_HashCode *my_id_key; struct GNUNET_HashCode *succ_key; - + strtok((char *)name,":"); my_id_str = strtok(NULL,":"); - + strncpy(truncated_my_id_str, my_id_str, 12); truncated_my_id_str[12] = '\0'; my_id_key = GNUNET_new(struct GNUNET_HashCode); @@ -1191,7 +1186,7 @@ successor_stats_iterator (void *cls, GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13); strncpy(truncated_successor_str, successor_str, 12); truncated_successor_str[12] ='\0'; - + succ_key = GNUNET_new(struct GNUNET_HashCode); GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key); @@ -1211,9 +1206,9 @@ successor_stats_iterator (void *cls, } -/* - * Task that collects peer and its corresponding successors. - * +/* + * Task that collects peer and its corresponding successors. + * * @param cls Closure (NULL). * @param tc Task Context. */ @@ -1225,16 +1220,16 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n"); GNUNET_assert(NULL != testbed_handles); - + if (0 != max_searches) - successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, + successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, GNUNET_NO); - successor_stats_op = + successor_stats_op = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles, "dht", NULL, - successor_stats_iterator, + successor_stats_iterator, successor_stats_cont, cls); - + GNUNET_assert(NULL != successor_stats_op); } @@ -1260,13 +1255,13 @@ service_started (void *cls, ctx->op = NULL; peers_started++; DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); - if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) + if (NULL == successor_stats_task && peers_started == num_peers) { DEBUG("successor_stats_task \n"); struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); collect_stat_cls->service_connect_ctx = cls; collect_stat_cls->op = op; - + successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, &collect_stats, collect_stat_cls); @@ -1294,7 +1289,7 @@ test_run (void *cls, { unsigned int cnt; unsigned int ac_cnt; - testbed_handles = peers; + testbed_handles = peers; if (NULL == peers) { /* exit */ @@ -1311,10 +1306,10 @@ test_run (void *cls, GNUNET_free (a_ctx); return; } - + a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); ac_cnt = 0; - + #if ENABLE_MALICIOUS unsigned int malicious_peers; if(PUT_PROBABILITY + MALICIOUS_PROBABILITY > 100) @@ -1324,13 +1319,13 @@ test_run (void *cls, GNUNET_free (a_ctx); return; } - + /* Select the peers which should act maliciously. */ n_malicious = num_peers * MALICIOUS_PROBABILITY / 100; - + a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext)); malicious_peers = 0; - + for (cnt = 0; cnt < num_peers && malicious_peers < n_malicious; cnt++) { if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= @@ -1339,12 +1334,12 @@ test_run (void *cls, a_ctx[cnt].mc = &a_mc[malicious_peers]; a_mc[malicious_peers].ctx = &a_ctx[cnt]; malicious_peers++; - } + } n_malicious = malicious_peers; INFO ("Malicious Peers: %u\n",malicious_peers); - + #endif - + a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); ac_cnt = 0; for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) @@ -1352,12 +1347,12 @@ test_run (void *cls, if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= PUT_PROBABILITY)) continue; - + #if ENABLE_MALICIOUS if(a_ctx[ac_cnt].mc != NULL) continue; #endif - + a_ctx[cnt].ac = &a_ac[ac_cnt]; a_ac[ac_cnt].ctx = &a_ctx[cnt]; ac_cnt++;