gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: Worked on Plugin


From: gnunet
Subject: [taler-anastasis] branch master updated: Worked on Plugin
Date: Tue, 29 Oct 2019 22:14:45 +0100

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new e1f9f74  Worked on Plugin
e1f9f74 is described below

commit e1f9f741fc3adb508e2bc12c3e3e5e6edc6d3016
Author: Dennis Neufeld <address@hidden>
AuthorDate: Tue Oct 29 21:14:34 2019 +0000

    Worked on Plugin
---
 src/backup-db/plugin_anastasis_postgres.c |  43 ++++++-
 src/backup-db/test_anastasis_db.c         | 204 ++++++++++++++++++++++++++++++
 src/include/anastasis_database_plugin.h   |  12 +-
 src/include/anastasis_error_codes.h       |  77 +++++++++++
 4 files changed, 328 insertions(+), 8 deletions(-)

diff --git a/src/backup-db/plugin_anastasis_postgres.c 
b/src/backup-db/plugin_anastasis_postgres.c
index 77d9a83..a87163b 100644
--- a/src/backup-db/plugin_anastasis_postgres.c
+++ b/src/backup-db/plugin_anastasis_postgres.c
@@ -86,8 +86,9 @@ postgres_drop_tables (void *cls)
  * @param pg connection to check
  */
 static void
-check_connection (struct PostgresClosure *pg)
+check_connection (void *cls)
 {
+  struct PostgresClosure *pg = cls;
   GNUNET_PQ_reconnect_if_down (pg->conn);
 }
 
@@ -131,12 +132,15 @@ postgres_preflight (void *cls)
  * Start a transaction.
  *
  * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param name unique name identifying the transaction (for debugging),
+ *             must point to a constant
  * @return #GNUNET_OK on success
  */
 static int
-begin_transaction (struct PostgresClosure *pg,
+begin_transaction (void *cls,
                    const char *name)
 {
+  struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_ExecuteStatement es[] = {
     GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
@@ -162,8 +166,9 @@ begin_transaction (struct PostgresClosure *pg,
 * @return #GNUNET_OK on success
 */
 static void
-rollback (struct PostgresClosure *pg)
+rollback (void *cls)
 {
+  struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_ExecuteStatement es[] = {
     GNUNET_PQ_make_execute ("ROLLBACK"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
@@ -187,8 +192,9 @@ rollback (struct PostgresClosure *pg)
  */
 
 static enum ANASTASIS_DB_QueryStatus
-commit_transaction (struct PostgresClosure *pg)
+commit_transaction (void *cls)
 {
+  struct PostgresClosure *pg = cls;
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_PQ_QueryParam no_params[] = {
     GNUNET_PQ_query_param_end
@@ -269,6 +275,9 @@ postgres_store_recovery_document (void *cls,
     paid_until = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
                                            paid_until);
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   // rollback if user hasn't paid
@@ -311,6 +320,9 @@ postgres_store_recovery_document (void *cls,
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   if (postcounter == 0 )
@@ -348,6 +360,9 @@ postgres_store_recovery_document (void *cls,
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   /* get the version for the recoverydocument */
@@ -381,6 +396,9 @@ postgres_store_recovery_document (void *cls,
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     (*version)++;
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   {
@@ -410,6 +428,9 @@ postgres_store_recovery_document (void *cls,
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   qs = commit_transaction (pg);
@@ -481,6 +502,9 @@ postgres_record_payment (void *cls,
       paid_until = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
                                              paid_until);
       break;
+    default:
+    //FIXME: Some Action
+    return qs;
     }
   }
   paid_until = GNUNET_TIME_absolute_add (paid_until,
@@ -526,6 +550,9 @@ postgres_record_payment (void *cls,
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   {
@@ -554,6 +581,9 @@ postgres_record_payment (void *cls,
       return ANASTASIS_DB_STATUS_HARD_ERROR;
     case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
       break;
+    default:
+    //FIXME: Some Action
+    return qs;
     }
   }
 
@@ -578,7 +608,7 @@ postgres_store_truth (void *cls,
                       const struct ANASTASIS_uuid *uuid,
                       const void *truth_data,
                       size_t truth_data_size,
-                      const char mime_type,
+                      const char *mime_type,
                       const void *encrypted_key_share,
                       size_t encrypted_key_share_size,
                       struct GNUNET_TIME_Relative truth_expiration)
@@ -625,6 +655,9 @@ postgres_store_truth (void *cls,
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
+  default:
+    //FIXME: Some Action
+    return qs;
   }
 
   qs = commit_transaction (pg);
diff --git a/src/backup-db/test_anastasis_db.c 
b/src/backup-db/test_anastasis_db.c
new file mode 100644
index 0000000..3f238c1
--- /dev/null
+++ b/src/backup-db/test_anastasis_db.c
@@ -0,0 +1,204 @@
+/*
+  This file is part of TALER
+  (C) 2014-2017 INRIA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Lesser General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER 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
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file anastasis/test_anastasis_db.c
+ * @brief testcase for anastasis postgres db plugin
+ * @author Marcello Stanisci
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_db_lib.h>
+#include <taler/taler_util.h>
+#include "anastasis_database_plugin.h"
+
+#define FAILIF(cond)                            \
+  do {                                          \
+    if (! (cond)) { break;}                       \
+    GNUNET_break (0);                           \
+    goto drop;                                  \
+  } while (0)
+
+#define RND_BLK(ptr)                                                    \
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
+
+/**
+ * Global return value for the test.  Initially -1, set to 0 upon
+ * completion.  Other values indicate some kind of error.
+ */
+static int result;
+
+/**
+ * Handle to the plugin we are testing.
+ */
+static struct ANASTASIS_DatabasePlugin *plugin;
+
+/**
+ * Payment Secret for the test, set to a random value
+ */
+static struct ANASTASIS_PaymentSecretP paymentSecretP;
+
+/**
+ * UUID of the Truth to test, set to a UUID value
+ */
+static struct ANASTASIS_uuid uuid;
+
+/**
+ * User public key, set to a random value
+ */
+static struct ANASTASIS_AccountPubP accountPubP;
+
+/**
+ * Amount which is deposited, set to random value
+ */
+static struct TALER_Amount amount;
+
+/**
+ * How many posts are paid by the payment
+ */
+const unsigned int *post_counter;
+
+/**
+ * Recoverydata which is stored into the Database, set to a random value
+ */
+const void *recovery_data;
+
+/**
+ * Truthdata which is stored into the Database, set to a random value
+ */
+const void *truth_data;
+
+/**
+ * Keyshare which is stored into the Database, set to a random value
+ */
+const void *key_share;
+
+/**
+ * Version of a Recoverydocument
+ */
+const unsigned int *version;
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+static void
+run (void *cls)
+{
+
+    struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+    struct GNUNET_TIME_Absolute fake_now;
+
+    if (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg)))
+    {
+        result = 77;
+        return;
+    }
+    if (GNUNET_OK != plugin->drop_tables (plugin->cls))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Dropping tables failed\n");
+        result = 77;
+        return;
+    }
+    TALER_MERCHANTDB_plugin_unload (plugin);
+    if (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg)))
+    {
+        result = 77;
+        return;
+    }
+
+    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+            plugin->store_recovery_document (plugin->cls,
+                                             accountPubP,
+                                             recovery_data,
+                                             recovery_data_size,
+                                             paymentSecretP,
+                                             version));
+    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+            plugin->record_payment (plugin->cls,
+                                    amount,
+                                    accountPubP,
+                                    &post_counter,
+                                    fake_now,
+                                    paymentSecretP));
+    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+            plugin->store_truth (plugin->cls,
+                                 uuid,
+                                 truth_data,
+                                 truth_data_size,
+                                 expiration,
+                                 version));
+
+    if (-1 == result)
+        result = 0;
+
+    drop:
+    GNUNET_break (GNUNET_OK ==
+                  plugin->drop_tables (plugin->cls));
+    TALER_MERCHANTDB_plugin_unload (plugin);
+    plugin = NULL;
+    if (NULL != deposit_proof)
+        json_decref (deposit_proof);
+    if (NULL != transfer_proof)
+        json_decref (transfer_proof);
+}
+
+
+int
+main (int argc,
+      char *const argv[])
+{
+    const char *plugin_name;
+    char *config_filename;
+    char *testname;
+    struct GNUNET_CONFIGURATION_Handle *cfg;
+
+    result = -1;
+    if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+    {
+        GNUNET_break (0);
+        return -1;
+    }
+    GNUNET_log_setup (argv[0], "DEBUG", NULL);
+    plugin_name++;
+    (void) GNUNET_asprintf (&testname,
+                            "test-merchantdb-%s",
+                            plugin_name);
+    (void) GNUNET_asprintf (&config_filename,
+                            "%s.conf",
+                            testname);
+    cfg = GNUNET_CONFIGURATION_create ();
+    if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_parse (cfg,
+                                    config_filename))
+    {
+        GNUNET_break (0);
+        GNUNET_free (config_filename);
+        GNUNET_free (testname);
+        return 2;
+    }
+    GNUNET_SCHEDULER_run (&run, cfg);
+    GNUNET_CONFIGURATION_destroy (cfg);
+    GNUNET_free (config_filename);
+    GNUNET_free (testname);
+    return result;
+}
+
+/* end of test_merchantdb.c */
\ No newline at end of file
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index b272f97..9ddb921 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -22,7 +22,7 @@
 #define ANASTASIS_DATABASE_PLUGIN_H
 
 #include <gnunet/gnunet_util_lib.h>
-#include <anastasis_db_lib.h>
+#include <anastasis_error_codes.h>
 #include <jansson.h>
 #include <taler/taler_util.h>
 
@@ -116,7 +116,7 @@ struct ANASTASIS_DatabasePlugin
   * @param pg connection to check
   */
   void
-  (*check_connection) (struct PostgresClosure *pg);
+  (*check_connection) (void *cls);
 
   /**
   * Roll back the current transaction of a database connection.
@@ -131,10 +131,13 @@ struct ANASTASIS_DatabasePlugin
    * Start a transaction.
    *
    * @param cls the `struct PostgresClosure` with the plugin-specific state
+   * @param name unique name identifying the transaction (for debugging),
+   *             must point to a constant
    * @return #GNUNET_OK on success
    */
   int
-  (*start) (void *cls);
+  (*start) (void *cls,
+            const char *name);
 
   /**
    * Commit the current transaction of a database connection.
@@ -236,6 +239,9 @@ struct ANASTASIS_DatabasePlugin
                  const struct ANASTASIS_uuid *uuid,
                  const void *truth_data,
                  size_t truth_data_size,
+                 const char *mime_type,
+                 const void *encrypted_key_share,
+                 size_t encrypted_key_share_size,
                  struct GNUNET_TIME_Relative truth_expiration);
 
 
diff --git a/src/include/anastasis_error_codes.h 
b/src/include/anastasis_error_codes.h
new file mode 100644
index 0000000..3fa89b7
--- /dev/null
+++ b/src/include/anastasis_error_codes.h
@@ -0,0 +1,77 @@
+/*
+   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 Affero General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   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
+   Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/**
+ * @file include/ANASTASIS_DB_lib.h
+ * @brief shared defintions for transactional databases
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ */
+#ifndef ANASTASIS_DB_LIB_H
+#define ANASTASIS_DB_LIB_H
+
+
+/**
+ * Status code returned from functions running database commands.
+ * Can be combined with a function that returns the number
+ * of results, so all non-negative values indicate success.
+ */
+enum ANASTASIS_DB_QueryStatus
+{
+  /**
+   * A hard error occurred, retrying will not help.
+   */
+  ANASTASIS_DB_STATUS_HARD_ERROR = -2,
+
+  /**
+   * A soft error occurred, retrying the transaction may succeed.
+   * Includes DEADLOCKS and SERIALIZATION errors.
+   */
+  ANASTASIS_DB_STATUS_SOFT_ERROR = -1,
+
+  /**
+   * The transaction succeeded, but yielded zero results.
+   * May include the case where an INSERT failed with UNIQUE
+   * violation (i.e. row already exists) or where DELETE
+   * failed to remove anything (i.e. nothing matched).
+   */
+  ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS = 0,
+
+  /**
+   * The transaction succeeded, and yielded one result.
+   */
+  ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT = 1,
+
+  /**
+   * The specified User was unknown
+   */
+  ANASTASIS_DB_STATUS_UNKNOWN_USER = 6000,
+
+   /**
+   * The Users Payment had not sufficient posts left
+   */
+  ANASTASIS_DB_STATUS_NOT_SUFFICIENT_POSTS = 6001,
+
+   /**
+   * The Payment from the User has expired.
+   */
+  ANASTASIS_DB_STATUS_PAYMENT_EXPIRED = 6002
+};
+
+#endif

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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