gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: modify reducer to return policy


From: gnunet
Subject: [taler-anastasis] branch master updated: modify reducer to return policy expiration dates to frontend
Date: Mon, 19 Jul 2021 14:22:59 +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 57a2bab  modify reducer to return policy expiration dates to frontend
57a2bab is described below

commit 57a2bab421478c3d2b337b41d9edaa34f0063086
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Jul 19 14:22:52 2021 +0200

    modify reducer to return policy expiration dates to frontend
---
 doc/sphinx/reducer.rst                      | 10 ++++
 src/backend/anastasis-httpd_policy_upload.c | 40 ++++++++++++-
 src/include/anastasis.h                     | 32 +++++++---
 src/include/anastasis_crypto_lib.h          | 10 +++-
 src/include/anastasis_database_plugin.h     |  4 +-
 src/include/anastasis_service.h             |  6 ++
 src/lib/anastasis_backup.c                  | 17 ++++--
 src/reducer/anastasis_api_backup_redux.c    | 17 +++---
 src/restclient/anastasis_api_policy_store.c | 46 ++++++++++++++-
 src/stasis/plugin_anastasis_postgres.c      | 90 ++++++++++++++++++++++++-----
 src/stasis/test_anastasis_db.c              | 15 +++--
 src/testing/test_anastasis_api.conf         |  2 +
 12 files changed, 242 insertions(+), 47 deletions(-)

diff --git a/doc/sphinx/reducer.rst b/doc/sphinx/reducer.rst
index 1fadedb..e5f1699 100644
--- a/doc/sphinx/reducer.rst
+++ b/doc/sphinx/reducer.rst
@@ -1198,6 +1198,16 @@ Example results are thus:
 
     {
       "backup_state": "BACKUP_FINISHED",
+      "success_details": {
+        "http://localhost:8080/"; : {
+          "policy_version" : 1,
+          "policy_expiration" : { "t_ms" : 1245362362000 }
+        },
+        "http://localhost:8081/"; : {
+          "policy_version" : 3,
+          "policy_expiration" : { "t_ms" : 1245362362000 }
+        }
+      }
     }
 
 
diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index c8f8e87..078f08e 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -462,7 +462,8 @@ check_payment_cb (void *cls,
       qs = db->increment_lifetime (db->cls,
                                    &puc->account,
                                    &puc->payment_identifier,
-                                   paid_until);
+                                   paid_until,
+                                   &puc->paid_until);
       if (0 <= qs)
         return; /* continue as planned */
       GNUNET_break (0);
@@ -622,6 +623,8 @@ prepare_payment (struct PolicyUploadContext *puc)
       &puc->payment_identifier,
       sizeof (struct ANASTASIS_PaymentSecretP));
     puc->payment_identifier_provided = true;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "No payment identifier, initiating payment\n");
     return begin_payment (puc);
   }
   await_payment (puc);
@@ -887,6 +890,13 @@ AH_handler_policy_post (
             puc->payment_identifier_provided = false;
             if (0 == puc->years_to_pay)
               puc->years_to_pay = 1;
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Too many uploads with this payment identifier, 
initiating fresh payment\n");
+          }
+          else
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                        "Given payment identifer not known to be paid, 
initiating payment\n");
           }
           return prepare_payment (puc);
         }
@@ -906,13 +916,17 @@ AH_handler_policy_post (
                                     sizeof (struct ANASTASIS_PaymentSecretP));
         if (0 != TALER_amount_cmp (&AH_annual_fee,
                                    &zero_amount))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "No payment identifier, requesting payment\n");
           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 */,
+                                        AH_post_counter,
                                         &puc->payment_identifier,
                                         &AH_annual_fee);
         if (qs <= 0)
@@ -928,10 +942,11 @@ AH_handler_policy_post (
                     GNUNET_STRINGS_relative_time_to_string (rel,
                                                             GNUNET_YES),
                     ANASTASIS_MAX_YEARS_STORAGE);
+        puc->paid_until = GNUNET_TIME_relative_to_absolute (rel);
         qs = db->update_lifetime (db->cls,
                                   account_pub,
                                   &puc->payment_identifier,
-                                  GNUNET_TIME_relative_to_absolute (rel));
+                                  puc->paid_until);
         if (qs <= 0)
         {
           GNUNET_break (0);
@@ -975,6 +990,8 @@ AH_handler_policy_post (
       switch (as)
       {
       case ANASTASIS_DB_ACCOUNT_STATUS_PAYMENT_REQUIRED:
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Expiration too low, initiating payment\n");
         return prepare_payment (puc);
       case ANASTASIS_DB_ACCOUNT_STATUS_HARD_ERROR:
         return TALER_MHD_reply_with_error (puc->con,
@@ -1084,6 +1101,7 @@ AH_handler_policy_post (
     enum ANASTASIS_DB_StoreStatus ss;
     uint32_t version = UINT32_MAX;
     char version_s[14];
+    char expir_s[32];
 
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 "Uploading recovery document\n");
@@ -1099,18 +1117,30 @@ AH_handler_policy_post (
                      sizeof (version_s),
                      "%u",
                      (unsigned int) version);
+    GNUNET_snprintf (expir_s,
+                     sizeof (expir_s),
+                     "%llu",
+                     (unsigned long long)
+                     (puc->paid_until.abs_value_us
+                      / GNUNET_TIME_UNIT_SECONDS.rel_value_us));
     switch (ss)
     {
     case ANASTASIS_DB_STORE_STATUS_STORE_LIMIT_EXCEEDED:
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Storage request limit exceeded, requesting payment\n");
       if (! puc->payment_identifier_provided)
       {
         GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
                                     &puc->payment_identifier,
                                     sizeof (struct ANASTASIS_PaymentSecretP));
         puc->payment_identifier_provided = true;
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Also no payment identifier, requesting payment\n");
       }
       return begin_payment (puc);
     case ANASTASIS_DB_STORE_STATUS_PAYMENT_REQUIRED:
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Policy store operation requires payment\n");
       if (! puc->payment_identifier_provided)
       {
         GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
@@ -1162,6 +1192,10 @@ AH_handler_policy_post (
                       MHD_add_response_header (resp,
                                                
ANASTASIS_HTTP_HEADER_POLICY_VERSION,
                                                version_s));
+        GNUNET_break (MHD_YES ==
+                      MHD_add_response_header (resp,
+                                               
ANASTASIS_HTTP_HEADER_POLICY_EXPIRATION,
+                                               expir_s));
         ret = MHD_queue_response (connection,
                                   MHD_HTTP_NO_CONTENT,
                                   resp);
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 7015df3..1591106 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -804,6 +804,29 @@ enum ANASTASIS_ShareStatus
 };
 
 
+/**
+ * Per-provider status upon successful backup.
+ */
+struct ANASTASIS_ProviderSuccessStatus
+{
+  /**
+   * Base URL of the provider.
+   */
+  const char *provider_url;
+
+  /**
+   * When will the policy expire?
+   */
+  struct GNUNET_TIME_Absolute policy_expiration;
+
+  /**
+   * Version number of the policy at the provider.
+   */
+  unsigned long long policy_version;
+
+};
+
+
 /**
  * Complete result of a secret sharing operation.
  */
@@ -824,14 +847,9 @@ struct ANASTASIS_ShareResult
     {
 
       /**
-       * Array of version numbers of the resulting policy (on success).
-       */
-      unsigned long long *policy_versions;
-
-      /**
-       * Array of Base URLs of the providers that stored the policy.
+       * Array of status details for each provider.
        */
-      const char **provider_urls;
+      const struct ANASTASIS_ProviderSuccessStatus *pss;
 
       /**
        * Length of the @e policy_version and @e provider_urls arrays.
diff --git a/src/include/anastasis_crypto_lib.h 
b/src/include/anastasis_crypto_lib.h
index bddcb5b..bf29b27 100644
--- a/src/include/anastasis_crypto_lib.h
+++ b/src/include/anastasis_crypto_lib.h
@@ -29,15 +29,21 @@
  */
 #define ANASTASIS_HTTP_HEADER_POLICY_VERSION "Anastasis-Version"
 
+/**
+ * Server to client: this is the policy expiration time.
+ */
+#define ANASTASIS_HTTP_HEADER_POLICY_EXPIRATION "Anastasis-Policy-Expiration"
+
 /**
  * Client to server: use this to decrypt the truth.
  */
-#define ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY "Truth-Decryption-Key"
+#define ANASTASIS_HTTP_HEADER_TRUTH_DECRYPTION_KEY \
+  "Anastasis-Truth-Decryption-Key"
 
 /**
  * Client to server: I paid using this payment secret.
  */
-#define ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER "Payment-Identifier"
+#define ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER "Anastasis-Payment-Identifier"
 
 /**
  * Client to server: I am authorized to update this policy, or
diff --git a/src/include/anastasis_database_plugin.h 
b/src/include/anastasis_database_plugin.h
index 0584b73..488a5af 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -438,6 +438,7 @@ struct ANASTASIS_DatabasePlugin
    * @param account_pub which account received a payment
    * @param payment_identifier proof of payment, must be unique and match 
pending payment
    * @param lifetime for how long is the account now paid (increment)
+   * @param[out] paid_until set to the end of the lifetime after the operation
    * @return transaction status
    */
   enum GNUNET_DB_QueryStatus
@@ -445,7 +446,8 @@ struct ANASTASIS_DatabasePlugin
     void *cls,
     const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
     const struct ANASTASIS_PaymentSecretP *payment_identifier,
-    struct GNUNET_TIME_Relative lifetime);
+    struct GNUNET_TIME_Relative lifetime,
+    struct GNUNET_TIME_Absolute *paid_until);
 
 
   /**
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 4fc04fd..98ac490 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -333,6 +333,12 @@ struct ANASTASIS_UploadDetails
        */
       const struct GNUNET_HashCode *curr_backup_hash;
 
+      /**
+       * At what time is the provider set to forget this
+       * policy (because the account expires)?
+       */
+      struct GNUNET_TIME_Absolute policy_expiration;
+
       /**
        * Version number of the resulting policy.
        */
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index 1f78ac8..ea55e6a 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -569,6 +569,11 @@ struct PolicyStoreState
    */
   unsigned long long policy_version;
 
+  /**
+   * When will the policy expire at the provider.
+   */
+  struct GNUNET_TIME_Absolute policy_expiration;
+
 };
 
 /**
@@ -634,6 +639,7 @@ policy_store_cb (void *cls,
   {
   case ANASTASIS_US_SUCCESS:
     pss->policy_version = ud->details.success.policy_version;
+    pss->policy_expiration = ud->details.success.policy_expiration;
     break;
   case ANASTASIS_US_PAYMENT_REQUIRED:
     pss->payment_request = GNUNET_strdup (ud->details.payment.payment_request);
@@ -666,8 +672,7 @@ policy_store_cb (void *cls,
 
   {
     struct ANASTASIS_SharePaymentRequest spr[GNUNET_NZL (ss->pss_length)];
-    const char *provider_urls[GNUNET_NZL (ss->pss_length)];
-    unsigned long long versions[GNUNET_NZL (ss->pss_length)];
+    struct ANASTASIS_ProviderSuccessStatus apss[GNUNET_NZL (ss->pss_length)];
     unsigned int off = 0;
     unsigned int voff = 0;
     struct ANASTASIS_ShareResult sr;
@@ -678,8 +683,9 @@ policy_store_cb (void *cls,
 
       if (NULL == pssi->payment_request)
       {
-        versions[voff] = pssi->policy_version;
-        provider_urls[voff] = pssi->anastasis_url;
+        apss[voff].policy_version = pssi->policy_version;
+        apss[voff].provider_url = pssi->anastasis_url;
+        apss[voff].policy_expiration = pssi->policy_expiration;
         voff++;
       }
       else
@@ -699,8 +705,7 @@ policy_store_cb (void *cls,
     else
     {
       sr.ss = ANASTASIS_SHARE_STATUS_SUCCESS;
-      sr.details.success.policy_versions = versions;
-      sr.details.success.provider_urls = provider_urls;
+      sr.details.success.pss = apss;
       sr.details.success.num_providers = voff;
     }
     ss->src (ss->src_cls,
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index c07f887..c8c89af 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -2799,22 +2799,25 @@ secret_share_result_cb (void *cls,
     (void) json_object_del (uc->state,
                             "core_secret");
     {
-      json_t *sa = json_array ();
+      json_t *sa = json_object ();
 
       GNUNET_assert (NULL != sa);
       for (unsigned int i = 0; i<sr->details.success.num_providers; i++)
       {
+        const struct ANASTASIS_ProviderSuccessStatus *pssi
+          = &sr->details.success.pss[i];
         json_t *d;
 
-        d = json_pack ("{s:s, s:I}",
-                       "provider_url",
-                       sr->details.success.provider_urls[i],
+        d = json_pack ("{s:I, s:o}",
                        "policy_version",
-                       (json_int_t) sr->details.success.policy_versions[i]);
+                       pssi->policy_version,
+                       "policy_expiration",
+                       GNUNET_JSON_from_time_abs (pssi->policy_expiration));
         GNUNET_assert (NULL != d);
         GNUNET_assert (0 ==
-                       json_array_append_new (sa,
-                                              d));
+                       json_object_set_new (sa,
+                                            "pssi->provider_url",
+                                            d));
       }
       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 9b8c370..7c6c244 100644
--- a/src/restclient/anastasis_api_policy_store.c
+++ b/src/restclient/anastasis_api_policy_store.c
@@ -71,6 +71,11 @@ struct ANASTASIS_PolicyStoreOperation
    */
   char *policy_version;
 
+  /**
+   * Policy expiration we received from the service, or NULL.
+   */
+  char *policy_expiration;
+
   /**
    * Copy of the uploaded data. Needed by curl.
    */
@@ -93,6 +98,7 @@ ANASTASIS_policy_store_cancel (
     pso->job = NULL;
   }
   GNUNET_free (pso->policy_version);
+  GNUNET_free (pso->policy_expiration);
   GNUNET_free (pso->pay_uri);
   GNUNET_free (pso->url);
   GNUNET_free (pso->postcopy);
@@ -135,6 +141,7 @@ handle_policy_store_finished (void *cls,
   case MHD_HTTP_NOT_MODIFIED:
     {
       unsigned long long version;
+      unsigned long long expiration;
       char dummy;
 
       if (1 != sscanf (pso->policy_version,
@@ -146,8 +153,23 @@ handle_policy_store_finished (void *cls,
         ud.us = ANASTASIS_US_SERVER_ERROR;
         break;
       }
+      if (1 != sscanf (pso->policy_expiration,
+                       "%llu%c",
+                       &expiration,
+                       &dummy))
+      {
+        ud.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+        ud.us = ANASTASIS_US_SERVER_ERROR;
+        break;
+      }
       ud.us = ANASTASIS_US_SUCCESS;
       ud.details.success.curr_backup_hash = &pso->new_upload_hash;
+      ud.details.success.policy_expiration
+        = GNUNET_TIME_absolute_add (
+            GNUNET_TIME_UNIT_ZERO_ABS,
+            GNUNET_TIME_relative_multiply (
+              GNUNET_TIME_UNIT_SECONDS,
+              expiration));
       ud.details.success.policy_version = version;
     }
     break;
@@ -296,6 +318,24 @@ handle_header (char *buffer,
     }
   }
 
+  if (0 == strcasecmp (hdr_type,
+                       ANASTASIS_HTTP_HEADER_POLICY_EXPIRATION))
+  {
+    size_t len;
+
+    /* found policy expiration we care about! */
+    GNUNET_free (pso->policy_expiration); /* In case of duplicate header */
+    pso->policy_expiration = GNUNET_strdup (hdr_val);
+    len = strlen (pso->policy_expiration);
+    while ( (len > 0) &&
+            ( ('\n' == pso->policy_expiration[len - 1]) ||
+              ('\r' == pso->policy_expiration[len - 1]) ) )
+    {
+      len--;
+      pso->policy_expiration[len] = '\0';
+    }
+  }
+
   GNUNET_free (ndup);
   return total;
 }
@@ -343,7 +383,8 @@ ANASTASIS_policy_store (
     val = GNUNET_STRINGS_data_to_string_alloc (&account_sig,
                                                sizeof (account_sig));
     GNUNET_asprintf (&hdr,
-                     "Anastasis-Policy-Signature: %s",
+                     "%s: %s",
+                     ANASTASIS_HTTP_HEADER_POLICY_SIGNATURE,
                      val);
     GNUNET_free (val);
     ext = curl_slist_append (job_headers,
@@ -388,7 +429,8 @@ ANASTASIS_policy_store (
                   "Beginning policy store operation with payment secret 
`%s'\n",
                   paid_order_id);
       GNUNET_asprintf (&hdr,
-                       "Payment-Identifier: %s",
+                       "%s: %s",
+                       ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER,
                        paid_order_id);
       GNUNET_free (paid_order_id);
       ext = curl_slist_append (job_headers,
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index 4cccc3a..4aba97c 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -25,6 +25,14 @@
 #include "anastasis_database_lib.h"
 #include <taler/taler_pq_lib.h>
 
+/**
+ * How long do we keep transient accounts open (those that have
+ * not been paid at all, but are awaiting payment). This puts
+ * a cap on how long users have to make a payment after a payment
+ * request was generated.
+ */
+#define TRANSIENT_LIFETIME GNUNET_TIME_UNIT_WEEKS
+
 /**
  * How often do we re-try if we run into a DB serialization error?
  */
@@ -499,6 +507,7 @@ retry:
  * @param anastasis_pub which account received a payment
  * @param payment_identifier proof of payment, must be unique and match 
pending payment
  * @param lifetime for how long is the account now paid (increment)
+ * @param[out] paid_until set to the end of the lifetime after the operation
  * @return transaction status
  */
 static enum GNUNET_DB_QueryStatus
@@ -506,7 +515,8 @@ postgres_increment_lifetime (
   void *cls,
   const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub,
   const struct ANASTASIS_PaymentSecretP *payment_identifier,
-  struct GNUNET_TIME_Relative lifetime)
+  struct GNUNET_TIME_Relative lifetime,
+  struct GNUNET_TIME_Absolute *paid_until)
 {
   struct PostgresClosure *pg = cls;
   enum GNUNET_DB_QueryStatus qs;
@@ -531,17 +541,25 @@ postgres_increment_lifetime (
       qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                "recdoc_payment_done",
                                                params);
-      if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
-        goto retry;
-      if (0 >= qs)
+      switch (qs)
       {
-        /* payment made before, or unknown, or error => no further action! */
+      case GNUNET_DB_STATUS_HARD_ERROR:
         rollback (pg);
+        *paid_until = GNUNET_TIME_UNIT_ZERO_ABS;
         return qs;
+      case GNUNET_DB_STATUS_SOFT_ERROR:
+        goto retry;
+      case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+        /* continued below */
+        break;
+      case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+        /* continued below */
+        break;
       }
     }
 
     {
+      enum GNUNET_DB_QueryStatus qs2;
       struct GNUNET_PQ_QueryParam params[] = {
         GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
         GNUNET_PQ_query_param_end
@@ -553,18 +571,26 @@ postgres_increment_lifetime (
         GNUNET_PQ_result_spec_end
       };
 
-      qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                     "user_select",
-                                                     params,
-                                                     rs);
-      switch (qs)
+      qs2 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                      "user_select",
+                                                      params,
+                                                      rs);
+      switch (qs2)
       {
       case GNUNET_DB_STATUS_HARD_ERROR:
         rollback (pg);
-        return qs;
+        return qs2;
       case GNUNET_DB_STATUS_SOFT_ERROR:
         goto retry;
       case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+        if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+        {
+          /* inconsistent, cannot have recdoc payment but no user!? */
+          GNUNET_break (0);
+          rollback (pg);
+          return GNUNET_DB_STATUS_HARD_ERROR;
+        }
+        else
         {
           /* user does not exist, create new one */
           struct GNUNET_PQ_QueryParam params[] = {
@@ -576,12 +602,25 @@ postgres_increment_lifetime (
           expiration = GNUNET_TIME_relative_to_absolute (lifetime);
           GNUNET_break (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
                         expiration.abs_value_us);
+          *paid_until = expiration;
           qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                    "user_insert",
                                                    params);
         }
         break;
       case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+        if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+        {
+          /* existing rec doc payment, return expiration */
+          *paid_until = expiration;
+          rollback (pg);
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "Payment existed, lifetime of account %s unchanged at 
%s\n",
+                      TALER_B2S (anastasis_pub),
+                      GNUNET_STRINGS_absolute_time_to_string (*paid_until));
+          return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+        }
+        else
         {
           /* user exists, update expiration_date */
           struct GNUNET_PQ_QueryParam params[] = {
@@ -594,6 +633,7 @@ postgres_increment_lifetime (
                                                  lifetime);
           GNUNET_break (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
                         expiration.abs_value_us);
+          *paid_until = expiration;
           qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                    "user_update",
                                                    params);
@@ -621,6 +661,10 @@ postgres_increment_lifetime (
       goto retry;
     if (qs < 0)
       return GNUNET_DB_STATUS_HARD_ERROR;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Incremented lifetime of account %s to %s\n",
+                TALER_B2S (anastasis_pub),
+                GNUNET_STRINGS_absolute_time_to_string (*paid_until));
     return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
 retry:
     rollback (pg);
@@ -673,8 +717,12 @@ postgres_update_lifetime (
         goto retry;
       if (0 >= qs)
       {
-        /* payment made before, or unknown, or error => no further action! */
+        /* same payment made before, or unknown, or error
+           => no further action! */
         rollback (pg);
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Payment existed, lifetime of account %s unchanged\n",
+                    TALER_B2S (anastasis_pub));
         return qs;
       }
     }
@@ -716,6 +764,10 @@ postgres_update_lifetime (
           qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                    "user_insert",
                                                    params);
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "Created new account %s with expiration %s\n",
+                      TALER_B2S (anastasis_pub),
+                      GNUNET_STRINGS_absolute_time_to_string (eol));
         }
         break;
       case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
@@ -734,6 +786,10 @@ postgres_update_lifetime (
           qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                                    "user_update",
                                                    params);
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                      "Updated account %s to new expiration %s\n",
+                      TALER_B2S (anastasis_pub),
+                      GNUNET_STRINGS_absolute_time_to_string (expiration));
         }
         break;
       }
@@ -829,10 +885,12 @@ postgres_record_recdoc_payment (
     return GNUNET_DB_STATUS_HARD_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     {
-      /* create new user */
+      /* create new user with short lifetime */
+      struct GNUNET_TIME_Absolute exp
+        = GNUNET_TIME_relative_to_absolute (TRANSIENT_LIFETIME);
       struct GNUNET_PQ_QueryParam params[] = {
         GNUNET_PQ_query_param_auto_from_type (anastasis_pub),
-        GNUNET_PQ_query_param_absolute_time (&now),
+        GNUNET_PQ_query_param_absolute_time (&exp),
         GNUNET_PQ_query_param_end
       };
 
@@ -851,6 +909,10 @@ postgres_record_recdoc_payment (
         return GNUNET_DB_STATUS_HARD_ERROR;
       case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
         /* successful, continue below */
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Created new account %s with transient life until %s\n",
+                    TALER_B2S (anastasis_pub),
+                    GNUNET_STRINGS_absolute_time_to_string (exp));
         break;
       }
     }
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index 1680cfd..5e21530 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -150,11 +150,16 @@ run (void *cls)
                                          post_counter,
                                          &paymentSecretP,
                                          &amount));
-  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
-          plugin->increment_lifetime (plugin->cls,
-                                      &accountPubP,
-                                      &paymentSecretP,
-                                      rel_time));
+  {
+    struct GNUNET_TIME_Absolute res_time;
+
+    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+            plugin->increment_lifetime (plugin->cls,
+                                        &accountPubP,
+                                        &paymentSecretP,
+                                        rel_time,
+                                        &res_time));
+  }
   FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->check_payment_identifier (plugin->cls,
                                             &paymentSecretP,
diff --git a/src/testing/test_anastasis_api.conf 
b/src/testing/test_anastasis_api.conf
index 4566c06..bde7ee1 100644
--- a/src/testing/test_anastasis_api.conf
+++ b/src/testing/test_anastasis_api.conf
@@ -50,6 +50,8 @@ BUSINESS_NAME = "Checker's Test Inc."
 # Upload limit
 UPLOAD_LIMIT_MB = 1
 
+ANNUAL_POLICY_UPLOAD_LIMIT = 64
+
 INSURANCE = EUR:0
 
 SERVER_SALT = salty

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