diff --git a/src/exchange-lib/backoff.h b/src/exchange-lib/backoff.h new file mode 100644 index 000000000..2af41e7c7 --- /dev/null +++ b/src/exchange-lib/backoff.h @@ -0,0 +1,38 @@ +/* + This file is part of TALER + Copyright (C) 2014-2018 GNUnet e.V. + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + +*/ + +/** + * @file exchange-lib/backoff.h + * @brief backoff computation for the exchange lib + * @author Florian Dold + */ + + +#ifndef _TALER_BACKOFF_H +#define _TALER_BACKOFF_H + +#include "platform.h" +#include + +/** + * Random exponential backoff used in the exchange lib. + */ +#define EXCHANGE_LIB_BACKOFF(r) GNUNET_TIME_randomized_backoff ( \ + (r), \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)); + +#endif diff --git a/src/exchange-lib/curl_defaults.h b/src/exchange-lib/curl_defaults.h index 87fccf842..4ca574230 100644 --- a/src/exchange-lib/curl_defaults.h +++ b/src/exchange-lib/curl_defaults.h @@ -21,6 +21,10 @@ * @author Florian Dold */ +#ifndef _TALER_CURL_DEFAULTS_H +#define _TALER_CURL_DEFAULTS_H + + #include "platform.h" #include @@ -33,3 +37,5 @@ */ CURL * TEL_curl_easy_get (char *url); + +#endif /* _TALER_CURL_DEFAULTS_H */ diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c index 89915aacf..a5f4f6969 100644 --- a/src/exchange-lib/exchange_api_handle.c +++ b/src/exchange-lib/exchange_api_handle.c @@ -28,6 +28,7 @@ #include "taler_signatures.h" #include "exchange_api_handle.h" #include "curl_defaults.h" +#include "backoff.h" /** * Which revision of the Taler protocol is implemented @@ -848,7 +849,7 @@ keys_completed_cb (void *cls, free_keys_request (kr); exchange->kr = NULL; GNUNET_assert (NULL == exchange->retry_task); - exchange->retry_delay = GNUNET_TIME_randomized_backoff (exchange->retry_delay); + exchange->retry_delay = EXCHANGE_LIB_BACKOFF (exchange->retry_delay); exchange->retry_task = GNUNET_SCHEDULER_add_delayed (exchange->retry_delay, &request_keys, exchange); diff --git a/src/exchange-lib/testing_api_cmd_deposit.c b/src/exchange-lib/testing_api_cmd_deposit.c index 25a56e829..ecace5654 100644 --- a/src/exchange-lib/testing_api_cmd_deposit.c +++ b/src/exchange-lib/testing_api_cmd_deposit.c @@ -29,6 +29,7 @@ #include "exchange_api_handle.h" #include "taler_testing_lib.h" #include "taler_signatures.h" +#include "backoff.h" /** @@ -181,7 +182,7 @@ deposit_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ds->backoff = GNUNET_TIME_UNIT_ZERO; else - ds->backoff = GNUNET_TIME_randomized_backoff (ds->backoff); + ds->backoff = EXCHANGE_LIB_BACKOFF (ds->backoff); ds->retry_task = GNUNET_SCHEDULER_add_delayed (ds->backoff, &do_retry, ds); diff --git a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c index 84ac3dcc5..1f6015192 100644 --- a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c +++ b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c @@ -32,6 +32,7 @@ #include "taler_signatures.h" #include "taler_testing_lib.h" #include "taler_testing_bank_lib.h" +#include "backoff.h" /** * State for a "fakebank transfer" CMD. @@ -212,7 +213,7 @@ add_incoming_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) fts->backoff = GNUNET_TIME_UNIT_ZERO; else - fts->backoff = GNUNET_TIME_randomized_backoff (fts->backoff); + fts->backoff = EXCHANGE_LIB_BACKOFF (fts->backoff); fts->retry_task = GNUNET_SCHEDULER_add_delayed (fts->backoff, &do_retry, fts); diff --git a/src/exchange-lib/testing_api_cmd_refresh.c b/src/exchange-lib/testing_api_cmd_refresh.c index 3ca04d220..23fb4715b 100644 --- a/src/exchange-lib/testing_api_cmd_refresh.c +++ b/src/exchange-lib/testing_api_cmd_refresh.c @@ -29,6 +29,7 @@ #include "exchange_api_handle.h" #include "taler_testing_lib.h" #include "taler_signatures.h" +#include "backoff.h" /** * Data for a coin to be melted. @@ -322,7 +323,7 @@ reveal_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) rrs->backoff = GNUNET_TIME_UNIT_ZERO; else - rrs->backoff = GNUNET_TIME_randomized_backoff (rrs->backoff); + rrs->backoff = EXCHANGE_LIB_BACKOFF (rrs->backoff); rrs->retry_task = GNUNET_SCHEDULER_add_delayed (rrs->backoff, &do_reveal_retry, rrs); @@ -551,7 +552,7 @@ link_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) rls->backoff = GNUNET_TIME_UNIT_ZERO; else - rls->backoff = GNUNET_TIME_randomized_backoff (rls->backoff); + rls->backoff = EXCHANGE_LIB_BACKOFF (rls->backoff); rls->retry_task = GNUNET_SCHEDULER_add_delayed (rls->backoff, &do_link_retry, rls); @@ -837,7 +838,7 @@ melt_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) rms->backoff = GNUNET_TIME_UNIT_ZERO; else - rms->backoff = GNUNET_TIME_randomized_backoff (rms->backoff); + rms->backoff = EXCHANGE_LIB_BACKOFF (rms->backoff); rms->retry_task = GNUNET_SCHEDULER_add_delayed (rms->backoff, &do_melt_retry, rms); diff --git a/src/exchange-lib/testing_api_cmd_withdraw.c b/src/exchange-lib/testing_api_cmd_withdraw.c index 58464d4d4..51dd1d719 100644 --- a/src/exchange-lib/testing_api_cmd_withdraw.c +++ b/src/exchange-lib/testing_api_cmd_withdraw.c @@ -29,6 +29,7 @@ #include "exchange_api_handle.h" #include "taler_signatures.h" #include "taler_testing_lib.h" +#include "backoff.h" @@ -183,7 +184,7 @@ reserve_withdraw_cb (void *cls, if (TALER_EC_DB_COMMIT_FAILED_ON_RETRY == ec) ws->backoff = GNUNET_TIME_UNIT_ZERO; else - ws->backoff = GNUNET_TIME_randomized_backoff (ws->backoff); + ws->backoff = EXCHANGE_LIB_BACKOFF (ws->backoff); ws->retry_task = GNUNET_SCHEDULER_add_delayed (ws->backoff, &do_retry, ws);