diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-12-31 11:47:06 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-12-31 11:47:06 +0100 |
commit | c76ed196f2bfe4077e15d69dd06857d60b409e0d (patch) | |
tree | 814b0001fcaf65e3199f91cb27969074b03fcf2c /src/anastasis/anastasis-gtk_action.c | |
parent | 7be22e36e6cac8893d3d37d2691e8957fd2d2a10 (diff) | |
download | anastasis-gtk-c76ed196f2bfe4077e15d69dd06857d60b409e0d.tar.gz anastasis-gtk-c76ed196f2bfe4077e15d69dd06857d60b409e0d.tar.bz2 anastasis-gtk-c76ed196f2bfe4077e15d69dd06857d60b409e0d.zip |
show exact timeout frequency issue (#7054)
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c index 8ad386f..df6edb0 100644 --- a/src/anastasis/anastasis-gtk_action.c +++ b/src/anastasis/anastasis-gtk_action.c @@ -1671,10 +1671,12 @@ find_challenge_by_uuid (const char *uuid) * Translate the @a state into a localized, human-readable * string. * + * @param f full json state about the state * @param state a challenge state, as a string */ -static const char * -translate_state (const char *state) +static char * +translate_state (const json_t *f, + const char *state) { struct { @@ -1698,8 +1700,6 @@ translate_state (const char *state) { .in = "truth-unknown", .out = _ ("fatal: challenge unknown to provider; " "maybe you can solve another policy?") }, - { .in = "rate-limit-exceeded", - .out = _ ("wait, tries exceeded at this time") }, { .in = "authentication-timeout", .out = _ ("awaiting completion of authentication process") }, { .in = "external-instructions", @@ -1708,17 +1708,52 @@ translate_state (const char *state) .out = NULL } }; + if (0 == strcmp (state, + "rate-limit-exceeded")) + { + uint32_t request_limit; + struct GNUNET_TIME_Relative rf; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint32 ("request_limit", + &request_limit), + GNUNET_JSON_spec_relative_time ("request_frequency", + &rf), + GNUNET_JSON_spec_end () + }; + char *reply; + + if (GNUNET_OK != + GNUNET_JSON_parse (f, + spec, + NULL, NULL)) + { + GNUNET_break (0); + json_dumpf (f, + stderr, + JSON_INDENT (2)); + return GNUNET_strdup ( + _ ("wait, tries exceeded at this time")); + + } + GNUNET_asprintf (&reply, + _ ("exceeded limit of %u attempts in %s"), + (unsigned int) request_limit, + GNUNET_TIME_relative2s (rf, + true)); + return reply; + } + for (unsigned int i = 0; NULL != state_map[i].in; i++) { if (0 != strcmp (state_map[i].in, state)) continue; - return state_map[i].out; + return GNUNET_strdup (state_map[i].out); } GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not localize unexpected state `%s'\n", state); - return state; + return GNUNET_strdup (state); } @@ -1826,15 +1861,17 @@ show_challenge_feedback (const char *uuid, } else { - const char *hint; + char *hint; GtkLabel *l; - hint = translate_state (state); + hint = translate_state (f, + state); l = GTK_LABEL (gtk_builder_get_object (builder, "hint_label")); gtk_label_set_text (l, hint); gtk_widget_show (GTK_WIDGET (l)); + GNUNET_free (hint); } if (0 == strcmp (state, "details")) |