From d782dd7f54a1b86c402a99428364e86f38552f76 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 7 Jan 2023 13:53:59 +0100 Subject: [PATCH] wirewatch: ensure wirewatch doesn't busy-loop even if the server errors or ignores long-polling --- src/exchange/taler-exchange-wirewatch.c | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c index 337b11ca3..957060329 100644 --- a/src/exchange/taler-exchange-wirewatch.c +++ b/src/exchange/taler-exchange-wirewatch.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016--2022 Taler Systems SA + Copyright (C) 2016--2023 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 published by the Free Software @@ -51,6 +51,17 @@ static const struct TALER_EXCHANGEDB_AccountInfo *ai; */ static struct TALER_BANK_CreditHistoryHandle *hh; +/** + * Set to true if the request for history did actually + * return transaction items. + */ +static bool hh_returned_data; + +/** + * When did we start the last @e hh request? + */ +static struct GNUNET_TIME_Absolute hh_start_time; + /** * Until when is processing this wire plugin delayed? */ @@ -455,6 +466,18 @@ transaction_completed (void) GNUNET_SCHEDULER_shutdown (); return; } + if (! hh_returned_data) + { + /* Enforce long polling delay even if the server ignored it + and returned earlier */ + struct GNUNET_TIME_Relative latency; + struct GNUNET_TIME_Relative left; + + latency = GNUNET_TIME_absolute_get_duration (hh_start_time); + left = GNUNET_TIME_relative_subtract (LONGPOLL_TIMEOUT, + latency); + delayed_until = GNUNET_TIME_relative_to_absolute (left); + } GNUNET_assert (NULL == task); schedule_transfers (); } @@ -482,6 +505,7 @@ process_reply (const struct TALER_BANK_CreditDetails *details, transaction_completed (); return; } + hh_returned_data = true; /* check serial IDs for range constraints */ for (unsigned int i = 0; iauth, latest_row_off,