diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-02-01 14:41:49 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-01 14:41:49 +0100 |
commit | 62f1faf2e03da6dbb26cd6b1475f2264c452a70a (patch) | |
tree | 777a0d76b011400c7b53d498cbd209f09cf83e70 /src/anastasis/anastasis-gtk_action.c | |
parent | cba65eea1c1a8e3113b0b659ea860f7fb91e4f18 (diff) | |
download | anastasis-gtk-62f1faf2e03da6dbb26cd6b1475f2264c452a70a.tar.gz anastasis-gtk-62f1faf2e03da6dbb26cd6b1475f2264c452a70a.tar.bz2 anastasis-gtk-62f1faf2e03da6dbb26cd6b1475f2264c452a70a.zip |
reintroduce recently 'lost' poll challenges logic
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 206 |
1 files changed, 117 insertions, 89 deletions
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 @@ -42,12 +42,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? */ bool AG_in_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 (); |