diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-01-07 13:53:59 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-01-07 13:53:59 +0100 |
commit | d782dd7f54a1b86c402a99428364e86f38552f76 (patch) | |
tree | 803de7c50bd42e03af9d9765535769c0257ac421 | |
parent | 854e9fda1ee848b18fc34b2e02c62852c12096cc (diff) |
wirewatch: ensure wirewatch doesn't busy-loop even if the server errors or ignores long-polling
-rw-r--r-- | src/exchange/taler-exchange-wirewatch.c | 30 |
1 files changed, 29 insertions, 1 deletions
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 @@ -52,6 +52,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? */ static struct GNUNET_TIME_Absolute delayed_until; @@ -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; i<details_length; i++) { @@ -720,6 +744,7 @@ process_reply_batched (const struct TALER_BANK_CreditDetails *details, enum GNUNET_DB_QueryStatus qss[details_length]; struct TALER_EXCHANGEDB_ReserveInInfo reserves[details_length]; + hh_returned_data = true; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Importing %u transactions\n", details_length); @@ -865,6 +890,7 @@ process_reply_batched2 (unsigned int batch_size, transaction_completed (); return; } + hh_returned_data = true; /* check serial IDs for range constraints */ for (unsigned int i = 0; i<details_length; i++) { @@ -1121,6 +1147,8 @@ continue_with_shard (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting credit history staring from %llu\n", (unsigned long long) latest_row_off); + hh_start_time = GNUNET_TIME_absolute_get (); + hh_returned_data = false; hh = TALER_BANK_credit_history (ctx, ai->auth, latest_row_off, |