From a7379930d273b53429684603df92411cf39b9976 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Jun 2016 11:35:28 +0200 Subject: turn libfakebank into libtalerfakebank so we can use it for testcases in the merchant --- src/bank-lib/Makefile.am | 21 +++--- src/bank-lib/fakebank.c | 40 ++++++------ src/bank-lib/fakebank.h | 94 --------------------------- src/bank-lib/test_bank_interpreter.c | 12 ++-- src/exchange-lib/Makefile.am | 2 +- src/exchange-lib/test_exchange_api.c | 12 ++-- src/exchange/test_taler_exchange_aggregator.c | 12 ++-- src/include/Makefile.am | 5 +- src/include/taler_fakebank_lib.h | 94 +++++++++++++++++++++++++++ 9 files changed, 148 insertions(+), 144 deletions(-) delete mode 100644 src/bank-lib/fakebank.h create mode 100644 src/include/taler_fakebank_lib.h (limited to 'src') diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am index 7e4dd51f4..289135023 100644 --- a/src/bank-lib/Makefile.am +++ b/src/bank-lib/Makefile.am @@ -7,10 +7,8 @@ if USE_COVERAGE endif lib_LTLIBRARIES = \ - libtalerbank.la - -noinst_LTLIBRARIES = \ - libfakebank.la + libtalerbank.la \ + libtalerfakebank.la libtalerbank_la_LDFLAGS = \ -version-info 0:0:0 \ @@ -27,10 +25,15 @@ libtalerbank_la_LIBADD = \ -ljansson \ $(XLIB) -libfakebank_la_SOURCES = \ - fakebank.c fakebank.h -libfakebank_la_LIBADD = \ +libtalerfakebank_la_LDFLAGS = \ + -version-info 0:0:0 \ + -no-undefined + +libtalerfakebank_la_SOURCES = \ + fakebank.c + +libtalerfakebank_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ -lgnunetjson \ -lgnunetutil \ @@ -58,7 +61,7 @@ test_bank_api_SOURCES = \ test_bank_api.c test_bank_api_LDADD = \ libtalerbank.la \ - libfakebank.la \ + libtalerfakebank.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetcurl \ -lgnunetutil \ @@ -70,7 +73,7 @@ test_bank_api_with_fakebank_SOURCES = \ test_bank_api_with_fakebank.c test_bank_api_with_fakebank_LDADD = \ libtalerbank.la \ - libfakebank.la \ + libtalerfakebank.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetcurl \ -lgnunetutil \ diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index 8598e007c..13bfa1cb5 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -21,7 +21,7 @@ */ #include "platform.h" -#include "fakebank.h" +#include "taler_fakebank_lib.h" /** * Maximum POST request size (for /admin/add/incoming) @@ -71,7 +71,7 @@ struct Transaction /** * Handle for the fake bank. */ -struct FAKEBANK_Handle +struct TALER_FAKEBANK_Handle { /** * We store transactions in a DLL. @@ -109,11 +109,11 @@ struct FAKEBANK_Handle * @return #GNUNET_OK on success */ int -FAKEBANK_check (struct FAKEBANK_Handle *h, - const struct TALER_Amount *want_amount, - uint64_t want_debit, - uint64_t want_credit, - struct TALER_WireTransferIdentifierRawP *wtid) +TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, + const struct TALER_Amount *want_amount, + uint64_t want_debit, + uint64_t want_credit, + struct TALER_WireTransferIdentifierRawP *wtid) { struct Transaction *t; @@ -152,14 +152,14 @@ FAKEBANK_check (struct FAKEBANK_Handle *h, /** * Check that no wire transfers were ordered (or at least none - * that have not been taken care of via #FAKEBANK_check()). + * that have not been taken care of via #TALER_FAKEBANK_check()). * If any transactions are onrecord, return #GNUNET_SYSERR. * * @param h bank instance * @return #GNUNET_OK on success */ int -FAKEBANK_check_empty (struct FAKEBANK_Handle *h) +TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h) { struct Transaction *t; @@ -190,7 +190,7 @@ FAKEBANK_check_empty (struct FAKEBANK_Handle *h) * @param h bank to stop */ void -FAKEBANK_stop (struct FAKEBANK_Handle *h) +TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h) { if (NULL != h->mhd_task) { @@ -226,7 +226,7 @@ handle_mhd_completion_callback (void *cls, void **con_cls, enum MHD_RequestTerminationCode toe) { - /* struct FAKEBANK_Handle *h = cls; */ + /* struct TALER_FAKEBANK_Handle *h = cls; */ GNUNET_JSON_post_parser_cleanup (*con_cls); *con_cls = NULL; @@ -256,7 +256,7 @@ handle_mhd_request (void *cls, size_t *upload_data_size, void **con_cls) { - struct FAKEBANK_Handle *h = cls; + struct TALER_FAKEBANK_Handle *h = cls; enum GNUNET_JSON_PostResult pr; json_t *json; struct Transaction *t; @@ -331,7 +331,7 @@ handle_mhd_request (void *cls, /** * Task run whenever HTTP server operations are pending. * - * @param cls the `struct FAKEBANK_Handle` + * @param cls the `struct TALER_FAKEBANK_Handle` */ static void run_mhd (void *cls); @@ -343,7 +343,7 @@ run_mhd (void *cls); * always be called later whenever there is work to be done. */ static void -schedule_httpd (struct FAKEBANK_Handle *h) +schedule_httpd (struct TALER_FAKEBANK_Handle *h) { fd_set rs; fd_set ws; @@ -399,12 +399,12 @@ schedule_httpd (struct FAKEBANK_Handle *h) /** * Task run whenever HTTP server operations are pending. * - * @param cls the `struct FAKEBANK_Handle` + * @param cls the `struct TALER_FAKEBANK_Handle` */ static void run_mhd (void *cls) { - struct FAKEBANK_Handle *h = cls; + struct TALER_FAKEBANK_Handle *h = cls; h->mhd_task = NULL; MHD_run (h->mhd_bank); @@ -418,12 +418,12 @@ run_mhd (void *cls) * @param port port to listen to * @return NULL on error */ -struct FAKEBANK_Handle * -FAKEBANK_start (uint16_t port) +struct TALER_FAKEBANK_Handle * +TALER_FAKEBANK_start (uint16_t port) { - struct FAKEBANK_Handle *h; + struct TALER_FAKEBANK_Handle *h; - h = GNUNET_new (struct FAKEBANK_Handle); + h = GNUNET_new (struct TALER_FAKEBANK_Handle); h->mhd_bank = MHD_start_daemon (MHD_USE_DEBUG, port, NULL, NULL, diff --git a/src/bank-lib/fakebank.h b/src/bank-lib/fakebank.h deleted file mode 100644 index 5a4c13cd1..000000000 --- a/src/bank-lib/fakebank.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - This file is part of TALER - (C) 2016 Inria and 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, If not, see -*/ - -/** - * @file bank-lib/fakebank.h - * @brief API for a library that fakes being a Taler bank - * @author Christian Grothoff - */ -#ifndef FAKEBANK_H -#define FAKEBANK_H - -#include "taler_util.h" -#include -#include "taler_json_lib.h" -#include - -/** - * Handle for the fake bank. - */ -struct FAKEBANK_Handle; - - -/** - * Start the fake bank. The fake bank will, like the normal bank, - * listen for requests for /admin/add/incoming. However, instead of - * executing or storing those requests, it will simply allow querying - * whether such a request has been made via #FAKEBANK_check(). - * - * This is useful for writing testcases to check whether the exchange - * would have issued the correct wire transfer orders. - * - * @param port port to listen to - * @return NULL on error - */ -struct FAKEBANK_Handle * -FAKEBANK_start (uint16_t port); - - -/** - * Check that no wire transfers were ordered (or at least none - * that have not been taken care of via #FAKEBANK_check()). - * If any transactions are onrecord, return #GNUNET_SYSERR. - * - * @param h bank instance - * @return #GNUNET_OK on success - */ -int -FAKEBANK_check_empty (struct FAKEBANK_Handle *h); - - -/** - * Check that the @a want_amount was transferred from the @a - * want_debit to the @a want_credit account. If so, set the @a wtid - * to the transfer identifier and remove the transaction from the - * list. If the transaction was not recorded, return #GNUNET_SYSERR. - * - * @param h bank instance - * @param want_amount transfer amount desired - * @param want_debit account that should have been debited - * @param want_debit account that should have been credited - * @param[out] wtid set to the wire transfer identifier - * @return #GNUNET_OK on success - */ -int -FAKEBANK_check (struct FAKEBANK_Handle *h, - const struct TALER_Amount *want_amount, - uint64_t want_debit, - uint64_t want_credit, - struct TALER_WireTransferIdentifierRawP *wtid); - - -/** - * Stop running the fake bank. - * - * @param h bank to stop - */ -void -FAKEBANK_stop (struct FAKEBANK_Handle *h); - - -#endif diff --git a/src/bank-lib/test_bank_interpreter.c b/src/bank-lib/test_bank_interpreter.c index 840f9942b..a77af8ddf 100644 --- a/src/bank-lib/test_bank_interpreter.c +++ b/src/bank-lib/test_bank_interpreter.c @@ -26,7 +26,7 @@ #include #include #include "test_bank_interpreter.h" -#include "fakebank.h" +#include "taler_fakebank_lib.h" /** @@ -72,7 +72,7 @@ struct InterpreterState /** * Fakebank, or NULL if we are not using the fakebank. */ - struct FAKEBANK_Handle *fakebank; + struct TALER_FAKEBANK_Handle *fakebank; /** * Instruction pointer. Tells #interpreter_run() which @@ -242,7 +242,7 @@ interpreter_run (void *cls) TALER_string_to_amount (ref->details.admin_add_incoming.amount, &amount)); if (GNUNET_OK != - FAKEBANK_check (is->fakebank, + TALER_FAKEBANK_check (is->fakebank, &amount, ref->details.admin_add_incoming.debit_account_no, ref->details.admin_add_incoming.credit_account_no, @@ -265,7 +265,7 @@ interpreter_run (void *cls) is); return; case TBI_OC_EXPECT_TRANSFERS_EMPTY: - if (GNUNET_OK != FAKEBANK_check_empty (is->fakebank)) + if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank)) { GNUNET_break (0); fail (is); @@ -355,7 +355,7 @@ do_shutdown (void *cls) } if (NULL != is->fakebank) { - FAKEBANK_stop (is->fakebank); + TALER_FAKEBANK_stop (is->fakebank); is->fakebank = NULL; } GNUNET_CURL_fini (is->ctx); @@ -381,7 +381,7 @@ TBI_run_interpreter (int *resultp, is = GNUNET_new (struct InterpreterState); if (GNUNET_YES == run_bank) - is->fakebank = FAKEBANK_start (8081); + is->fakebank = TALER_FAKEBANK_start (8081); is->resultp = resultp; is->commands = commands; is->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am index 757955579..3cab9d456 100644 --- a/src/exchange-lib/Makefile.am +++ b/src/exchange-lib/Makefile.am @@ -56,7 +56,7 @@ test_exchange_api_SOURCES = \ test_exchange_api_LDADD = \ libtalerexchange.la \ $(LIBGCRYPT_LIBS) \ - $(top_builddir)/src/bank-lib/libfakebank.la \ + $(top_builddir)/src/bank-lib/libtalerfakebank.la \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetcurl \ diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 83fb0eb32..102c37b08 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -26,7 +26,7 @@ #include "taler_json_lib.h" #include #include -#include "fakebank.h" +#include "taler_fakebank_lib.h" /** @@ -62,7 +62,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; /** * Handle to our fakebank. */ -static struct FAKEBANK_Handle *fakebank; +static struct TALER_FAKEBANK_Handle *fakebank; /** * Result of the testcases, #GNUNET_OK on success @@ -2252,7 +2252,7 @@ interpreter_run (void *cls) return; } if (GNUNET_OK != - FAKEBANK_check (fakebank, + TALER_FAKEBANK_check (fakebank, &amount, cmd->details.check_bank_transfer.account_debit, cmd->details.check_bank_transfer.account_credit, @@ -2268,7 +2268,7 @@ interpreter_run (void *cls) case OC_CHECK_BANK_TRANSFERS_EMPTY: { if (GNUNET_OK != - FAKEBANK_check_empty (fakebank)) + TALER_FAKEBANK_check_empty (fakebank)) { GNUNET_break (0); fail (is); @@ -2580,7 +2580,7 @@ do_shutdown (void *cls) GNUNET_free (is); if (NULL != fakebank) { - FAKEBANK_stop (fakebank); + TALER_FAKEBANK_stop (fakebank); fakebank = NULL; } if (NULL != exchange) @@ -3012,7 +3012,7 @@ run (void *cls) &rc); GNUNET_assert (NULL != ctx); rc = GNUNET_CURL_gnunet_rc_create (ctx); - fakebank = FAKEBANK_start (8082); + fakebank = TALER_FAKEBANK_start (8082); exchange = TALER_EXCHANGE_connect (ctx, "http://localhost:8081", &cert_cb, is, diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c index dd8e4575b..a5ce044de 100644 --- a/src/exchange/test_taler_exchange_aggregator.c +++ b/src/exchange/test_taler_exchange_aggregator.c @@ -25,7 +25,7 @@ #include "taler_json_lib.h" #include "taler_exchangedb_plugin.h" #include -#include "fakebank.h" +#include "taler_fakebank_lib.h" @@ -247,7 +247,7 @@ static struct GNUNET_CRYPTO_RsaPublicKey *coin_pub; /** * Handle for our fake bank. */ -static struct FAKEBANK_Handle *fb; +static struct TALER_FAKEBANK_Handle *fb; /** @@ -295,7 +295,7 @@ shutdown_action (void *cls) } if (NULL != fb) { - FAKEBANK_stop (fb); + TALER_FAKEBANK_stop (fb); fb = NULL; } if (NULL != child_death_task) @@ -532,7 +532,7 @@ interpreter (void *cls) } return; case OPCODE_EXPECT_TRANSACTIONS_EMPTY: - if (GNUNET_OK != FAKEBANK_check_empty (fb)) + if (GNUNET_OK != TALER_FAKEBANK_check_empty (fb)) { fail (cmd); return; @@ -561,7 +561,7 @@ interpreter (void *cls) return; } if (GNUNET_OK != - FAKEBANK_check (fb, + TALER_FAKEBANK_check (fb, &want_amount, cmd->details.expect_transaction.debit_account, cmd->details.expect_transaction.credit_account, @@ -1179,7 +1179,7 @@ run (void *cls) &timeout_action, NULL); result = 1; /* test failed for undefined reason */ - fb = FAKEBANK_start (8082); + fb = TALER_FAKEBANK_start (8082); if (NULL == fb) { GNUNET_SCHEDULER_shutdown (); diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 310263f0b..d01852666 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -15,11 +15,12 @@ talerinclude_HEADERS = \ taler_amount_lib.h \ taler_bank_service.h \ taler_crypto_lib.h \ - taler_json_lib.h \ - taler_util.h \ taler_exchange_service.h \ taler_exchangedb_lib.h \ taler_exchangedb_plugin.h \ + taler_fakebank_lib.h \ + taler_json_lib.h \ + taler_util.h \ taler_pq_lib.h \ taler_signatures.h \ taler_wire_lib.h \ diff --git a/src/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h new file mode 100644 index 000000000..38b996f0e --- /dev/null +++ b/src/include/taler_fakebank_lib.h @@ -0,0 +1,94 @@ +/* + This file is part of TALER + (C) 2016 Inria and 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, If not, see +*/ + +/** + * @file bank-lib/fakebank.h + * @brief API for a library that fakes being a Taler bank + * @author Christian Grothoff + */ +#ifndef TALER_FAKEBANK_H +#define TALER_FAKEBANK_H + +#include "taler_util.h" +#include +#include "taler_json_lib.h" +#include + +/** + * Handle for the fake bank. + */ +struct TALER_FAKEBANK_Handle; + + +/** + * Start the fake bank. The fake bank will, like the normal bank, + * listen for requests for /admin/add/incoming. However, instead of + * executing or storing those requests, it will simply allow querying + * whether such a request has been made via #TALER_FAKEBANK_check(). + * + * This is useful for writing testcases to check whether the exchange + * would have issued the correct wire transfer orders. + * + * @param port port to listen to + * @return NULL on error + */ +struct TALER_FAKEBANK_Handle * +TALER_FAKEBANK_start (uint16_t port); + + +/** + * Check that no wire transfers were ordered (or at least none + * that have not been taken care of via #TALER_FAKEBANK_check()). + * If any transactions are onrecord, return #GNUNET_SYSERR. + * + * @param h bank instance + * @return #GNUNET_OK on success + */ +int +TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h); + + +/** + * Check that the @a want_amount was transferred from the @a + * want_debit to the @a want_credit account. If so, set the @a wtid + * to the transfer identifier and remove the transaction from the + * list. If the transaction was not recorded, return #GNUNET_SYSERR. + * + * @param h bank instance + * @param want_amount transfer amount desired + * @param want_debit account that should have been debited + * @param want_debit account that should have been credited + * @param[out] wtid set to the wire transfer identifier + * @return #GNUNET_OK on success + */ +int +TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, + const struct TALER_Amount *want_amount, + uint64_t want_debit, + uint64_t want_credit, + struct TALER_WireTransferIdentifierRawP *wtid); + + +/** + * Stop running the fake bank. + * + * @param h bank to stop + */ +void +TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h); + + +#endif -- cgit v1.2.3 From 46c593f93ea0bb68c41c55b2ab3f8a9580e77c2e Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 8 Jun 2016 16:12:31 +0200 Subject: - calling exchange via GNUNET_OS_ interface - getting currency via /keys - adding -c option (benchmark) --- src/benchmark/taler-exchange-benchmark.c | 138 +++++++++++++++++++++++++--- src/benchmark/taler-exchange-benchmark.conf | 2 + 2 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 src/benchmark/taler-exchange-benchmark.conf (limited to 'src') diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index 939fc58ec..bb4697243 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -32,6 +32,16 @@ */ static unsigned int pool_size = 100; +/** + * Configuration file path + */ +static char *config_file; + +/** + * Configuation object (used to get BANK_URI) + */ +struct GNUNET_CONFIGURATION_Handle *cfg; + /** * How many reservers ought to be created given the pool size */ @@ -182,7 +192,7 @@ static struct TALER_MerchantPrivateKeyP merchant_priv; /** * URI under which the exchange is reachable during the benchmark. */ -#define EXCHANGE_URI "http://localhost:8081" +#define EXCHANGE_URI "http://localhost:8081/" /** * How many coins (AKA withdraw operations) per reserve should be withdrawn @@ -190,17 +200,21 @@ static struct TALER_MerchantPrivateKeyP merchant_priv; #define COINS_PER_RESERVE 12 /** - * Used currency (to be preferably gotten via config file, together - * exchange URI and other needed values) + * Used currency (read from /keys' output) */ -#define CURRENCY "PUDOS" - +static char *currency; /** * Large enough value to allow having 12 coins per reserve without parsing * /keys in the first place */ -#define RESERVE_AMOUNT CURRENCY":1000" +#define RESERVE_VALUE 1000 + +/** + * The benchmark withdraws always the same denomination, since the calculation + * for refreshing is statically done (at least in its very first version). + */ +#define COIN_VALUE 5 /** * Probability a coin can be spent @@ -246,6 +260,7 @@ fail (const char *msg) "%s\n", msg); GNUNET_SCHEDULER_shutdown (); + return; } @@ -335,7 +350,6 @@ deposit_cb (void *cls, { /* TODO: all the refresh logic here */ refreshed_once = GNUNET_YES; - } } @@ -482,7 +496,8 @@ add_incoming_cb (void *cls, coin_index = reserve_index * COINS_PER_RESERVE + i; coins[coin_index].coin_priv.eddsa_priv = *coin_priv; coins[coin_index].reserve_index = reserve_index; - TALER_string_to_amount (CURRENCY":5", &amount); + TALER_amount_get_zero (currency, &amount); + amount.value = COIN_VALUE; GNUNET_assert (NULL != (coins[coin_index].pk = find_pk (keys, &amount))); GNUNET_free (coin_priv); coins[coin_index].wsh = @@ -521,7 +536,8 @@ benchmark_run (void *cls) GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &blinding_key, sizeof (blinding_key)); - TALER_string_to_amount (RESERVE_AMOUNT, &reserve_amount); + TALER_amount_get_zero (currency, &reserve_amount); + reserve_amount.value = RESERVE_VALUE; sender_details = json_loads ("{ \"type\":\"test\", \"bank_uri\":\"https://bank.test.taler.net/\", \"account_number\":62}", JSON_REJECT_DUPLICATES, NULL); @@ -530,9 +546,6 @@ benchmark_run (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "benchmark_run() invoked\n"); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "gotten pool_size of %d\n", - pool_size); nreserves = pool_size / COINS_PER_RESERVE; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating %d reserves\n", @@ -600,6 +613,9 @@ cert_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Certificate callback invoked, invoking benchmark_run()\n"); keys = _keys; + currency = _keys->denom_keys[0].value.currency; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Using currency: %s\n", currency); benchmark_task = GNUNET_SCHEDULER_add_now (&benchmark_run, NULL); } @@ -692,8 +708,26 @@ do_shutdown (void *cls) static void run (void *cls) { + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running run()\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "gotten pool_size of %d\n", + pool_size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "config file: %s\n", + config_file); + if (NULL == config_file) + fail ("-c option is mandatory\n"); + + /** + * Read BANK_URI in here + */ + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, config_file)) + fail ("failed to parse configuration file\n"); + GNUNET_array_append (spent_coins, spent_coins_size, 1); @@ -720,18 +754,96 @@ main (int argc, char * const *argv) { + struct GNUNET_OS_Process *proc; + struct GNUNET_OS_Process *exchanged; + unsigned int cnt; + GNUNET_log_setup ("taler-exchange-benchmark", "WARNING", NULL); const struct GNUNET_GETOPT_CommandLineOption options[] = { {'s', "pool-size", NULL, "How many coins this benchmark should instantiate", GNUNET_YES, - &GNUNET_GETOPT_set_uint, &pool_size} + &GNUNET_GETOPT_set_uint, &pool_size}, + {'c', "config", NULL, + "Configuration file", GNUNET_YES, + &GNUNET_GETOPT_set_string, &config_file} }; GNUNET_assert (GNUNET_SYSERR != GNUNET_GETOPT_run ("taler-exchange-benchmark", options, argc, argv)); + + proc = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-keyup", + "taler-exchange-keyup", + NULL); + if (NULL == proc) + { + fprintf (stderr, + "Failed to run taler-exchange-keyup. Check your PATH.\n"); + return 77; + } + + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_destroy (proc); + + proc = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-dbinit", + "taler-exchange-dbinit", + "-r", + NULL); + + + if (NULL == proc) + { + fprintf (stderr, + "Failed to run taler-exchange-dbinit. Check your PATH.\n"); + return 77; + } + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_destroy (proc); + + exchanged = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-httpd", + "taler-exchange-httpd", + NULL); + if (NULL == exchanged) + { + fprintf (stderr, + "Failed to run taler-exchange-httpd. Check your PATH.\n"); + return 77; + } + + cnt = 0; + do + { + fprintf (stderr, "."); + sleep (1); + cnt++; + if (cnt > 60) + { + fprintf (stderr, + "\nFailed to start taler-exchange-httpd\n"); + GNUNET_OS_process_kill (exchanged, + SIGKILL); + GNUNET_OS_process_wait (exchanged); + GNUNET_OS_process_destroy (exchanged); + return 77; + } + } + while (0 != system ("wget -q -t 1 -T 1 " EXCHANGE_URI "keys -o /dev/null -O /dev/null")); + fprintf (stderr, "\n"); + GNUNET_SCHEDULER_run (&run, NULL); + GNUNET_OS_process_wait (exchanged); + GNUNET_OS_process_destroy (exchanged); + return GNUNET_OK; } diff --git a/src/benchmark/taler-exchange-benchmark.conf b/src/benchmark/taler-exchange-benchmark.conf new file mode 100644 index 000000000..1f3538c7a --- /dev/null +++ b/src/benchmark/taler-exchange-benchmark.conf @@ -0,0 +1,2 @@ +[benchmark] +BANK_URI = https://bank.test.taler.net/ -- cgit v1.2.3 From feb60291b623193c312c8cc1e3f5289311134c9c Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 8 Jun 2016 17:11:33 +0200 Subject: getting banking details through config file in benchmark --- src/benchmark/merchant_details.json | 1 + src/benchmark/sender_details.json | 1 + src/benchmark/taler-exchange-benchmark.c | 48 +++++++++++++++++++++-------- src/benchmark/taler-exchange-benchmark.conf | 3 +- 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/benchmark/merchant_details.json create mode 100644 src/benchmark/sender_details.json (limited to 'src') diff --git a/src/benchmark/merchant_details.json b/src/benchmark/merchant_details.json new file mode 100644 index 000000000..d6f60005b --- /dev/null +++ b/src/benchmark/merchant_details.json @@ -0,0 +1 @@ +{"type":"test", "bank_uri":"https://bank.test.taler.net/", "account_number":63} diff --git a/src/benchmark/sender_details.json b/src/benchmark/sender_details.json new file mode 100644 index 000000000..d6f60005b --- /dev/null +++ b/src/benchmark/sender_details.json @@ -0,0 +1 @@ +{"type":"test", "bank_uri":"https://bank.test.taler.net/", "account_number":63} diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index bb4697243..dc670456b 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -26,6 +26,7 @@ #include #include #include +#include /** * How many coins the benchmark should operate on @@ -47,6 +48,16 @@ struct GNUNET_CONFIGURATION_Handle *cfg; */ static unsigned int nreserves; +/** + * Bank details of who creates reserves + */ +json_t *sender_details; + +/** + * Bank details of who deposits coins + */ +json_t *merchant_details; + /** * Needed information for a reserve. Other values are the same for all reserves, therefore defined in global variables */ @@ -387,7 +398,6 @@ reserve_withdraw_cb (void *cls, struct GNUNET_TIME_Absolute timestamp; struct GNUNET_TIME_Absolute refund_deadline; struct GNUNET_HashCode h_contract; - json_t *merchant_details; struct TALER_CoinSpendPublicKeyP coin_pub; struct TALER_DepositRequestPS dr; struct TALER_MerchantPublicKeyP merchant_pub; @@ -408,10 +418,6 @@ reserve_withdraw_cb (void *cls, TALER_amount_subtract (&amount, &coins[coin_index].pk->value, &coins[coin_index].pk->fee_deposit); - merchant_details = json_loads ("{ \"type\":\"test\", \"bank_uri\":\"https://bank.test.taler.net/\", \"account_number\":63}", - JSON_REJECT_DUPLICATES, - NULL); - memset (&dr, 0, sizeof (dr)); dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT); @@ -523,7 +529,6 @@ benchmark_run (void *cls) unsigned int i; struct GNUNET_CRYPTO_EddsaPrivateKey *priv; json_t *transfer_details; - json_t *sender_details; char *uuid; struct TALER_ReservePublicKeyP reserve_pub; struct GNUNET_TIME_Absolute execution_date; @@ -538,9 +543,6 @@ benchmark_run (void *cls) sizeof (blinding_key)); TALER_amount_get_zero (currency, &reserve_amount); reserve_amount.value = RESERVE_VALUE; - sender_details = json_loads ("{ \"type\":\"test\", \"bank_uri\":\"https://bank.test.taler.net/\", \"account_number\":62}", - JSON_REJECT_DUPLICATES, - NULL); execution_date = GNUNET_TIME_absolute_get (); GNUNET_TIME_round_abs (&execution_date); @@ -708,7 +710,8 @@ do_shutdown (void *cls) static void run (void *cls) { - + char *sender_details_filename; + char *merchant_details_filename; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running run()\n"); @@ -722,17 +725,36 @@ run (void *cls) fail ("-c option is mandatory\n"); /** - * Read BANK_URI in here + * Read sender_details.json here */ cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, config_file)) fail ("failed to parse configuration file\n"); - + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, + "benchmark", + "sender_details", + &sender_details_filename)) + fail ("failed to get SENDER_DETAILS value\n"); + + sender_details = json_load_file (sender_details_filename, + JSON_REJECT_DUPLICATES, + NULL); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, + "benchmark", + "merchant_details", + &merchant_details_filename)) + fail ("failed to get MERCHANT_DETAILS value\n"); + + merchant_details = json_load_file (merchant_details_filename, + JSON_REJECT_DUPLICATES, + NULL); + + GNUNET_CONFIGURATION_destroy (cfg); GNUNET_array_append (spent_coins, spent_coins_size, 1); spent_coins_size++; - reserves = NULL; coins = NULL; ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, diff --git a/src/benchmark/taler-exchange-benchmark.conf b/src/benchmark/taler-exchange-benchmark.conf index 1f3538c7a..3dc2128fb 100644 --- a/src/benchmark/taler-exchange-benchmark.conf +++ b/src/benchmark/taler-exchange-benchmark.conf @@ -1,2 +1,3 @@ [benchmark] -BANK_URI = https://bank.test.taler.net/ +SENDER_DETAILS = ~/exchange/src/benchmark/sender_details.json +MERCHANT_DETAILS = ~/exchange/src/benchmark/merchant_details.json -- cgit v1.2.3 From f50d4b0f359064c15087b9d7b8b1bba84b9e7e89 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 8 Jun 2016 17:34:46 +0200 Subject: json_decref in shutdown --- src/benchmark/taler-exchange-benchmark.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index dc670456b..b3fe173eb 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -680,6 +680,11 @@ do_shutdown (void *cls) } + if (NULL != sender_details) + json_decref (sender_details); + if (NULL != merchant_details) + json_decref (sender_details); + GNUNET_free_non_null (reserves); GNUNET_free_non_null (coins); GNUNET_free_non_null (spent_coins); -- cgit v1.2.3