gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: fix provider selection logic


From: gnunet
Subject: [taler-anastasis] branch master updated: fix provider selection logic
Date: Sun, 28 Mar 2021 00:24:37 +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 eeb45be  fix provider selection logic
eeb45be is described below

commit eeb45be830399cf0d0f183d3cf82fadc75f3507e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Mar 28 00:24:34 2021 +0100

    fix provider selection logic
---
 src/reducer/anastasis_api_recovery_redux.c | 116 ++++++++++++++++++++---------
 1 file changed, 80 insertions(+), 36 deletions(-)

diff --git a/src/reducer/anastasis_api_recovery_redux.c 
b/src/reducer/anastasis_api_recovery_redux.c
index 6c0147f..23fbe9c 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -1735,6 +1735,11 @@ struct RecoverSecretState
    */
   void *cb_cls;
 
+  /**
+   * Set if recovery must be done with this provider.
+   */
+  char *provider_url;
+
   /**
    * version of the recovery document to request.
    */
@@ -1790,6 +1795,7 @@ free_rss (void *cls)
   json_decref (rss->state);
   json_decref (rss->id_data);
   GNUNET_assert (0 == rss->pending);
+  GNUNET_free (rss->provider_url);
   GNUNET_free (rss);
 }
 
@@ -2105,6 +2111,63 @@ policy_lookup_cb (void *cls,
 }
 
 
+/**
+ * Try to launch recovery at provider @a provider_url with config @a p_cfg.
+ *
+ * @param[in,out] rss recovery context
+ * @param provider_url base URL of the provider to try
+ * @param p_cfg configuration of the provider
+ * @return true if a recovery was launched
+ */
+static bool
+launch_recovery (struct RecoverSecretState *rss,
+                 const char *provider_url,
+                 const json_t *p_cfg)
+{
+  struct PolicyDownloadEntry *pd = GNUNET_new (struct PolicyDownloadEntry);
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("salt",
+                                 &pd->salt),
+    GNUNET_JSON_spec_end ()
+  };
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (p_cfg,
+                         spec,
+                         NULL, NULL))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "No salt for `%s', provider offline?\n",
+                provider_url);
+    GNUNET_free (pd);
+    return false;
+  }
+  pd->backend_url = GNUNET_strdup (provider_url);
+  pd->rss = rss;
+  pd->recovery = ANASTASIS_recovery_begin (ANASTASIS_REDUX_ctx_,
+                                           rss->id_data,
+                                           rss->have_version
+                                           ? rss->version
+                                           : 0,
+                                           pd->backend_url,
+                                           &pd->salt,
+                                           &policy_lookup_cb,
+                                           pd,
+                                           &core_early_secret_cb,
+                                           pd);
+  if (NULL != pd->recovery)
+  {
+    GNUNET_CONTAINER_DLL_insert (rss->pd_head,
+                                 rss->pd_tail,
+                                 pd);
+    return true;
+  }
+  GNUNET_free (pd->backend_url);
+  GNUNET_free (pd);
+  return false;
+}
+
+
 /**
  * We finished downloading /config from all providers, merge
  * into the main state, trigger the continuation and free our
@@ -2157,53 +2220,33 @@ providers_complete (struct RecoverSecretState *rss)
   }
 
   /* now iterate over providers and begin downloading */
+  if (NULL != rss->provider_url)
+  {
+    json_t *p_cfg;
+
+    p_cfg = json_object_get (tlist,
+                             rss->provider_url);
+    if (NULL != p_cfg)
+      launched = launch_recovery (rss,
+                                  rss->provider_url,
+                                  p_cfg);
+  }
+  else
   {
     json_t *p_cfg;
     const char *provider_url;
 
     json_object_foreach (tlist, provider_url, p_cfg)
     {
-      struct PolicyDownloadEntry *pd = GNUNET_new (struct PolicyDownloadEntry);
-      struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_fixed_auto ("salt",
-                                     &pd->salt),
-        GNUNET_JSON_spec_end ()
-      };
-
-      GNUNET_CONTAINER_DLL_insert (rss->pd_head,
-                                   rss->pd_tail,
-                                   pd);
-      pd->backend_url = GNUNET_strdup (provider_url);
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (p_cfg,
-                             spec,
-                             NULL, NULL))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                    "No salt for `%s', provider offline?\n",
-                    provider_url);
-        continue;
-      }
-      pd->rss = rss;
-      pd->recovery = ANASTASIS_recovery_begin (ANASTASIS_REDUX_ctx_,
-                                               rss->id_data,
-                                               rss->have_version
-                                               ? rss->version
-                                               : 0,
-                                               pd->backend_url,
-                                               &pd->salt,
-                                               &policy_lookup_cb,
-                                               pd,
-                                               &core_early_secret_cb,
-                                               pd);
-      if (NULL != pd->recovery)
-        launched = true;
+      launched |= launch_recovery (rss,
+                                   provider_url,
+                                   p_cfg);
     }
   }
   if (! launched)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "No provider online, need user to manually specfy 
providers!\n");
+                "No provider online, need user to specfy different 
provider!\n");
     return_no_policy (rss,
                       true);
     return;
@@ -2319,6 +2362,7 @@ ANASTASIS_REDUX_recovery_challenge_begin_ (json_t *state,
                                                      "provider_url"));
   if (NULL != provider_url)
   {
+    rss->provider_url = GNUNET_strdup (provider_url);
     begin_query_provider (rss,
                           provider_url);
   }

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