diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-reserves.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c index 095264d3..b2cc14c6 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020 Taler Systems SA + (C) 2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -30,6 +30,14 @@ /** + * How long to wait before giving up processing with the exchange? + */ +#define EXCHANGE_GENERIC_TIMEOUT (GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, \ + 15)) + + +/** * Information we keep for an individual call to the POST /reserves handler. */ struct PostReserveContext @@ -76,6 +84,11 @@ struct PostReserveContext struct TMH_EXCHANGES_FindOperation *fo; /** + * Task run on timeout. + */ + struct GNUNET_SCHEDULER_Task *timeout_task; + + /** * Initial balance of the reserve. */ struct TALER_Amount initial_balance; @@ -127,6 +140,11 @@ TMH_force_rc_resume () rc = rcn) { rcn = rc->next; + if (NULL != rc->timeout_task) + { + GNUNET_SCHEDULER_cancel (rc->timeout_task); + rc->timeout_task = NULL; + } if (rc->suspended) { rc->suspended = false; @@ -159,6 +177,11 @@ reserve_context_cleanup (void *cls) TMH_EXCHANGES_find_exchange_cancel (rc->fo); rc->fo = NULL; } + if (NULL != rc->timeout_task) + { + GNUNET_SCHEDULER_cancel (rc->timeout_task); + rc->timeout_task = NULL; + } GNUNET_assert (! rc->suspended); GNUNET_free (rc->payto_uri); GNUNET_free (rc); @@ -189,6 +212,11 @@ handle_exchange (void *cls, rc->fo = NULL; rc->suspended = false; + if (NULL != rc->timeout_task) + { + GNUNET_SCHEDULER_cancel (rc->timeout_task); + rc->timeout_task = NULL; + } MHD_resume_connection (rc->connection); GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, @@ -229,6 +257,35 @@ handle_exchange (void *cls, } +/** + * Handle a timeout for the processing of the wire request. + * + * @param cls closure + */ +static void +handle_exchange_timeout (void *cls) +{ + struct PostReserveContext *rc = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Resuming POST /private/reserves with error after timeout\n"); + rc->timeout_task = NULL; + if (NULL != rc->fo) + { + TMH_EXCHANGES_find_exchange_cancel (rc->fo); + rc->fo = NULL; + } + rc->suspended = false; + MHD_resume_connection (rc->connection); + GNUNET_CONTAINER_DLL_remove (rc_head, + rc_tail, + rc); + rc->ec = TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT; + rc->http_status = MHD_HTTP_GATEWAY_TIMEOUT; + TMH_trigger_daemon (); /* we resumed, kick MHD */ +} + + MHD_RESULT TMH_private_post_reserves (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, @@ -283,6 +340,10 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, GNUNET_NO, &handle_exchange, rc); + rc->timeout_task + = GNUNET_SCHEDULER_add_delayed (EXCHANGE_GENERIC_TIMEOUT, + &handle_exchange_timeout, + rc); rc->suspended = true; GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, |