implement revocation block plugin, get revocation test to pass again
authorChristian Grothoff <christian@grothoff.org>
Mon, 27 Feb 2017 14:28:00 +0000 (15:28 +0100)
committerChristian Grothoff <christian@grothoff.org>
Mon, 27 Feb 2017 14:28:00 +0000 (15:28 +0100)
13 files changed:
src/block/block.c
src/block/plugin_block_template.c
src/consensus/plugin_block_consensus.c
src/dht/plugin_block_dht.c
src/fs/plugin_block_fs.c
src/gns/plugin_block_gns.c
src/include/gnunet_block_lib.h
src/include/gnunet_plugin_lib.h
src/regex/plugin_block_regex.c
src/revocation/Makefile.am
src/revocation/gnunet-service-revocation.c
src/revocation/plugin_block_revocation.c [new file with mode: 0644]
src/set/plugin_block_set_test.c

index d6e61acf6cd20e4ba482da24449dfe1d6bbd006e..4b6f3826d9251419658273d4db6f7d3d62c361e5 100644 (file)
@@ -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;
index 2edca17ecb10441f8f44a76d7c4277f58169965e..0105fac3869572d97a4ce0535277b4ebf9321cb6 100644 (file)
@@ -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;
index 0cb64867e1d1227283f6468147b9badae185fb84..de0f0886f7dcf84d262fd94ab31034f06ac0caa1 100644 (file)
@@ -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;
index 96349ae9d7edca95d30c09fe3f625a3227951b38..24f8b21b253937ef8a3c0b4486a0e121e71b82a2 100644 (file)
@@ -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;
index c5e63c9e2f79c40cc9809ef576bda6375960048f..902519f15522acd241d27ccbedf0210795a8c717 100644 (file)
@@ -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;
index 558ded6f4e59bd28fc2383b197d8bf62c287eaa7..a42fef9530331a7ce3cfaa4e6d829d70e575ce7e 100644 (file)
@@ -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;
index 3e36f11f04dc1e2a12c5f9e49c521412c4093539..d8ee68c21c5c9800c51e2bc65f8e33e88b4dc3c0 100644 (file)
@@ -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
    */
index b76b9f9cf7569b31fa5887bd573f218b7ea80c7a..9e3e72a215133c7e37a5efbecfeefd6ffe8683eb 100644 (file)
@@ -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
index 0b3ef703e6ce449ad723e05d891398bf1d6b50e9..287ecf905d23cfc38ad0d9446480efa6628e463f 100644 (file)
@@ -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;
index 541c7120d8685d2a34367e5e82ef496778c02c4f..82755b48573fd7e9d97e4b0a430b1b8c64007ddb 100644 (file)
@@ -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
-
index 99bec1fc8a034147b7ca0ed24c4768decbcb7242..9d077f874dd3e7176cefcc9ba9a5105f0856e5f4 100644 (file)
@@ -38,6 +38,7 @@
 #include "platform.h"
 #include <math.h>
 #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 (file)
index 0000000..eb0766b
--- /dev/null
@@ -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 */
index c4f73abe0be3676cdffc0a8fce364d069e30af19..01b0c8602c79486fde819625418b79489d247c88 100644 (file)
@@ -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;