gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: reintroduce recently 'lost'


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: reintroduce recently 'lost' poll challenges logic
Date: Tue, 01 Feb 2022 14:41:51 +0100

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

grothoff pushed a commit to branch master
in repository anastasis-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new 62f1faf  reintroduce recently 'lost' poll challenges logic
62f1faf is described below

commit 62f1faf2e03da6dbb26cd6b1475f2264c452a70a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Feb 1 14:41:49 2022 +0100

    reintroduce recently 'lost' poll challenges logic
---
 src/anastasis/anastasis-gtk.c        |  32 +++---
 src/anastasis/anastasis-gtk.h        |  53 ++++++++-
 src/anastasis/anastasis-gtk_action.c | 206 ++++++++++++++++++++---------------
 3 files changed, 183 insertions(+), 108 deletions(-)

diff --git a/src/anastasis/anastasis-gtk.c b/src/anastasis/anastasis-gtk.c
index 7d0a990..e3742a0 100644
--- a/src/anastasis/anastasis-gtk.c
+++ b/src/anastasis/anastasis-gtk.c
@@ -1,6 +1,6 @@
 /*
      This file is part of anastasis-gtk.
-     Copyright (C) 2020, 2021 Anastasis SARL
+     Copyright (C) 2020, 2021, 2022 Anastasis SARL
 
      Anastasis is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -68,12 +68,7 @@ struct ANASTASIS_ReduxAction *AG_ra;
 /**
  * Handle to an ongoing background action.
  */
-struct ANASTASIS_ReduxAction *AG_long_action;
-
-/**
- * Handle to task to reschedule #AG_long_action.
- */
-struct GNUNET_SCHEDULER_Task *AG_long_task;
+struct ANASTASIS_LongAction AG_lacs[ANASTASIS_LP_CNT];
 
 
 /**
@@ -85,15 +80,22 @@ json_t *AG_redux_state;
 void
 AG_stop_long_action (void)
 {
-  if (NULL != AG_long_action)
-  {
-    ANASTASIS_redux_action_cancel (AG_long_action);
-    AG_long_action = NULL;
-  }
-  if (NULL != AG_long_task)
+  for (enum ANASTASIS_LongActionKind i = 0;
+       i < ANASTASIS_LP_CNT;
+       i++)
   {
-    GNUNET_SCHEDULER_cancel (AG_long_task);
-    AG_long_task = NULL;
+    struct ANASTASIS_LongAction *la = &AG_lacs[i];
+
+    if (NULL != la->ra)
+    {
+      ANASTASIS_redux_action_cancel (la->ra);
+      la->ra = NULL;
+    }
+    if (NULL != la->task)
+    {
+      GNUNET_SCHEDULER_cancel (la->task);
+      la->task = NULL;
+    }
   }
 }
 
diff --git a/src/anastasis/anastasis-gtk.h b/src/anastasis/anastasis-gtk.h
index 7497223..54c47fb 100644
--- a/src/anastasis/anastasis-gtk.h
+++ b/src/anastasis/anastasis-gtk.h
@@ -61,15 +61,60 @@ extern json_t *AG_redux_state;
  */
 extern struct ANASTASIS_ReduxAction *AG_ra;
 
+
 /**
- * Handle to an ongoing background action.
+ * State associated with a background long action.
+ */
+struct ANASTASIS_LongAction
+{
+  /**
+   * Action handle of the background action.
+   */
+  struct ANASTASIS_ReduxAction *ra;
+
+  /**
+   * Handle to task to reschedule the action.
+   */
+  struct GNUNET_SCHEDULER_Task *task;
+
+  /**
+   * Next time we schedule the task.
+   */
+  struct GNUNET_TIME_Absolute next_time;
+
+};
+
+
+/**
+ * Enumeration for long poll actions we have.
  */
-extern struct ANASTASIS_ReduxAction *AG_long_action;
+enum ANASTASIS_LongActionKind
+{
+  /**
+   * Poll on async challenge completion.
+   */
+  ANASTASIS_LP_POLL_CHALLENGES,
+
+  /**
+   * Poll for /config on all known providers.
+   */
+  ANASTASIS_LP_SYNC_PROVIDERS,
+
+  /**
+   * Wait for challenge-specific providers being ready.
+   */
+  ANASTASIS_LP_POLL_PROVIDERS,
+
+  /**
+   * Number of pollers we have.
+   */
+  ANASTASIS_LP_CNT /* must be last! */
+};
 
 /**
- * Handle to task to reschedule #AG_long_action.
+ * Handle to an ongoing background action.
  */
-extern struct GNUNET_SCHEDULER_Task *AG_long_task;
+extern struct ANASTASIS_LongAction AG_lacs[ANASTASIS_LP_CNT];
 
 
 /**
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 0723c97..63e37bf 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -1,6 +1,6 @@
 /*
      This file is part of anastasis-gtk.
-     Copyright (C) 2020, 2021 Anastasis SARL
+     Copyright (C) 2020, 2021, 2022 Anastasis SARL
 
      Anastasis is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -41,12 +41,6 @@
  */
 #define LP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 
-/**
- * Next time we schedule the #long_task.
- */
-static struct GNUNET_TIME_Absolute long_next;
-
-
 /**
  * Are we currently processing an action?
  */
@@ -1980,53 +1974,53 @@ expand_policy_list (void *cls,
  * @param response new state as result or config information of a provider
  */
 static void
-long_poll_action_cb (void *cls,
-                     enum TALER_ErrorCode error_code,
-                     json_t *response);
+long_poll_challenges_cb (void *cls,
+                         enum TALER_ErrorCode error_code,
+                         json_t *response);
 
 
 /**
- * Schedules the "poll" action.
+ * Schedules the "poll" challenges action.
  *
  * @param cls NULL
- * FIXME: dead code!??
  */
 static void
-long_poll_task (void *cls)
+long_poll_challenges_task (void *cls)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES];
   json_t *tspec;
 
   (void) cls;
-  AG_long_task = NULL;
-  if (GNUNET_TIME_absolute_is_future (long_next))
+  la->task = NULL;
+  if (GNUNET_TIME_absolute_is_future (la->next_time))
   {
-    AG_long_task = GNUNET_SCHEDULER_add_at (long_next,
-                                            &long_poll_task,
-                                            cls);
+    la->task = GNUNET_SCHEDULER_add_at (la->next_time,
+                                        &long_poll_challenges_task,
+                                        NULL);
     return;
   }
-  long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
+  la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
   tspec = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_time_rel ("timeout",
                                LP_TIMEOUT));
-  AG_long_action
-    = ANASTASIS_redux_action (AG_redux_state,
-                              "poll",
-                              tspec,
-                              &long_poll_action_cb,
-                              NULL);
+  la->ra = ANASTASIS_redux_action (AG_redux_state,
+                                   "poll",
+                                   tspec,
+                                   &long_poll_challenges_cb,
+                                   NULL);
   json_decref (tspec);
 }
 
 
-// FIXME: dead code!??
 static void
-long_poll_action_cb (void *cls,
-                     enum TALER_ErrorCode error_code,
-                     json_t *response)
+long_poll_challenges_cb (void *cls,
+                         enum TALER_ErrorCode error_code,
+                         json_t *response)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES];
+
   (void) cls;
-  AG_long_action = NULL;
+  la->ra = NULL;
   switch (error_code)
   {
   case TALER_EC_NONE:
@@ -2037,15 +2031,10 @@ long_poll_action_cb (void *cls,
               TALER_ErrorCode_get_hint (error_code),
               (unsigned int) error_code);
     /* simply try again */
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_task,
-                                             NULL);
+    la->task = GNUNET_SCHEDULER_add_now (&long_poll_challenges_task,
+                                         NULL);
     return;
   }
-  if (NULL != AG_ra)
-  {
-    GNUNET_break (0);
-    ANASTASIS_redux_action_cancel (AG_ra);
-  }
   AG_action_cb (NULL,
                 TALER_EC_NONE,
                 response);
@@ -2073,27 +2062,27 @@ long_poll_sync_action_cb (void *cls,
 static void
 long_poll_sync_task (void *cls)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS];
   json_t *tspec;
 
   (void) cls;
-  AG_long_task = NULL;
-  if (GNUNET_TIME_absolute_is_future (long_next))
+  la->task = NULL;
+  if (GNUNET_TIME_absolute_is_future (la->next_time))
   {
-    AG_long_task = GNUNET_SCHEDULER_add_at (long_next,
-                                            &long_poll_sync_task,
-                                            cls);
+    la->task = GNUNET_SCHEDULER_add_at (la->next_time,
+                                        &long_poll_sync_task,
+                                        NULL);
     return;
   }
-  long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
+  la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
   tspec = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_time_rel ("timeout",
                                LP_TIMEOUT));
-  AG_long_action
-    = ANASTASIS_redux_action (AG_redux_state,
-                              "sync_providers",
-                              tspec,
-                              &long_poll_sync_action_cb,
-                              NULL);
+  la->ra = ANASTASIS_redux_action (AG_redux_state,
+                                   "sync_providers",
+                                   tspec,
+                                   &long_poll_sync_action_cb,
+                                   NULL);
   json_decref (tspec);
 }
 
@@ -2103,8 +2092,10 @@ long_poll_sync_action_cb (void *cls,
                           enum TALER_ErrorCode error_code,
                           json_t *response)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS];
+
   (void) cls;
-  AG_long_action = NULL;
+  la->ra = NULL;
   switch (error_code)
   {
   case TALER_EC_NONE:
@@ -2118,15 +2109,10 @@ long_poll_sync_action_cb (void *cls,
               TALER_ErrorCode_get_hint (error_code),
               (unsigned int) error_code);
     /* simply try again */
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task,
-                                             NULL);
+    la->task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task,
+                                         NULL);
     return;
   }
-  if (NULL != AG_ra)
-  {
-    GNUNET_break (0);
-    ANASTASIS_redux_action_cancel (AG_ra);
-  }
   AG_action_cb (NULL,
                 TALER_EC_NONE,
                 response);
@@ -2154,29 +2140,29 @@ long_poll_providers_action_cb (void *cls,
 static void
 long_poll_providers_task (void *cls)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
   json_t *tspec;
 
   (void) cls;
-  AG_long_task = NULL;
-  if (GNUNET_TIME_absolute_is_future (long_next))
+  la->task = NULL;
+  if (GNUNET_TIME_absolute_is_future (la->next_time))
   {
-    AG_long_task = GNUNET_SCHEDULER_add_at (long_next,
-                                            &long_poll_providers_task,
-                                            cls);
+    la->task = GNUNET_SCHEDULER_add_at (la->next_time,
+                                        &long_poll_providers_task,
+                                        NULL);
     return;
   }
-  long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
+  la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
   tspec = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_time_rel ("timeout",
                                LP_TIMEOUT));
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Starting long polling task for provider configurations\n");
-  AG_long_action
-    = ANASTASIS_redux_action (AG_redux_state,
-                              "poll_providers",
-                              tspec,
-                              &long_poll_providers_action_cb,
-                              cls);
+  la->ra = ANASTASIS_redux_action (AG_redux_state,
+                                   "poll_providers",
+                                   tspec,
+                                   &long_poll_providers_action_cb,
+                                   NULL);
   json_decref (tspec);
 }
 
@@ -2195,11 +2181,12 @@ long_poll_providers_action_cb (void *cls,
                                enum TALER_ErrorCode error_code,
                                json_t *response)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
   json_t *ap;
   const char *url;
   json_t *obj;
 
-  AG_long_action = NULL;
+  la->ra = NULL;
   switch (error_code)
   {
   case TALER_EC_NONE:
@@ -2210,8 +2197,8 @@ long_poll_providers_action_cb (void *cls,
               TALER_ErrorCode_get_hint (error_code),
               (unsigned int) error_code);
     /* simply try again */
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
-                                             NULL);
+    la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
+                                         NULL);
     return;
   }
   GNUNET_assert (NULL != AG_pd);
@@ -2246,6 +2233,7 @@ long_poll_providers_action_cb (void *cls,
 static void
 begin_discovery (void)
 {
+  struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
   GtkListStore *ls;
   json_t *ap;
   const char *url;
@@ -2283,9 +2271,9 @@ begin_discovery (void)
   }
   if (poll)
   {
-    long_next = GNUNET_TIME_UNIT_ZERO_ABS;
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
-                                             NULL);
+    la->next_time = GNUNET_TIME_UNIT_ZERO_ABS;
+    la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
+                                         NULL);
   }
   if (NULL == AG_pd)
     AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state,
@@ -2682,24 +2670,64 @@ action_challenge_selecting (void)
   }
   if (sp)
   {
-    long_next = GNUNET_TIME_UNIT_ZERO_ABS;
-    GNUNET_assert (NULL == AG_long_task);
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task,
-                                             NULL);
+    struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS];
+
+    la->next_time = GNUNET_TIME_UNIT_ZERO_ABS;
+    GNUNET_assert (NULL == la->task);
+    la->task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task,
+                                         NULL);
   }
-#if FIXME
-  /* FIXME: Did we loose some logic like this here for the
-     long-polling challenges? At least the
-     'long_poll_task' appears to have turned into dead code
-     and something like this would seem to be needed
-     here for the polling challenges (SEPA transfer) */
-  if (poll)
+
   {
-    long_next = GNUNET_TIME_UNIT_ZERO_ABS;
-    AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_task,
+    struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES];
+    json_t *rd;
+    json_t *challenges;
+    size_t index;
+    json_t *challenge;
+
+    rd = json_object_get (AG_redux_state,
+                          "recovery_document");
+    GNUNET_assert (NULL != rd);
+    challenges = json_object_get (rd,
+                                  "cs");
+    GNUNET_assert (NULL != challenges);
+    json_array_foreach (challenges, index, challenge)
+    {
+      bool async = false;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_bool ("async",
+                                 &async)),
+        GNUNET_JSON_spec_end ()
+      };
+      const json_t *ks;
+
+      ks = json_object_get (challenge,
+                            "key_share");
+      if ( (NULL != ks) &&
+           (! json_is_null (ks)) )
+        continue;   /* already solved */
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (challenge,
+                             spec,
+                             NULL, NULL))
+      {
+        GNUNET_break (0);
+        json_dumpf (challenge,
+                    stderr,
+                    JSON_INDENT (2));
+        continue;
+      }
+      if (async &&
+          (NULL == la->task) )
+      {
+        la->next_time = GNUNET_TIME_UNIT_ZERO_ABS;
+        la->task = GNUNET_SCHEDULER_add_now (&long_poll_challenges_task,
                                              NULL);
+      }
+    }
   }
-#endif
+
   AG_sensitive ("anastasis_gtk_review_policy_treeview");
   AG_show ("anastasis_gtk_progress_vbox");
   AG_progress_update ();

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