diff options
Diffstat (limited to 'src/exchange/taler-exchange-wirewatch.c')
-rw-r--r-- | src/exchange/taler-exchange-wirewatch.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c index a7a6b004f..da5d9c098 100644 --- a/src/exchange/taler-exchange-wirewatch.c +++ b/src/exchange/taler-exchange-wirewatch.c @@ -58,6 +58,12 @@ static struct TALER_BANK_CreditHistoryHandle *hh; static bool hh_returned_data; /** + * Set to true if the request for history did not + * succeed because the account was unknown. + */ +static bool hh_account_404; + +/** * When did we start the last @e hh request? */ static struct GNUNET_TIME_Absolute hh_start_time; @@ -290,7 +296,7 @@ add_account_cb (void *cls, if (! in_ai->credit_enabled) return; /* not enabled for us, skip */ if ( (NULL != account_section) && - (0 != strcasecmp (ai->section_name, + (0 != strcasecmp (in_ai->section_name, account_section)) ) return; /* not enabled for us, skip */ if (NULL != ai) @@ -356,7 +362,6 @@ exchange_serve_process_config (void) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No accounts enabled for credit!\n"); GNUNET_SCHEDULER_shutdown (); - global_ret = EXIT_INVALIDARGUMENT; return GNUNET_SYSERR; } return GNUNET_OK; @@ -472,9 +477,9 @@ transaction_completed (void) GNUNET_SCHEDULER_shutdown (); return; } - if (! hh_returned_data) + if (! (hh_returned_data || hh_account_404) ) { - /* Enforce long polling delay even if the server ignored it + /* Enforce long-polling delay even if the server ignored it and returned earlier */ struct GNUNET_TIME_Relative latency; struct GNUNET_TIME_Relative left; @@ -482,8 +487,17 @@ transaction_completed (void) latency = GNUNET_TIME_absolute_get_duration (hh_start_time); left = GNUNET_TIME_relative_subtract (longpoll_timeout, latency); + if (! (test_mode || + GNUNET_TIME_relative_is_zero (left)) ) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Server did not respect long-polling, enforcing client-side by sleeping for %s\n", + GNUNET_TIME_relative2s (left, + true)); delayed_until = GNUNET_TIME_relative_to_absolute (left); } + if (hh_account_404) + delayed_until = GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_UNIT_MILLISECONDS); if (test_mode) delayed_until = GNUNET_TIME_UNIT_ZERO_ABS; GNUNET_assert (NULL == task); @@ -495,13 +509,11 @@ transaction_completed (void) * We got incoming transaction details from the bank. Add them * to the database. * - * @param batch_size desired batch size * @param details array of transaction details * @param details_length length of the @a details array */ static void -process_reply (unsigned int batch_size, - const struct TALER_BANK_CreditDetails *details, +process_reply (const struct TALER_BANK_CreditDetails *details, unsigned int details_length) { enum GNUNET_DB_QueryStatus qs; @@ -570,7 +582,6 @@ process_reply (unsigned int batch_size, qs = db_plugin->reserves_in_insert (db_plugin->cls, reserves, details_length, - batch_size, qss); switch (qs) { @@ -580,8 +591,8 @@ process_reply (unsigned int batch_size, return; case GNUNET_DB_STATUS_SOFT_ERROR: GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Got DB soft error for batch2_reserves_in_insert (%u). Rolling back.\n", - batch_size); + "Got DB soft error for reserves_in_insert (%u). Rolling back.\n", + details_length); handle_soft_error (); return; default: @@ -618,7 +629,7 @@ process_reply (unsigned int batch_size, break; case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Imported transaction %llu.", + "Imported transaction %llu.\n", (unsigned long long) cd->serial_id); /* normal case */ progress = true; @@ -686,43 +697,23 @@ static void history_cb (void *cls, const struct TALER_BANK_CreditHistoryResponse *reply) { - static int batch_mode = -2; - (void) cls; - if (-2 == batch_mode) - { - const char *mode = getenv ("TALER_WIREWATCH_BATCH_SIZE"); - char dummy; - - if ( (NULL == mode) || - (1 != sscanf (mode, - "%d%c", - &batch_mode, - &dummy)) ) - { - if (NULL != mode) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Bad batch mode `%s' specified\n", - mode); - batch_mode = 8; /* maximum supported is currently 8 */ - } - } GNUNET_assert (NULL == task); hh = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "History request returned with HTTP status %u\n", reply->http_status); switch (reply->http_status) { case MHD_HTTP_OK: - process_reply (batch_mode, - reply->details.success.details, - reply->details.success.details_length); + process_reply (reply->details.ok.details, + reply->details.ok.details_length); return; case MHD_HTTP_NO_CONTENT: transaction_completed (); return; case MHD_HTTP_NOT_FOUND: + hh_account_404 = true; if (ignore_account_404) { transaction_completed (); @@ -757,10 +748,11 @@ continue_with_shard (void *cls) shard_end - latest_row_off); GNUNET_assert (NULL == hh); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Requesting credit history staring from %llu\n", + "Requesting credit history starting from %llu\n", (unsigned long long) latest_row_off); hh_start_time = GNUNET_TIME_absolute_get (); hh_returned_data = false; + hh_account_404 = false; hh = TALER_BANK_credit_history (ctx, ai->auth, latest_row_off, @@ -857,6 +849,17 @@ lock_shard (void *cls) job_name, GNUNET_STRINGS_relative_time_to_string (rdelay, true)); +#if 1 + if (GNUNET_TIME_relative_cmp (rdelay, + >, + GNUNET_TIME_UNIT_SECONDS)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Delay would have been for %s\n", + GNUNET_TIME_relative2s (rdelay, + true)); + rdelay = GNUNET_TIME_relative_min (rdelay, + GNUNET_TIME_UNIT_SECONDS); +#endif delayed_until = GNUNET_TIME_relative_to_absolute (rdelay); } GNUNET_assert (NULL == task); @@ -869,7 +872,7 @@ lock_shard (void *cls) job_name, GNUNET_STRINGS_relative_time_to_string ( wirewatch_idle_sleep_interval, - GNUNET_YES)); + true)); delayed_until = GNUNET_TIME_relative_to_absolute ( wirewatch_idle_sleep_interval); shard_open = false; @@ -947,6 +950,7 @@ run (void *cls, { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); + global_ret = EXIT_NO_RESTART; return; } rc = GNUNET_CURL_gnunet_rc_create (ctx); @@ -978,7 +982,7 @@ main (int argc, GNUNET_GETOPT_option_relative_time ('f', "longpoll-timeout", "DELAY", - "what is the timeout when asking the bank about new transactions", + "what is the timeout when asking the bank about new transactions, specify with unit (e.g. --longpoll-timeout=30s)", &longpoll_timeout), GNUNET_GETOPT_option_flag ('I', "ignore-not-found", |