wirewatch: ensure wirewatch doesn't busy-loop even if the server errors or ignores long-polling

This commit is contained in:
Christian Grothoff 2023-01-07 13:53:59 +01:00
parent 854e9fda1e
commit d782dd7f54
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 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; 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? * Until when is processing this wire plugin delayed?
*/ */
@ -455,6 +466,18 @@ transaction_completed (void)
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; 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); GNUNET_assert (NULL == task);
schedule_transfers (); schedule_transfers ();
} }
@ -482,6 +505,7 @@ process_reply (const struct TALER_BANK_CreditDetails *details,
transaction_completed (); transaction_completed ();
return; return;
} }
hh_returned_data = true;
/* check serial IDs for range constraints */ /* check serial IDs for range constraints */
for (unsigned int i = 0; i<details_length; i++) 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]; enum GNUNET_DB_QueryStatus qss[details_length];
struct TALER_EXCHANGEDB_ReserveInInfo reserves[details_length]; struct TALER_EXCHANGEDB_ReserveInInfo reserves[details_length];
hh_returned_data = true;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Importing %u transactions\n", "Importing %u transactions\n",
details_length); details_length);
@ -865,6 +890,7 @@ process_reply_batched2 (unsigned int batch_size,
transaction_completed (); transaction_completed ();
return; return;
} }
hh_returned_data = true;
/* check serial IDs for range constraints */ /* check serial IDs for range constraints */
for (unsigned int i = 0; i<details_length; i++) for (unsigned int i = 0; i<details_length; i++)
{ {
@ -1121,6 +1147,8 @@ continue_with_shard (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting credit history staring from %llu\n", "Requesting credit history staring from %llu\n",
(unsigned long long) latest_row_off); (unsigned long long) latest_row_off);
hh_start_time = GNUNET_TIME_absolute_get ();
hh_returned_data = false;
hh = TALER_BANK_credit_history (ctx, hh = TALER_BANK_credit_history (ctx,
ai->auth, ai->auth,
latest_row_off, latest_row_off,