summaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_action.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-30 13:56:31 +0100
committerChristian Grothoff <christian@grothoff.org>2022-01-30 13:56:31 +0100
commit160075f3b5a8728643ae0b05948744f0be39b9e2 (patch)
tree0912c548d1cb7afceffea8cd737b9ba6f103f688 /src/anastasis/anastasis-gtk_action.c
parent527f3e1ca1440785ab63012667197a61efff3c57 (diff)
downloadanastasis-gtk-160075f3b5a8728643ae0b05948744f0be39b9e2.tar.gz
anastasis-gtk-160075f3b5a8728643ae0b05948744f0be39b9e2.tar.bz2
anastasis-gtk-160075f3b5a8728643ae0b05948744f0be39b9e2.zip
-working on new policy discovery
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r--src/anastasis/anastasis-gtk_action.c303
1 files changed, 244 insertions, 59 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c
index 8da6719..6aabd19 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -493,7 +493,11 @@ update_label (const char *name,
/**
- * FIXME.
+ * We are entering the tab where the user has to enter their personal
+ * attributes. Show widgets applicable to the selected country, and
+ * dynamically generate widgets if necessary. Furthermore, restore
+ * widget contents from our state (if stored attribute values are
+ * present in our state).
*/
static void
action_user_attributes_collecting (void)
@@ -646,6 +650,7 @@ action_user_attributes_collecting (void)
AG_show ("anastasis_gtk_recovery_progress_scrolled_window");
AG_hide ("anastasis_gtk_backup_progress_scrolled_window");
}
+ AG_show ("anastasis_gtk_main_window_save_as_button");
AG_show ("anastasis_gtk_main_control_vbox");
AG_show ("anastasis_gtk_main_window_prev_button");
AG_enable_next ();
@@ -677,6 +682,9 @@ activate_by_method (json_t *methods)
NULL, NULL))
{
GNUNET_break (0);
+ json_dumpf (method,
+ stderr,
+ JSON_INDENT (2));
continue;
}
@@ -855,6 +863,9 @@ lookup_recovery_cost (const char *provider,
if (NULL == ap)
{
GNUNET_break (0);
+ json_dumpf (aps,
+ stderr,
+ JSON_INDENT (2));
return GNUNET_SYSERR;
}
methods = json_object_get (ap,
@@ -877,6 +888,9 @@ lookup_recovery_cost (const char *provider,
NULL, NULL))
{
GNUNET_break (0);
+ json_dumpf (method,
+ stderr,
+ JSON_INDENT (2));
continue;
}
if (0 == strcmp (mtype,
@@ -887,6 +901,9 @@ lookup_recovery_cost (const char *provider,
}
}
GNUNET_break (0);
+ json_dumpf (methods,
+ stderr,
+ JSON_INDENT (2));
return GNUNET_SYSERR;
}
@@ -1953,61 +1970,105 @@ expand_policy_list (void *cls,
/**
- * Function called when it is time for the user to select a secret
- * from the list of secrets. Builds the respective tree model.
+ * Function called with the results of #ANASTASIS_redux_action on "poll".
+ *
+ * @param cls NULL
+ * @param error_code Error code
+ * @param response new state as result or config information of a provider
*/
static void
-action_secret_selecting (void)
+long_poll_action_cb (void *cls,
+ enum TALER_ErrorCode error_code,
+ json_t *response);
+
+
+/**
+ * Schedules the "poll" action.
+ *
+ * @param cls NULL
+ * FIXME: dead code!??
+ */
+static void
+long_poll_task (void *cls)
{
- GtkListStore *ls;
+ json_t *tspec;
- AG_hide ("anastasis_gtk_start_frame");
- if (AG_have_error)
- AG_show ("anastasis_gtk_error_label");
- AG_hide ("anastasis_gtk_challenge_frame");
- AG_hide ("anastasis_gtk_identity_frame");
- ls = GTK_LIST_STORE (GCG_get_main_window_object (
- "secret_selection_liststore"));
- gtk_list_store_clear (ls);
- GNUNET_assert (NULL != ls);
- GNUNET_assert (NULL == AG_pd);
- AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state,
- NULL,
- &expand_policy_list,
- ls);
- AG_show ("anastasis_gtk_progress_vbox");
- AG_progress_update ();
- AG_show ("anastasis_gtk_recovery_progress_scrolled_window");
- AG_hide ("anastasis_gtk_backup_progress_scrolled_window");
- AG_show ("anastasis_gtk_main_control_vbox");
- AG_show ("anastasis_gtk_main_window_save_as_button");
- AG_show ("anastasis_gtk_select_secret_frame");
- AG_show ("anastasis_gtk_main_window_prev_button");
- AG_hide ("anastasis_gtk_main_window_quit_button");
- AG_insensitive ("anastasis_gtk_main_window_forward_button");
+ (void) cls;
+ AG_long_task = NULL;
+ if (GNUNET_TIME_absolute_is_future (long_next))
+ {
+ AG_long_task = GNUNET_SCHEDULER_add_at (long_next,
+ &long_poll_task,
+ cls);
+ return;
+ }
+ long_next = 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);
+ json_decref (tspec);
+}
+
+
+// FIXME: dead code!??
+static void
+long_poll_action_cb (void *cls,
+ enum TALER_ErrorCode error_code,
+ json_t *response)
+{
+ (void) cls;
+ AG_long_action = NULL;
+ switch (error_code)
+ {
+ case TALER_EC_NONE:
+ /* continued below */
+ break;
+ default:
+ AG_error (_ ("poll failed: %s (#%u)"),
+ TALER_ErrorCode_get_hint (error_code),
+ (unsigned int) error_code);
+ /* simply try again */
+ AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_task,
+ NULL);
+ return;
+ }
+ if (NULL != AG_ra)
+ {
+ GNUNET_break (0);
+ ANASTASIS_redux_action_cancel (AG_ra);
+ }
+ AG_action_cb (NULL,
+ TALER_EC_NONE,
+ response);
}
/**
- * Function called with the results of #ANASTASIS_redux_action on "poll".
+ * Function called with the results of #ANASTASIS_redux_action on "poll_providers".
*
- * @param cls closure, NULL
+ * @param cls NULL
* @param error_code Error code
* @param response new state as result or config information of a provider
*/
static void
-long_action_cb (void *cls,
- enum TALER_ErrorCode error_code,
- json_t *response);
+long_poll_providers_action_cb (void *cls,
+ enum TALER_ErrorCode error_code,
+ json_t *response);
/**
- * Schedules the 'poll' action.
+ * Schedules the specified action.
*
* @param cls NULL
*/
static void
-long_task (void *cls)
+long_poll_providers_task (void *cls)
{
json_t *tspec;
@@ -2016,36 +2077,44 @@ long_task (void *cls)
if (GNUNET_TIME_absolute_is_future (long_next))
{
AG_long_task = GNUNET_SCHEDULER_add_at (long_next,
- &long_task,
- NULL);
+ &long_poll_providers_task,
+ cls);
return;
}
long_next = 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",
+ "poll_providers",
tspec,
- &long_action_cb,
- NULL);
+ &long_poll_providers_action_cb,
+ cls);
json_decref (tspec);
}
/**
- * Function called with the results of #ANASTASIS_redux_action on "poll".
- *
- * @param cls closure, NULL
- * @param error_code Error code
- * @param response new state as result or config information of a provider
+ * Start policy discovery process. Triggers download(s)
+ * of the various provider configurations and (once we
+ * have any) starts the policy discovery process.
*/
static void
-long_action_cb (void *cls,
- enum TALER_ErrorCode error_code,
- json_t *response)
+begin_discovery (void);
+
+
+static void
+long_poll_providers_action_cb (void *cls,
+ enum TALER_ErrorCode error_code,
+ json_t *response)
{
+ json_t *ap;
+ const char *url;
+ json_t *obj;
+
AG_long_action = NULL;
switch (error_code)
{
@@ -2053,22 +2122,125 @@ long_action_cb (void *cls,
/* continued below */
break;
default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "'poll' action failed: %s\n",
- TALER_ErrorCode_get_hint (error_code));
+ AG_error (_ ("Polling for providers failed: %s (#%u)"),
+ TALER_ErrorCode_get_hint (error_code),
+ (unsigned int) error_code);
/* simply try again */
- AG_long_task = GNUNET_SCHEDULER_add_now (&long_task,
+ AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
NULL);
return;
}
- if (NULL != AG_ra)
+ GNUNET_assert (NULL != AG_pd);
+ /* Find out which provider is new, merge that one! */
+ ap = json_object_get (response,
+ "authentication_providers");
+ GNUNET_assert (NULL != ap);
+ json_object_foreach (ap, url, obj)
{
- GNUNET_break (0);
- ANASTASIS_redux_action_cancel (AG_ra);
+ struct ANASTASIS_CRYPTO_ProviderSaltP salt;
+
+ if (GNUNET_OK ==
+ ANASTASIS_reducer_lookup_salt (AG_redux_state,
+ url,
+ &salt))
+ continue;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Expanding policy discovery to recently discovered live provider `%s'\n",
+ url);
+ ANASTASIS_policy_discovery_more (AG_pd,
+ url,
+ obj);
+ }
+ /* update our state to the new state, but without
+ going through the usual action loop */
+ json_decref (AG_redux_state);
+ AG_redux_state = json_incref (response);
+ GNUNET_assert (NULL != AG_redux_state);
+}
+
+
+static void
+begin_discovery (void)
+{
+ GtkListStore *ls;
+ json_t *ap;
+ const char *url;
+ json_t *obj;
+ bool ready = false;
+ bool poll = false;
+
+ ls = GTK_LIST_STORE (GCG_get_main_window_object (
+ "secret_selection_liststore"));
+ GNUNET_assert (NULL != ls);
+ if (NULL == AG_pd)
+ gtk_list_store_clear (ls);
+ ap = json_object_get (AG_redux_state,
+ "authentication_providers");
+ json_object_foreach (ap, url, obj)
+ {
+ struct ANASTASIS_CRYPTO_ProviderSaltP salt;
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = ANASTASIS_reducer_lookup_salt (AG_redux_state,
+ url,
+ &salt);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ ready = true;
+ break;
+ case GNUNET_NO:
+ poll = true;
+ break;
+ case GNUNET_SYSERR:
+ GNUNET_break (0);
+ break;
+ }
}
- AG_action_cb (NULL,
- TALER_EC_NONE,
- response);
+ if (poll)
+ {
+ long_next = GNUNET_TIME_UNIT_ZERO_ABS;
+ AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
+ NULL);
+ }
+ if (NULL == AG_pd)
+ AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state,
+ NULL,
+ &expand_policy_list,
+ ls);
+ if ( (! ready) &&
+ (! poll) )
+ {
+ AG_error (_ ("No available providers! Try to add one!"));
+ }
+}
+
+
+/**
+ * Function called when it is time for the user to select a secret
+ * from the list of secrets. Builds the respective tree model.
+ */
+static void
+action_secret_selecting (void)
+{
+ AG_hide ("anastasis_gtk_start_frame");
+ AG_stop_long_action ();
+ if (AG_have_error)
+ AG_show ("anastasis_gtk_error_label");
+ AG_hide ("anastasis_gtk_challenge_frame");
+ AG_hide ("anastasis_gtk_identity_frame");
+ if (NULL == AG_pd)
+ begin_discovery ();
+ AG_show ("anastasis_gtk_progress_vbox");
+ AG_progress_update ();
+ AG_show ("anastasis_gtk_recovery_progress_scrolled_window");
+ AG_hide ("anastasis_gtk_backup_progress_scrolled_window");
+ AG_show ("anastasis_gtk_main_control_vbox");
+ AG_show ("anastasis_gtk_main_window_save_as_button");
+ AG_show ("anastasis_gtk_select_secret_frame");
+ AG_show ("anastasis_gtk_main_window_prev_button");
+ AG_hide ("anastasis_gtk_main_window_quit_button");
+ AG_insensitive ("anastasis_gtk_main_window_forward_button");
}
@@ -2361,6 +2533,19 @@ action_challenge_selecting (void)
policy);
}
}
+#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,
+ NULL);
+ }
+#endif
AG_sensitive ("anastasis_gtk_review_policy_treeview");
AG_show ("anastasis_gtk_progress_vbox");
AG_progress_update ();