From: Florian Dold Date: Tue, 28 Feb 2017 17:53:31 +0000 (+0100) Subject: fix completely broken implementation of variable size elements X-Git-Tag: taler-0.2.1~8^2~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a9a6b98c54f5cc3e680c8ea2f9c69e3955e2a7da;p=oweals%2Fgnunet.git fix completely broken implementation of variable size elements --- diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index a6c900f5e..8404b191c 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c @@ -61,8 +61,7 @@ static struct GNUNET_SET_ListenHandle *set_listener; static int byzantine; static int force_delta; static int force_full; - -static unsigned int element_length = 32; +static unsigned int element_size = 32; /** * Handle to the statistics service. @@ -92,7 +91,7 @@ map_remove_iterator (void *cls, GNUNET_assert (NULL != key); - ret = GNUNET_CONTAINER_multihashmap_remove (m, key, NULL); + ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key); if (GNUNET_OK != ret) printf ("spurious element\n"); return GNUNET_YES; @@ -198,7 +197,7 @@ set_result_cb (void *cls, GNUNET_assert (0); } - if (element->size != sizeof (struct GNUNET_HashCode)) + if (element->size != element_size) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "wrong element size: %u, expected %u\n", @@ -210,8 +209,10 @@ set_result_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", info->id, GNUNET_h2s (element->data)); GNUNET_assert (NULL != element->data); + struct GNUNET_HashCode data_hash; + GNUNET_CRYPTO_hash (element->data, element_size, &data_hash); GNUNET_CONTAINER_multihashmap_put (info->received, - element->data, NULL, + &data_hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } @@ -265,14 +266,9 @@ set_insert_iterator (void *cls, struct GNUNET_SET_Handle *set = cls; struct GNUNET_SET_Element el; - GNUNET_assert (element_length > 0); - char payload[element_length]; - - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, payload, element_length); - el.element_type = 0; - el.data = payload; - el.size = element_length; + el.data = value; + el.size = element_size; GNUNET_SET_add_element (set, &el, NULL, NULL); return GNUNET_YES; } @@ -325,6 +321,8 @@ run (void *cls, config = cfg; + GNUNET_assert (element_size > 0); + if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); @@ -348,22 +346,28 @@ run (void *cls, for (i = 0; i < num_a; i++) { - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); - GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, NULL, + char *data = GNUNET_malloc (element_size); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash (data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } for (i = 0; i < num_b; i++) { - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); - GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, NULL, + char *data = GNUNET_malloc (element_size); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash (data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } for (i = 0; i < num_c; i++) { - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); - GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, NULL, + char *data = GNUNET_malloc (element_size); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); + GNUNET_CRYPTO_hash (data, element_size, &hash); + GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); } @@ -435,9 +439,6 @@ main (int argc, char **argv) { 'f', "force-full", NULL, gettext_noop ("force sending full set"), GNUNET_NO, &GNUNET_GETOPT_set_uint, &force_full }, - { 'w', "element-length", NULL, - gettext_noop ("element length in byte"), - GNUNET_NO, &GNUNET_GETOPT_set_uint, &element_length }, { 'd', "force-delta", NULL, gettext_noop ("number delta operation"), GNUNET_NO, &GNUNET_GETOPT_set_uint, &force_delta }, @@ -447,6 +448,9 @@ main (int argc, char **argv) { 'x', "operation", NULL, gettext_noop ("operation to execute"), GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str }, + { 'w', "element-size", NULL, + gettext_noop ("element size"), + GNUNET_YES, &GNUNET_GETOPT_set_uint, &element_size }, { 's', "statistics", NULL, gettext_noop ("write statistics to file"), GNUNET_YES, &GNUNET_GETOPT_set_filename, &statistics_filename },