diff options
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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of anastasis-gtk. | 2 | This file is part of anastasis-gtk. |
3 | Copyright (C) 2020, 2021 Anastasis SARL | 3 | Copyright (C) 2020, 2021, 2022 Anastasis SARL |
4 | 4 | ||
5 | Anastasis is free software; you can redistribute it and/or modify | 5 | Anastasis is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -42,12 +42,6 @@ | |||
42 | #define LP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 42 | #define LP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Next time we schedule the #long_task. | ||
46 | */ | ||
47 | static struct GNUNET_TIME_Absolute long_next; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Are we currently processing an action? | 45 | * Are we currently processing an action? |
52 | */ | 46 | */ |
53 | bool AG_in_action; | 47 | bool AG_in_action; |
@@ -1980,53 +1974,53 @@ expand_policy_list (void *cls, | |||
1980 | * @param response new state as result or config information of a provider | 1974 | * @param response new state as result or config information of a provider |
1981 | */ | 1975 | */ |
1982 | static void | 1976 | static void |
1983 | long_poll_action_cb (void *cls, | 1977 | long_poll_challenges_cb (void *cls, |
1984 | enum TALER_ErrorCode error_code, | 1978 | enum TALER_ErrorCode error_code, |
1985 | json_t *response); | 1979 | json_t *response); |
1986 | 1980 | ||
1987 | 1981 | ||
1988 | /** | 1982 | /** |
1989 | * Schedules the "poll" action. | 1983 | * Schedules the "poll" challenges action. |
1990 | * | 1984 | * |
1991 | * @param cls NULL | 1985 | * @param cls NULL |
1992 | * FIXME: dead code!?? | ||
1993 | */ | 1986 | */ |
1994 | static void | 1987 | static void |
1995 | long_poll_task (void *cls) | 1988 | long_poll_challenges_task (void *cls) |
1996 | { | 1989 | { |
1990 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES]; | ||
1997 | json_t *tspec; | 1991 | json_t *tspec; |
1998 | 1992 | ||
1999 | (void) cls; | 1993 | (void) cls; |
2000 | AG_long_task = NULL; | 1994 | la->task = NULL; |
2001 | if (GNUNET_TIME_absolute_is_future (long_next)) | 1995 | if (GNUNET_TIME_absolute_is_future (la->next_time)) |
2002 | { | 1996 | { |
2003 | AG_long_task = GNUNET_SCHEDULER_add_at (long_next, | 1997 | la->task = GNUNET_SCHEDULER_add_at (la->next_time, |
2004 | &long_poll_task, | 1998 | &long_poll_challenges_task, |
2005 | cls); | 1999 | NULL); |
2006 | return; | 2000 | return; |
2007 | } | 2001 | } |
2008 | long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); | 2002 | la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); |
2009 | tspec = GNUNET_JSON_PACK ( | 2003 | tspec = GNUNET_JSON_PACK ( |
2010 | GNUNET_JSON_pack_time_rel ("timeout", | 2004 | GNUNET_JSON_pack_time_rel ("timeout", |
2011 | LP_TIMEOUT)); | 2005 | LP_TIMEOUT)); |
2012 | AG_long_action | 2006 | la->ra = ANASTASIS_redux_action (AG_redux_state, |
2013 | = ANASTASIS_redux_action (AG_redux_state, | 2007 | "poll", |
2014 | "poll", | 2008 | tspec, |
2015 | tspec, | 2009 | &long_poll_challenges_cb, |
2016 | &long_poll_action_cb, | 2010 | NULL); |
2017 | NULL); | ||
2018 | json_decref (tspec); | 2011 | json_decref (tspec); |
2019 | } | 2012 | } |
2020 | 2013 | ||
2021 | 2014 | ||
2022 | // FIXME: dead code!?? | ||
2023 | static void | 2015 | static void |
2024 | long_poll_action_cb (void *cls, | 2016 | long_poll_challenges_cb (void *cls, |
2025 | enum TALER_ErrorCode error_code, | 2017 | enum TALER_ErrorCode error_code, |
2026 | json_t *response) | 2018 | json_t *response) |
2027 | { | 2019 | { |
2020 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES]; | ||
2021 | |||
2028 | (void) cls; | 2022 | (void) cls; |
2029 | AG_long_action = NULL; | 2023 | la->ra = NULL; |
2030 | switch (error_code) | 2024 | switch (error_code) |
2031 | { | 2025 | { |
2032 | case TALER_EC_NONE: | 2026 | case TALER_EC_NONE: |
@@ -2037,15 +2031,10 @@ long_poll_action_cb (void *cls, | |||
2037 | TALER_ErrorCode_get_hint (error_code), | 2031 | TALER_ErrorCode_get_hint (error_code), |
2038 | (unsigned int) error_code); | 2032 | (unsigned int) error_code); |
2039 | /* simply try again */ | 2033 | /* simply try again */ |
2040 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_task, | 2034 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_challenges_task, |
2041 | NULL); | 2035 | NULL); |
2042 | return; | 2036 | return; |
2043 | } | 2037 | } |
2044 | if (NULL != AG_ra) | ||
2045 | { | ||
2046 | GNUNET_break (0); | ||
2047 | ANASTASIS_redux_action_cancel (AG_ra); | ||
2048 | } | ||
2049 | AG_action_cb (NULL, | 2038 | AG_action_cb (NULL, |
2050 | TALER_EC_NONE, | 2039 | TALER_EC_NONE, |
2051 | response); | 2040 | response); |
@@ -2073,27 +2062,27 @@ long_poll_sync_action_cb (void *cls, | |||
2073 | static void | 2062 | static void |
2074 | long_poll_sync_task (void *cls) | 2063 | long_poll_sync_task (void *cls) |
2075 | { | 2064 | { |
2065 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS]; | ||
2076 | json_t *tspec; | 2066 | json_t *tspec; |
2077 | 2067 | ||
2078 | (void) cls; | 2068 | (void) cls; |
2079 | AG_long_task = NULL; | 2069 | la->task = NULL; |
2080 | if (GNUNET_TIME_absolute_is_future (long_next)) | 2070 | if (GNUNET_TIME_absolute_is_future (la->next_time)) |
2081 | { | 2071 | { |
2082 | AG_long_task = GNUNET_SCHEDULER_add_at (long_next, | 2072 | la->task = GNUNET_SCHEDULER_add_at (la->next_time, |
2083 | &long_poll_sync_task, | 2073 | &long_poll_sync_task, |
2084 | cls); | 2074 | NULL); |
2085 | return; | 2075 | return; |
2086 | } | 2076 | } |
2087 | long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); | 2077 | la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); |
2088 | tspec = GNUNET_JSON_PACK ( | 2078 | tspec = GNUNET_JSON_PACK ( |
2089 | GNUNET_JSON_pack_time_rel ("timeout", | 2079 | GNUNET_JSON_pack_time_rel ("timeout", |
2090 | LP_TIMEOUT)); | 2080 | LP_TIMEOUT)); |
2091 | AG_long_action | 2081 | la->ra = ANASTASIS_redux_action (AG_redux_state, |
2092 | = ANASTASIS_redux_action (AG_redux_state, | 2082 | "sync_providers", |
2093 | "sync_providers", | 2083 | tspec, |
2094 | tspec, | 2084 | &long_poll_sync_action_cb, |
2095 | &long_poll_sync_action_cb, | 2085 | NULL); |
2096 | NULL); | ||
2097 | json_decref (tspec); | 2086 | json_decref (tspec); |
2098 | } | 2087 | } |
2099 | 2088 | ||
@@ -2103,8 +2092,10 @@ long_poll_sync_action_cb (void *cls, | |||
2103 | enum TALER_ErrorCode error_code, | 2092 | enum TALER_ErrorCode error_code, |
2104 | json_t *response) | 2093 | json_t *response) |
2105 | { | 2094 | { |
2095 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS]; | ||
2096 | |||
2106 | (void) cls; | 2097 | (void) cls; |
2107 | AG_long_action = NULL; | 2098 | la->ra = NULL; |
2108 | switch (error_code) | 2099 | switch (error_code) |
2109 | { | 2100 | { |
2110 | case TALER_EC_NONE: | 2101 | case TALER_EC_NONE: |
@@ -2118,15 +2109,10 @@ long_poll_sync_action_cb (void *cls, | |||
2118 | TALER_ErrorCode_get_hint (error_code), | 2109 | TALER_ErrorCode_get_hint (error_code), |
2119 | (unsigned int) error_code); | 2110 | (unsigned int) error_code); |
2120 | /* simply try again */ | 2111 | /* simply try again */ |
2121 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task, | 2112 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task, |
2122 | NULL); | 2113 | NULL); |
2123 | return; | 2114 | return; |
2124 | } | 2115 | } |
2125 | if (NULL != AG_ra) | ||
2126 | { | ||
2127 | GNUNET_break (0); | ||
2128 | ANASTASIS_redux_action_cancel (AG_ra); | ||
2129 | } | ||
2130 | AG_action_cb (NULL, | 2116 | AG_action_cb (NULL, |
2131 | TALER_EC_NONE, | 2117 | TALER_EC_NONE, |
2132 | response); | 2118 | response); |
@@ -2154,29 +2140,29 @@ long_poll_providers_action_cb (void *cls, | |||
2154 | static void | 2140 | static void |
2155 | long_poll_providers_task (void *cls) | 2141 | long_poll_providers_task (void *cls) |
2156 | { | 2142 | { |
2143 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; | ||
2157 | json_t *tspec; | 2144 | json_t *tspec; |
2158 | 2145 | ||
2159 | (void) cls; | 2146 | (void) cls; |
2160 | AG_long_task = NULL; | 2147 | la->task = NULL; |
2161 | if (GNUNET_TIME_absolute_is_future (long_next)) | 2148 | if (GNUNET_TIME_absolute_is_future (la->next_time)) |
2162 | { | 2149 | { |
2163 | AG_long_task = GNUNET_SCHEDULER_add_at (long_next, | 2150 | la->task = GNUNET_SCHEDULER_add_at (la->next_time, |
2164 | &long_poll_providers_task, | 2151 | &long_poll_providers_task, |
2165 | cls); | 2152 | NULL); |
2166 | return; | 2153 | return; |
2167 | } | 2154 | } |
2168 | long_next = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); | 2155 | la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); |
2169 | tspec = GNUNET_JSON_PACK ( | 2156 | tspec = GNUNET_JSON_PACK ( |
2170 | GNUNET_JSON_pack_time_rel ("timeout", | 2157 | GNUNET_JSON_pack_time_rel ("timeout", |
2171 | LP_TIMEOUT)); | 2158 | LP_TIMEOUT)); |
2172 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2173 | "Starting long polling task for provider configurations\n"); | 2160 | "Starting long polling task for provider configurations\n"); |
2174 | AG_long_action | 2161 | la->ra = ANASTASIS_redux_action (AG_redux_state, |
2175 | = ANASTASIS_redux_action (AG_redux_state, | 2162 | "poll_providers", |
2176 | "poll_providers", | 2163 | tspec, |
2177 | tspec, | 2164 | &long_poll_providers_action_cb, |
2178 | &long_poll_providers_action_cb, | 2165 | NULL); |
2179 | cls); | ||
2180 | json_decref (tspec); | 2166 | json_decref (tspec); |
2181 | } | 2167 | } |
2182 | 2168 | ||
@@ -2195,11 +2181,12 @@ long_poll_providers_action_cb (void *cls, | |||
2195 | enum TALER_ErrorCode error_code, | 2181 | enum TALER_ErrorCode error_code, |
2196 | json_t *response) | 2182 | json_t *response) |
2197 | { | 2183 | { |
2184 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; | ||
2198 | json_t *ap; | 2185 | json_t *ap; |
2199 | const char *url; | 2186 | const char *url; |
2200 | json_t *obj; | 2187 | json_t *obj; |
2201 | 2188 | ||
2202 | AG_long_action = NULL; | 2189 | la->ra = NULL; |
2203 | switch (error_code) | 2190 | switch (error_code) |
2204 | { | 2191 | { |
2205 | case TALER_EC_NONE: | 2192 | case TALER_EC_NONE: |
@@ -2210,8 +2197,8 @@ long_poll_providers_action_cb (void *cls, | |||
2210 | TALER_ErrorCode_get_hint (error_code), | 2197 | TALER_ErrorCode_get_hint (error_code), |
2211 | (unsigned int) error_code); | 2198 | (unsigned int) error_code); |
2212 | /* simply try again */ | 2199 | /* simply try again */ |
2213 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, | 2200 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, |
2214 | NULL); | 2201 | NULL); |
2215 | return; | 2202 | return; |
2216 | } | 2203 | } |
2217 | GNUNET_assert (NULL != AG_pd); | 2204 | GNUNET_assert (NULL != AG_pd); |
@@ -2246,6 +2233,7 @@ long_poll_providers_action_cb (void *cls, | |||
2246 | static void | 2233 | static void |
2247 | begin_discovery (void) | 2234 | begin_discovery (void) |
2248 | { | 2235 | { |
2236 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; | ||
2249 | GtkListStore *ls; | 2237 | GtkListStore *ls; |
2250 | json_t *ap; | 2238 | json_t *ap; |
2251 | const char *url; | 2239 | const char *url; |
@@ -2283,9 +2271,9 @@ begin_discovery (void) | |||
2283 | } | 2271 | } |
2284 | if (poll) | 2272 | if (poll) |
2285 | { | 2273 | { |
2286 | long_next = GNUNET_TIME_UNIT_ZERO_ABS; | 2274 | la->next_time = GNUNET_TIME_UNIT_ZERO_ABS; |
2287 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, | 2275 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, |
2288 | NULL); | 2276 | NULL); |
2289 | } | 2277 | } |
2290 | if (NULL == AG_pd) | 2278 | if (NULL == AG_pd) |
2291 | AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state, | 2279 | AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state, |
@@ -2682,24 +2670,64 @@ action_challenge_selecting (void) | |||
2682 | } | 2670 | } |
2683 | if (sp) | 2671 | if (sp) |
2684 | { | 2672 | { |
2685 | long_next = GNUNET_TIME_UNIT_ZERO_ABS; | 2673 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_SYNC_PROVIDERS]; |
2686 | GNUNET_assert (NULL == AG_long_task); | 2674 | |
2687 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task, | 2675 | la->next_time = GNUNET_TIME_UNIT_ZERO_ABS; |
2688 | NULL); | 2676 | GNUNET_assert (NULL == la->task); |
2677 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_sync_task, | ||
2678 | NULL); | ||
2689 | } | 2679 | } |
2690 | #if FIXME | 2680 | |
2691 | /* FIXME: Did we loose some logic like this here for the | ||
2692 | long-polling challenges? At least the | ||
2693 | 'long_poll_task' appears to have turned into dead code | ||
2694 | and something like this would seem to be needed | ||
2695 | here for the polling challenges (SEPA transfer) */ | ||
2696 | if (poll) | ||
2697 | { | 2681 | { |
2698 | long_next = GNUNET_TIME_UNIT_ZERO_ABS; | 2682 | struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_CHALLENGES]; |
2699 | AG_long_task = GNUNET_SCHEDULER_add_now (&long_poll_task, | 2683 | json_t *rd; |
2684 | json_t *challenges; | ||
2685 | size_t index; | ||
2686 | json_t *challenge; | ||
2687 | |||
2688 | rd = json_object_get (AG_redux_state, | ||
2689 | "recovery_document"); | ||
2690 | GNUNET_assert (NULL != rd); | ||
2691 | challenges = json_object_get (rd, | ||
2692 | "cs"); | ||
2693 | GNUNET_assert (NULL != challenges); | ||
2694 | json_array_foreach (challenges, index, challenge) | ||
2695 | { | ||
2696 | bool async = false; | ||
2697 | struct GNUNET_JSON_Specification spec[] = { | ||
2698 | GNUNET_JSON_spec_mark_optional ( | ||
2699 | GNUNET_JSON_spec_bool ("async", | ||
2700 | &async)), | ||
2701 | GNUNET_JSON_spec_end () | ||
2702 | }; | ||
2703 | const json_t *ks; | ||
2704 | |||
2705 | ks = json_object_get (challenge, | ||
2706 | "key_share"); | ||
2707 | if ( (NULL != ks) && | ||
2708 | (! json_is_null (ks)) ) | ||
2709 | continue; /* already solved */ | ||
2710 | if (GNUNET_OK != | ||
2711 | GNUNET_JSON_parse (challenge, | ||
2712 | spec, | ||
2713 | NULL, NULL)) | ||
2714 | { | ||
2715 | GNUNET_break (0); | ||
2716 | json_dumpf (challenge, | ||
2717 | stderr, | ||
2718 | JSON_INDENT (2)); | ||
2719 | continue; | ||
2720 | } | ||
2721 | if (async && | ||
2722 | (NULL == la->task) ) | ||
2723 | { | ||
2724 | la->next_time = GNUNET_TIME_UNIT_ZERO_ABS; | ||
2725 | la->task = GNUNET_SCHEDULER_add_now (&long_poll_challenges_task, | ||
2700 | NULL); | 2726 | NULL); |
2727 | } | ||
2728 | } | ||
2701 | } | 2729 | } |
2702 | #endif | 2730 | |
2703 | AG_sensitive ("anastasis_gtk_review_policy_treeview"); | 2731 | AG_sensitive ("anastasis_gtk_review_policy_treeview"); |
2704 | AG_show ("anastasis_gtk_progress_vbox"); | 2732 | AG_show ("anastasis_gtk_progress_vbox"); |
2705 | AG_progress_update (); | 2733 | AG_progress_update (); |