gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix #6842


From: gnunet
Subject: [taler-anastasis] branch master updated: fix #6842
Date: Sun, 11 Apr 2021 17:26:00 +0200

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 51e44d8  fix #6842
51e44d8 is described below

commit 51e44d8bb05e045e30df2ab8b6d040d6819f4ca9
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 11 17:25:57 2021 +0200

    fix #6842
---
 src/backend/anastasis-httpd_policy_upload.c    |  80 +++------------
 src/cli/test_anastasis_reducer_enter_secret.sh |   3 -
 src/include/anastasis.h                        |   5 +
 src/include/anastasis_database_plugin.h        |  17 ----
 src/lib/anastasis_backup.c                     |   1 +
 src/reducer/anastasis_api_backup_redux.c       |  35 +++++++
 src/restclient/anastasis_api_policy_store.c    |  13 ++-
 src/stasis/plugin_anastasis_postgres.c         | 134 -------------------------
 8 files changed, 65 insertions(+), 223 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index d97b58b..b15edab 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2019 GNUnet e.V.
+  Copyright (C) 2021 Anastasis SARL
 
   TALER 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
@@ -357,35 +357,6 @@ proposal_cb (void *cls,
 }
 
 
-/**
- * Function called on all pending payments for the right
- * account.
- *
- * @param cls closure, our `struct BackupContext`
- * @param timestamp for how long have we been waiting
- * @param ps payment secret in the backend
- * @param amount how much is the order for
- */
-static void
-ongoing_payment_cb (void *cls,
-                    struct GNUNET_TIME_Absolute timestamp,
-                    const struct ANASTASIS_PaymentSecretP *ps,
-                    const struct TALER_Amount *amount)
-{
-  struct PolicyUploadContext *puc = cls;
-
-  (void) amount;
-  if (0 != TALER_amount_cmp (amount,
-                             &AH_annual_fee))
-    return; /* can't re-use, fees changed */
-  if (puc->existing_pi_timestamp.abs_value_us < timestamp.abs_value_us)
-  {
-    puc->payment_identifier = *ps;
-    puc->existing_pi_timestamp = timestamp;
-  }
-}
-
-
 /**
  * Callback to process a GET /check-payment request
  *
@@ -514,10 +485,9 @@ await_payment (struct PolicyUploadContext *puc)
 
 
 /**
- * Helper function used to ask our backend to begin
- * processing a payment for the user's account.
- * May perform asynchronous operations by suspending the connection
- * if required.
+ * Helper function used to ask our backend to begin processing a
+ * payment for the user's account.  May perform asynchronous
+ * operations by suspending the connection if required.
  *
  * @param puc context to begin payment for.
  * @return MHD status code
@@ -526,31 +496,6 @@ static MHD_RESULT
 begin_payment (struct PolicyUploadContext *puc)
 {
   json_t *order;
-  enum GNUNET_DB_QueryStatus qs;
-
-  qs = db->lookup_pending_payments_by_account (db->cls,
-                                               &puc->account,
-                                               &ongoing_payment_cb,
-                                               puc);
-  if (qs < 0)
-  {
-    struct MHD_Response *resp;
-    MHD_RESULT ret;
-
-    resp = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
-                                 "pending payments by account");
-    ret = MHD_queue_response (puc->con,
-                              MHD_HTTP_INTERNAL_SERVER_ERROR,
-                              resp);
-    MHD_destroy_response (resp);
-    return ret;
-  }
-
-  if (0 != puc->existing_pi_timestamp.abs_value_us)
-  {
-    await_payment (puc);
-    return MHD_YES;
-  }
 
   GNUNET_CONTAINER_DLL_insert (puc_head,
                                puc_tail,
@@ -655,6 +600,9 @@ AH_handler_policy_post (
                                              " header must be a base32-encoded 
Payment-Secret");
         }
         puc->payment_identifier_provided = true;
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Policy upload started with payment identifier `%s'\n",
+                    pay_id);
       }
     }
     puc->account = *account_pub;
@@ -822,15 +770,9 @@ AH_handler_policy_post (
 
         if ( (! paid) || (! valid_counter) )
         {
-          if (0 == qs)
-          {
-            /* generate fresh payment identifier */
-            GNUNET_CRYPTO_random_block (
-              GNUNET_CRYPTO_QUALITY_STRONG,
-              &puc->payment_identifier,
-              sizeof (struct ANASTASIS_PaymentSecretP));
-          }
-          return begin_payment (puc);
+          if (! valid_counter)
+            puc->payment_identifier_provided = false;
+          return prepare_payment (puc);
         }
       }
 
@@ -849,6 +791,8 @@ AH_handler_policy_post (
                                    &zero_amount))
           return begin_payment (puc);
         /* Cost is zero, fake "zero" payment having happened */
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Policy upload is free, allowing upload without 
payment\n");
         qs = db->record_recdoc_payment (db->cls,
                                         account_pub,
                                         16 /* post_counter */,
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 5236281..358d517 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -288,9 +288,6 @@ then
 fi
 
 echo " OK"
-#echo -e $COLOR$BOLD"Current state of policy uploads:"$NORM$NOCOLOR
-#POLICY_UPLOADS=`jq -r -e .policy_payment_requests < $TFILE`
-#echo $POLICY_UPLOADS
 #Pay
 
 echo -en $COLOR$BOLD"Withdrawing amount to wallet ..."$NORM$NOCOLOR
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index c654987..1e8c1af 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -769,6 +769,11 @@ struct ANASTASIS_SharePaymentRequest
    * Base URL of the provider requesting payment.
    */
   const char *provider_url;
+
+  /**
+   * The payment secret (aka order ID) extracted from the @e 
payment_request_url.
+   */
+  struct ANASTASIS_PaymentSecretP payment_secret;
 };
 
 
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 4853375..8bd702e 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -392,23 +392,6 @@ struct ANASTASIS_DatabasePlugin
     uint32_t *version);
 
 
-  /**
-   * Lookup pending payments by account.
-   *
-   * @param cls closure
-   * @param anastasis_pub account to look for pending payment under
-   * @param it iterator to call on all pending payments
-   * @param it_cls closure for @a it
-   * @return transaction status
-   */
-  enum GNUNET_DB_QueryStatus
-  (*lookup_pending_payments_by_account)(
-    void *cls,
-    const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
-    ANASTASIS_DB_PaymentPendingIterator it,
-    void *it_cls);
-
-
   /**
    * Check payment identifier. Used to check if a payment identifier given by
    * the user is valid (existing and paid).
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index 396a243..2e00a2b 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -719,6 +719,7 @@ policy_store_cb (void *cls,
       {
         spr[off].payment_request_url = pssi->payment_request;
         spr[off].provider_url = pssi->anastasis_url;
+        spr[off].payment_secret = pssi->payment_secret;
         off++;
       }
     }
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index 5f085f7..aa5b595 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1601,7 +1601,10 @@ secret_share_result_cb (void *cls,
   case ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED:
     {
       json_t *ra;
+      json_t *providers;
 
+      providers = json_object_get (uc->state,
+                                   "policy_providers");
       set_state (uc->state,
                  ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
       serialize_truth (uc);
@@ -1612,6 +1615,8 @@ secret_share_result_cb (void *cls,
       {
         const struct ANASTASIS_SharePaymentRequest *spr;
         json_t *pr;
+        size_t off;
+        json_t *provider;
 
         spr = &sr->details.payment_required.payment_requests[i];
         pr = json_pack ("{s:s, s:s}",
@@ -1622,6 +1627,36 @@ secret_share_result_cb (void *cls,
         GNUNET_assert (0 ==
                        json_array_append_new (ra,
                                               pr));
+        json_array_foreach (providers, off, provider)
+        {
+          const char *purl = json_string_value (json_object_get (provider,
+                                                                 
"provider_url"));
+
+          if (NULL == purl)
+          {
+            GNUNET_break (0);
+            ANASTASIS_redux_fail_ (uc->cb,
+                                   uc->cb_cls,
+                                   TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+                                   "policy_providers array contents are 
invalid");
+            json_decref (ra);
+            return;
+          }
+          if (0 == strcmp (purl,
+                           spr->provider_url))
+          {
+            json_t *psj;
+
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Remembering payment secret for provider `%s'\n",
+                        spr->provider_url);
+            psj = GNUNET_JSON_from_data_auto (&spr->payment_secret);
+            GNUNET_assert (0 ==
+                           json_object_set_new (provider,
+                                                "payment_secret",
+                                                psj));
+          }
+        }
       }
       GNUNET_assert (0 ==
                      json_object_set_new (uc->state,
diff --git a/src/restclient/anastasis_api_policy_store.c 
b/src/restclient/anastasis_api_policy_store.c
index 1ab08fc..babf06e 100644
--- a/src/restclient/anastasis_api_policy_store.c
+++ b/src/restclient/anastasis_api_policy_store.c
@@ -1,6 +1,6 @@
 /*
   This file is part of ANASTASIS
-  Copyright (C) 2014-2019 GNUnet e.V. and INRIA
+  Copyright (C) 2014-2021 Anastasis SARL
 
   ANASTASIS is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -170,6 +170,9 @@ handle_policy_store_finished (void *cls,
         ud.ec = TALER_EC_ANASTASIS_GENERIC_INVALID_PAYMENT_REQUEST;
         break;
       }
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Policy store operation requires payment `%s'\n",
+                  pso->pay_uri);
       if (GNUNET_OK !=
           GNUNET_STRINGS_string_to_data (
             pd.order_id,
@@ -381,6 +384,9 @@ ANASTASIS_policy_store (
       paid_order_id = GNUNET_STRINGS_data_to_string_alloc (
         payment_secret,
         sizeof (*payment_secret));
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Beginning policy store operation with payment secret 
`%s'\n",
+                  paid_order_id);
       GNUNET_asprintf (&hdr,
                        "Payment-Identifier: %s",
                        paid_order_id);
@@ -396,6 +402,11 @@ ANASTASIS_policy_store (
       }
       job_headers = ext;
     }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Beginning policy store operation without payment secret\n");
+    }
   }
   /* Finished setting up headers */
   pso = GNUNET_new (struct ANASTASIS_PolicyStoreOperation);
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 21f2ae7..e183211 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -259,126 +259,6 @@ postgres_gc (void *cls,
 }
 
 
-/**
- * Closure for #payment_by_account_cb.
- */
-struct PaymentIteratorContext
-{
-  /**
-   * Function to call on each result
-   */
-  ANASTASIS_DB_PaymentPendingIterator it;
-
-  /**
-   * Closure for @e it.
-   */
-  void *it_cls;
-
-  /**
-   * Plugin context.
-   */
-  struct PostgresClosure *pg;
-
-  /**
-   * Query status to return.
-   */
-  enum GNUNET_DB_QueryStatus qs;
-
-};
-
-
-/**
- * Helper function for #postgres_lookup_pending_payments_by_account().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PaymentIteratorContext *`
- * @param result the postgres result
- * @param num_result the number of results in @a result
- */
-static void
-payment_by_account_cb (void *cls,
-                       PGresult *result,
-                       unsigned int num_results)
-{
-  struct PaymentIteratorContext *pic = cls;
-
-  for (unsigned int i = 0; i < num_results; i++)
-  {
-    struct GNUNET_TIME_Absolute creation_date;
-    struct ANASTASIS_PaymentSecretP payment_identifier;
-    struct TALER_Amount amount;
-    struct GNUNET_PQ_ResultSpec rs[] = {
-      GNUNET_PQ_result_spec_absolute_time ("creation_date",
-                                           &creation_date),
-      GNUNET_PQ_result_spec_auto_from_type ("payment_identifier",
-                                            &payment_identifier),
-      TALER_PQ_result_spec_amount ("amount",
-                                   pic->pg->currency,
-                                   &amount),
-      GNUNET_PQ_result_spec_end
-    };
-
-    if (GNUNET_OK !=
-        GNUNET_PQ_extract_result (result,
-                                  rs,
-                                  i))
-    {
-      GNUNET_break (0);
-      pic->qs = GNUNET_DB_STATUS_HARD_ERROR;
-      return;
-    }
-    pic->qs = i + 1;
-    pic->it (pic->it_cls,
-             creation_date,
-             &payment_identifier,
-             &amount);
-    GNUNET_PQ_cleanup_result (rs);
-  }
-}
-
-
-/**
- * Lookup pending payments by account.
- *
- * @param cls closure
- * @param anastasis_pub account to look for pending payment under
- * @param it iterator to call on all pending payments
- * @param it_cls closure for @a it
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_pending_payments_by_account (
-  void *cls,
-  const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
-  ANASTASIS_DB_PaymentPendingIterator it,
-  void *it_cls)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
-    GNUNET_PQ_query_param_end
-  };
-  struct PaymentIteratorContext pic = {
-    .it = it,
-    .it_cls = it_cls,
-    .pg = pg
-  };
-  enum GNUNET_DB_QueryStatus qs;
-
-  check_connection (pg);
-  postgres_preflight (pg);
-  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
-                                             
"recdoc_payments_select_by_account",
-                                             params,
-                                             &payment_by_account_cb,
-                                             &pic);
-  if (qs > 0)
-    return pic.qs;
-  GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
-  return qs;
-}
-
-
 /**
  * Store encrypted recovery document.
  *
@@ -1953,18 +1833,6 @@ libanastasis_plugin_db_postgres_init (void *cls)
                             " FROM anastasis_recdoc_payment"
                             " WHERE paid=FALSE;",
                             0),
-    GNUNET_PQ_make_prepare ("recdoc_payments_select_by_account",
-                            "SELECT"
-                            " creation_date"
-                            ",payment_identifier"
-                            ",amount_val"
-                            ",amount_frac"
-                            " FROM anastasis_recdoc_payment"
-                            " WHERE"
-                            "  paid=FALSE"
-                            " AND"
-                            "  user_id=$1;",
-                            1),
     GNUNET_PQ_make_prepare ("gc_accounts",
                             "DELETE FROM anastasis_user "
                             "WHERE"
@@ -2172,8 +2040,6 @@ libanastasis_plugin_db_postgres_init (void *cls)
   plugin->get_recovery_document = &postgres_get_recovery_document;
   plugin->lookup_account = &postgres_lookup_account;
   plugin->check_payment_identifier = &postgres_check_payment_identifier;
-  plugin->lookup_pending_payments_by_account =
-    &postgres_lookup_pending_payments_by_account;
   plugin->increment_lifetime = &postgres_increment_lifetime;
   plugin->start = &begin_transaction;
   plugin->check_connection = &check_connection;

-- 
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]