From 830137e312e8e565c9113a20411aa3073fbd1cbd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 27 Feb 2017 15:28:00 +0100 Subject: implement revocation block plugin, get revocation test to pass again --- src/block/block.c | 2 +- src/block/plugin_block_template.c | 4 +- src/consensus/plugin_block_consensus.c | 2 +- src/dht/plugin_block_dht.c | 2 +- src/fs/plugin_block_fs.c | 2 +- src/gns/plugin_block_gns.c | 2 +- src/include/gnunet_block_lib.h | 5 + src/include/gnunet_plugin_lib.h | 2 +- src/regex/plugin_block_regex.c | 2 +- src/revocation/Makefile.am | 17 +- src/revocation/gnunet-service-revocation.c | 16 +- src/revocation/plugin_block_revocation.c | 257 +++++++++++++++++++++++++++++ src/set/plugin_block_set_test.c | 2 +- 13 files changed, 298 insertions(+), 17 deletions(-) create mode 100644 src/revocation/plugin_block_revocation.c (limited to 'src') diff --git a/src/block/block.c b/src/block/block.c index d6e61acf6..4b6f3826d 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -136,7 +136,7 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) ctx = GNUNET_new (struct GNUNET_BLOCK_Context); ctx->cfg = cfg; GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", - NULL, + (void *) cfg, &add_plugin, ctx); return ctx; diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c index 2edca17ec..0105fac38 100644 --- a/src/block/plugin_block_template.c +++ b/src/block/plugin_block_template.c @@ -157,6 +157,8 @@ block_plugin_template_get_key (void *cls, /** * Entry point for the plugin. + * + * @param cls a `const struct GNUNET_CONFIGURATION_Handle` */ void * libgnunet_plugin_block_template_init (void *cls) @@ -183,7 +185,7 @@ libgnunet_plugin_block_template_init (void *cls) void * libgnunet_plugin_block_template_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c index 0cb64867e..de0f0886f 100644 --- a/src/consensus/plugin_block_consensus.c +++ b/src/consensus/plugin_block_consensus.c @@ -128,7 +128,7 @@ libgnunet_plugin_block_consensus_init (void *cls) void * libgnunet_plugin_block_consensus_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 96349ae9d..24f8b21b2 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c @@ -237,7 +237,7 @@ libgnunet_plugin_block_dht_init (void *cls) void * libgnunet_plugin_block_dht_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c index c5e63c9e2..902519f15 100644 --- a/src/fs/plugin_block_fs.c +++ b/src/fs/plugin_block_fs.c @@ -276,7 +276,7 @@ libgnunet_plugin_block_fs_init (void *cls) void * libgnunet_plugin_block_fs_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 558ded6f4..a42fef953 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -238,7 +238,7 @@ libgnunet_plugin_block_gns_init (void *cls) void * libgnunet_plugin_block_gns_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 3e36f11f0..d8ee68c21 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h @@ -111,6 +111,11 @@ enum GNUNET_BLOCK_Type */ GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11, + /** + * Block type for a revocation message by which a key is revoked. + */ + GNUNET_BLOCK_TYPE_REVOCATION = 12, + /** * Block to store a cadet regex state */ diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h index b76b9f9cf..9e3e72a21 100644 --- a/src/include/gnunet_plugin_lib.h +++ b/src/include/gnunet_plugin_lib.h @@ -87,7 +87,7 @@ GNUNET_PLUGIN_load (const char *library_name, /** - * Signature of a function called by 'GNUNET_PLUGIN_load_all'. + * Signature of a function called by #GNUNET_PLUGIN_load_all(). * * @param cls closure * @param library_name full name of the library (to be used with diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c index 0b3ef703e..287ecf905 100644 --- a/src/regex/plugin_block_regex.c +++ b/src/regex/plugin_block_regex.c @@ -395,7 +395,7 @@ libgnunet_plugin_block_regex_init (void *cls) void * libgnunet_plugin_block_regex_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am index 541c7120d..82755b485 100644 --- a/src/revocation/Makefile.am +++ b/src/revocation/Makefile.am @@ -1,6 +1,8 @@ # This Makefile.am is in the public domain AM_CPPFLAGS = -I$(top_srcdir)/src/include +plugindir = $(libdir)/gnunet + if MINGW WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols endif @@ -21,6 +23,20 @@ bin_PROGRAMS = \ gnunet-revocation +plugin_LTLIBRARIES = \ + libgnunet_plugin_block_revocation.la + +libgnunet_plugin_block_revocation_la_SOURCES = \ + plugin_block_revocation.c +libgnunet_plugin_block_revocation_la_LIBADD = \ + libgnunetrevocation.la \ + $(top_builddir)/src/block/libgnunetblockgroup.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(LTLIBINTL) +libgnunet_plugin_block_revocation_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) + + gnunet_revocation_SOURCES = \ gnunet-revocation.c gnunet_revocation_LDADD = \ @@ -86,4 +102,3 @@ test_local_revocation.py: test_local_revocation.py.in Makefile EXTRA_DIST = test_revocation.conf \ test_local_revocation.py.in - diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 99bec1fc8..9d077f874 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -38,6 +38,7 @@ #include "platform.h" #include #include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" #include "gnunet_constants.h" #include "gnunet_protocols.h" #include "gnunet_signatures.h" @@ -215,7 +216,7 @@ client_connect_cb (void *cls, * @param client the new client * @param app_cls must alias @a client */ -static void +static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls) @@ -352,7 +353,7 @@ publicize_rm (const struct RevokeMessage *rm) GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); /* add to set for future connections */ e.size = htons (rm->header.size); - e.element_type = 0; + e.element_type = GNUNET_BLOCK_TYPE_REVOCATION; e.data = rm; if (GNUNET_OK != GNUNET_SET_add_element (revocation_set, @@ -452,11 +453,12 @@ add_revocation (void *cls, GNUNET_break_op (0); return; } - if (0 != element->element_type) + if (GNUNET_BLOCK_TYPE_REVOCATION != element->element_type) { GNUNET_STATISTICS_update (stats, gettext_noop ("# unsupported revocations received via set union"), - 1, GNUNET_NO); + 1, + GNUNET_NO); return; } rm = element->data; @@ -604,12 +606,12 @@ handle_core_disconnect (void *cls, void *internal_cls) { struct PeerEntry *peer_entry = internal_cls; - + if (0 == memcmp (peer, &my_identity, sizeof (my_identity))) return; - GNUNET_assert (NULL != peer_entry); + GNUNET_assert (NULL != peer_entry); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us\n", GNUNET_i2s (peer)); @@ -783,7 +785,7 @@ handle_revocation_union_request (void *cls, static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) + struct GNUNET_SERVICE_Handle *service) { struct GNUNET_MQ_MessageHandler core_handlers[] = { GNUNET_MQ_hd_fixed_size (p2p_revoke, diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c new file mode 100644 index 000000000..eb0766b81 --- /dev/null +++ b/src/revocation/plugin_block_revocation.c @@ -0,0 +1,257 @@ +/* + This file is part of GNUnet + Copyright (C) 2017 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 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. +*/ + +/** + * @file block/plugin_block_revocation.c + * @brief revocation for a block plugin + * @author Christian Grothoff + */ + +#include "platform.h" +#include "gnunet_signatures.h" +#include "gnunet_block_plugin.h" +#include "gnunet_block_group_lib.h" +#include "revocation.h" +#include "gnunet_revocation_service.h" + +#define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING + +/** + * Number of bits we set per entry in the bloomfilter. + * Do not change! + */ +#define BLOOMFILTER_K 16 + + +/** + * How big is the BF we use for DHT blocks? + */ +#define REVOCATION_BF_SIZE 8 + + +/** + * Context used inside the plugin. + */ +struct InternalContext +{ + + unsigned int matching_bits; + +}; + + +/** + * Create a new block group. + * + * @param ctx block context in which the block group is created + * @param type type of the block for which we are creating the group + * @param nonce random value used to seed the group creation + * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh + * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh + * @param va variable arguments specific to @a type + * @return block group handle, NULL if block groups are not supported + * by this @a type of block (this is not an error) + */ +static struct GNUNET_BLOCK_Group * +block_plugin_revocation_create_group (void *cls, + enum GNUNET_BLOCK_Type type, + uint32_t nonce, + const void *raw_data, + size_t raw_data_size, + va_list va) +{ + unsigned int bf_size; + const char *guard; + + guard = va_arg (va, const char *); + if (0 == strcmp (guard, + "seen-set-size")) + bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), + BLOOMFILTER_K); + else if (0 == strcmp (guard, + "filter-size")) + bf_size = va_arg (va, unsigned int); + else + { + GNUNET_break (0); + bf_size = REVOCATION_BF_SIZE; + } + GNUNET_break (NULL == va_arg (va, const char *)); + return GNUNET_BLOCK_GROUP_bf_create (cls, + bf_size, + BLOOMFILTER_K, + type, + nonce, + raw_data, + raw_data_size); +} + + +/** + * Function called to validate a reply or a request. For + * request evaluation, simply pass "NULL" for the reply_block. + * + * @param cls our `struct InternalContext` + * @param ctx context + * @param type block type + * @param group block group to use + * @param eo control flags + * @param query original query (hash) + * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery_size number of bytes in xquery + * @param reply_block response to validate + * @param reply_block_size number of bytes in reply block + * @return characterization of result + */ +static enum GNUNET_BLOCK_EvaluationResult +block_plugin_revocation_evaluate (void *cls, + struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BLOCK_Group *group, + enum GNUNET_BLOCK_EvaluationOptions eo, + const struct GNUNET_HashCode *query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) +{ + struct InternalContext *ic = cls; + struct GNUNET_HashCode chash; + const struct RevokeMessage *rm = reply_block; + + if (NULL == reply_block) + return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + if (reply_block_size != sizeof (*rm)) + { + GNUNET_break_op (0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if (GNUNET_YES != + GNUNET_REVOCATION_check_pow (&rm->public_key, + rm->proof_of_work, + ic->matching_bits)) + { + GNUNET_break_op (0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_REVOCATION, + &rm->purpose, + &rm->signature, + &rm->public_key)) + { + GNUNET_break_op (0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + GNUNET_CRYPTO_hash (&rm->public_key, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), + &chash); + if (GNUNET_YES == + GNUNET_BLOCK_GROUP_bf_test_and_set (group, + &chash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; +} + + +/** + * Function called to obtain the key for a block. + * + * @param cls closure + * @param type block type + * @param block block to get the key for + * @param block_size number of bytes in block + * @param key set to the key (query) for the given block + * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported + * (or if extracting a key from a block of this type does not work) + */ +static int +block_plugin_revocation_get_key (void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + struct GNUNET_HashCode *key) +{ + const struct RevokeMessage *rm = block; + + if (block_size != sizeof (*rm)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_CRYPTO_hash (&rm->public_key, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), + key); + return GNUNET_OK; +} + + +/** + * Entry point for the plugin. + * + * @param cls the configuration to use + */ +void * +libgnunet_plugin_block_revocation_init (void *cls) +{ + static enum GNUNET_BLOCK_Type types[] = + { + GNUNET_BLOCK_TYPE_REVOCATION, + GNUNET_BLOCK_TYPE_ANY /* end of list */ + }; + const struct GNUNET_CONFIGURATION_Handle *cfg = cls; + struct GNUNET_BLOCK_PluginFunctions *api; + struct InternalContext *ic; + unsigned long long matching_bits; + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg, + "REVOCATION", + "WORKBITS", + &matching_bits)) + return NULL; + + api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api->evaluate = &block_plugin_revocation_evaluate; + api->get_key = &block_plugin_revocation_get_key; + api->create_group = &block_plugin_revocation_create_group; + api->types = types; + ic = GNUNET_new (struct InternalContext); + ic->matching_bits = (unsigned int) matching_bits; + api->cls = ic; + return api; +} + + +/** + * Exit point from the plugin. + */ +void * +libgnunet_plugin_block_revocation_done (void *cls) +{ + struct GNUNET_BLOCK_PluginFunctions *api = cls; + struct InternalContext *ic = api->cls; + + GNUNET_free (ic); + GNUNET_free (api); + return NULL; +} + +/* end of plugin_block_revocation.c */ diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c index c4f73abe0..01b0c8602 100644 --- a/src/set/plugin_block_set_test.c +++ b/src/set/plugin_block_set_test.c @@ -114,7 +114,7 @@ libgnunet_plugin_block_set_test_init (void *cls) void * libgnunet_plugin_block_set_test_done (void *cls) { - struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + struct GNUNET_BLOCK_PluginFunctions *api = cls; GNUNET_free (api); return NULL; -- cgit v1.2.3 From 67935d7aa1090eed2eb00212741dcc4d13c0bb40 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 04:07:26 +0100 Subject: completing sq_result_helper --- src/include/gnunet_sq_lib.h | 4 +- src/pq/pq_result_helper.c | 50 +--- src/sq/sq.c | 2 + src/sq/sq_result_helper.c | 553 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 561 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h index 4484c2851..c03f83e07 100644 --- a/src/include/gnunet_sq_lib.h +++ b/src/include/gnunet_sq_lib.h @@ -252,7 +252,9 @@ struct GNUNET_SQ_ResultSpec size_t dst_size; /** - * Where to store actual size of the result. + * Where to store actual size of the result. If left at + * NULL, will be made to point to @e dst_size before + * @a conv is called. */ size_t *result_size; diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 180c5fc18..c5c8e56b9 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -77,9 +77,7 @@ extract_varsize_blob (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -156,9 +154,7 @@ extract_fixed_blob (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -173,11 +169,7 @@ extract_fixed_blob (void *cls, fnum); if (*dst_size != len) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' has wrong size (got %u, expected %u)\n", - fname, - (unsigned int) len, - (unsigned int) *dst_size); + GNUNET_break (0); return GNUNET_SYSERR; } res = PQgetvalue (result, @@ -243,9 +235,7 @@ extract_rsa_public_key (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -265,9 +255,7 @@ extract_rsa_public_key (void *cls, len); if (NULL == *pk) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' contains bogus value (fails to decode)\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } return GNUNET_OK; @@ -346,9 +334,7 @@ extract_rsa_signature (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -368,9 +354,7 @@ extract_rsa_signature (void *cls, len); if (NULL == *sig) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' contains bogus value (fails to decode)\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } return GNUNET_OK; @@ -449,9 +433,7 @@ extract_string (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -471,9 +453,7 @@ extract_string (void *cls, len); if (NULL == *str) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' contains bogus value (fails to decode)\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } return GNUNET_OK; @@ -583,9 +563,7 @@ extract_uint16 (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -655,9 +633,7 @@ extract_uint32 (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, @@ -727,9 +703,7 @@ extract_uint64 (void *cls, fname); if (fnum < 0) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Field `%s' does not exist in result\n", - fname); + GNUNET_break (0); return GNUNET_SYSERR; } if (PQgetisnull (result, diff --git a/src/sq/sq.c b/src/sq/sq.c index 47fcaf24e..dc4416761 100644 --- a/src/sq/sq.c +++ b/src/sq/sq.c @@ -75,6 +75,8 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result, for (unsigned int i=0;NULL != rs[i].conv; i++) { + if (NULL == rs[i].result_size) + rs[i].result_size = &rs[i].dst_size; if (GNUNET_OK != rs[i].conv (rs[i].cls, result, diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c index 36ce53317..9ac2e2533 100644 --- a/src/sq/sq_result_helper.c +++ b/src/sq/sq_result_helper.c @@ -24,26 +24,75 @@ /** - * Extract fixed-sized binary data from a Postgres database @a result at row @a row. + * Extract variable-sized binary data from a Postgres database @a result at row @a row. * * @param cls closure * @param result where to extract data from - * @param row row to extract data from * @param column column to extract data from * @param[in,out] dst_size where to store size of result, may be NULL - * @param[out] dst where to store the result + * @param[out] dst where to store the result (actually a `void **`) * @return * #GNUNET_YES if all results could be extracted * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) */ static int -extract_fixed_blob (void *cls, - sqlite3_stmt *result, - int row, - unsigned int column, - size_t *dst_size, - void *dst) +extract_var_blob (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) { + int have; + const void *ret; + void **rdst = (void **) dst; + + if (SQLITE_BLOB != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* sqlite manual says to invoke 'sqlite3_column_blob()' + before calling sqlite3_column_bytes() */ + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); + if (have < 0) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *dst_size = have; + if (0 == have) + { + *rdst = NULL; + return GNUNET_OK; + } + *rdst = GNUNET_malloc (have); + GNUNET_memcpy (*rdst, + ret, + have); + return GNUNET_OK; +} + + +/** + * Cleanup memory allocated by #extract_var_blob(). + * + * @param cls pointer to pointer of allocation + */ +static void +clean_var_blob (void *cls) +{ + void **dptr = (void **) cls; + + if (NULL != *dptr) + { + GNUNET_free (*dptr); + *dptr = NULL; + } } @@ -58,6 +107,62 @@ struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size (void **dst, size_t *sptr) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_var_blob, + .cleaner = &clean_var_blob, + .cls = dst, + .result_size = sptr, + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract fixed-sized binary data from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_fixed_blob (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + int have; + const void *ret; + + if (SQLITE_BLOB != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* sqlite manual says to invoke 'sqlite3_column_blob()' + before calling sqlite3_column_bytes() */ + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); + if (*dst_size != have) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + GNUNET_memcpy (dst, + ret, + have); + return GNUNET_OK; } @@ -72,6 +177,76 @@ struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size (void *dst, size_t dst_size) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_fixed_blob, + .dst = dst, + .dst_size = dst_size, + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract fixed-sized binary data from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_utf8_string (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + const char *text; + char **rdst = dst; + + if (SQLITE_TEXT != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* sqlite manual guarantees that 'sqlite3_column_text()' + is 0-terminated */ + text = (const char *) sqlite3_column_text (result, + column); + if (NULL == text) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *dst_size = strlen (text) + 1; + *rdst = GNUNET_strdup (text); + return GNUNET_OK; +} + + +/** + * Cleanup memory allocated by #extract_var_blob(). + * + * @param cls pointer to pointer of allocation + */ +static void +clean_utf8_string (void *cls) +{ + char **dptr = (char **) cls; + + if (NULL != *dptr) + { + GNUNET_free (*dptr); + *dptr = NULL; + } } @@ -84,6 +259,87 @@ GNUNET_SQ_result_spec_fixed_size (void *dst, struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string (char **dst) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_utf8_string, + .cleaner = &clean_utf8_string, + .cls = dst, + .dst = dst, + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract data from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_rsa_pub (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + struct GNUNET_CRYPTO_RsaPublicKey **pk = dst; + int have; + const void *ret; + + if (SQLITE_BLOB != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* sqlite manual says to invoke 'sqlite3_column_blob()' + before calling sqlite3_column_bytes() */ + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); + if (have < 0) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + *pk = GNUNET_CRYPTO_rsa_public_key_decode (ret, + have); + if (NULL == *pk) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + +/** + * Function called to clean up memory allocated + * by a #GNUNET_PQ_ResultConverter. + * + * @param cls closure + */ +static void +clean_rsa_pub (void *cls) +{ + struct GNUNET_CRYPTO_RsaPublicKey **pk = cls; + + if (NULL != *pk) + { + GNUNET_CRYPTO_rsa_public_key_free (*pk); + *pk = NULL; + } } @@ -96,6 +352,87 @@ GNUNET_SQ_result_spec_string (char **dst) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_rsa_pub, + .cleaner = &clean_rsa_pub, + .dst = rsa, + .cls = rsa, + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract data from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_rsa_sig (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + struct GNUNET_CRYPTO_RsaSignature **sig = dst; + int have; + const void *ret; + + if (SQLITE_BLOB != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + /* sqlite manual says to invoke 'sqlite3_column_blob()' + before calling sqlite3_column_bytes() */ + ret = sqlite3_column_blob (result, + column); + have = sqlite3_column_bytes (result, + column); + if (have < 0) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + *sig = GNUNET_CRYPTO_rsa_signature_decode (ret, + have); + if (NULL == *sig) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + +/** + * Function called to clean up memory allocated + * by a #GNUNET_PQ_ResultConverter. + * + * @param cls result data to clean up + */ +static void +clean_rsa_sig (void *cls) +{ + struct GNUNET_CRYPTO_RsaSignature **sig = cls; + + if (NULL != *sig) + { + GNUNET_CRYPTO_rsa_signature_free (*sig); + *sig = NULL; + } } @@ -108,6 +445,15 @@ GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_rsa_sig, + .cleaner = &clean_rsa_sig, + .dst = sig, + .cls = sig, + .num_params = 1 + }; + + return rs; } @@ -120,6 +466,44 @@ GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) { + return GNUNET_SQ_result_spec_uint64 (&at->abs_value_us); +} + + +/** + * Extract absolute time value in NBO from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_abs_time_nbo (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + struct GNUNET_TIME_AbsoluteNBO *u = dst; + struct GNUNET_TIME_Absolute t; + + GNUNET_assert (sizeof (uint64_t) == *dst_size); + if (SQLITE_INTEGER != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + t.abs_value_us = (uint64_t) sqlite3_column_int64 (result, + column); + *u = GNUNET_TIME_absolute_hton (t); + return GNUNET_OK; } @@ -132,6 +516,56 @@ GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_abs_time_nbo, + .dst = at, + .dst_size = sizeof (struct GNUNET_TIME_AbsoluteNBO), + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract 16-bit integer from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_uint16 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + uint64_t v; + uint32_t *u = dst; + + GNUNET_assert (sizeof (uint16_t) == *dst_size); + if (SQLITE_INTEGER != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + v = (uint64_t) sqlite3_column_int64 (result, + column); + if (v > UINT16_MAX) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint16_t) v; + return GNUNET_OK; } @@ -144,6 +578,56 @@ GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16 (uint16_t *u16) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_uint16, + .dst = u16, + .dst_size = sizeof (uint16_t), + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract 32-bit integer from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_uint32 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + uint64_t v; + uint32_t *u = dst; + + GNUNET_assert (sizeof (uint32_t) == *dst_size); + if (SQLITE_INTEGER != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + v = (uint64_t) sqlite3_column_int64 (result, + column); + if (v > UINT32_MAX) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint32_t) v; + return GNUNET_OK; } @@ -156,6 +640,49 @@ GNUNET_SQ_result_spec_uint16 (uint16_t *u16) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32 (uint32_t *u32) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_uint32, + .dst = u32, + .dst_size = sizeof (uint32_t), + .num_params = 1 + }; + + return rs; +} + + +/** + * Extract 64-bit integer from a Postgres database @a result at row @a row. + * + * @param cls closure + * @param result where to extract data from + * @param column column to extract data from + * @param[in,out] dst_size where to store size of result, may be NULL + * @param[out] dst where to store the result + * @return + * #GNUNET_YES if all results could be extracted + * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) + */ +static int +extract_uint64 (void *cls, + sqlite3_stmt *result, + unsigned int column, + size_t *dst_size, + void *dst) +{ + uint64_t *u = dst; + + GNUNET_assert (sizeof (uint64_t) == *dst_size); + if (SQLITE_INTEGER != + sqlite3_column_type (result, + column)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + *u = (uint64_t) sqlite3_column_int64 (result, + column); + return GNUNET_OK; } @@ -168,6 +695,14 @@ GNUNET_SQ_result_spec_uint32 (uint32_t *u32) struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64 (uint64_t *u64) { + struct GNUNET_SQ_ResultSpec rs = { + .conv = &extract_uint64, + .dst = u64, + .dst_size = sizeof (uint64_t), + .num_params = 1 + }; + + return rs; } -- cgit v1.2.3 From cb130cc9dfc179e3b6cb9f19a7b559106efa3b33 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 05:25:49 +0100 Subject: fix sq logic, add to build --- src/Makefile.am | 5 +++++ src/sq/sq_result_helper.c | 1 + 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 21d4ee818..e466cbc28 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,10 @@ CONVERSATION_DIR = conversation endif endif +if HAVE_SQLITE + SQLITE_DIR = sq +endif + if HAVE_MYSQL MYSQL_DIR = mysql my endif @@ -78,6 +82,7 @@ SUBDIRS = \ arm \ $(TESTING) \ peerinfo \ + $(SQLITE_DIR) \ $(MYSQL_DIR) \ $(POSTGRES_DIR) \ datacache \ diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c index 9ac2e2533..eaf606aa4 100644 --- a/src/sq/sq_result_helper.c +++ b/src/sq/sq_result_helper.c @@ -110,6 +110,7 @@ GNUNET_SQ_result_spec_variable_size (void **dst, struct GNUNET_SQ_ResultSpec rs = { .conv = &extract_var_blob, .cleaner = &clean_var_blob, + .dst = dst, .cls = dst, .result_size = sptr, .num_params = 1 -- cgit v1.2.3 From ebb8d4e79c9ea21befad74973da051fa09efb0d0 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 02:14:27 +0100 Subject: consensus: slack-a2a evilness mode and static replication in profiler --- src/consensus/gnunet-consensus-profiler.c | 52 ++++++++++++++++++++++--------- src/consensus/gnunet-service-consensus.c | 18 +++++++++++ 2 files changed, 56 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c index 290263d95..65542f4cd 100644 --- a/src/consensus/gnunet-consensus-profiler.c +++ b/src/consensus/gnunet-consensus-profiler.c @@ -55,6 +55,8 @@ static struct GNUNET_HashCode session_id; static unsigned int peers_done = 0; +static int dist_static; + static unsigned *results_for_peer; /** @@ -217,26 +219,45 @@ do_consensus () { int unique_indices[replication]; unsigned int i; + unsigned int j; + struct GNUNET_HashCode val; + struct GNUNET_SET_Element element; - for (i = 0; i < num_values; i++) + if (dist_static) { - unsigned int j; - struct GNUNET_HashCode val; - struct GNUNET_SET_Element element; + for (i = 0; i < num_values; i++) + { - generate_indices (unique_indices); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val); - element.data = &val; - element.size = sizeof (val); - for (j = 0; j < replication; j++) + element.data = &val; + element.size = sizeof (val); + for (j = 0; j < replication; j++) + { + GNUNET_CONSENSUS_insert (consensus_handles[j], + &element, + NULL, NULL); + } + } + } + else + { + for (i = 0; i < num_values; i++) { - int cid; + generate_indices (unique_indices); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val); - cid = unique_indices[j]; - GNUNET_CONSENSUS_insert (consensus_handles[cid], - &element, - NULL, NULL); + element.data = &val; + element.size = sizeof (val); + for (j = 0; j < replication; j++) + { + int cid; + + cid = unique_indices[j]; + GNUNET_CONSENSUS_insert (consensus_handles[cid], + &element, + NULL, NULL); + } } } @@ -513,6 +534,9 @@ main (int argc, char **argv) { 's', "statistics", NULL, gettext_noop ("write statistics to file"), GNUNET_YES, &GNUNET_GETOPT_set_filename, &statistics_filename }, + { 'S', "dist-static", NULL, + gettext_noop ("distribute elements to a static subset of good peers"), + GNUNET_YES, &GNUNET_GETOPT_set_one, &dist_static }, { 'V', "verbose", NULL, gettext_noop ("be more verbose (print received values)"), GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose }, diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index 6662ae8ca..b934f468f 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c @@ -1153,6 +1153,7 @@ enum EvilnessType EVILNESS_CRAM_LEAD, EVILNESS_CRAM_ECHO, EVILNESS_SLACK, + EVILNESS_SLACK_A2A, }; enum EvilnessSubType @@ -1245,6 +1246,10 @@ get_evilness (struct ConsensusSession *session, struct Evilness *evil) { evil->type = EVILNESS_SLACK; } + if (0 == strcmp ("slack-a2a", evil_type_str)) + { + evil->type = EVILNESS_SLACK_A2A; + } else if (0 == strcmp ("cram-all", evil_type_str)) { evil->type = EVILNESS_CRAM_ALL; @@ -1417,6 +1422,19 @@ commit_set (struct ConsensusSession *session, "P%u: evil peer: slacking\n", (unsigned int) session->local_peer_idx); /* Do nothing. */ + case EVILNESS_SLACK_A2A: + if ( (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind ) || + (PHASE_KIND_ALL_TO_ALL == task->key.kind) ) + { + struct GNUNET_SET_Handle *empty_set; + empty_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); + GNUNET_SET_commit (setop->op, empty_set); + GNUNET_SET_destroy (empty_set); + } + else + { + GNUNET_SET_commit (setop->op, set->h); + } break; case EVILNESS_NONE: GNUNET_SET_commit (setop->op, set->h); -- cgit v1.2.3 From 62722a6898c5e0420893140326edcb64ebd1ea99 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 13:19:56 +0100 Subject: logging --- src/set/gnunet-service-set_union.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index c69aa2a9c..b8e210f54 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -1560,6 +1560,10 @@ handle_p2p_full_element (void *cls, (op->state->received_fresh < op->state->received_total / 3) ) { /* The other peer gave us lots of old elements, there's something wrong. */ + LOG (GNUNET_ERROR_TYPE_ERROR, + "Other peer sent only %llu/%llu fresh elements, failing operation\n", + (unsigned long long) op->state->received_fresh, + (unsigned long long) op->state->received_total); GNUNET_break_op (0); fail_union_operation (op); return; -- cgit v1.2.3 From c5b8b75adb5428bee0fdd52d89fe9e829f33a752 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 13:24:58 +0100 Subject: higher constant before applying limit --- src/set/gnunet-service-set_union.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index b8e210f54..a19c36206 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -1556,7 +1556,7 @@ handle_p2p_full_element (void *cls, } if ( (GNUNET_YES == op->spec->byzantine) && - (op->state->received_total > 8) && + (op->state->received_total > 150) && (op->state->received_fresh < op->state->received_total / 3) ) { /* The other peer gave us lots of old elements, there's something wrong. */ -- cgit v1.2.3 From c9e806d1862c68a7ae765127982622311304a928 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 13:36:13 +0100 Subject: don't run set with valgrind per default --- src/consensus/test_consensus.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/consensus/test_consensus.conf b/src/consensus/test_consensus.conf index c75205739..d1b33c4fd 100644 --- a/src/consensus/test_consensus.conf +++ b/src/consensus/test_consensus.conf @@ -41,7 +41,7 @@ OPTIONS = -LERROR [set] #OPTIONS = -L INFO #PREFIX = valgrind --leak-check=full -PREFIX = valgrind +#PREFIX = valgrind [testbed] OVERLAY_TOPOLOGY = CLIQUE -- cgit v1.2.3 From 6588438f94ba8053f8b4917b9b30a5165e9181ad Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 14:38:56 +0100 Subject: misc minor fixes --- src/cadet/gnunet-service-cadet-new.c | 8 +++++--- src/cadet/gnunet-service-cadet-new_channel.c | 10 ++++++---- src/consensus/test_consensus.conf | 13 ++++++++----- src/util/service_new.c | 4 ++-- 4 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index b0a818c7c..de85db5b6 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -716,9 +716,11 @@ handle_local_data (void *cls, msg->ccn); if (NULL == ch) { - /* Channel does not exist! */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); + /* Channel does not exist (anymore) */ + LOG (GNUNET_ERROR_TYPE_WARNING, + "Dropping payload for channel %u from client (channel unknown, other endpoint may have disconnected)\n", + (unsigned int) ntohl (msg->ccn.channel_of_client)); + GNUNET_SERVICE_client_continue (c->client); return; } payload_size = ntohs (msg->header.size) - sizeof (*msg); diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index c418893a8..8769601c2 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -1618,7 +1618,8 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, return; } ccc = (NULL != ch->owner) ? ch->owner : ch->dest; - if (NULL != ccc->head_recv) + if ( (NULL != ccc) && + (NULL != ccc->head_recv) ) { LOG (GNUNET_ERROR_TYPE_WARNING, "Lost end of transmission due to remote shutdown on %s\n", @@ -1626,9 +1627,10 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, /* FIXME: change API to notify client about truncated transmission! */ } ch->destroy = GNUNET_YES; - GSC_handle_remote_channel_destroy (ccc->c, - ccc->ccn, - ch); + if (NULL != ccc) + GSC_handle_remote_channel_destroy (ccc->c, + ccc->ccn, + ch); channel_destroy (ch); } diff --git a/src/consensus/test_consensus.conf b/src/consensus/test_consensus.conf index d1b33c4fd..f78b77d09 100644 --- a/src/consensus/test_consensus.conf +++ b/src/consensus/test_consensus.conf @@ -17,19 +17,22 @@ BINARY = gnunet-service-evil-consensus RESOURCE_DIAGNOSTICS = resource.log.${PEERID:-master} [core] -FORECESTART = YES +FORCESTART = YES [revocation] -FORECESTART = NO +FORCESTART = NO [fs] -FORECESTART = NO +FORCESTART = NO [gns] -FORECESTART = NO +FORCESTART = NO + +[zonemaster] +FORCESTART = NO [hostlist] -FORECESTART = NO +FORCESTART = NO [cadet] #PREFIX = valgrind diff --git a/src/util/service_new.c b/src/util/service_new.c index 8371f7703..22eec0bde 100644 --- a/src/util/service_new.c +++ b/src/util/service_new.c @@ -2402,8 +2402,8 @@ resume_client_receive (void *cls) GNUNET_YES); if (GNUNET_SYSERR == ret) { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c); + if (NULL != c->drop_task) + GNUNET_SERVICE_client_drop (c); return; } if (GNUNET_NO == ret) -- cgit v1.2.3 From e0a04a70bbb2f89a7346e67de026b6c78f22dd7c Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Tue, 28 Feb 2017 14:49:43 +0100 Subject: multicast: fix replay_req_remove_client() --- src/multicast/gnunet-service-multicast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index d8a9c8f93..b068f1308 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c @@ -518,7 +518,7 @@ replay_req_remove_client (struct Group *grp, struct GNUNET_SERVICE_Client *clien { if (c == client) { - GNUNET_CONTAINER_multihashmap_remove (replay_req_client, &key, client); + GNUNET_CONTAINER_multihashmap_remove (grp_replay_req, &key, client); GNUNET_CONTAINER_multihashmap_iterator_destroy (it); return GNUNET_YES; } -- cgit v1.2.3 From 7079032ef4d9db825b158e564434205af497f27f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 14:53:32 +0100 Subject: fix some breaks, add stats for encrypted/decrypted bytes in CADET --- src/cadet/cadet_api_new.c | 11 ++++++----- src/cadet/gnunet-service-cadet-new.c | 8 +++++--- src/cadet/gnunet-service-cadet-new_tunnels.c | 12 ++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/cadet/cadet_api_new.c b/src/cadet/cadet_api_new.c index a62de0a47..efdb6d8a6 100644 --- a/src/cadet/cadet_api_new.c +++ b/src/cadet/cadet_api_new.c @@ -626,7 +626,6 @@ handle_channel_created (void *cls, struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg; struct GNUNET_MQ_Envelope *env; - GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channel %X (on port %s, recently closed?)\n", ntohl (ccn.channel_of_client), @@ -682,16 +681,18 @@ handle_channel_destroy (void *cls, struct GNUNET_CADET_Handle *h = cls; struct GNUNET_CADET_Channel *ch; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received channel destroy for channel %X from CADET service\n", - ntohl (msg->ccn.channel_of_client)); ch = find_channel (h, msg->ccn); if (NULL == ch) { - GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received channel destroy for unknown channel %X from CADET service\n", + ntohl (msg->ccn.channel_of_client)); return; } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received channel destroy for channel %X from CADET service\n", + ntohl (msg->ccn.channel_of_client)); destroy_channel (ch); } diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index de85db5b6..02126d57d 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -760,9 +760,11 @@ handle_local_ack (void *cls, msg->ccn); if (NULL == ch) { - /* Channel does not exist! */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); + /* Channel does not exist (anymore) */ + LOG (GNUNET_ERROR_TYPE_WARNING, + "Ignoring local ACK for channel %u from client (channel unknown, other endpoint may have disconnected)\n", + (unsigned int) ntohl (msg->ccn.channel_of_client)); + GNUNET_SERVICE_client_continue (c->client); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c index bf05fae6b..d50860629 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.c +++ b/src/cadet/gnunet-service-cadet-new_tunnels.c @@ -3082,10 +3082,6 @@ GCT_handle_encrypted (struct CadetTConnection *ct, break; } - GNUNET_STATISTICS_update (stats, - "# received encrypted", - 1, - GNUNET_NO); decrypted_size = -1; if (CADET_TUNNEL_KEY_OK == t->estate) { @@ -3166,6 +3162,10 @@ GCT_handle_encrypted (struct CadetTConnection *ct, &t->ax); return; } + GNUNET_STATISTICS_update (stats, + "# decrypted bytes", + decrypted_size, + GNUNET_NO); /* The MST will ultimately call #handle_decrypted() on each message. */ t->current_ct = ct; @@ -3217,6 +3217,10 @@ GCT_send (struct CadetTunnel *t, &ax_msg[1], message, payload_size); + GNUNET_STATISTICS_update (stats, + "# encrypted bytes", + payload_size, + GNUNET_NO); ax_msg->ax_header.Ns = htonl (t->ax.Ns++); ax_msg->ax_header.PNs = htonl (t->ax.PNs); /* FIXME: we should do this once, not once per message; -- cgit v1.2.3 From b567a7a9231f91f0c5f7c074bb6904471e3f85ad Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 14:56:37 +0100 Subject: more stats for happy Florian --- src/cadet/gnunet-service-cadet-new.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index 02126d57d..93f53de4c 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -724,6 +724,10 @@ handle_local_data (void *cls, return; } payload_size = ntohs (msg->header.size) - sizeof (*msg); + GNUNET_STATISTICS_update (stats, + "# payload received from clients", + payload_size, + GNUNET_NO); buf = (const char *) &msg[1]; LOG (GNUNET_ERROR_TYPE_DEBUG, "Received %u bytes payload from %s for %s\n", -- cgit v1.2.3 From d0b5f5ba30665a8a25cec029e298a4f2c575df14 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 15:19:15 +0100 Subject: start with larger IBF --- src/set/gnunet-service-set_union.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index a19c36206..1a421063e 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -761,7 +761,8 @@ get_order_from_difference (unsigned int diff) ibf_order++; if (ibf_order > MAX_IBF_ORDER) ibf_order = MAX_IBF_ORDER; - return ibf_order; + // add one for correction + return ibf_order + 1; } @@ -1556,7 +1557,7 @@ handle_p2p_full_element (void *cls, } if ( (GNUNET_YES == op->spec->byzantine) && - (op->state->received_total > 150) && + (op->state->received_total > 128) && (op->state->received_fresh < op->state->received_total / 3) ) { /* The other peer gave us lots of old elements, there's something wrong. */ -- cgit v1.2.3 From 1ba3554564c3d1b1110f5db9c37df498dee0cb9b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 15:21:32 +0100 Subject: do not bitch at CADET for issues that can happen in normal operation --- src/cadet/cadet_api_new.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/cadet/cadet_api_new.c b/src/cadet/cadet_api_new.c index efdb6d8a6..2d5d853b3 100644 --- a/src/cadet/cadet_api_new.c +++ b/src/cadet/cadet_api_new.c @@ -686,7 +686,7 @@ handle_channel_destroy (void *cls, if (NULL == ch) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received channel destroy for unknown channel %X from CADET service\n", + "Received channel destroy for unknown channel %X from CADET service (recently close?)\n", ntohl (msg->ccn.channel_of_client)); return; } @@ -709,8 +709,6 @@ static int check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) { - struct GNUNET_CADET_Handle *h = cls; - struct GNUNET_CADET_Channel *ch; uint16_t size; size = ntohs (message->header.size); @@ -719,15 +717,6 @@ check_local_data (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } - - ch = find_channel (h, - message->ccn); - if (NULL == ch) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_OK; } @@ -752,8 +741,9 @@ handle_local_data (void *cls, message->ccn); if (NULL == ch) { - GNUNET_break (0); - reconnect (h); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Unknown channel %X for incoming data (recently closed?)\n", + ntohl (message->ccn.channel_of_client)); return; } -- cgit v1.2.3 From f56a318a49c109d0246d4b5d188cffb50d2b91c8 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 15:34:29 +0100 Subject: set: more statistics --- src/set/gnunet-service-set_union.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 1a421063e..b51939da0 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -895,6 +895,10 @@ handle_p2p_strata_estimator (void *cls, "Sending full set (diff=%d, own set=%u)\n", diff, op->state->initial_size); + GNUNET_STATISTICS_update (_GSS_statistics, + "# of full sends", + 1, + GNUNET_NO); if (op->state->initial_size <= other_size) { send_full_set (op); @@ -909,6 +913,10 @@ handle_p2p_strata_estimator (void *cls, } else { + GNUNET_STATISTICS_update (_GSS_statistics, + "# of ibf sends", + 1, + GNUNET_NO); if (GNUNET_OK != send_ibf (op, get_order_from_difference (diff))) -- cgit v1.2.3 From b6bfe7cb157d4e64b674419a2f8e8e82f3d82f17 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 15:49:37 +0100 Subject: set: different thresholds --- src/set/gnunet-service-set_union.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index b51939da0..90f52ff47 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -889,7 +889,7 @@ handle_p2p_strata_estimator (void *cls, } - if ( (GNUNET_YES == op->spec->force_full) || (diff > op->state->initial_size / 2)) + if ( (GNUNET_YES == op->spec->force_full) || (diff > op->state->initial_size / 4)) { LOG (GNUNET_ERROR_TYPE_INFO, "Sending full set (diff=%d, own set=%u)\n", @@ -1565,8 +1565,8 @@ handle_p2p_full_element (void *cls, } if ( (GNUNET_YES == op->spec->byzantine) && - (op->state->received_total > 128) && - (op->state->received_fresh < op->state->received_total / 3) ) + (op->state->received_total > 128 + op->state->received_fresh * 4) && + (op->state->received_fresh < op->state->received_total / 6) ) { /* The other peer gave us lots of old elements, there's something wrong. */ LOG (GNUNET_ERROR_TYPE_ERROR, -- cgit v1.2.3 From 5879deb3c2412ede68b6b1d1aad98a7e359a153a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 16:07:46 +0100 Subject: set: adjust strata estimator bias --- src/set/gnunet-service-set_union.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 90f52ff47..f46713c31 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -873,6 +873,10 @@ handle_p2p_strata_estimator (void *cls, GNUNET_assert (NULL != op->state->se); diff = strata_estimator_difference (remote_se, op->state->se); + + if (diff > 200) + diff = diff * 3 / 2; + strata_estimator_destroy (remote_se); strata_estimator_destroy (op->state->se); op->state->se = NULL; @@ -1565,7 +1569,7 @@ handle_p2p_full_element (void *cls, } if ( (GNUNET_YES == op->spec->byzantine) && - (op->state->received_total > 128 + op->state->received_fresh * 4) && + (op->state->received_total > 384 + op->state->received_fresh * 4) && (op->state->received_fresh < op->state->received_total / 6) ) { /* The other peer gave us lots of old elements, there's something wrong. */ -- cgit v1.2.3 From c7df81667de9046ada75fbe15924a426d8b5d765 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 16:53:19 +0100 Subject: set: zero out listener to make tracking down bug easier --- src/set/gnunet-service-set.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 30d43e8a1..3e6e0791a 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -233,6 +233,7 @@ listener_destroy (struct Listener *listener) GNUNET_CONTAINER_DLL_remove (listeners_head, listeners_tail, listener); + *listener = (struct Listener) { 0 }; GNUNET_free (listener); } -- cgit v1.2.3 From c9bc0115c53e10a31ffffb6dbb1cb85e77168dda Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 17:26:05 +0100 Subject: set: destroy client mq properly --- src/consensus/test_consensus.conf | 2 +- src/set/gnunet-service-set.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/consensus/test_consensus.conf b/src/consensus/test_consensus.conf index f78b77d09..036150b7f 100644 --- a/src/consensus/test_consensus.conf +++ b/src/consensus/test_consensus.conf @@ -44,7 +44,7 @@ OPTIONS = -LERROR [set] #OPTIONS = -L INFO #PREFIX = valgrind --leak-check=full -#PREFIX = valgrind +PREFIX = valgrind [testbed] OVERLAY_TOPOLOGY = CLIQUE diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 3e6e0791a..4168685f1 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -223,6 +223,9 @@ listener_destroy (struct Listener *listener) { struct GNUNET_SERVICE_Client *client = listener->client; + GNUNET_MQ_destroy (listener->client_mq); + listener->client_mq = NULL; + listener->client = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting listener client\n"); @@ -233,7 +236,6 @@ listener_destroy (struct Listener *listener) GNUNET_CONTAINER_DLL_remove (listeners_head, listeners_tail, listener); - *listener = (struct Listener) { 0 }; GNUNET_free (listener); } -- cgit v1.2.3 From d1aa49fc2767aa141e83ba664cd1d10b3ad1987b Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 18:14:19 +0100 Subject: set profiler: allow variable element size via -w (width) option --- src/set/gnunet-service-set.c | 82 ++++++++++++++++++++++++------------------- src/set/gnunet-set-profiler.c | 25 ++++++++----- 2 files changed, 62 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 4168685f1..b0f8b2091 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -613,42 +613,6 @@ client_connect_cb (void *cls, } -/** - * Clean up after a client has disconnected - * - * @param cls closure, unused - * @param client the client to clean up after - * @param internal_cls our client-specific internal data structure - */ -static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *internal_cls) -{ - struct Listener *listener; - struct Set *set; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "client disconnected, cleaning up\n"); - set = set_get (client); - if (NULL != set) - { - set->client = NULL; - set_destroy (set); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client's set destroyed\n"); - } - listener = listener_get (client); - if (NULL != listener) - { - listener->client = NULL; - listener_destroy (listener); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client's listener destroyed\n"); - } -} - - /** * Destroy an incoming request from a remote peer * @@ -683,6 +647,52 @@ incoming_destroy (struct Operation *incoming) } +/** + * Clean up after a client has disconnected + * + * @param cls closure, unused + * @param client the client to clean up after + * @param internal_cls our client-specific internal data structure + */ +static void +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) +{ + struct Set *set; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "client disconnected, cleaning up\n"); + set = set_get (client); + if (NULL != set) + { + set->client = NULL; + set_destroy (set); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client's set destroyed\n"); + } + struct Listener *listener = listener_get (client); + struct Operation *op = incoming_head; + if (NULL != listener) + { + /* destroy all incoming operations whose client just + * got destroyed */ + while (NULL != op) + { + struct Operation *curr = op; + op = op->next; + if ( (GNUNET_YES == curr->is_incoming) && + (curr->listener == listener) ) + incoming_destroy (curr); + } + listener->client = NULL; + listener_destroy (listener); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Client's listener destroyed\n"); + } +} + + /** * Suggest the given request to the listener. The listening client can * then accept or reject the remote request. diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index d83e034a6..7de58a0d1 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c @@ -62,6 +62,8 @@ static int byzantine; static int force_delta; static int force_full; +static unsigned int element_length = 32; + /** * Handle to the statistics service. */ @@ -261,15 +263,17 @@ set_insert_iterator (void *cls, 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; - GNUNET_memcpy (&el[1], key, sizeof *key); - el->data = &el[1]; - el->size = sizeof *key; - GNUNET_SET_add_element (set, el, NULL, NULL); + 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; + GNUNET_SET_add_element (set, &el, NULL, NULL); GNUNET_free (el); return GNUNET_YES; } @@ -432,6 +436,9 @@ main (int argc, char **argv) { 'f', "force-full", NULL, gettext_noop ("force sending full set"), GNUNET_NO, &GNUNET_GETOPT_set_uint, &force_full }, + { 'l', "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 }, -- cgit v1.2.3 From 237dd9f9c93cabd29015d0f5e3c8ceff8af3f071 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 18:23:12 +0100 Subject: don't free element that is stack-allocated now --- src/consensus/test_consensus.conf | 4 ++-- src/set/gnunet-set-profiler.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/consensus/test_consensus.conf b/src/consensus/test_consensus.conf index 036150b7f..881251a66 100644 --- a/src/consensus/test_consensus.conf +++ b/src/consensus/test_consensus.conf @@ -5,7 +5,7 @@ GNUNET_TEST_HOME = /tmp/test-consensus/ #OPTIONS = -L INFO BINARY = gnunet-service-evil-consensus -#PREFIX = valgrind +PREFIX = valgrind #EVIL_SPEC = 0;cram-all;noreplace;5 #EVIL_SPEC = 0;cram;5/1;cram;5 @@ -44,7 +44,7 @@ OPTIONS = -LERROR [set] #OPTIONS = -L INFO #PREFIX = valgrind --leak-check=full -PREFIX = valgrind +#PREFIX = valgrind [testbed] OVERLAY_TOPOLOGY = CLIQUE diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 7de58a0d1..a6c900f5e 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c @@ -274,7 +274,6 @@ set_insert_iterator (void *cls, el.data = payload; el.size = element_length; GNUNET_SET_add_element (set, &el, NULL, NULL); - GNUNET_free (el); return GNUNET_YES; } @@ -436,7 +435,7 @@ main (int argc, char **argv) { 'f', "force-full", NULL, gettext_noop ("force sending full set"), GNUNET_NO, &GNUNET_GETOPT_set_uint, &force_full }, - { 'l', "element-length", NULL, + { 'w', "element-length", NULL, gettext_noop ("element length in byte"), GNUNET_NO, &GNUNET_GETOPT_set_uint, &element_length }, { 'd', "force-delta", NULL, -- cgit v1.2.3 From a9a6b98c54f5cc3e680c8ea2f9c69e3955e2a7da Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 18:53:31 +0100 Subject: fix completely broken implementation of variable size elements --- src/set/gnunet-set-profiler.c | 46 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src') 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 }, -- cgit v1.2.3 From 6ece270b1f87ef98a9df8ee6a4c08db4a131b8b9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 28 Feb 2017 19:56:37 +0100 Subject: get rid of warning for missing directory on friends.txt creation --- src/topology/friends.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/topology/friends.c b/src/topology/friends.c index 59c70e4b0..a960fad17 100644 --- a/src/topology/friends.c +++ b/src/topology/friends.c @@ -58,14 +58,20 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, return GNUNET_SYSERR; } if ( (GNUNET_OK != GNUNET_DISK_file_test (fn)) && - (GNUNET_OK != GNUNET_DISK_fn_write (fn, NULL, 0, + (GNUNET_OK != GNUNET_DISK_fn_write (fn, + NULL, + 0, GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) ) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_OPEN_CREATE)) ) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "write", + fn); if ( (GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, - GNUNET_NO, GNUNET_YES)) || + GNUNET_NO, + GNUNET_YES)) || (0 == fsize) ) { GNUNET_free (fn); @@ -93,8 +99,8 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, pos++; if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (&data[start], - pos - start, - &pid.public_key)) + pos - start, + &pid.public_key)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Syntax error in FRIENDS file at offset %llu, skipping bytes `%.*s'.\n"), -- cgit v1.2.3 From 90f6407e2ed835241c29bbd8c57bac47dd76e59c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 20:10:39 +0100 Subject: set: fix make check --- src/set/gnunet-service-set.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index b0f8b2091..454ad9784 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -672,11 +672,12 @@ client_disconnect_cb (void *cls, "Client's set destroyed\n"); } struct Listener *listener = listener_get (client); - struct Operation *op = incoming_head; if (NULL != listener) { /* destroy all incoming operations whose client just * got destroyed */ + //struct Operation *op = incoming_head; + /* while (NULL != op) { struct Operation *curr = op; @@ -685,6 +686,7 @@ client_disconnect_cb (void *cls, (curr->listener == listener) ) incoming_destroy (curr); } + */ listener->client = NULL; listener_destroy (listener); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, -- cgit v1.2.3 From 4bf1d97b60faba3b75e0964678b3834bd859475f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 20:24:24 +0100 Subject: allow destruction while iteration is active --- src/set/set_api.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/set/set_api.c b/src/set/set_api.c index 5b5b1b8ee..04a4e4910 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c @@ -349,6 +349,9 @@ handle_iter_done (void *cls, set->iteration_id++; iter (set->iterator_cls, NULL); + + if (GNUNET_YES == set->destroy_requested) + GNUNET_SET_destroy (set); } @@ -733,8 +736,7 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) /* destroying set while iterator is active is currently not supported; we should expand the API to allow clients to explicitly cancel the iteration! */ - GNUNET_assert (NULL == set->iterator); - if (NULL != set->ops_head) + if ( (NULL != set->ops_head) || (NULL != set->iterator) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Set operations are pending, delaying set destruction\n"); -- cgit v1.2.3 From 50034dd9abff47b5e81a5d91128fd3cb6ae906d5 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Feb 2017 20:43:12 +0100 Subject: consensus: destroy set handles --- src/consensus/gnunet-service-consensus.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index b934f468f..ba84f64a2 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c @@ -393,6 +393,14 @@ struct DiffEntry struct GNUNET_CONTAINER_MultiHashMap *changes; }; +struct SetHandle +{ + struct SetHandle *prev; + struct SetHandle *next; + + struct GNUNET_SET_Handle *h; +}; + /** @@ -499,6 +507,9 @@ struct ConsensusSession * Bounded Eppstein lower bound. */ uint64_t lower_bound; + + struct SetHandle *set_handles_head; + struct SetHandle *set_handles_tail; }; /** @@ -1663,6 +1674,12 @@ set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy) struct TaskEntry *task = scc->task; struct SetKey dst_set_key = scc->dst_set_key; struct SetEntry *set; + struct SetHandle *sh = GNUNET_new (struct SetHandle); + + sh->h = copy; + GNUNET_CONTAINER_DLL_insert (task->step->session->set_handles_head, + task->step->session->set_handles_tail, + sh); GNUNET_free (scc); set = GNUNET_new (struct SetEntry); @@ -3152,6 +3169,11 @@ handle_client_join (void *cls, client_set = GNUNET_new (struct SetEntry); client_set->h = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); + struct SetHandle *sh = GNUNET_new (struct SetHandle); + sh->h = client_set->h; + GNUNET_CONTAINER_DLL_insert (session->set_handles_head, + session->set_handles_tail, + sh); client_set->key = ((struct SetKey) { SET_KIND_CURRENT, 0, 0 }); put_set (session, client_set); @@ -3370,6 +3392,14 @@ client_disconnect_cb (void *cls, GNUNET_CONTAINER_DLL_remove (sessions_head, sessions_tail, session); + + while (session->set_handles_head) + { + struct SetHandle *sh = session->set_handles_head; + session->set_handles_head = sh->next; + GNUNET_SET_destroy (sh->h); + GNUNET_free (sh); + } GNUNET_free (session); } -- cgit v1.2.3 From 2f3ffc2b053725a26be07763b02091439ae41005 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 1 Mar 2017 00:03:51 +0100 Subject: set: log set difference estimate --- src/set/gnunet-service-set_union.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index f46713c31..9ca9961ef 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -877,6 +877,8 @@ handle_p2p_strata_estimator (void *cls, if (diff > 200) diff = diff * 3 / 2; + + strata_estimator_destroy (remote_se); strata_estimator_destroy (op->state->se); op->state->se = NULL; @@ -885,6 +887,17 @@ handle_p2p_strata_estimator (void *cls, diff, 1<spec->byzantine) && (other_size < op->spec->byzantine_lower_bound)) { GNUNET_break (0); -- cgit v1.2.3 From d129b74cff8ef6126a9139bc1b22a5ca281e0d8c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 1 Mar 2017 00:11:10 +0100 Subject: missing newline --- src/set/gnunet-service-set_union.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 9ca9961ef..f6737ba65 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -892,7 +892,7 @@ handle_p2p_strata_estimator (void *cls, set_debug = getenv ("GNUNET_SET_BENCHMARK"); if ( (NULL != set_debug) && (0 == strcmp (set_debug, "1")) ) { - FILE *f = fopen ("set.log", "a"); + FILE *f = fopen ("set.log\n", "a"); fprintf (f, "%llu", (unsigned long long) diff); fclose (f); } -- cgit v1.2.3 From 13b340c41157eb7d1d37e2d16058ce791a7c768e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 1 Mar 2017 00:13:29 +0100 Subject: eh, oops --- src/set/gnunet-service-set_union.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index f6737ba65..b5b602074 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -892,8 +892,8 @@ handle_p2p_strata_estimator (void *cls, set_debug = getenv ("GNUNET_SET_BENCHMARK"); if ( (NULL != set_debug) && (0 == strcmp (set_debug, "1")) ) { - FILE *f = fopen ("set.log\n", "a"); - fprintf (f, "%llu", (unsigned long long) diff); + FILE *f = fopen ("set.log", "a"); + fprintf (f, "%llu\n", (unsigned long long) diff); fclose (f); } } -- cgit v1.2.3