This file is part of GNUnet
Copyright (C) 2013 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ Affero General Public License for more details.
*/
/**
static struct GNUNET_SET_ListenHandle *set_listener;
+static int byzantine;
+static unsigned int force_delta;
+static unsigned int force_full;
+static unsigned int element_size = 32;
+
/**
* Handle to the statistics service.
*/
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;
}
statistics_file = fopen (statistics_filename, "w");
- GNUNET_STATISTICS_get (statistics, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL,
- statistics_done, statistics_result, NULL);
+ GNUNET_STATISTICS_get (statistics, NULL, NULL,
+ &statistics_done,
+ &statistics_result, NULL);
}
static void
set_result_cb (void *cls,
const struct GNUNET_SET_Element *element,
+ uint64_t current_size,
enum GNUNET_SET_Status status)
{
struct SetInfo *info = 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", element->size, sizeof (struct GNUNET_HashCode));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "wrong element size: %u, expected %u\n",
+ element->size,
+ (unsigned int) sizeof (struct GNUNET_HashCode));
GNUNET_assert (0);
}
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);
}
const struct GNUNET_MessageHeader *context_msg,
struct GNUNET_SET_Request *request)
{
+ /* max. 2 options plus terminator */
+ struct GNUNET_SET_Option opts[3] = {{0}};
+ unsigned int n_opts = 0;
+
if (NULL == request)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_assert (NULL == info2.oh);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"set listen cb called\n");
+ if (byzantine)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE };
+ }
+ GNUNET_assert (!(force_full && force_delta));
+ if (force_full)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL };
+ }
+ if (force_delta)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA };
+ }
+
+ opts[n_opts].type = 0;
info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC,
- set_result_cb, &info2);
+ opts,
+ set_result_cb, &info2);
GNUNET_SET_commit (info2.oh, info2.set);
}
void *value)
{
struct GNUNET_SET_Handle *set = cls;
- struct GNUNET_SET_Element *el;
-
- el = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) +
- sizeof (struct GNUNET_HashCode));
- el->element_type = 0;
- memcpy (&el[1], key, sizeof *key);
- el->data = &el[1];
- el->size = sizeof *key;
- GNUNET_SET_add_element (set, el, NULL, NULL);
- GNUNET_free (el);
+ struct GNUNET_SET_Element el;
+
+ el.element_type = 0;
+ el.data = value;
+ el.size = element_size;
+ GNUNET_SET_add_element (set, &el, NULL, NULL);
return GNUNET_YES;
}
{
unsigned int i;
struct GNUNET_HashCode hash;
+ /* max. 2 options plus terminator */
+ struct GNUNET_SET_Option opts[3] = {{0}};
+ unsigned int n_opts = 0;
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");
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);
}
set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
&app_id, set_listen_cb, NULL);
+
+ if (byzantine)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE };
+ }
+ GNUNET_assert (!(force_full && force_delta));
+ if (force_full)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL };
+ }
+ if (force_delta)
+ {
+ opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA };
+ }
+
+ opts[n_opts].type = 0;
+
info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL,
GNUNET_SET_RESULT_SYMMETRIC,
+ opts,
set_result_cb, &info1);
GNUNET_SET_commit (info1.oh, info1.set);
GNUNET_SET_destroy (info1.set);
int
main (int argc, char **argv)
{
- static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- { 'A', "num-first", NULL,
- gettext_noop ("number of values"),
- GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_a },
- { 'B', "num-second", NULL,
- gettext_noop ("number of values"),
- GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_b },
- { 'C', "num-common", NULL,
- gettext_noop ("number of values"),
- GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_c },
- { 'x', "operation", NULL,
- gettext_noop ("operation to execute"),
- GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str },
- { 's', "statistics", NULL,
- gettext_noop ("write statistics to file"),
- GNUNET_YES, &GNUNET_GETOPT_set_filename, &statistics_filename },
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_uint ('A',
+ "num-first",
+ NULL,
+ gettext_noop ("number of values"),
+ &num_a),
+
+ GNUNET_GETOPT_option_uint ('B',
+ "num-second",
+ NULL,
+ gettext_noop ("number of values"),
+ &num_b),
+
+ GNUNET_GETOPT_option_flag ('b',
+ "byzantine",
+ gettext_noop ("use byzantine mode"),
+ &byzantine),
+
+ GNUNET_GETOPT_option_uint ('f',
+ "force-full",
+ NULL,
+ gettext_noop ("force sending full set"),
+ &force_full),
+
+ GNUNET_GETOPT_option_uint ('d',
+ "force-delta",
+ NULL,
+ gettext_noop ("number delta operation"),
+ &force_delta),
+
+ GNUNET_GETOPT_option_uint ('C',
+ "num-common",
+ NULL,
+ gettext_noop ("number of values"),
+ &num_c),
+
+ GNUNET_GETOPT_option_string ('x',
+ "operation",
+ NULL,
+ gettext_noop ("operation to execute"),
+ &op_str),
+
+ GNUNET_GETOPT_option_uint ('w',
+ "element-size",
+ NULL,
+ gettext_noop ("element size"),
+ &element_size),
+
+ GNUNET_GETOPT_option_filename ('s',
+ "statistics",
+ "FILENAME",
+ gettext_noop ("write statistics to file"),
+ &statistics_filename),
+
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",