clean up new block logic, avoid direct linkage against blockgroup lib from DHT service
authorChristian Grothoff <christian@grothoff.org>
Wed, 22 Feb 2017 10:10:02 +0000 (11:10 +0100)
committerChristian Grothoff <christian@grothoff.org>
Wed, 22 Feb 2017 10:10:02 +0000 (11:10 +0100)
src/block/block.c
src/dht/Makefile.am
src/dht/gnunet-service-dht_neighbours.c
src/dht/plugin_block_dht.c

index b7a19ae9041d6b7d0e40585bf2b169cdbb19bb2e..23caacd382f37a97d4c539361e1a1e213891abfa 100644 (file)
@@ -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);
 }
 
 
index 4216af4009c0b50537758c623aa4497b455aad68..b95083c858d4210330414d21571369c76f0ad672 100644 (file)
@@ -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
index 1bbc95a06fecf1d9ed5f49f08ba693857a047712..975872f1beaf758e55c1b0cc3629f46eee5fafc5 100644 (file)
@@ -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,
index 0304dad87fddd4b9acfd3c2c328bbeeba706ec70..168497440d3508a44480bb5d55ad8a43055a53e1 100644 (file)
@@ -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