From 6f0c4869ffb5edba4c4e21c0ba746f590a60b80a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 7 Sep 2020 15:49:00 +0530 Subject: dynamic /pay timeout --- .../taler-merchant-httpd_post-orders-ID-pay.c | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/backend') diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c index 915f3056..38682a24 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -34,12 +34,6 @@ #include "taler-merchant-httpd_private-get-orders.h" -/** - * How long to wait before giving up processing with the exchange? - */ -#define PAY_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ - 30)) - /** * How often do we retry the (complex!) database transaction? */ @@ -364,6 +358,29 @@ static struct PayContext *pc_head; static struct PayContext *pc_tail; +/** + * Compute the timeout for a /pay request based on the number of coins + * involved. + * + * @param num_coins number of coins + * @returns timeout for the /pay request + */ +static struct GNUNET_TIME_Relative +get_pay_timeout (unsigned int num_coins) +{ + struct GNUNET_TIME_Relative t; + struct GNUNET_TIME_Relative sec5; + + sec5 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + 5); + t = GNUNET_TIME_relative_add (sec5, + GNUNET_TIME_relative_multiply (sec5, + num_coins / 20)); + + return t; +} + + /** * Abort all pending /deposit operations. * @@ -1867,9 +1884,10 @@ TMH_post_orders_ID_pay (const struct TMH_RequestHandler *rh, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending pay handling while working with the exchange\n"); GNUNET_assert (NULL == pc->timeout_task); - pc->timeout_task = GNUNET_SCHEDULER_add_delayed (PAY_TIMEOUT, - &handle_pay_timeout, - pc); + pc->timeout_task = + GNUNET_SCHEDULER_add_delayed (get_pay_timeout (pc->coins_cnt), + &handle_pay_timeout, + pc); begin_transaction (pc); return MHD_YES; } -- cgit v1.2.3