From 697ea51cbbe8a32b8484630433c51a5c5ddb595a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 30 Jan 2022 13:55:51 +0100 Subject: -more work towards nicer policy discovery logic --- src/reducer/anastasis_api_recovery_redux.c | 83 ++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) (limited to 'src/reducer/anastasis_api_recovery_redux.c') diff --git a/src/reducer/anastasis_api_recovery_redux.c b/src/reducer/anastasis_api_recovery_redux.c index 5f087f3..2be963f 100644 --- a/src/reducer/anastasis_api_recovery_redux.c +++ b/src/reducer/anastasis_api_recovery_redux.c @@ -2076,9 +2076,9 @@ sync_providers (json_t *state, return NULL; } if (GNUNET_OK == - ANASTASIS_reducer_lookup_salt_ (state, - provider_url, - &salt)) + ANASTASIS_reducer_lookup_salt (state, + provider_url, + &salt)) continue; /* provider already ready */ se = GNUNET_new (struct SyncEntry); se->ms = ms; @@ -2107,6 +2107,78 @@ sync_providers (json_t *state, } +/** + * Try to obtain configuration information on all configured + * providers. Upon success, call @a cb with the updated provider + * status data. + * + * @param[in] state we are in + * @param arguments our arguments with the solution + * @param cb functiont o call with the new state + * @param cb_cls closure for @a cb + * @return handle to cancel challenge selection step + */ +static struct ANASTASIS_ReduxAction * +poll_providers (json_t *state, + const json_t *arguments, + ANASTASIS_ActionCallback cb, + void *cb_cls) +{ + json_t *ap; + const char *url; + json_t *obj; + struct MasterSync *ms; + + ap = json_object_get (state, + "authentication_providers"); + if (NULL == ap) + { + GNUNET_break (0); + ANASTASIS_redux_fail_ (cb, + cb_cls, + TALER_EC_ANASTASIS_REDUCER_STATE_INVALID, + "'authentication_providers' missing"); + return NULL; + } + ms = GNUNET_new (struct MasterSync); + ms->cb = cb; + ms->cb_cls = cb_cls; + json_object_foreach (ap, url, obj) + { + struct ANASTASIS_CRYPTO_ProviderSaltP salt; + struct SyncEntry *se; + + if (GNUNET_OK == + ANASTASIS_reducer_lookup_salt (state, + url, + &salt)) + continue; + se = GNUNET_new (struct SyncEntry); + se->ms = ms; + GNUNET_CONTAINER_DLL_insert (ms->se_head, + ms->se_tail, + se); + se->ra = ANASTASIS_REDUX_add_provider_to_state_ (url, + state, + &sync_progress, + se); + } + if (NULL == ms->se_head) + { + /* everything already synced */ + clean_sync (ms); + ANASTASIS_redux_fail_ (cb, + cb_cls, + TALER_EC_ANASTASIS_REDUCER_ACTION_INVALID, + "already in sync"); + return NULL; + } + ms->ra.cleanup = &clean_sync; + ms->ra.cleanup_cls = ms; + return &ms->ra; +} + + /** * The user pressed "back" during challenge solving. * Transition back to selecting another challenge. @@ -2592,6 +2664,11 @@ ANASTASIS_recovery_action_ (json_t *state, "add_provider", &add_provider }, + { + ANASTASIS_RECOVERY_STATE_SECRET_SELECTING, + "poll_providers", + &poll_providers + }, { ANASTASIS_RECOVERY_STATE_SECRET_SELECTING, "next", -- cgit v1.2.3