gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/15: set state to CHALLENGE_SELECTING


From: gnunet
Subject: [taler-anastasis] 01/15: set state to CHALLENGE_SELECTING
Date: Sun, 31 Jan 2021 17:06:07 +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 d2421f8cf3e90222ddcedfc044a49584e8eaef71
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Dec 29 17:19:41 2020 +0100

    set state to CHALLENGE_SELECTING
---
 src/lib/anastasis_api_backup_redux.c   | 68 ++++++++++++++++++++++++----------
 src/lib/anastasis_api_recovery_redux.c | 20 +++++-----
 src/lib/anastasis_api_redux.c          | 20 +++++++---
 3 files changed, 73 insertions(+), 35 deletions(-)

diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 531e165..1fc1224 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -328,18 +328,10 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
   json_t *continents = json_array ();
   json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
 
-  if (NULL == redux_countries)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+  GNUNET_assert (NULL != redux_countries);
   root = json_object_get (redux_countries,
                           "countries");
-  if (NULL == root)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
+  GNUNET_assert (NULL != root);
 
   json_array_foreach (root, index, temp_country)
   {
@@ -1290,9 +1282,11 @@ initialize_payment_details (json_t *state,
  * Initialize policies for recovery document.
  *
  * @param state json state to operate on
+ * @param provider_ids if not NULL only policies for the providers set here 
are initialized
  */
 static void
-initialize_policies (json_t *state)
+initialize_policies (json_t *state,
+                     json_t *provider_ids)
 {
   size_t p_index;
   json_t *rec_doc_uploads;
@@ -1327,6 +1321,28 @@ initialize_policies (json_t *state)
     {
       const char *tu_key;
       json_t *tu_value;
+      json_t *provider_id = json_object_get (auth_method,
+                                             "provider");
+      // initialize policies to upload recovery document just to
+      // specified providers
+      if (NULL != provider_ids)
+      {
+        size_t ids_index;
+        json_t *id;
+        bool provider_match = false;
+
+        GNUNET_assert (json_is_array (provider_ids));
+        json_array_foreach (provider_ids, ids_index, id)
+        {
+          if (1 == json_equal (provider_id, id))
+          {
+            provider_match = true;
+            break;
+          }
+        }
+        if (! provider_match)
+          continue;
+      }
       unsigned int auth_method_index = json_integer_value (json_object_get (
                                                              auth_method,
                                                              
"authentication_method"));
@@ -1351,8 +1367,7 @@ initialize_policies (json_t *state)
         bool existing = false;
         const char *upload_key;
         json_t *upload_value;
-        json_t *provider_id = json_object_get (auth_method,
-                                               "provider");
+
         if (0 < json_object_size (rec_doc_uploads))
         {
           json_object_foreach (rec_doc_uploads, upload_key, upload_value)
@@ -1604,19 +1619,22 @@ free_enter_secret (void *cls)
  * Upload recovery documents.
  *
  * @param state json state to operate on
+ * @param provider_ids ids of providers to upload recovery document explicitly 
to
  * @param ctx CURL context
  * @param cb callback (#DispatchHandler) to call during/after operation
  * @param cb_cls callback closure
  */
 static void
 upload_rec_documents (json_t *state,
+                      json_t *provider_ids,
                       struct GNUNET_CURL_Context *ctx,
                       ANASTASIS_ActionCallback cb,
                       void *cb_cls)
 {
   if (0 == policy_arr_length)
   {
-    initialize_policies (state);
+    initialize_policies (state,
+                         provider_ids);
   }
   struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
   unsigned int pds_len;
@@ -1748,6 +1766,7 @@ truth_upload_cb (void *cls,
   {
     // try uploading recovery document
     upload_rec_documents (tus->state,
+                          NULL,
                           tus->ctx,
                           tus->cb,
                           tus->cb_cls);
@@ -1932,11 +1951,9 @@ upload_truths (json_t *state,
     }
     if (0 != truth_uploads_size)
     {
-      // FIXME: this seems redundant with the logic in 'enter_secret'.
       GNUNET_assert (0 ==
-                     json_object_set (state,
-                                      "truth_uploads",
-                                      json_object ()));
+                     json_object_del (state,
+                                      "truth_uploads"));
     }
     json_array_foreach (truths, truth_index, truth)
     {
@@ -2097,12 +2114,22 @@ pay_backup (json_t *state,
   if (NULL != json_object_get (arguments,
                                "provider_id"))
   {
-    // FIXME: implement
+    upload_rec_documents (state,
+                          json_object_get (arguments,
+                                           "provider_id"),
+                          ctx,
+                          cb,
+                          cb_cls);
   }
   else if (NULL != json_object_get (arguments,
                                     "truth_index"))
   {
-    // FIXME: implement
+    upload_truths (state,
+                   json_object_get (arguments,
+                                    "truth_index"),
+                   ctx,
+                   cb,
+                   cb_cls);
   }
   else
   {
@@ -2113,6 +2140,7 @@ pay_backup (json_t *state,
     GNUNET_assert (json_is_object (truth_uploads));
     if (check_uploads (truth_uploads, true))
       upload_rec_documents (state,
+                            NULL,
                             ctx,
                             cb,
                             cb_cls);
diff --git a/src/lib/anastasis_api_recovery_redux.c 
b/src/lib/anastasis_api_recovery_redux.c
index c76aa57..5424e37 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -114,11 +114,12 @@ ANASTASIS_recovery_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
     json_t *inner_continent;
     json_t *continent = json_object_get (json_array_get (root, index),
                                          "continent");
-
     bool existing = false;
+
     json_array_foreach (continents, inner_index, inner_continent)
     {
-      if (1 == json_equal (continent, inner_continent))
+      if (1 == json_equal (continent,
+                           inner_continent))
       {
         existing = true;
         break;
@@ -127,13 +128,13 @@ ANASTASIS_recovery_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
     if (! existing)
       json_array_append_new (continents, continent);
   }
-
   initial_state = json_pack ("{s:s, s:o}",
                              "recovery_state",
-                             ANASTASIS_recovery_state_to_string (
+                             ANASTASIS_generic_state_to_string (
                                ANASTASIS_RECOVERY_STATE_CONTINENT_SELECTING),
                              "continents",
                              continents);
+  GNUNET_assert (NULL != initial_state);
   return initial_state;
 }
 
@@ -280,7 +281,8 @@ ANASTASIS_recovery_action_ (struct GNUNET_CURL_Context *ctx,
   for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
   {
     if ( (rs == dispatchers[i].recovery_state) &&
-         (0 == strcmp (action, dispatchers[i].recovery_action)) )
+         (0 == strcmp (action,
+                       dispatchers[i].recovery_action)) )
     {
       return dispatchers[i].fun (state,
                                  arguments,
@@ -289,9 +291,9 @@ ANASTASIS_recovery_action_ (struct GNUNET_CURL_Context *ctx,
                                  cb_cls);
     }
   }
-  GNUNET_break (0);
-  cb (cb_cls,
-      ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-      NULL);
+  ANASTASIS_redux_fail (cb,
+                        cb_cls,
+                        TALER_EC_ANASTASIS_REDUCER_ACTION_INVALID,
+                        action);
   return NULL;
 }
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 710082b..42d9ddf 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -979,20 +979,28 @@ enter_user_attributes (json_t *state,
                                             "authentication_providers");
 
   if (0 == strcmp (s_mode, "backup_state"))
+  {
     json_object_set_new (state,
                          s_mode,
                          json_string (
                            ANASTASIS_backup_state_to_string (
                              ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING)));
-  /** else FIXME: do something for recovery mode*/
-
+    if (NULL != auth_providers)
+      json_object_set_new (state,
+                           "authentication_providers",
+                           auth_providers);
+  }
+  else
+  {
+    json_object_set_new (state,
+                         s_mode,
+                         json_string (
+                           ANASTASIS_recovery_state_to_string (
+                             ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING)));
+  }
   json_object_set_new (state,
                        "identity_attributes",
                        attributes);
-  if (NULL != auth_providers)
-    json_object_set_new (state,
-                         "authentication_providers",
-                         auth_providers);
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);

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