diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-01-12 23:09:24 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-01-12 23:10:11 +0100 |
commit | 117b8006d628b03d6e5945338c2362720a7f0e94 (patch) | |
tree | 261e383fd6865b24fae2e3e6914907301da5764e /src/merchant-tools | |
parent | af6b944efb53f429c1a67c30b7ae7576a464b0f5 (diff) | |
download | merchant-117b8006d628b03d6e5945338c2362720a7f0e94.tar.gz merchant-117b8006d628b03d6e5945338c2362720a7f0e94.tar.bz2 merchant-117b8006d628b03d6e5945338c2362720a7f0e94.zip |
fix #7570 and #7571
Diffstat (limited to 'src/merchant-tools')
-rw-r--r-- | src/merchant-tools/taler-merchant-setup-reserve.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/merchant-tools/taler-merchant-setup-reserve.c b/src/merchant-tools/taler-merchant-setup-reserve.c index cb43eaf5..1ed50530 100644 --- a/src/merchant-tools/taler-merchant-setup-reserve.c +++ b/src/merchant-tools/taler-merchant-setup-reserve.c @@ -24,6 +24,10 @@ #include <gnunet/gnunet_util_lib.h> #include "taler_merchant_service.h" +/** + * How often do we try before giving up? + */ +#define MAX_TRIES 30 /** * Return value from main(). @@ -97,6 +101,17 @@ static char *apikey; static char *keypass; /** + * How often have we tried? + */ +static unsigned int tries; + +/** + * Task to do the main work. + */ +static struct GNUNET_SCHEDULER_Task *task; + + +/** * Shutdown task (invoked when the process is being terminated) * * @param cls NULL @@ -104,6 +119,11 @@ static char *keypass; static void do_shutdown (void *cls) { + if (NULL != task) + { + GNUNET_SCHEDULER_cancel (task); + task = NULL; + } if (NULL != ctx) { GNUNET_CURL_fini (ctx); @@ -123,6 +143,15 @@ do_shutdown (void *cls) /** + * Function that makes the call to setup the reserve. + * + * @param cls NULL + */ +static void +do_request (void *cls); + + +/** * Callbacks of this type are used to work the result of submitting a * POST /reserves request to a merchant * @@ -161,6 +190,32 @@ result_cb (void *cls, res_str); } break; + case MHD_HTTP_CONFLICT: + fprintf (stderr, + "Conflict trying to setup reserve: %u/%d\nHint: %s\n", + hr->http_status, + (int) hr->ec, + hr->hint); + global_ret = 1; + break; + case MHD_HTTP_INTERNAL_SERVER_ERROR: + case MHD_HTTP_BAD_GATEWAY: + tries++; + if (tries < MAX_TRIES) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Merchant failed, will try again.\n"); + task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &do_request, + NULL); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Merchant failed too often (%u/%d), giving up\n", + hr->http_status, + hr->ec); + global_ret = 1; + break; default: fprintf (stderr, "Unexpected backend failure: %u/%d\nHint: %s\n", @@ -219,10 +274,19 @@ run (void *cls, } GNUNET_free (auth_header); } - /* setup termination logic */ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); + task = GNUNET_SCHEDULER_add_now (&do_request, + NULL); +} + + +static void +do_request (void *cls) +{ + (void) cls; + task = NULL; /* run actual (async) operation */ prh = TALER_MERCHANT_reserves_post (ctx, merchant_base_url, |