From 8000747074b82caeacb0f43710940220d9840d37 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 22 Feb 2017 11:10:02 +0100 Subject: [PATCH] clean up new block logic, avoid direct linkage against blockgroup lib from DHT service --- src/block/block.c | 34 ++++++++---- src/dht/Makefile.am | 1 - src/dht/gnunet-service-dht_neighbours.c | 70 ++++++++++++++----------- src/dht/plugin_block_dht.c | 2 +- 4 files changed, 64 insertions(+), 43 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index b7a19ae90..23caacd38 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2010 GNUnet e.V. + Copyright (C) 2010, 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 @@ -84,8 +84,12 @@ GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode *in, { struct GNUNET_HashCode m; - GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m); - GNUNET_CRYPTO_hash_xor (&m, in, hc); + GNUNET_CRYPTO_hash (&mingle_number, + sizeof (uint32_t), + &m); + GNUNET_CRYPTO_hash_xor (&m, + in, + hc); } @@ -111,7 +115,9 @@ add_plugin (void *cls, plugin = GNUNET_new (struct Plugin); plugin->api = api; plugin->library_name = GNUNET_strdup (library_name); - GNUNET_array_append (ctx->plugins, ctx->num_plugins, plugin); + GNUNET_array_append (ctx->plugins, + ctx->num_plugins, + plugin); } @@ -129,7 +135,10 @@ 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, &add_plugin, ctx); + GNUNET_PLUGIN_load_all ("libgnunet_plugin_block_", + NULL, + &add_plugin, + ctx); return ctx; } @@ -149,7 +158,8 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx) { plugin = ctx->plugins[i]; GNUNET_break (NULL == - GNUNET_PLUGIN_unload (plugin->library_name, plugin->api)); + GNUNET_PLUGIN_unload (plugin->library_name, + plugin->api)); GNUNET_free (plugin->library_name); GNUNET_free (plugin); } @@ -249,10 +259,9 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type) { struct Plugin *plugin; - unsigned int i; unsigned int j; - for (i = 0; i < ctx->num_plugins; i++) + for (unsigned i = 0; i < ctx->num_plugins; i++) { plugin = ctx->plugins[i]; j = 0; @@ -294,7 +303,8 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, type); if (NULL == plugin->create_group) return NULL; - va_start (ap, raw_data_size); + va_start (ap, + raw_data_size); bg = plugin->create_group (plugin->cls, type, nonce, @@ -375,7 +385,11 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, if (plugin == NULL) return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; - return plugin->get_key (plugin->cls, type, block, block_size, key); + return plugin->get_key (plugin->cls, + type, + block, + block_size, + key); } diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 4216af400..b95083c85 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -82,7 +82,6 @@ gnunet_service_dht_LDADD = \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/block/libgnunetblock.la \ - $(top_builddir)/src/block/libgnunetblockgroup.la \ $(top_builddir)/src/datacache/libgnunetdatacache.la \ $(top_builddir)/src/util/libgnunetutil.la \ -lm diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 1bbc95a06..975872f1b 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -27,7 +27,6 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_block_lib.h" -#include "gnunet_block_group_lib.h" #include "gnunet_hello_lib.h" #include "gnunet_constants.h" #include "gnunet_protocols.h" @@ -622,8 +621,9 @@ add_known_to_bloom (void *cls, GNUNET_CRYPTO_hash (key, sizeof (struct GNUNET_PeerIdentity), &key_hash); - GNUNET_BLOCK_GROUP_bf_test_and_set (bg, - &key_hash); + GNUNET_BLOCK_group_set_seen (bg, + &key_hash, + 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding known peer (%s) to bloomfilter for FIND PEER\n", GNUNET_i2s (key)); @@ -656,14 +656,12 @@ send_find_peer_message (void *cls) newly_found_peers = 0; return; } - bg = GNUNET_BLOCK_GROUP_bf_create (NULL, - DHT_BLOOM_SIZE, - GNUNET_CONSTANTS_BLOOMFILTER_K, - GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX), - NULL, - 0); + bg = GNUNET_BLOCK_group_create (GDS_block_context, + GNUNET_BLOCK_TYPE_DHT_HELLO, + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT32_MAX), + NULL, + 0); GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, &add_known_to_bloom, bg); @@ -1839,22 +1837,26 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, struct PeerInfo *peer; unsigned int choice; const struct GNUNET_HELLO_Message *hello; + size_t hello_size; /* first, check about our own HELLO */ if (NULL != GDS_my_hello) { - if (GNUNET_YES != - GNUNET_BLOCK_GROUP_bf_test_and_set (bg, - &my_identity_hash)) + hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); + GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); + if (GNUNET_BLOCK_EVALUATION_OK_MORE == + GNUNET_BLOCK_evaluate (GDS_block_context, + GNUNET_BLOCK_TYPE_DHT_HELLO, + bg, + GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, + &my_identity_hash, + NULL, 0, + GDS_my_hello, + hello_size)) { - size_t hello_size; - - hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); - GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, - GNUNET_TIME_relative_to_absolute - (hello_expiration), + GNUNET_TIME_relative_to_absolute (hello_expiration), key, 0, NULL, @@ -1910,10 +1912,17 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, if (NULL == peer) peer = bucket->head; hello = GDS_HELLO_get (peer->id); + hello_size = GNUNET_HELLO_size (hello); } while ( (NULL == hello) || - (GNUNET_YES == - GNUNET_BLOCK_GROUP_bf_test_and_set (bg, - &peer->phash)) ); + (GNUNET_BLOCK_EVALUATION_OK_MORE != + GNUNET_BLOCK_evaluate (GDS_block_context, + GNUNET_BLOCK_TYPE_DHT_HELLO, + bg, + GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, + &peer->phash, + NULL, 0, + hello, + hello_size)) ); GDS_NEIGHBOURS_handle_reply (sender, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_TIME_relative_to_absolute @@ -1924,7 +1933,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, 0, NULL, hello, - GNUNET_HELLO_size (hello)); + hello_size); } @@ -2052,15 +2061,10 @@ handle_dht_p2p_get (void *cls, xquery); GNUNET_free (tmp); } - bg = GNUNET_BLOCK_group_create (GDS_block_context, - type, - get->bf_mutator, - &xquery[xquery_size], - reply_bf_size); eval = GNUNET_BLOCK_evaluate (GDS_block_context, type, - bg, + NULL, GNUNET_BLOCK_EO_NONE, &get->key, xquery, @@ -2071,7 +2075,6 @@ handle_dht_p2p_get (void *cls, { /* request invalid or block type not supported */ GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); - GNUNET_BLOCK_group_destroy (bg); return; } peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, @@ -2080,6 +2083,11 @@ handle_dht_p2p_get (void *cls, GNUNET_break_op (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (peer_bf, &peer->phash)); + bg = GNUNET_BLOCK_group_create (GDS_block_context, + type, + get->bf_mutator, + &xquery[xquery_size], + reply_bf_size); /* remember request for routing replies */ GDS_ROUTING_add (peer->id, type, diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 0304dad87..168497440 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2010 GNUnet e.V. + Copyright (C) 2010, 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 -- 2.25.1