gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 07/12: work on secret share


From: gnunet
Subject: [taler-anastasis] 07/12: work on secret share
Date: Mon, 07 Dec 2020 20:28:41 +0100

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

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

commit ab42bfbf2b801051c6c26d7795ec51ab24269192
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Dec 4 12:10:42 2020 +0100

    work on secret share
---
 src/lib/anastasis.c                | 111 ++++++++++++++++++++++++++++++-------
 src/lib/anastasis_api_redux.c      |   3 +-
 src/lib/testing_cmd_secret_share.c |   6 +-
 src/lib/testing_cmd_truth_upload.c |  16 +++++-
 4 files changed, 110 insertions(+), 26 deletions(-)

diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 45ce1a2..3483ea7 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -24,6 +24,12 @@
 #include <taler/taler_json_lib.h>
 #include <gnunet/gnunet_util_lib.h>
 
+/**
+ * How long do we wait at most for a /policy reply from an Anastasis provider.
+ * 60s is very generous, given the tiny bandwidth required, even for the most
+ * remote locations.
+ */
+#define POLICY_STORE_GENERIC_TIMEOUT GNUNET_TIME_UNIT_MINUTES
 
 /**
  * stores provider URLs, identity key material, decrypted recovery document 
(internally!)
@@ -1087,7 +1093,6 @@ truth_store_callback (void *cls,
   struct ANASTASIS_TruthUpload *tu = cls;
   tu->tso = NULL;
 
-  // FIXME
   if (NULL != ud)
   {
     switch (ud->us)
@@ -1301,11 +1306,7 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
             t);
     tu->tc = NULL;
   }
-  else
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+
   // FIXME PAYMENT CALLBACK
   return tu;
 }
@@ -1471,11 +1472,17 @@ ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p)
 }
 
 
+struct ANASTASIS_SecretShare;
+
 /**
  * State for a "policy store" CMD.
  */
 struct PolicyStoreState
 {
+  struct PolicyStoreState *next;
+
+  struct PolicyStoreState *prev;
+
   /**
    * User identifier used as entropy source for the account public key
    */
@@ -1570,6 +1577,8 @@ struct PolicyStoreState
    * reference to SecretShare
    */
   struct ANASTASIS_SecretShare *ss;
+
+  struct GNUNET_SCHEDULER_Task *tt;
 };
 
 /**
@@ -1577,6 +1586,10 @@ struct PolicyStoreState
 */
 struct ANASTASIS_SecretShare
 {
+  struct PolicyStoreState *pss_head;
+
+  struct PolicyStoreState *pss_tail;
+
   /**
    * Callback which gives back the payment details
    */
@@ -1630,18 +1643,47 @@ policy_store_cleanup (void *cls)
     ANASTASIS_policy_store_cancel (pss->pso);
     pss->pso = NULL;
   }
+  if (NULL != pss->tt)
+    GNUNET_SCHEDULER_cancel (pss->tt);
   if (NULL != pss->recovery_data)
-  {
     GNUNET_free (pss->recovery_data);
-  }
   if (NULL != pss->payment_order_id)
-  {
     GNUNET_free (pss->payment_order_id);
-  }
   GNUNET_free (pss);
 }
 
 
+/**
+ * Function which collects all configurations from the different
+ * servers and calls the #ANASTASIS_ActionCallback.
+ *
+ * @param sch a handle to a country selection action
+ */
+static void
+conclude_policy_store (struct ANASTASIS_SecretShare *ss)
+{
+  struct PolicyStoreState *pss;
+
+  /* Are we waiting for more /policy requests to complete? */
+  for (pss = ss->pss_head; NULL != pss; pss = pss->next)
+    if (NULL != pss->pso)
+      return;
+
+  while (NULL != (pss = ss->pss_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (ss->pss_head,
+                                 ss->pss_tail,
+                                 pss);
+    if ( (MHD_HTTP_NO_CONTENT != pss->http_status) &&
+         (MHD_HTTP_PAYMENT_REQUIRED != pss->http_status))
+    {
+      policy_store_cleanup (pss);
+      continue;
+    }
+  }
+}
+
+
 static void
 policy_store_cb (void *cls,
                  enum ANASTASIS_ErrorCode ec,
@@ -1673,7 +1715,7 @@ policy_store_cb (void *cls,
                     ec,
                     http_status);
       pss->ss->src = NULL;
-      policy_store_cleanup (pss);
+      conclude_policy_store (pss->ss);
     }
     return;
   }
@@ -1740,6 +1782,7 @@ policy_store_cb (void *cls,
                         pss->anastasis_url,
                         ec);
           pss->ss->spc = NULL;
+          conclude_policy_store (pss->ss);
         }
       }
       return;
@@ -1767,6 +1810,7 @@ policy_store_cb (void *cls,
                     http_status);
       pss->ss->src = NULL;
     }
+    conclude_policy_store (pss->ss);
     return;
   }
   GNUNET_break (0);
@@ -1861,6 +1905,23 @@ ANASTASIS_get_num_urls (const struct ANASTASIS_Policy 
*policies[],
 }
 
 
+/**
+ * Retries a "policy store" after timeout.
+ *
+ * @param cls closure for a "policy store" request
+ */
+static void
+policy_store_timeout (void *cls)
+{
+  struct PolicyStoreState *pss = cls;
+
+  pss->tt = NULL;
+  ANASTASIS_policy_store_cancel (pss->pso);
+  pss->pso = NULL;
+  conclude_policy_store (pss->ss);
+}
+
+
 struct ANASTASIS_SecretShare *
 ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         const json_t *id_data,
@@ -1884,7 +1945,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     encrypted_master_keys[policies_len];
   struct ANASTASIS_CRYPTO_PolicyKeyP policy_keys[policies_len];
   void *encrypted_core_secret;
-
   // Recovery document contains the array decryption policies and the array 
escrow methods
   json_t *recovery_document;
   size_t recovery_document_size;
@@ -2142,6 +2202,9 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                 TALER_B2S (&ss->pss[l]->curr_hash),
                 (unsigned long long) sizeof (struct GNUNET_HashCode));
 
+    GNUNET_CONTAINER_DLL_insert (ss->pss_head,
+                                 ss->pss_tail,
+                                 ss->pss[l]);
     ss->pss[l]->pso = ANASTASIS_policy_store (ss->ctx,
                                               ss->pss[l]->anastasis_url,
                                               &ss->pss[l]->anastasis_priv,
@@ -2164,7 +2227,15 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       GNUNET_break (0);
       return NULL;
     }
+    else
+    {
+      ss->pss[l]->tt = GNUNET_SCHEDULER_add_delayed (
+        POLICY_STORE_GENERIC_TIMEOUT,
+        &policy_store_timeout,
+        ss->pss[l]);
+    }
   }
+  conclude_policy_store (ss);
   return ss;
 }
 
@@ -2178,16 +2249,16 @@ ANASTASIS_secret_share_cancel (struct 
ANASTASIS_SecretShare *ss)
 {
   if (NULL != ss)
   {
-    if (NULL != ss->pss)
+    struct PolicyStoreState *pss;
+
+    while (NULL != (pss = ss->pss_head))
     {
-      for (unsigned int i = 0; i< ss->pss_length; i++)
-      {
-        if (NULL != ss->pss[i])
-        {
-          GNUNET_free (ss->pss[i]);
-        }
-      }
+      GNUNET_CONTAINER_DLL_remove (ss->pss_head,
+                                   ss->pss_tail,
+                                   pss);
+      policy_store_cleanup (pss);
     }
+
     GNUNET_free (ss);
   }
 }
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 2bbc4f6..69a1895 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -154,7 +154,6 @@ struct ConfigRequest
   json_t *backend_methods;
 
   struct GNUNET_SCHEDULER_Task *tt;
-
 };
 
 
@@ -207,7 +206,7 @@ typedef struct ANASTASIS_ReduxAction *
 
 
 /**
- * Function to free a #ConfigRequest an async operation.
+ * Function to free a #ConfigRequest, an async operation.
  *
  * @param cr state for a "get config" operation
  */
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index 6669821..253efcd 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -403,7 +403,11 @@ secret_share_cleanup (void *cls,
   }
   if (NULL != sss->sso)
   {
-    GNUNET_free (sss->sso);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command '%s' did not complete\n",
+                cmd->label);
+    ANASTASIS_secret_share_cancel (sss->sso);
+    sss->sso = NULL;
   }
   json_decref ((json_t *) sss->id_data);
   GNUNET_free (sss);
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index 792a7b0..c5665c2 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -150,7 +150,18 @@ truth_payment_cb (void *cls,
   struct TruthUploadState *tus = cls;
   tus->tuo = NULL;
   // FIXME: Payment handling
-  return;
+  if (NULL == taler_pay_url)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Errorcode /%d in command %s in %s:%u\n",
+                (int) ec,
+                tus->is->commands[tus->is->ip].label,
+                __FILE__,
+                __LINE__);
+    TALER_TESTING_interpreter_fail (tus->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (tus->is);
 }
 
 
@@ -216,7 +227,6 @@ truth_upload_run (void *cls,
   {
     GNUNET_break (0);
     TALER_TESTING_interpreter_fail (tus->is);
-    return;
   }
 }
 
@@ -247,7 +257,7 @@ truth_upload_cleanup (void *cls,
     json_decref ((json_t *) tus->id_data);
   if (NULL != tus->truth)
   {
-    GNUNET_free (tus->truth);
+    ANASTASIS_truth_free (tus->truth);
   }
   GNUNET_free (tus);
 }

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