add validation for inner consensus element
authorFlorian Dold <florian.dold@gmail.com>
Sun, 26 Feb 2017 22:39:29 +0000 (23:39 +0100)
committerFlorian Dold <florian.dold@gmail.com>
Sun, 26 Feb 2017 22:39:29 +0000 (23:39 +0100)
The nested block validation requires the block context, and thus the
evaluate callback not also receives the block context.

src/block/block.c
src/block/plugin_block_template.c
src/block/plugin_block_test.c
src/consensus/plugin_block_consensus.c
src/dht/plugin_block_dht.c
src/dns/plugin_block_dns.c
src/fs/plugin_block_fs.c
src/gns/plugin_block_gns.c
src/include/gnunet_block_plugin.h
src/regex/plugin_block_regex.c
src/set/Makefile.am

index 23caacd382f37a97d4c539361e1a1e213891abfa..d6e61acf6cd20e4ba482da24449dfe1d6bbd006e 100644 (file)
@@ -351,6 +351,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
   if (NULL == plugin)
     return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
   return plugin->evaluate (plugin->cls,
+                           ctx,
                            type,
                            group,
                            eo,
index b714b68585284b3fc367a9da096ddca1af0b9abc..2edca17ecb10441f8f44a76d7c4277f58169965e 100644 (file)
@@ -95,6 +95,7 @@ block_plugin_template_create_group (void *cls,
  * request evaluation, simply pass "NULL" for the reply_block.
  *
  * @param cls closure
+ * @param ctx context
  * @param type block type
  * @param group block group to use
  * @param eo control flags
@@ -107,6 +108,7 @@ block_plugin_template_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_template_evaluate (void *cls,
+                                struct GNUNET_BLOCK_Context *ctx,
                                 enum GNUNET_BLOCK_Type type,
                                 struct GNUNET_BLOCK_Group *group,
                                 enum GNUNET_BLOCK_EvaluationOptions eo,
index b9f71cacbc567add2a5eaa63abe82f45c449976c..e359acd7f36a6b86c53f885546dc5f39c199e261 100644 (file)
@@ -93,6 +93,7 @@ block_plugin_test_create_group (void *cls,
  * request evaluation, simply pass "NULL" for the reply_block.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param group group to check against
  * @param eo control flags
@@ -105,6 +106,7 @@ block_plugin_test_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_test_evaluate (void *cls,
+                            struct GNUNET_BLOCK_Context *ctx,
                             enum GNUNET_BLOCK_Type type,
                             struct GNUNET_BLOCK_Group *group,
                             enum GNUNET_BLOCK_EvaluationOptions eo,
index 39e348b18eeabb5804e38c8405c71e8b5190b50a..3ad3357604b178719c77b97cce94f367536721c1 100644 (file)
@@ -35,6 +35,7 @@
  * request evaluation, simply pass "NULL" for the reply_block.
  *
  * @param cls closure
+ * @param ctx context
  * @param type block type
  * @param group block group to use
  * @param eo control flags
@@ -47,6 +48,7 @@
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_consensus_evaluate (void *cls,
+                                 struct GNUNET_BLOCK_Context *ctx,
                                  enum GNUNET_BLOCK_Type type,
                                  struct GNUNET_BLOCK_Group *group,
                                  enum GNUNET_BLOCK_EvaluationOptions eo,
@@ -57,10 +59,23 @@ block_plugin_consensus_evaluate (void *cls,
                                  size_t reply_block_size)
 {
   if (reply_block_size < sizeof (struct ConsensusElement))
-  {
     return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
-  }
-  return GNUNET_BLOCK_EVALUATION_OK_MORE;
+
+  const struct ConsensusElement *ce = reply_block;
+
+  if ( (GNUNET_YES == ce->is_contested_marker) ||
+       (0 == ce->payload_type ) )
+    return GNUNET_BLOCK_EVALUATION_OK_MORE;
+
+  return GNUNET_BLOCK_evaluate (ctx,
+                                type,
+                                group,
+                                eo,
+                                query,
+                                xquery,
+                                xquery_size,
+                                &ce[1],
+                                reply_block_size - sizeof (struct ConsensusElement));
 }
 
 
index 74498746c6bd5c6a0b5087128140f337727211db..96349ae9d7edca95d30c09fe3f625a3227951b38 100644 (file)
@@ -92,6 +92,7 @@ block_plugin_dht_create_group (void *cls,
  * request evaluation, simply pass "NULL" for the @a reply_block.
  *
  * @param cls closure
+ * @param ctx context
  * @param type block type
  * @param group block group to check against
  * @param eo control flags
@@ -104,6 +105,7 @@ block_plugin_dht_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_dht_evaluate (void *cls,
+                           struct GNUNET_BLOCK_Context *ctx,
                            enum GNUNET_BLOCK_Type type,
                            struct GNUNET_BLOCK_Group *group,
                            enum GNUNET_BLOCK_EvaluationOptions eo,
index fe416e450d699342a39b571641058dbec6b85459..ca6ea84c464ab41182cd4ab0c8abea06eb719dcb 100644 (file)
@@ -93,6 +93,7 @@ block_plugin_dns_create_group (void *cls,
  * request evaluation, simply pass "NULL" for the reply_block.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param bg group to evaluate against
  * @param eo control flags
@@ -105,6 +106,7 @@ block_plugin_dns_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_dns_evaluate (void *cls,
+                           struct GNUNET_BLOCK_Context *ctx,
                            enum GNUNET_BLOCK_Type type,
                            struct GNUNET_BLOCK_Group *bg,
                            enum GNUNET_BLOCK_EvaluationOptions eo,
index b6749b4183be10059d65941fa5a27ecbd6f577f1..c5e63c9e2f79c40cc9809ef576bda6375960048f 100644 (file)
@@ -109,6 +109,7 @@ block_plugin_fs_create_group (void *cls,
  * be done with the #GNUNET_BLOCK_get_key() function.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param bg group to use for evaluation
  * @param eo control flags
@@ -121,6 +122,7 @@ block_plugin_fs_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_fs_evaluate (void *cls,
+                          struct GNUNET_BLOCK_Context *ctx,
                           enum GNUNET_BLOCK_Type type,
                           struct GNUNET_BLOCK_Group *bg,
                           enum GNUNET_BLOCK_EvaluationOptions eo,
index 2ef48f09423a39938d3e028645a1c301445739e4..558ded6f4e59bd28fc2383b197d8bf62c287eaa7 100644 (file)
@@ -98,6 +98,7 @@ block_plugin_gns_create_group (void *cls,
  * be done with the "get_key" function.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param bg block group to use for evaluation
  * @param eo control flags
@@ -110,6 +111,7 @@ block_plugin_gns_create_group (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_gns_evaluate (void *cls,
+                           struct GNUNET_BLOCK_Context *ctx,
                            enum GNUNET_BLOCK_Type type,
                            struct GNUNET_BLOCK_Group *bg,
                            enum GNUNET_BLOCK_EvaluationOptions eo,
index 171b6cfc05a407b94c453d862fdd264598ac5f26..3eb031573eb33531d4114fc117d266bc7b537e8c 100644 (file)
@@ -171,6 +171,7 @@ typedef struct GNUNET_BLOCK_Group *
  * be done with the "get_key" function.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param group which block group to use for evaluation
  * @param eo evaluation options to control evaluation
@@ -183,6 +184,7 @@ typedef struct GNUNET_BLOCK_Group *
  */
 typedef enum GNUNET_BLOCK_EvaluationResult
 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
+                                    struct GNUNET_BLOCK_Context *ctx,
                                    enum GNUNET_BLOCK_Type type,
                                     struct GNUNET_BLOCK_Group *group,
                                     enum GNUNET_BLOCK_EvaluationOptions eo,
index a345dfedb349db77fc461419e009366cb33ce0ae..0b3ef703e6ce449ad723e05d891398bf1d6b50e9 100644 (file)
@@ -269,6 +269,7 @@ evaluate_block_regex_accept (void *cls,
  * be done with the #GNUNET_BLOCK_get_key() function.
  *
  * @param cls closure
+ * @param ctx block context
  * @param type block type
  * @param bg group to evaluate against
  * @param eo control flags
@@ -281,6 +282,7 @@ evaluate_block_regex_accept (void *cls,
  */
 static enum GNUNET_BLOCK_EvaluationResult
 block_plugin_regex_evaluate (void *cls,
+                             struct GNUNET_BLOCK_Context *ctx,
                              enum GNUNET_BLOCK_Type type,
                              struct GNUNET_BLOCK_Group *bg,
                              enum GNUNET_BLOCK_EvaluationOptions eo,
index 10f7ddc5d7046dee0bdc0166247943d5ba472809..cfe95bc1a62274b04e2d1fae06144038bd1c2a18 100644 (file)
@@ -5,6 +5,8 @@ pkgcfgdir= $(pkgdatadir)/config.d/
 
 libexecdir= $(pkglibdir)/libexec/
 
+plugindir = $(libdir)/gnunet
+
 pkgcfg_DATA = \
   set.conf
 
@@ -112,5 +114,19 @@ test_set_union_copy_LDADD = \
   $(top_builddir)/src/testing/libgnunettesting.la \
   libgnunetset.la
 
+plugin_LTLIBRARIES = \
+  libgnunet_plugin_block_set_test.la
+
+libgnunet_plugin_block_set_test_la_SOURCES = \
+  plugin_block_set_test.c
+libgnunet_plugin_block_set_test_la_LIBADD = \
+  $(top_builddir)/src/block/libgnunetblock.la \
+  $(top_builddir)/src/block/libgnunetblockgroup.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(LTLIBINTL)
+libgnunet_plugin_block_set_test_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+
 EXTRA_DIST = \
   test_set.conf