From 0108f132a418aa48222e2798dba4de38de8dfef5 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 22:53:30 +0100 Subject: rps: get rid of warnings about harmless uninitialized variables --- src/rps/gnunet-service-rps.c | 2 ++ src/rps/rps-sampler_client.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index ecbc8e208..0e3759c4c 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -596,8 +596,10 @@ static const uint32_t num_valid_peers_max = UINT32_MAX; static void do_round (void *cls); +#if ENABLE_MALICIOUS static void do_mal_round (void *cls); +#endif /* ENABLE_MALICIOUS */ /** diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c index 5ab854e01..714943b51 100644 --- a/src/rps/rps-sampler_client.c +++ b/src/rps/rps-sampler_client.c @@ -379,7 +379,8 @@ sampler_mod_get_rand_peer (void *cls) return; } /* compute probability */ - /* Currently disabled due to numerical limitations */ + /* FIXME: Currently disabled due to numerical limitations */ + prob_observed_n = 0; // Inititialise to some value // prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, // s_elem->num_peers, // sampler->deficiency_factor); -- cgit v1.2.3 From 607211bb755160fd5744d6ea6124dadecf4a9e18 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 22:55:49 +0100 Subject: rps: use correct types in format strings --- src/rps/rps-test_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index d2cdd3aa7..b73be3457 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c @@ -186,7 +186,7 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf) if (size_buf != size_written) { LOG (GNUNET_ERROR_TYPE_WARNING, - "Unable to write to file! (Size: %u, size_written: %u)\n", + "Unable to write to file! (Size: %zu, size_written: %zu)\n", size_buf, size_written); @@ -197,7 +197,7 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf) return; } LOG (GNUNET_ERROR_TYPE_WARNING, - "Wrote %u bytes raw.\n", + "Wrote %zu bytes raw.\n", size_written); if (GNUNET_YES != GNUNET_DISK_file_close (f)) LOG (GNUNET_ERROR_TYPE_WARNING, @@ -238,7 +238,7 @@ to_file_raw_unaligned (const char *file_name, "num_bits_buf_unaligned: %u\n", num_bits_buf_unaligned); LOG (GNUNET_ERROR_TYPE_DEBUG, - "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", + "ua args: size_buf: %zu, bits_needed: %u -> iter: %u\n", size_buf, bits_needed, bytes_iter); -- cgit v1.2.3 From 89ea7681905d58ac3f25cea581ee084a70715efc Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 22:56:27 +0100 Subject: rps: use correct buffer sizes --- src/rps/rps-test_util.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 2f11f0105..72aa78803 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h @@ -73,7 +73,7 @@ close_all_files (); "Failed to create tmp_buf\n"); \ break; \ } \ - (void) strncat (tmp_buf, "\n", 512); \ + (void) strncat (tmp_buf, "\n", 511); \ GNUNET_DISK_file_write (get_file_handle (file_name), \ tmp_buf, \ strnlen (tmp_buf, 512)); \ @@ -94,8 +94,7 @@ close_all_files (); "Failed to create tmp_buf\n"); \ break; \ } \ - (void) strncat (tmp_buf, "\n", \ - len); \ + (void) strncat (tmp_buf, "\n", 2); \ GNUNET_DISK_file_write ( \ get_file_handle (file_name), \ tmp_buf, \ -- cgit v1.2.3 From 266823196daab39713bef4a017b10d60d39bfa93 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 22:56:47 +0100 Subject: rps: use proper signedness --- src/rps/test_service_rps_custommap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rps/test_service_rps_custommap.c b/src/rps/test_service_rps_custommap.c index 05590b097..3d885ca6b 100644 --- a/src/rps/test_service_rps_custommap.c +++ b/src/rps/test_service_rps_custommap.c @@ -35,7 +35,7 @@ check () struct CustomPeerMap *c_m; struct GNUNET_PeerIdentity k1; struct GNUNET_PeerIdentity k2; - int j; + unsigned int j; CHECK (NULL != (c_m = CustomPeerMap_create (4))); memset (&k1, 0, sizeof(k1)); -- cgit v1.2.3 From 0950b1df774f5a040bc1d16d56e939480babe068 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 22:59:12 +0100 Subject: rps: properly initialise memory --- src/rps/gnunet-rps-profiler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index 392a3c18f..7d6bf407f 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c @@ -2652,10 +2652,11 @@ pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) store_prefix_file_name (rps_peer->index, "probs"); rps_peer->file_name_probs_hist = store_prefix_file_name (rps_peer->index, "probs_hist"); + rps_peer->eval_probs_cache = GNUNET_new_array (num_peers, double); + memset (rps_peer->eval_probs_cache, 0, num_peers * sizeof (double)); GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); } - void write_final_stats (void) { -- cgit v1.2.3 From d30ec0f1fb9ced559b8add2f48eda05a8b58fac0 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 23:36:12 +0100 Subject: rps: comment ill-defined code --- src/rps/gnunet-service-rps.c | 113 +++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 52 deletions(-) diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 0e3759c4c..48b5194c8 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -2950,12 +2950,16 @@ new_sub (const struct GNUNET_HashCode *hash, /* Logging of internals */ #ifdef TO_FILE_FULL - sub->file_name_view_log = store_prefix_file_name (&own_identity, "view"); + // FIXME: The service cannot know the index, which is required by this + // function: + // sub->file_name_view_log = store_prefix_file_name (&own_identity, "view"); #endif /* TO_FILE_FULL */ #ifdef TO_FILE #ifdef TO_FILE_FULL - sub->file_name_observed_log = store_prefix_file_name (&own_identity, - "observed"); + // FIXME: The service cannot know the index, which is required by this + // function: + // sub->file_name_observed_log = store_prefix_file_name (&own_identity, + // "observed"); #endif /* TO_FILE_FULL */ sub->num_observed_peers = 0; sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, @@ -2983,46 +2987,50 @@ new_sub (const struct GNUNET_HashCode *hash, #ifdef TO_FILE -/** - * @brief Write all numbers in the given array into the given file - * - * Single numbers devided by a newline - * - * @param hist_array[] the array to dump - * @param file_name file to dump into - */ -static void -write_histogram_to_file (const uint32_t hist_array[], - const char *file_name) -{ - char collect_str[SIZE_DUMP_FILE + 1] = ""; - char *recv_str_iter; - char *file_name_full; - - recv_str_iter = collect_str; - file_name_full = store_prefix_file_name (&own_identity, - file_name); - for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) - { - char collect_str_tmp[8]; - - GNUNET_snprintf (collect_str_tmp, - sizeof(collect_str_tmp), - "%" PRIu32 "\n", - hist_array[i]); - recv_str_iter = stpncpy (recv_str_iter, - collect_str_tmp, - 6); - } - (void) stpcpy (recv_str_iter, - "\n"); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Writing push stats to disk\n"); - to_file_w_len (file_name_full, - SIZE_DUMP_FILE, "%s", - collect_str); - GNUNET_free (file_name_full); -} +// /** +// * @brief Write all numbers in the given array into the given file +// * +// * Single numbers devided by a newline +// * +// * FIXME: The call to store_prefix_file_name expects the index of the peer, +// * which cannot be known to the service. +// * Write a dedicated function that uses the peer id. +// * +// * @param hist_array[] the array to dump +// * @param file_name file to dump into +// */ +// static void +// write_histogram_to_file (const uint32_t hist_array[], +// const char *file_name) +// { +// char collect_str[SIZE_DUMP_FILE + 1] = ""; +// char *recv_str_iter; +// char *file_name_full; +// +// recv_str_iter = collect_str; +// file_name_full = store_prefix_file_name (&own_identity, +// file_name); +// for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) +// { +// char collect_str_tmp[8]; +// +// GNUNET_snprintf (collect_str_tmp, +// sizeof(collect_str_tmp), +// "%" PRIu32 "\n", +// hist_array[i]); +// recv_str_iter = stpncpy (recv_str_iter, +// collect_str_tmp, +// 6); +// } +// (void) stpcpy (recv_str_iter, +// "\n"); +// LOG (GNUNET_ERROR_TYPE_DEBUG, +// "Writing push stats to disk\n"); +// to_file_w_len (file_name_full, +// SIZE_DUMP_FILE, "%s", +// collect_str); +// GNUNET_free (file_name_full); +// } #endif /* TO_FILE */ @@ -3067,17 +3075,18 @@ destroy_sub (struct Sub *sub) sub->file_name_observed_log = NULL; #endif /* TO_FILE_FULL */ - /* Write push frequencies to disk */ - write_histogram_to_file (sub->push_recv, - "push_recv"); + // FIXME: Currently this calls malfunctionning code + // /* Write push frequencies to disk */ + // write_histogram_to_file (sub->push_recv, + // "push_recv"); - /* Write push deltas to disk */ - write_histogram_to_file (sub->push_delta, - "push_delta"); + // /* Write push deltas to disk */ + // write_histogram_to_file (sub->push_delta, + // "push_delta"); - /* Write pull delays to disk */ - write_histogram_to_file (sub->pull_delays, - "pull_delays"); + // /* Write pull delays to disk */ + // write_histogram_to_file (sub->pull_delays, + // "pull_delays"); GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers); sub->observed_unique_peers = NULL; -- cgit v1.2.3 From 91e8c2ff26ab0f65bbfec3de0b4acbaa95e52a47 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Mon, 16 Nov 2020 23:57:08 +0100 Subject: rps: deal with currently unused code --- src/rps/gnunet-rps-profiler.c | 209 +++++++++++++++--------------------------- src/rps/gnunet-service-rps.c | 2 + src/rps/rps-sampler_client.c | 66 ++++++------- 3 files changed, 109 insertions(+), 168 deletions(-) diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index 7d6bf407f..0ec2fec71 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c @@ -59,10 +59,10 @@ static struct GNUNET_TIME_Relative duration; static struct GNUNET_TIME_Relative timeout; -/** - * Portion of malicious peers - */ -static double portion = .1; +// /** +// * Portion of malicious peers +// */ +// static double portion = .1; /** * Type of malicious peer to test @@ -1228,29 +1228,6 @@ post_test_op (void *cls) } -/** - * Seed peers. - */ -static void -seed_peers (void *cls) -{ - struct RPSPeer *peer = cls; - unsigned int amount; - unsigned int i; - - // TODO if malicious don't seed mal peers - amount = round (.5 * num_peers); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); - for (i = 0; i < amount; i++) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", - i, - GNUNET_i2s (&rps_peer_ids[i])); - - GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); -} - - /** * Get the id of peer i. */ @@ -1635,76 +1612,76 @@ cancel_pending_req_rep (struct RPSPeer *rps_peer) * MALICIOUS ***********************************/ -/** - * Initialise only non-mal RPSPeers - */ -static void -mal_init_peer (struct RPSPeer *rps_peer) -{ - if (rps_peer->index >= round (portion * num_peers)) - rps_peer->num_ids_to_request = 1; -} - - -/** - * @brief Set peers to (non-)malicious before execution - * - * Of signature #PreTest - * - * @param rps_peer the peer to set (non-) malicious - * @param h the handle to the service - */ -static void -mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) -{ - #if ENABLE_MALICIOUS - uint32_t num_mal_peers; - - GNUNET_assert ((1 >= portion) && - (0 < portion)); - num_mal_peers = round (portion * num_peers); - - if (rps_peer->index < num_mal_peers) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%u. peer [%s] of %" PRIu32 - " malicious peers turning malicious\n", - rps_peer->index, - GNUNET_i2s (rps_peer->peer_id), - num_mal_peers); - - GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, - rps_peer_ids, target_peer); - } - #endif /* ENABLE_MALICIOUS */ -} - - -static void -mal_cb (struct RPSPeer *rps_peer) -{ - if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test)) - { - return; - } - - #if ENABLE_MALICIOUS - uint32_t num_mal_peers; - - GNUNET_assert ((1 >= portion) && - (0 < portion)); - num_mal_peers = round (portion * num_peers); - - if (rps_peer->index >= num_mal_peers) - { /* It's useless to ask a malicious peer about a random sample - - it's not sampling */ - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_SECONDS, 2), - seed_peers, rps_peer); - schedule_missing_requests (rps_peer); - } - #endif /* ENABLE_MALICIOUS */ -} +///** +// * Initialise only non-mal RPSPeers +// */ +//static void +//mal_init_peer (struct RPSPeer *rps_peer) +//{ +// if (rps_peer->index >= round (portion * num_peers)) +// rps_peer->num_ids_to_request = 1; +//} + + +///** +// * @brief Set peers to (non-)malicious before execution +// * +// * Of signature #PreTest +// * +// * @param rps_peer the peer to set (non-) malicious +// * @param h the handle to the service +// */ +//static void +//mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) +//{ +// #if ENABLE_MALICIOUS +// uint32_t num_mal_peers; +// +// GNUNET_assert ((1 >= portion) && +// (0 < portion)); +// num_mal_peers = round (portion * num_peers); +// +// if (rps_peer->index < num_mal_peers) +// { +// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +// "%u. peer [%s] of %" PRIu32 +// " malicious peers turning malicious\n", +// rps_peer->index, +// GNUNET_i2s (rps_peer->peer_id), +// num_mal_peers); +// +// GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, +// rps_peer_ids, target_peer); +// } +// #endif /* ENABLE_MALICIOUS */ +//} + + +// static void +// mal_cb (struct RPSPeer *rps_peer) +// { +// if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test)) +// { +// return; +// } +// +// #if ENABLE_MALICIOUS +// uint32_t num_mal_peers; +// +// GNUNET_assert ((1 >= portion) && +// (0 < portion)); +// num_mal_peers = round (portion * num_peers); +// +// if (rps_peer->index >= num_mal_peers) +// { /* It's useless to ask a malicious peer about a random sample - +// it's not sampling */ +// GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( +// GNUNET_TIME_UNIT_SECONDS, 2), +// seed_peers, rps_peer); +// schedule_missing_requests (rps_peer); +// } +// #endif /* ENABLE_MALICIOUS */ +// } /*********************************** @@ -1714,44 +1691,6 @@ mal_cb (struct RPSPeer *rps_peer) static void churn (void *cls); -/** - * @brief Starts churn - * - * Has signature of #MainTest - * - * This is not implemented too nicely as this is called for each peer, but we - * only need to call it once. (Yes we check that we only schedule the task - * once.) - * - * @param rps_peer The peer it's called for - */ -static void -churn_test_cb (struct RPSPeer *rps_peer) -{ - if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test)) - { - return; - } - - /* Start churn */ - if ((HAVE_CHURN == cur_test_run.have_churn) && (NULL == churn_task)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting churn task\n"); - churn_task = GNUNET_SCHEDULER_add_delayed ( - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), - churn, - NULL); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not starting churn task\n"); - } - - schedule_missing_requests (rps_peer); -} - /*********************************** * PROFILER diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 48b5194c8..dc4c5dab7 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -2466,6 +2466,7 @@ resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size) } +#if ENABLE_MALICIOUS /** * Add all peers in @a peer_array to @a peer_map used as set. * @@ -2502,6 +2503,7 @@ add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, } } } +#endif /* ENABLE_MALICIOUS */ /** diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c index 714943b51..f6e98ce29 100644 --- a/src/rps/rps-sampler_client.c +++ b/src/rps/rps-sampler_client.c @@ -258,39 +258,39 @@ RPS_sampler_mod_init (size_t init_size, } -/** - * @brief Compute the probability that we already observed all peers from a - * biased stream of peer ids. - * - * Deficiency factor: - * As introduced by Brahms: Factor between the number of unique ids in a - * truly random stream and number of unique ids in the gossip stream. - * - * @param num_peers_estim The estimated number of peers in the network - * @param num_peers_observed The number of peers the given element has observed - * @param deficiency_factor A factor that catches the 'bias' of a random stream - * of peer ids - * - * @return The estimated probability - */ -static double -prob_observed_n_peers (uint32_t num_peers_estim, - uint32_t num_peers_observed, - double deficiency_factor) -{ - uint32_t num_peers = num_peers_estim * (1 / deficiency_factor); - uint64_t sum = 0; - - for (uint32_t i = 0; i < num_peers; i++) - { - uint64_t a = pow (-1, num_peers - i); - uint64_t b = binom (num_peers, i); - uint64_t c = pow (i, num_peers_observed); - sum += a * b * c; - } - - return sum / (double) pow (num_peers, num_peers_observed); -} +// /** +// * @brief Compute the probability that we already observed all peers from a +// * biased stream of peer ids. +// * +// * Deficiency factor: +// * As introduced by Brahms: Factor between the number of unique ids in a +// * truly random stream and number of unique ids in the gossip stream. +// * +// * @param num_peers_estim The estimated number of peers in the network +// * @param num_peers_observed The number of peers the given element has observed +// * @param deficiency_factor A factor that catches the 'bias' of a random stream +// * of peer ids +// * +// * @return The estimated probability +// */ +// static double +// prob_observed_n_peers (uint32_t num_peers_estim, +// uint32_t num_peers_observed, +// double deficiency_factor) +// { +// uint32_t num_peers = num_peers_estim * (1 / deficiency_factor); +// uint64_t sum = 0; +// +// for (uint32_t i = 0; i < num_peers; i++) +// { +// uint64_t a = pow (-1, num_peers - i); +// uint64_t b = binom (num_peers, i); +// uint64_t c = pow (i, num_peers_observed); +// sum += a * b * c; +// } +// +// return sum / (double) pow (num_peers, num_peers_observed); +// } /** -- cgit v1.2.3 From 52968789d280ee066e4527d6b191691625bd993a Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 18 Nov 2020 05:46:55 +0900 Subject: - do not cleanup client twice --- src/reclaim/gnunet-service-reclaim.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 0774fecea..5614f05db 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -602,17 +602,8 @@ cleanup_client (struct IdpClient *idp) static void cleanup () { - struct IdpClient *cl; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); - while (NULL != (cl = client_list_head)) - { - GNUNET_CONTAINER_DLL_remove (client_list_head, - client_list_tail, - cl); - cleanup_client (cl); - } RECLAIM_TICKETS_deinit (); if (NULL != timeout_task) GNUNET_SCHEDULER_cancel (timeout_task); -- cgit v1.2.3