gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: expose policy version via rest


From: gnunet
Subject: [taler-anastasis] branch master updated: expose policy version via rest and redux APIs
Date: Fri, 19 Mar 2021 21:10:27 +0100

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 fa9f9d0  expose policy version via rest and redux APIs
fa9f9d0 is described below

commit fa9f9d06b6ca4d9f9b74fcabbd134dbdce2f0b91
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Mar 19 21:10:23 2021 +0100

    expose policy version via rest and redux APIs
---
 src/include/anastasis.h                     |  5 +++
 src/include/anastasis_service.h             | 20 +++++++++---
 src/lib/anastasis_backup.c                  | 12 +++++++-
 src/reducer/anastasis_api_backup_redux.c    |  5 +++
 src/restclient/anastasis_api_policy_store.c | 48 ++++++++++++++++++++++++++---
 src/testing/testing_api_cmd_policy_store.c  |  2 +-
 6 files changed, 80 insertions(+), 12 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index 7e10325..34a3934 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -795,6 +795,11 @@ struct ANASTASIS_ShareResult
   union
   {
 
+    /**
+     * Version number of the resulting policy (on success).
+     */
+    unsigned long long max_policy_version;
+
     struct
     {
       /**
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 715c7c0..db0e9a8 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -325,11 +325,21 @@ struct ANASTASIS_UploadDetails
 
   union
   {
-    /**
-     * Hash of the stored recovery data, returned if
-     * @e us is #ANASTASIS_US_SUCCESS.
-     */
-    const struct GNUNET_HashCode *curr_backup_hash;
+
+    struct
+    {
+      /**
+       * Hash of the stored recovery data, returned if
+       * @e us is #ANASTASIS_US_SUCCESS.
+       */
+      const struct GNUNET_HashCode *curr_backup_hash;
+
+      /**
+       * Version number of the resulting policy.
+       */
+      unsigned long long policy_version;
+
+    } success;
 
     /**
      * Details about required payment.
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index c7d1354..3c1cd62 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -599,6 +599,11 @@ struct PolicyStoreState
    */
   struct ANASTASIS_SecretShare *ss;
 
+  /**
+   * Version of the policy created at the provider.
+   */
+  unsigned long long policy_version;
+
 };
 
 /**
@@ -655,7 +660,7 @@ policy_store_cb (void *cls,
     us = ud->us;
   if ( (ANASTASIS_US_SUCCESS == us) &&
        (0 != GNUNET_memcmp (&pss->curr_hash,
-                            ud->details.curr_backup_hash)) )
+                            ud->details.success.curr_backup_hash)) )
   {
     GNUNET_break_op (0);
     us = ANASTASIS_US_SERVER_ERROR;
@@ -663,6 +668,7 @@ policy_store_cb (void *cls,
   switch (us)
   {
   case ANASTASIS_US_SUCCESS:
+    pss->policy_version = ud->details.success.policy_version;
     break;
   case ANASTASIS_US_PAYMENT_REQUIRED:
     pss->payment_request = GNUNET_strdup (ud->details.payment.payment_request);
@@ -702,11 +708,14 @@ policy_store_cb (void *cls,
       struct ANASTASIS_SharePaymentRequest spr[GNUNET_NZL (pr_cnt)];
       unsigned int off = 0;
       struct ANASTASIS_ShareResult sr;
+      unsigned long long policy_version = 0;
 
       for (unsigned int i = 0; i<ss->pss_length; i++)
       {
         struct PolicyStoreState *pssi = &ss->pss[i];
 
+        policy_version = GNUNET_MAX (policy_version,
+                                     pssi->policy_version);
         if (NULL != ss->pss[i].payment_request)
         {
           spr[off].payment_request_url = pssi->payment_request;
@@ -723,6 +732,7 @@ policy_store_cb (void *cls,
       else
       {
         sr.ss = ANASTASIS_SHARE_STATUS_SUCCESS;
+        sr.details.max_policy_version = policy_version;
       }
       ss->src (ss->src_cls,
                &sr);
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index 75d1fdd..df012d0 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1401,6 +1401,11 @@ secret_share_result_cb (void *cls,
        accidentally preserved anywhere */
     (void) json_object_del (uc->state,
                             "core_secret");
+    GNUNET_assert (0 ==
+                   json_object_set (uc->state,
+                                    "max_policy_version",
+                                    json_integer (
+                                      sr->details.max_policy_version)));
     set_state (uc->state,
                ANASTASIS_BACKUP_STATE_BACKUP_FINISHED);
     uc->cb (uc->cb_cls,
diff --git a/src/restclient/anastasis_api_policy_store.c 
b/src/restclient/anastasis_api_policy_store.c
index e4f8bd5..1ab08fc 100644
--- a/src/restclient/anastasis_api_policy_store.c
+++ b/src/restclient/anastasis_api_policy_store.c
@@ -66,6 +66,11 @@ struct ANASTASIS_PolicyStoreOperation
    */
   char *pay_uri;
 
+  /**
+   * Policy version we received from the service, or NULL.
+   */
+  char *policy_version;
+
   /**
    * Copy of the uploaded data. Needed by curl.
    */
@@ -87,6 +92,7 @@ ANASTASIS_policy_store_cancel (
     GNUNET_CURL_job_cancel (pso->job);
     pso->job = NULL;
   }
+  GNUNET_free (pso->policy_version);
   GNUNET_free (pso->pay_uri);
   GNUNET_free (pso->url);
   GNUNET_free (pso->postcopy);
@@ -126,12 +132,24 @@ handle_policy_store_finished (void *cls,
     ud.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
     break;
   case MHD_HTTP_NO_CONTENT:
-    ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_upload_hash;
-    break;
   case MHD_HTTP_NOT_MODIFIED:
-    ud.us = ANASTASIS_US_SUCCESS;
-    ud.details.curr_backup_hash = &pso->new_upload_hash;
+    {
+      unsigned long long version;
+      char dummy;
+
+      if (1 != sscanf (pso->policy_version,
+                       "%llu%c",
+                       &version,
+                       &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_version = version;
+    }
     break;
   case MHD_HTTP_BAD_REQUEST:
     GNUNET_break (0);
@@ -245,6 +263,7 @@ handle_header (char *buffer,
     size_t len;
 
     /* found payment URI we care about! */
+    GNUNET_free (pso->pay_uri); /* In case of duplicate header */
     pso->pay_uri = GNUNET_strdup (hdr_val);
     len = strlen (pso->pay_uri);
     while ( (len > 0) &&
@@ -255,6 +274,25 @@ handle_header (char *buffer,
       pso->pay_uri[len] = '\0';
     }
   }
+
+  if (0 == strcasecmp (hdr_type,
+                       ANASTASIS_HTTP_HEADER_POLICY_VERSION))
+  {
+    size_t len;
+
+    /* found policy version we care about! */
+    GNUNET_free (pso->policy_version); /* In case of duplicate header */
+    pso->policy_version = GNUNET_strdup (hdr_val);
+    len = strlen (pso->policy_version);
+    while ( (len > 0) &&
+            ( ('\n' == pso->policy_version[len - 1]) ||
+              ('\r' == pso->policy_version[len - 1]) ) )
+    {
+      len--;
+      pso->policy_version[len] = '\0';
+    }
+  }
+
   GNUNET_free (ndup);
   return total;
 }
diff --git a/src/testing/testing_api_cmd_policy_store.c 
b/src/testing/testing_api_cmd_policy_store.c
index 5ef0fbb..a8f0a70 100644
--- a/src/testing/testing_api_cmd_policy_store.c
+++ b/src/testing/testing_api_cmd_policy_store.c
@@ -153,7 +153,7 @@ policy_store_cb (void *cls,
   {
   case ANASTASIS_US_SUCCESS:
     if (0 != GNUNET_memcmp (&pss->curr_hash,
-                            ud->details.curr_backup_hash))
+                            ud->details.success.curr_backup_hash))
     {
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (pss->is);

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