From 383fd75230fc5301d432f50e4cb3474a59cb33e8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 4 Aug 2021 13:46:08 +0200 Subject: -migrate benchmarks to new configuration structure --- src/benchmark/Makefile.am | 10 ++-- src/benchmark/taler-bank-benchmark.c | 66 +++++++++----------------- src/benchmark/taler-exchange-benchmark.c | 81 +++++++++++--------------------- 3 files changed, 56 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/src/benchmark/Makefile.am b/src/benchmark/Makefile.am index 89dc30061..1ead23df4 100644 --- a/src/benchmark/Makefile.am +++ b/src/benchmark/Makefile.am @@ -18,11 +18,12 @@ taler_bank_benchmark_SOURCES = \ taler-bank-benchmark.c taler_bank_benchmark_LDADD = \ $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/testing/libtalertesting.la \ $(top_builddir)/src/bank-lib/libtalerfakebank.la \ $(top_builddir)/src/bank-lib/libtalerbank.la \ + $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ + $(top_builddir)/src/json/libtalerjson.la \ + $(top_builddir)/src/util/libtalerutil.la \ -lgnunetjson \ -lgnunetcurl \ -lgnunetutil \ @@ -33,12 +34,13 @@ taler_exchange_benchmark_SOURCES = \ taler-exchange-benchmark.c taler_exchange_benchmark_LDADD = \ $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/json/libtalerjson.la \ - $(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/lib/libtalerexchange.la \ + $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ $(top_builddir)/src/testing/libtalertesting.la \ $(top_builddir)/src/bank-lib/libtalerfakebank.la \ $(top_builddir)/src/bank-lib/libtalerbank.la \ + $(top_builddir)/src/json/libtalerjson.la \ + $(top_builddir)/src/util/libtalerutil.la \ -lgnunetjson \ -lgnunetcurl \ -lgnunetutil \ diff --git a/src/benchmark/taler-bank-benchmark.c b/src/benchmark/taler-bank-benchmark.c index 53ea1357a..c4887ca7d 100644 --- a/src/benchmark/taler-bank-benchmark.c +++ b/src/benchmark/taler-bank-benchmark.c @@ -33,6 +33,7 @@ #include "taler_signatures.h" #include "taler_json_lib.h" #include "taler_bank_service.h" +#include "taler_exchangedb_lib.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" #include "taler_error_codes.h" @@ -74,7 +75,7 @@ enum BenchmarkMode /** * Hold information regarding which bank has the exchange account. */ -static struct TALER_BANK_AuthenticationData exchange_bank_account; +static const struct TALER_EXCHANGEDB_AccountInfo *exchange_bank_account; /** * Time snapshot taken right before executing the CMDs. @@ -249,26 +250,6 @@ print_stats (void) } -/** - * Decide which exchange account is going to be used to address a wire - * transfer to. Used at withdrawal time. - * - * @param cls closure - * @param section section name. - */ -static void -pick_exchange_account_cb (void *cls, - const char *section) -{ - const char **s = cls; - - if (0 == strncasecmp ("exchange-account-", - section, - strlen ("exchange-account-"))) - *s = section; -} - - /** * Actual commands construction and execution. * @@ -308,7 +289,7 @@ run (void *cls, TALER_TESTING_cmd_admin_add_incoming (add_label ( create_reserve_label), total_reserve_amount, - &exchange_bank_account, + exchange_bank_account->auth, add_label (user_payto_uri))); } GNUNET_free (total_reserve_amount); @@ -827,32 +808,29 @@ main (int argc, return BAD_CLI_ARG; } } + + if (GNUNET_OK != + TALER_EXCHANGEDB_load_accounts (cfg, + TALER_EXCHANGEDB_ALO_AUTHDATA + | TALER_EXCHANGEDB_ALO_CREDIT)) { - const char *bank_details_section; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Configuration fails to provide exchange bank details\n"); + GNUNET_free (cfg_filename); + return BAD_CONFIG_FILE; + } - GNUNET_CONFIGURATION_iterate_sections (cfg, - &pick_exchange_account_cb, - &bank_details_section); - if (NULL == bank_details_section) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Missing specification of bank account in configuration\n"); - GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; - } - if (GNUNET_OK != - TALER_BANK_auth_parse_cfg (cfg, - bank_details_section, - &exchange_bank_account)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Configuration fails to provide exchange bank details in section `%s'\n", - bank_details_section); - GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; - } + exchange_bank_account + = TALER_EXCHANGEDB_find_account_by_method ("x-taler-bank"); + if (NULL == exchange_bank_account) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No bank account for `x-taler-bank` given in configuration\n"); + GNUNET_free (cfg_filename); + return BAD_CONFIG_FILE; } result = parallel_benchmark (); + TALER_EXCHANGEDB_unload_accounts (); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (cfg_filename); diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index ee56805c4..1087c1526 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -29,6 +29,7 @@ #include #include "taler_util.h" #include "taler_signatures.h" +#include "taler_exchangedb_lib.h" #include "taler_exchange_service.h" #include "taler_json_lib.h" #include "taler_bank_service.h" @@ -82,7 +83,7 @@ enum BenchmarkMode /** * Hold information regarding which bank has the exchange account. */ -static struct TALER_BANK_AuthenticationData exchange_bank_account; +static const struct TALER_EXCHANGEDB_AccountInfo *exchange_bank_account; /** * Configuration of our exchange. @@ -252,34 +253,11 @@ static struct TALER_TESTING_Command cmd_transfer_to_exchange (const char *label, const char *amount) { - return TALER_TESTING_cmd_admin_add_incoming_retry - (TALER_TESTING_cmd_admin_add_incoming (label, - amount, - &exchange_bank_account, - user_payto_uri)); -} - - -/** - * Decide which exchange account is going to be - * used to address a wire transfer to. Used at - * withdrawal time. - * - * @param cls closure - * @param section section name. - */ -static void -pick_exchange_account_cb (void *cls, - const char *section) -{ - if (0 == strncasecmp ("exchange-account-", - section, - strlen ("exchange-account-"))) - { - const char **s = cls; - - *s = section; - } + return TALER_TESTING_cmd_admin_add_incoming_retry ( + TALER_TESTING_cmd_admin_add_incoming (label, + amount, + exchange_bank_account->auth, + user_payto_uri)); } @@ -520,8 +498,9 @@ launch_fakebank (void *cls) (void) cls; fakebank - = TALER_TESTING_run_fakebank (exchange_bank_account.wire_gateway_url, - currency); + = TALER_TESTING_run_fakebank ( + exchange_bank_account->auth->wire_gateway_url, + currency); if (NULL == fakebank) { GNUNET_break (0); @@ -1054,30 +1033,25 @@ main (int argc, return BAD_CONFIG_FILE; } + if (GNUNET_OK != + TALER_EXCHANGEDB_load_accounts (cfg, + TALER_EXCHANGEDB_ALO_AUTHDATA + | TALER_EXCHANGEDB_ALO_CREDIT)) { - const char *bank_details_section; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Configuration fails to provide exchange bank details\n"); + GNUNET_free (cfg_filename); + return BAD_CONFIG_FILE; + } - GNUNET_CONFIGURATION_iterate_sections (cfg, - &pick_exchange_account_cb, - &bank_details_section); - if (NULL == bank_details_section) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Missing specification of bank account in configuration\n"); - GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; - } - if (GNUNET_OK != - TALER_BANK_auth_parse_cfg (cfg, - bank_details_section, - &exchange_bank_account)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Configuration fails to provide exchange bank details in section `%s'\n", - bank_details_section); - GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; - } + exchange_bank_account + = TALER_EXCHANGEDB_find_account_by_method ("x-taler-bank"); + if (NULL == exchange_bank_account) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No bank account for `x-taler-bank` given in configuration\n"); + GNUNET_free (cfg_filename); + return BAD_CONFIG_FILE; } if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) ) { @@ -1156,6 +1130,7 @@ main (int argc, result = parallel_benchmark (&run, NULL, cfg_filename); + TALER_EXCHANGEDB_unload_accounts (); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (cfg_filename); -- cgit v1.2.3