gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (fb30bb5 -> ca6fa36)


From: gnunet
Subject: [taler-anastasis] branch master updated (fb30bb5 -> ca6fa36)
Date: Tue, 07 Apr 2020 01:02:12 +0200

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

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

    from fb30bb5  adapt to latest merchant API
     new b1516d6  changed shutdown routine
     new 00457bb  fix not initialized variable
     new 220fab1  fixed loop
     new 3b4bd7e  db
     new ca6fa36  merge

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/anastasis-httpd.c               |  11 +--
 src/backend/anastasis-httpd_policy.h        |   8 ++
 src/backend/anastasis-httpd_policy_upload.c |  58 ++++++++++----
 src/include/anastasis_database_plugin.h     |   4 +-
 src/stasis/plugin_anastasis_postgres.c      | 112 +++++++++++++++++++++++-----
 src/stasis/test_anastasis_db.c              |  11 ++-
 6 files changed, 160 insertions(+), 44 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 2de7f26..dbb5d86 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -365,6 +365,12 @@ static void
 do_shutdown (void *cls)
 {
   (void) cls;
+  AH_resume_all_bc ();
+  if (NULL != mhd_task)
+  {
+    GNUNET_SCHEDULER_cancel (mhd_task);
+    mhd_task = NULL;
+  }
   if (NULL != AH_ctx)
   {
     GNUNET_CURL_fini (AH_ctx);
@@ -375,11 +381,6 @@ do_shutdown (void *cls)
     GNUNET_CURL_gnunet_rc_destroy (rc);
     rc = NULL;
   }
-  if (NULL != mhd_task)
-  {
-    GNUNET_SCHEDULER_cancel (mhd_task);
-    mhd_task = NULL;
-  }
   if (NULL != mhd)
   {
     MHD_stop_daemon (mhd);
diff --git a/src/backend/anastasis-httpd_policy.h 
b/src/backend/anastasis-httpd_policy.h
index d05d46a..5e9cab1 100644
--- a/src/backend/anastasis-httpd_policy.h
+++ b/src/backend/anastasis-httpd_policy.h
@@ -24,6 +24,14 @@
 #define ANASTASIS_HTTPD_POLICY_H
 #include <microhttpd.h>
 
+
+/**
+ * Service is shutting down, resume all MHD connections NOW.
+ */
+void
+AH_resume_all_bc (void);
+
+
 /**
  * @param connection the MHD connection to handle
  * @param url handles a URL of the format 
"/policy/$ACCOUNT_PUB[&version=$NUMBER]"
diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index dfde43a..5395b7e 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -160,6 +160,34 @@ static struct PolicyUploadContext *puc_head;
 static struct PolicyUploadContext *puc_tail;
 
 
+/**
+ * Service is shutting down, resume all MHD connections NOW.
+ */
+void
+AH_resume_all_bc ()
+{
+  struct PolicyUploadContext *puc;
+
+  while (NULL != (puc = puc_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (puc_head,
+                                 puc_tail,
+                                 puc);
+    MHD_resume_connection (puc->con);
+    if (NULL != puc->po)
+    {
+      TALER_MERCHANT_proposal_cancel (puc->po);
+      puc->po = NULL;
+    }
+    if (NULL != puc->cpo)
+    {
+      TALER_MERCHANT_check_payment_cancel (puc->cpo);
+      puc->cpo = NULL;
+    }
+  }
+}
+
+
 /**
  * Function called to clean up a backup context.
  *
@@ -229,14 +257,8 @@ make_payment_request (const char *order_id)
 unsigned int
 amount_to_post_counter (const struct TALER_Amount *amount)
 {
-  /* FIXME: reasonable conversion from Taler Amount to post counter */
-  if ((0 == strcmp (amount->currency, "CHF")) || (0 == strcmp 
(amount->currency,
-                                                               "EUR")))
-  {
-    // FIXME: check if long long value is in int range
-    return (int) amount->value * 10;
-  }
-  return 0;
+  // FIXME: some logic to convert an amount to an unsigned integer (counter)
+  return 10;
 }
 
 
@@ -292,7 +314,11 @@ proposal_cb (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Storing payment request for order `%s'\n",
               order_id);
+
   post_counter = amount_to_post_counter (&AH_annual_fee);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Post counter to save: %i\n",
+              post_counter);
   qs = db->record_payment (db->cls,
                            &puc->account,
                            post_counter,
@@ -803,9 +829,9 @@ AH_handler_policy_post (struct MHD_Connection *connection,
       struct GNUNET_HashCode hc;
       enum ANASTASIS_DB_QueryStatus qs;
 
-      memset (&hc, 0, sizeof (hc));
       qs = db->lookup_account (db->cls,
-                               &accountPubP);
+                               &accountPubP,
+                               &hc);
       if (qs < 0)
         return handle_database_error (puc,
                                       qs);
@@ -880,9 +906,9 @@ AH_handler_policy_post (struct MHD_Connection *connection,
     *recovery_data_size = 0;
     return MHD_YES;
   }
-  else if ( (0 == puc->upload_off) &&
-            (0 != puc->upload_size) &&
-            (NULL == puc->resp) )
+  if ( (0 == puc->upload_off) &&
+       (0 != puc->upload_size) &&
+       (NULL == puc->resp) )
   {
     /* wait for upload */
     return MHD_YES;
@@ -934,14 +960,16 @@ AH_handler_policy_post (struct MHD_Connection *connection,
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "Uploading recovery document\n");
     qs = db->store_recovery_document (db->cls,
-                                      &accountPubP,
+                                      &puc->account,
                                       &puc->account_sig,
                                       &puc->new_policy_upload_hash,
                                       puc->upload,
                                       puc->upload_size,
                                       &puc->payment_identifier,
                                       &version);
-
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "DB status after uploading recovery document: %i\n",
+                qs);
     if (qs < 0)
       return handle_database_error (puc,
                                     qs);
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 562f962..dd9df56 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -305,12 +305,14 @@ struct ANASTASIS_DatabasePlugin
   /**
   * @param cls closure
   * @param anastasis_pub account identifier
+  * @param recovery_data_hash[OUT] set to hash of @a recovery document
   * @return transaction status
   */
   enum ANASTASIS_DB_QueryStatus
   (*lookup_account)(void *cls,
                     const struct
-                    ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub);
+                    ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub,
+                    struct GNUNET_HashCode *recovery_data_hash);
 
   /**
  * Lookup pending payments by account.
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 78fecff..c45ab4c 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -425,6 +425,10 @@ postgres_store_recovery_document (void *cls,
   postgres_preflight (pg);
   /* get the version for the recoverydocument */
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Public key used to query db: %s\n",
+                TALER_B2S (anastasis_pub));
+
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
       GNUNET_PQ_query_param_end
@@ -462,6 +466,10 @@ postgres_store_recovery_document (void *cls,
 
   /* First, check if account exists */
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Public key used to query db: %s\n",
+                TALER_B2S (anastasis_pub));
+
     struct GNUNET_TIME_Absolute ed;
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
@@ -503,7 +511,8 @@ postgres_store_recovery_document (void *cls,
       GNUNET_PQ_query_param_end
     };
     struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_uint32 ("post_counter", &postcounter),
+      GNUNET_PQ_result_spec_uint32 ("post_counter",
+                                    &postcounter),
       GNUNET_PQ_result_spec_end
     };
 
@@ -511,6 +520,9 @@ postgres_store_recovery_document (void *cls,
                                                    "postcounter_select",
                                                    params,
                                                    rs);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Post counter from db: %i\n",
+                postcounter);
   }
 
   switch (qs)
@@ -576,6 +588,10 @@ postgres_store_recovery_document (void *cls,
 
   /* check if existing recovery_data conflicts */
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Public key used to query db: %s\n",
+                TALER_B2S (anastasis_pub));
+
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
       GNUNET_PQ_query_param_end
@@ -700,13 +716,17 @@ postgres_increment_lifetime (void *cls,
   }
 
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Public key used to query db: %s\n",
+                TALER_B2S (anastasis_pub));
+
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
       GNUNET_PQ_query_param_end
     };
     struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_absolute_time ("expiration_date",
-                                           &expiration),
+      GNUNET_PQ_result_spec_auto_from_type ("expiration_date",
+                                            &expiration),
       GNUNET_PQ_result_spec_end
     };
 
@@ -727,6 +747,10 @@ postgres_increment_lifetime (void *cls,
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     {
       // user does not exist, create new one
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Public key to be saved to user db: %s\n",
+                  TALER_B2S (anastasis_pub));
+
       struct GNUNET_PQ_QueryParam params[] = {
         GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
         GNUNET_PQ_query_param_absolute_time (&expiration),
@@ -817,6 +841,10 @@ postgres_record_payment (void *cls,
                          const struct ANASTASIS_PaymentSecretP *payment_secret,
                          const struct TALER_Amount *amount)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Post counter to save: %i\n",
+              post_counter);
+
   struct PostgresClosure *pg = cls;
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
@@ -836,13 +864,17 @@ postgres_record_payment (void *cls,
   // because of constraint at user_id, first we have to verify
   // if user exists, otherwise we have to create one
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Public key used to query user db: %s\n",
+                TALER_B2S (anastasis_pub));
+
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
       GNUNET_PQ_query_param_end
     };
     struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_absolute_time ("expiration_date",
-                                           &expiration),
+      GNUNET_PQ_result_spec_auto_from_type ("expiration_date",
+                                            &expiration),
       GNUNET_PQ_result_spec_end
     };
 
@@ -862,6 +894,10 @@ postgres_record_payment (void *cls,
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     {
       // create new user
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Public key to be saved to user db: %s\n",
+                  TALER_B2S (anastasis_pub));
+
       struct GNUNET_PQ_QueryParam params[] = {
         GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
         GNUNET_PQ_query_param_absolute_time (&now),
@@ -1102,34 +1138,70 @@ postgres_get_key_share (void *cls,
 /**
 * @param cls closure
 * @param anastasis_pub account identifier
+* @param recovery_data_hash[OUT] set to hash of @a recovery document
 * @return transaction status
 */
 enum ANASTASIS_DB_QueryStatus
 postgres_lookup_account (void *cls,
                          const struct
-                         ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub)
+                         ANASTASIS_CRYPTO_AccountPublicKey *anastasis_pub,
+                         struct GNUNET_HashCode *recovery_data_hash)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Public key used to query db: %s\n",
+              TALER_B2S (anastasis_pub));
+
   struct PostgresClosure *pg = cls;
-  struct GNUNET_TIME_Absolute expiration_date;
   enum ANASTASIS_DB_QueryStatus qs;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
     GNUNET_PQ_query_param_end
   };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_absolute_time ("expiration_date",
-                                         &expiration_date),
-    GNUNET_PQ_result_spec_end
-  };
 
   check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                 "user_select",
-                                                 params,
-                                                 rs);
+  postgres_preflight (pg);
+  {
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("recovery_data_hash",
+                                            recovery_data_hash),
+      GNUNET_PQ_result_spec_end
+    };
+
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   
"recoverydocument_select_hash",
+                                                   params,
+                                                   rs);
+  }
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_SOFT_ERROR;
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    break; /* handle interesting case below */
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+  default:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  }
 
-  GNUNET_break (ANASTASIS_DB_STATUS_HARD_ERROR != qs);
+  /* check if account exists */
+  {
+    struct GNUNET_TIME_Absolute expiration_date;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("expiration_date",
+                                            &expiration_date),
+      GNUNET_PQ_result_spec_end
+    };
 
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "user_select",
+                                                   params,
+                                                   rs);
+  }
   switch (qs)
   {
   case GNUNET_DB_STATUS_HARD_ERROR:
@@ -1138,9 +1210,11 @@ postgres_lookup_account (void *cls,
     GNUNET_break (0);
     return ANASTASIS_DB_STATUS_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    /* indicates: no account */
     return ANASTASIS_DB_STATUS_PAYMENT_REQUIRED;
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+    /* indicates: no backup */
+    return ANASTASIS_DB_STATUS_NO_RESULTS;
   default:
     GNUNET_break (0);
     return ANASTASIS_DB_STATUS_HARD_ERROR;
@@ -1316,7 +1390,7 @@ libanastasis_plugin_db_postgres_init (void *cls)
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS anastasis_payment"
                             "(payment_id BIGSERIAL PRIMARY KEY,"
                             " user_id BYTEA NOT NULL REFERENCES 
anastasis_user(user_id),"
-                            " post_counter INTEGER,"
+                            " post_counter INT4 NOT NULL DEFAULT 0 
CHECK(post_counter >= 0),"
                             " amount_val INT8 NOT NULL," /* amount we were 
paid */
                             " amount_frac INT4 NOT NULL,"
                             " payment_identifier BYTEA NOT NULL 
CHECK(LENGTH(payment_identifier)=32),"
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index 2ae6536..5b2f535 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -193,6 +193,7 @@ run (void *cls)
   size_t keysharesize;
   const char *str = "AHV123456789";
   struct GNUNET_CRYPTO_EccSignaturePurpose purp;
+  struct GNUNET_HashCode r;
 
   GNUNET_CRYPTO_eddsa_private_key_from_string (str,
                                                sizeof (str),
@@ -263,10 +264,6 @@ run (void *cls)
                                       &paymentSecretP,
                                       rel_time));
 
-  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
-          plugin->lookup_account (plugin->cls,
-                                  &accountPubP));
-
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->store_truth (plugin->cls,
                                &uuid,
@@ -290,6 +287,12 @@ run (void *cls)
                                            sizeof (&recovery_data),
                                            &paymentSecretP,
                                            &docVersion));
+
+  FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
+          plugin->lookup_account (plugin->cls,
+                                  &accountPubP,
+                                  &r));
+
   /* FIXME: do we really get an escrow challenge?
   FAILIF (ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->get_escrow_challenge (plugin->cls,

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



reply via email to

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