gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: implement new block API for FS, fix FTBF


From: gnunet
Subject: [gnunet] branch master updated: implement new block API for FS, fix FTBFS
Date: Wed, 29 Dec 2021 00:11:43 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 68b028c18 implement new block API for FS, fix FTBFS
68b028c18 is described below

commit 68b028c18c8f701debc97c4480c903136274f71f
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Wed Dec 29 00:11:40 2021 +0100

    implement new block API for FS, fix FTBFS
---
 src/fs/plugin_block_fs.c       | 156 +++++++++++++++++++++++++++++++++++++++--
 src/gns/plugin_block_gns.c     |   8 ---
 src/include/gnunet_block_lib.h |   2 +-
 3 files changed, 151 insertions(+), 15 deletions(-)

diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 6a9ab3f41..0df434a34 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     Copyright (C) 2010, 2013 GNUnet e.V.
+     Copyright (C) 2010, 2013, 2021 GNUnet e.V.
 
      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
@@ -225,7 +225,7 @@ block_plugin_fs_evaluate (void *cls,
  * @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
+static enum GNUNET_GenericReturnValue
 block_plugin_fs_get_key (void *cls,
                          enum GNUNET_BLOCK_Type type,
                          const void *block,
@@ -238,9 +238,10 @@ block_plugin_fs_get_key (void *cls,
   {
   case GNUNET_BLOCK_TYPE_FS_DBLOCK:
   case GNUNET_BLOCK_TYPE_FS_IBLOCK:
-    GNUNET_CRYPTO_hash (block, block_size, key);
+    GNUNET_CRYPTO_hash (block,
+                        block_size,
+                        key);
     return GNUNET_OK;
-
   case GNUNET_BLOCK_TYPE_FS_UBLOCK:
     if (block_size < sizeof(struct UBlock))
     {
@@ -252,7 +253,6 @@ block_plugin_fs_get_key (void *cls,
                         sizeof(ub->verification_key),
                         key);
     return GNUNET_OK;
-
   default:
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -260,13 +260,154 @@ block_plugin_fs_get_key (void *cls,
 }
 
 
+/**
+ * Function called to validate a query.
+ *
+ * @param cls closure
+ * @param ctx block context
+ * @param type block type
+ * @param query original query (hash)
+ * @param xquery extrended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in @a xquery
+ * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
+ */
+static enum GNUNET_GenericReturnValue
+block_plugin_fs_check_query (void *cls,
+                             enum GNUNET_BLOCK_Type type,
+                             const struct GNUNET_HashCode *query,
+                             const void *xquery,
+                             size_t xquery_size)
+{
+  switch (type)
+  {
+  case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+  case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+  case GNUNET_BLOCK_TYPE_FS_UBLOCK:
+    if (0 != xquery_size)
+    {
+      GNUNET_break_op (0);
+      return GNUNET_NO;
+    }
+    return GNUNET_OK;
+  default:
+    return GNUNET_SYSERR;
+  }
+}
+
+
+/**
+ * Function called to validate a block for storage.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param query key for the block (hash), must match exactly
+ * @param block block data to validate
+ * @param block_size number of bytes in @a block
+ * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
+ */
+static enum GNUNET_GenericReturnValue
+block_plugin_fs_check_block (void *cls,
+                             enum GNUNET_BLOCK_Type type,
+                             const struct GNUNET_HashCode *query,
+                             const void *block,
+                             size_t block_size)
+{
+  switch (type)
+  {
+  case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+  case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+    return GNUNET_OK;
+  case GNUNET_BLOCK_TYPE_FS_UBLOCK:
+    {
+      const struct UBlock *ub;
+      
+      if (reply_block_size < sizeof(struct UBlock))
+      {
+        GNUNET_break_op (0);
+        return GNUNET_NO;
+      }
+      ub = reply_block;
+      if (reply_block_size !=
+          ntohl (ub->purpose.size) +
+          sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
+      {
+        GNUNET_break_op (0);
+        return GNUNET_NO;
+      }
+      if (GNUNET_OK !=
+          GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK,
+                                       &ub->purpose,
+                                       &ub->signature,
+                                       &ub->verification_key))
+      {
+        GNUNET_break_op (0);
+        return GNUNET_NO;
+      }
+      return GNUNET_OK;
+    }
+  default:
+    return GNUNET_SYSERR;
+  }
+}
+
+
+/**
+ * Function called to validate a reply to a request.  Note that it is assumed
+ * that the reply has already been matched to the key (and signatures checked)
+ * as it would be done with the GetKeyFunction and the
+ * BlockEvaluationFunction.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param group which block group to use for evaluation
+ * @param query original query (hash)
+ * @param xquery extrended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in @a xquery
+ * @param reply_block response to validate
+ * @param reply_block_size number of bytes in @a reply_block
+ * @return characterization of result
+ */
+static enum GNUNET_BLOCK_ReplyEvaluationResult
+block_plugin_fs_check_reply (void *cls,
+                             enum GNUNET_BLOCK_Type type,
+                             struct GNUNET_BLOCK_Group *group,
+                             const struct GNUNET_HashCode *query,
+                             const void *xquery,
+                             size_t xquery_size,
+                             const void *reply_block,
+                             size_t reply_block_size)
+{
+  switch (type)
+  {
+  case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+  case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+    return GNUNET_BLOCK_REPLY_OK_LAST;
+  case GNUNET_BLOCK_TYPE_FS_UBLOCK:
+    {
+      struct GNUNET_HashCode chash;
+
+      GNUNET_CRYPTO_hash (reply_block,
+                          reply_block_size,
+                          &chash);
+      if (GNUNET_YES ==
+          GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
+                                              &chash))
+        return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
+      return GNUNET_BLOCK_REPLY_OK_MORE;
+    }
+  default:
+    return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
+  }
+}
+
+
 /**
  * Entry point for the plugin.
  */
 void *
 libgnunet_plugin_block_fs_init (void *cls)
 {
-  static enum GNUNET_BLOCK_Type types[] = {
+  static const enum GNUNET_BLOCK_Type types[] = {
     GNUNET_BLOCK_TYPE_FS_DBLOCK,
     GNUNET_BLOCK_TYPE_FS_IBLOCK,
     GNUNET_BLOCK_TYPE_FS_UBLOCK,
@@ -278,6 +419,9 @@ libgnunet_plugin_block_fs_init (void *cls)
   api->evaluate = &block_plugin_fs_evaluate;
   api->get_key = &block_plugin_fs_get_key;
   api->create_group = &block_plugin_fs_create_group;
+  api->check_query = &block_plugin_fs_check_query;
+  api->check_block = &block_plugin_fs_check_block;
+  api->check_reply = &block_plugin_fs_check_reply;
   api->types = types;
   return api;
 }
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index e85b2e9df..083ea7cc4 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -271,14 +271,6 @@ block_plugin_gns_check_block (void *cls,
     GNUNET_break_op (0);
     return GNUNET_NO;
   }
-  GNUNET_GNSRECORD_query_from_block (block,
-                                     &h);
-  if (0 != GNUNET_memcmp (&h,
-                          query))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_NO;
-  }
   if (GNUNET_OK !=
       GNUNET_GNSRECORD_block_verify (block))
   {
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 78ade8218..6f82381ac 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -243,7 +243,7 @@ enum GNUNET_BLOCK_ReplyEvaluationResult
   /**
    * Specified block type not supported by any plugin.
    */
-  GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1
+  GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1,
   
   /**
    * Block does not match query (invalid result)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]