diff --git a/src/mintdb/perf_taler_mintdb.c b/src/mintdb/perf_taler_mintdb.c index 35a6b51b8..832332c61 100644 --- a/src/mintdb/perf_taler_mintdb.c +++ b/src/mintdb/perf_taler_mintdb.c @@ -19,6 +19,7 @@ * @author Nicolas Fournier */ #include "perf_taler_mintdb_interpreter.h" +#include "perf_taler_mintdb_values.h" /** * Runs the performances tests for the mint database @@ -39,17 +40,17 @@ main(int argc, char ** argv) INIT_CMD_END("end") }; - struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); + struct GNUNET_CONFIGURATION_Handle config ; + GNUNET_CONFIGURATION_load(*config "./test-mint-db-postgres.conf"); - // FIXME Add data to the config handler to be able to connect to the database - - struct TALER_MINTDB_Plugin *plugin = TALER_MINTDB_plugin_load(config); + struct TALER_MINTDB_Plugin *plugin = TALER_MINTDB_plugin_load(&config); struct TALER_MINTDB_Session *session = plugin->get_session(plugin->cls, GNUNET_YES); - + + // creation of temporary tables plugin->create_tables(plugin->cls, GNUNET_YES); - PERF_TALER_MINTDB_interprete(plugin, session, test); + PERF_TALER_MINTDB_interpret(plugin, session, test); plugin->drop_temporary(plugin->cls, session); diff --git a/src/mintdb/perf_taler_mintdb_init.c b/src/mintdb/perf_taler_mintdb_init.c index 801d928a5..227d5de6a 100644 --- a/src/mintdb/perf_taler_mintdb_init.c +++ b/src/mintdb/perf_taler_mintdb_init.c @@ -1,86 +1,114 @@ /* - This file is part of TALER - Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors) + This file is part of TALER + Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors) - 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 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. + 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 -*/ + 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 mintdb/perf_taler_mintdb_init.c * @brief Interpreter library for mint database performance analysis * @author Nicolas Fournier */ -#include "platform.h" +#include "../include/platform.h" #include #include -#include "taler_mintdb_plugin.h" -#include "taler_signatures.h" -#include "taler_amount_lib.h" +#include "../include/taler_mintdb_plugin.h" +#include "../include/taler_signatures.h" +#include "../include/taler_amount_lib.h" #define CURRENCY "EUR" + + struct TALER_MINTDB_CollectableBlindcoin * collectable_blindcoin_init () { // indent by 2 spaces - struct TALER_MINTDB_CollectableBlindcoin *coin = GNUNET_new (*coin); + struct TALER_MINTDB_CollectableBlindcoin *coin = + GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin); - struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create (); - struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512); + struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key; + GNUNET_assert (NULL != + (reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()) + ); + struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key ; + GNUNET_assert (NULL != + (denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512)) + ); - coin->denom_pub.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key); - GNUNET_CRYPTO_eddsa_key_get_public (reserve_sig_key, - &coin->reserve_pub.eddsa_pub); + GNUNET_assert (NULL == + (coin->denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key)) + ); + GNUNET_CRYPTO_eddsa_key_get_public (reserve_sig_key, + &coin->reserve_pub.eddsa_pub); - //TODO Randomise the amount that is deposited and apply a fee subsequently + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.1", + &coin->amount_with_fee)); - // GNUNET_assert (GNUNET_OK == - // TALER_string_to_amount (CURRENCY ":1.1", - // &coin->amount_with_fee)); - - coin->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY}; - coin->withdraw_fee = (struct TALER_Amount) {0, 1, CURRENCY}; - - - int random_int = rand(); // GNUNET_CRYPTO_random_u32 - coin->sig.rsa_signature = GNUNET_CRYPTO_rsa_sign(denomination_key, &random_int, sizeof(random_int)); - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &coin->h_coin_envelope); - - void *purpose = GNUNET_malloc (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int)); - ((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->size = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int); - ((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->purpose = GNUNET_SIGNATURE_PURPOSE_TEST; - *((int *)(purpose + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))) = random_int; - - GNUNET_CRYPTO_eddsa_sign(reserve_sig_key, purpose, &coin->reserve_sig.eddsa_signature); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.1", + &coin->withdraw_fee)); - GNUNET_free(reserve_sig_key); - GNUNET_CRYPTO_rsa_private_key_free(denomination_key); - return coin; + uint32_t random_int = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + GNUNET_assert (NULL != + (coin->sig.rsa_signature = + GNUNET_CRYPTO_rsa_sign (denomination_key, + &random_int, + sizeof (random_int) + )) + ); + + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &coin->h_coin_envelope); + + struct { + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + uint32_t data; + } unsigned_data; + + unsigned_data.purpose.size = sizeof (unsigned_data); + unsigned_data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_TEST; + unsigned_data.data = random_int; + + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (reserve_sig_key, + (struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data, + &coin->reserve_sig.eddsa_signature) + ); + + + GNUNET_CRYPTO_eddsa_key_clear (reserve_sig_key); + GNUNET_CRYPTO_rsa_private_key_free (denomination_key); + return coin; } /** - * @return a randomly generated blindcoin + * Liberate memory of @a coin */ int -collectable_blindcoin_free(struct TALER_MINTDB_CollectableBlindcoin *coin) +collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin) { - GNUNET_free(coin->sig.rsa_signature); - GNUNET_free(coin->denom_pub.rsa_public_key); + GNUNET_CRYPTO_rsa_signature_free (coin->sig.rsa_signature); + GNUNET_CRYPTO_rsa_public_key_free (coin->denom_pub.rsa_public_key); - GNUNET_free(coin); + GNUNET_free (coin); return GNUNET_OK; } @@ -90,195 +118,290 @@ collectable_blindcoin_free(struct TALER_MINTDB_CollectableBlindcoin *coin) * @return a randomly generated reserve */ struct TALER_MINTDB_Reserve * -reserve_init() +reserve_init () { - struct TALER_MINTDB_Reserve *reserve = GNUNET_malloc(sizeof(*reserve)); - struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv = GNUNET_CRYPTO_eddsa_key_create(); + struct TALER_MINTDB_Reserve *reserve ; + + GNUNET_assert (NULL != + (reserve = GNUNET_new (struct TALER_MINTDB_Reserve) + )); - GNUNET_CRYPTO_eddsa_key_get_public(reserve_priv , &(reserve->pub.eddsa_pub)); + struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv ; + GNUNET_assert (NULL != + (reserve_priv = GNUNET_CRYPTO_eddsa_key_create () + )); - reserve->balance = (struct TALER_Amount){1, 1, CURRENCY}; - reserve->expiry = GNUNET_TIME_absolute_get_forever_(); + GNUNET_CRYPTO_eddsa_key_get_public (reserve_priv , + &reserve->pub.eddsa_pub); + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.1", &reserve->balance) + ); - GNUNET_free(reserve_priv); - return reserve; + reserve->expiry = GNUNET_TIME_absolute_get_forever_ (); + + GNUNET_CRYPTO_eddsa_key_clear (reserve_priv); + return reserve; } - -struct TALER_MINTDB_RefreshSession * -refresh_session_init() -{ - struct TALER_MINTDB_RefreshSession *refresh_session = GNUNET_malloc(sizeof(*refresh_session)); - - refresh_session->noreveal_index = 1; - refresh_session->num_oldcoins = 1; - refresh_session->num_newcoins = 1; - - return refresh_session; -} - - -struct TALER_MINTDB_Deposit * -deposit_init() -{ - static int transaction_id = 0; - - struct TALER_MINTDB_Deposit *deposit = GNUNET_malloc(sizeof(*deposit)); - - deposit-> transaction_id = transaction_id; - transaction_id++; - - - //TODO Randomize the amount that is deposited - - deposit->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY}; - deposit->deposit_fee = (struct TALER_Amount) {0, 1, CURRENCY}; - - deposit->timestamp = GNUNET_TIME_absolute_get(); - deposit->refund_deadline = GNUNET_TIME_absolute_get(); - - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_contract); - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_wire); - - // Coin Spend Signature - { - struct GNUNET_CRYPTO_EddsaSignature sig; - - struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create(); - void *prp = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int)); - *((struct GNUNET_CRYPTO_EccSignaturePurpose *)prp) =(struct GNUNET_CRYPTO_EccSignaturePurpose) {sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int), GNUNET_SIGNATURE_PURPOSE_TEST}; - - - GNUNET_CRYPTO_eddsa_sign(p_eddsa_prvt, (struct GNUNET_CRYPTO_EccSignaturePurpose *) prp, &sig); - - deposit->csig.eddsa_signature = sig; - - GNUNET_free(p_eddsa_prvt); - } - - // Merchant Key - { - struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; - struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prv = GNUNET_CRYPTO_eddsa_key_create(); - - GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prv, &eddsa_pub); - - deposit->merchant_pub.eddsa_pub = eddsa_pub; - - GNUNET_free(p_eddsa_prv); - } - - // Coin - { - - - { - struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; - struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create(); - - GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prvt, &eddsa_pub); - - deposit->coin.coin_pub.eddsa_pub = eddsa_pub; - - GNUNET_free(p_eddsa_prvt); - } - - { - struct GNUNET_CRYPTO_rsa_PrivateKey *p_rsa_prv = GNUNET_CRYPTO_rsa_private_key_create(128); - struct GNUNET_CRYPTO_rsa_PublicKey *p_rsa_pub = GNUNET_CRYPTO_rsa_private_key_get_public(p_rsa_prv); - - deposit->coin.denom_pub.rsa_public_key = p_rsa_pub; - - - - deposit->coin.denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign(p_rsa_prv, - (void *) &(deposit->coin.coin_pub.eddsa_pub), - sizeof(&(deposit->coin.coin_pub.eddsa_pub))); - - GNUNET_CRYPTO_rsa_private_key_free(p_rsa_prv); - } - - } - - - return deposit; -} - - int -deposit_free(struct TALER_MINTDB_Deposit *deposit) +reserve_free (struct TALER_MINTDB_Reserve *reserve) { - GNUNET_free(deposit->coin.denom_pub.rsa_public_key); - GNUNET_free(deposit->coin.denom_sig.rsa_signature); - - GNUNET_free(deposit); + GNUNET_free (reserve); return GNUNET_OK; } -struct TALER_MINTDB_DenominationKeyIssueInformation * -denomination_init() +/** + * @return a randomly generated refresh session + */ +struct TALER_MINTDB_RefreshSession * +refresh_session_init () { - struct TALER_MINTDB_DenominationKeyIssueInformation *dki = GNUNET_malloc(sizeof(&dki)); + struct TALER_MINTDB_RefreshSession *refresh_session; + GNUNET_assert (NULL != + (refresh_session = GNUNET_new (struct TALER_MINTDB_RefreshSession) + )); + + refresh_session->noreveal_index = 1; + refresh_session->num_oldcoins = 1; + refresh_session->num_newcoins = 1; + + return refresh_session; +} - dki->denom_priv.rsa_private_key - = GNUNET_CRYPTO_rsa_private_key_create (128); - GNUNET_assert (NULL != dki->denom_priv.rsa_private_key); - dki->denom_pub.rsa_public_key - = GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv.rsa_private_key); +/** + * Free a refresh session + */ +int +refresh_session_free (struct TALER_MINTDB_RefreshSession *refresh_session) +{ + GNUNET_free (refresh_session); + + return GNUNET_OK; +} + + +/** + * Create a randomly generated deposit + */ +struct TALER_MINTDB_Deposit * +deposit_init () +{ + static int transaction_id = 0; + + struct TALER_MINTDB_Deposit *deposit ; + GNUNET_assert (NULL != + (deposit = GNUNET_new (struct TALER_MINTDB_Deposit) + )); + + deposit-> transaction_id = transaction_id; + transaction_id++; + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.1", &deposit->amount_with_fee) + ); + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":0.1", &deposit->deposit_fee) + ); + + + deposit->timestamp = GNUNET_TIME_absolute_get (); + deposit->refund_deadline = GNUNET_TIME_absolute_get (); + + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &deposit->h_contract); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &deposit->h_wire); + + // Coin Spend Signature + { + struct u32_presign + { + struct GNUNET_CRYPTO_EccSignaturePurpose purpose; + uint32_t data; + } unsigned_data; + + struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt; + GNUNET_assert (NULL != + (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create () + )); + + uint32_t random_int = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + + + unsigned_data.purpose.size = sizeof (unsigned_data); + unsigned_data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_TEST; + unsigned_data.data = random_int; + + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (eddsa_prvt, + (struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data, + &deposit->csig.eddsa_signature) + ); + + GNUNET_CRYPTO_eddsa_key_clear (eddsa_prvt); + } + + // Merchant Key + { + struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv; + GNUNET_assert(NULL != + (eddsa_prv = GNUNET_CRYPTO_eddsa_key_create () + )); + + GNUNET_CRYPTO_eddsa_key_get_public ( + eddsa_prv, + &deposit->merchant_pub.eddsa_pub); + + + GNUNET_CRYPTO_eddsa_key_clear (eddsa_prv); + } + + // Coin + { + { + struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt; + GNUNET_assert (NULL != + (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create () + )); + + GNUNET_CRYPTO_eddsa_key_get_public ( + eddsa_prvt, + &deposit->coin.coin_pub.eddsa_pub + ); + + + GNUNET_CRYPTO_eddsa_key_clear (eddsa_prvt); + } + + { + struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_prv; + GNUNET_assert (NULL != + (rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128) + )); + + GNUNET_assert (NULL != + (deposit->coin.denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv) + )); + + GNUNET_assert (NULL != + (deposit->coin.denom_sig.rsa_signature = + GNUNET_CRYPTO_rsa_sign (rsa_prv, + (void *) &deposit->coin.coin_pub.eddsa_pub, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + ) + )); + + GNUNET_CRYPTO_rsa_private_key_free (rsa_prv); + } + } + return deposit; +} + + +/** + * Free memory of a deposit + */ +int +deposit_free (struct TALER_MINTDB_Deposit *deposit) +{ + GNUNET_CRYPTO_rsa_public_key_free (deposit->coin.denom_pub.rsa_public_key); + GNUNET_CRYPTO_rsa_signature_free (deposit->coin.denom_sig.rsa_signature); + + GNUNET_free (deposit); + + return GNUNET_OK; +} + + +/** + * Generate a randomly generate DenominationKeyInformation + */ +struct TALER_MINTDB_DenominationKeyIssueInformation * +denomination_init () +{ + struct TALER_MINTDB_DenominationKeyIssueInformation *dki; + struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt; + struct GNUNET_TIME_Absolute anchor; + struct TALER_Amount amount; + + GNUNET_assert (NULL != + (dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation) + )); + + GNUNET_assert (NULL != + (dki->denom_priv.rsa_private_key + = GNUNET_CRYPTO_rsa_private_key_create (128) + )); + GNUNET_assert (NULL != + (dki->denom_pub.rsa_public_key = + GNUNET_CRYPTO_rsa_private_key_get_public (dki->denom_priv.rsa_private_key) + )); + GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key, - &dki->issue.denom_hash); + &dki->issue.denom_hash); - struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt = - GNUNET_CRYPTO_eddsa_key_create(); + GNUNET_assert (NULL != + (master_prvt = GNUNET_CRYPTO_eddsa_key_create () + )); - struct GNUNET_CRYPTO_EddsaPublicKey master_pub; - GNUNET_CRYPTO_eddsa_key_get_public(master_prvt, &master_pub); - dki->issue.master.eddsa_pub = master_pub; + GNUNET_CRYPTO_eddsa_key_get_public (master_prvt, + &dki->issue.master.eddsa_pub); - struct GNUNET_TIME_Absolute anchor = GNUNET_TIME_absolute_get(); + anchor = GNUNET_TIME_absolute_get (); dki->issue.start = GNUNET_TIME_absolute_hton (anchor); dki->issue.expire_withdraw = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_())); + GNUNET_TIME_relative_get_hour_ ())); dki->issue.expire_spend = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_())); + GNUNET_TIME_relative_get_hour_ ())); dki->issue.expire_legal = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor, - GNUNET_TIME_relative_get_hour_())); + GNUNET_TIME_relative_get_hour_ ())); - struct TALER_Amount amount = {.value = 1, .fraction = 1, .currency = CURRENCY}; + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.1", &amount) + ); TALER_amount_hton (&dki->issue.value, &amount); TALER_amount_hton (&dki->issue.fee_withdraw, &amount); TALER_amount_hton (&dki->issue.fee_deposit, &amount); TALER_amount_hton (&dki->issue.fee_refresh, &amount); dki->issue.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY); - dki->issue.purpose.size = htonl (sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation) - - offsetof (struct TALER_MINTDB_DenominationKeyIssueInformation, - issue.purpose)); + dki->issue.purpose.size = + htonl (sizeof (struct TALER_MINTDB_DenominationKeyIssueInformation) - + offsetof (struct TALER_MINTDB_DenominationKeyIssueInformation, + issue.purpose)); GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (master_prvt, - &dki->issue.purpose, - &dki->issue.signature.eddsa_signature)); + GNUNET_CRYPTO_eddsa_sign (master_prvt, + &dki->issue.purpose, + &dki->issue.signature.eddsa_signature)); + + GNUNET_CRYPTO_eddsa_key_clear (master_prvt); return dki; } - +/** + * Free memory for a DenominationKeyIssueInformation + */ int -denomination_free(struct TALER_MINTDB_DenominationKeyIssueInformation *dki) +denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki) { - GNUNET_free(dki->denom_priv.rsa_private_key); - GNUNET_free(dki->denom_pub.rsa_public_key); + GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key); + GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key); - GNUNET_free(dki); + GNUNET_free (dki); return GNUNET_OK; } diff --git a/src/mintdb/perf_taler_mintdb_init.h b/src/mintdb/perf_taler_mintdb_init.h index f313f8e9b..f1447b629 100644 --- a/src/mintdb/perf_taler_mintdb_init.h +++ b/src/mintdb/perf_taler_mintdb_init.h @@ -22,36 +22,49 @@ #define __PERF_TALER_MINTDB_INIT_H___ -#include -#include "taler_mintdb_lib.h" -#include "taler_mintdb_plugin.h" +#include "../include/platform.h" +#include "../include/taler_mintdb_lib.h" +#include "../include/taler_mintdb_plugin.h" #define CURRENCY "EUR" struct TALER_MINTDB_CollectableBlindcoin * -init_collectable_blindcoin(void); +collectable_blindcoin_init (void); + + +int +collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *NAME); + + +struct TALER_MINTDB_Reserve * +reserve_init (void); + + +int +reserve_free (struct TALER_MINTDB_Reserve); + struct TALER_MINTDB_RefreshSession * -init_refresh_session(void); +refresh_session_init (void); + struct TALER_MINTDB_Deposit * -init_deposit(int transaction_id); +deposit_init (int transaction_id); + struct TALER_MINTDB_DenominationKeyIssueInformation * init_denomination(void); +int +deposit_free (struct TALER_MINTDB_Deposit *deposit); + int -free_deposit(struct TALER_MINTDB_Deposit *deposit); +denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki); -int -free_collectable_blindcoin(struct TALER_MINTDB_CollectableBlindcoin *NAME); - -int -free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki); #endif diff --git a/src/mintdb/perf_taler_mintdb_interpreter.c b/src/mintdb/perf_taler_mintdb_interpreter.c index 755324219..ea38abe5b 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.c +++ b/src/mintdb/perf_taler_mintdb_interpreter.c @@ -20,7 +20,7 @@ */ #include "perf_taler_mintdb_interpreter.h" #include "perf_taler_mintdb_init.h" -#include "gauger.h" +#include "../include/gauger.h" /** @@ -34,8 +34,8 @@ cmd_find(const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search) { int i; - for (i=0; CMD_END != cmd[i].command; i++) - if (0 == strcmp (cmd[i].name, search)) + for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++) + if (0 == strcmp (cmd[i].label, search)) return i; return GNUNET_SYSERR; } @@ -43,25 +43,31 @@ cmd_find(const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search) // Initialization of a command array static int -cmd_init(struct PERF_TALER_MINTDB_CMD cmd[]) +cmd_init(struct PERF_TALER_MINTDB_Cmd cmd[]) { int i = 0; for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++) { switch (cmd[i].command) { - // Allocation of memmory for saving data case PERF_TALER_MINTDB_CMD_SAVE_ARRAY: - cmd[i].details.save_array.saved_data = - GNUNET_new_array(cmd[i].details.nb, union PERF_TALER_MINTDB_Data); + // Allocation of memory for saving data + cmd[i].details.save_array.data_saved = + GNUNET_new_array (cmd[i].details.save_array.nb_saved, + union PERF_TALER_MINTDB_Data); break; - // Creation of the permutation array case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: + // Creating the permutation array to randomize the data order cmd[i].details.load_array.permutation = - GNUNET_CRYPTO_random_permute( - GNUNET_CRYPTO_QUALITY_WEAK, - cmd[i].details.load_array.nb); + GNUNET_CRYPTO_random_permute ( + GNUNET_CRYPTO_QUALITY_WEAK, + cmd[i].details.load_array.nb); + + // Initializing the type based on the type of the saved array + cmd[i].exposed_type = cmd[ + cmd_find (cmd, cmd[i].details.load_array.label_save) + ].details.save_array.type_saved; break; default: @@ -75,40 +81,40 @@ cmd_init(struct PERF_TALER_MINTDB_CMD cmd[]) /** * Free the memory of the command chain */ - static int -cmd_clean(struct PERF_TALER_MINTDB_CMD cmd[]) +static int +cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[]) { int i = 0; for(i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++) { switch (cmd[i].command) { - case CMD_SAVE_ARRAY: + case PERF_TALER_MINTDB_CMD_SAVE_ARRAY: { int j; - switch (cmd[i].details.save_array.saved_type) + switch (cmd[i].details.save_array.type_saved) { case PERF_TALER_MINTDB_DEPOSIT: - for (j = 0; j < cmd[i].details.save_array.nb; j++) + for (j = 0; j < cmd[i].details.save_array.nb_saved; j++) { - deposit_free(cmd[i].details.save_array.saved_data.deposit[j]); - cmd[i].details.save_array.saved_data.deposit[j] = NULL; + deposit_free (cmd[i].details.save_array.data_saved[j].deposit); + cmd[i].details.save_array.data_saved[j].deposit = NULL; } - GNUNET_free(cmd[i].details.save_array.saved_data.deposit); + GNUNET_free (cmd[i].details.save_array.data_saved); break; default: break; } - cmd[i].details.save_array.saved_data.deposit = NULL; + cmd[i].details.save_array.data_saved = NULL; } - case CMD_INSERT_DEPOSIT: - free_deposit(cmd[i].exposed.deposit); + case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT: + deposit_free (cmd[i].exposed.deposit); break; - case CMD_LOAD_ARRAY: - GNUNET_free(cmd[i].details.load_array.permutation); + case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: + GNUNET_free (cmd[i].details.load_array.permutation); break; default: @@ -126,11 +132,11 @@ cmd_clean(struct PERF_TALER_MINTDB_CMD cmd[]) */ static int interpret(struct TALER_MINTDB_Plugin *db_plugin, - struct TALER_MINTDB_Session*session, - struct PERF_TALER_MINTDB_CMD cmd[]) + struct TALER_MINTDB_Session*session, + struct PERF_TALER_MINTDB_Cmd cmd[]) { int i=0; - for(i=0; PERF_TALER_MINTDB_MD_END == cmd[i].command; i++) + for(i=0; PERF_TALER_MINTDB_CMD_END == cmd[i].command; i++) { switch (cmd[i].command) { @@ -163,7 +169,7 @@ interpret(struct TALER_MINTDB_Plugin *db_plugin, switch (cmd[j].exposed_type) { case PERF_TALER_MINTDB_DEPOSIT: - free_deposit(cmd[j].exposed.deposit); + deposit_free (cmd[j].exposed.deposit); cmd[j].exposed.deposit = NULL; break; @@ -207,7 +213,7 @@ interpret(struct TALER_MINTDB_Plugin *db_plugin, case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT: { - struct TALER_MINTDB_Deposit *deposit = init_deposit(0); + struct TALER_MINTDB_Deposit *deposit = deposit_init (-1); db_plugin->insert_deposit(db_plugin->cls, session, deposit); cmd[i].exposed.deposit = deposit; @@ -239,26 +245,26 @@ interpret(struct TALER_MINTDB_Plugin *db_plugin, // If there is a lesser or equal number of iteration next than room remain in the array if ((cmd[loop_index].details.loop.max_iterations - cmd[loop_index].details.loop.curr_iteration <= - cmd[i].details.save_array.nb_saved - cmd[i].details.save_array.index) || + cmd[i].details.save_array.nb_saved - cmd[i].details.save_array.index) || (rnd == 0 && cmd[i].details.save_array.index < cmd[i].details.save_array.nb_saved)) { // We automaticly save the whatever we need to - switch (cmd[i].details.save_array.saved_type) + switch (cmd[i].details.save_array.type_saved) { case PERF_TALER_MINTDB_DEPOSIT: - cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] = - cmd[cmd_find (cmd, cmd[i].details.save_array.label_saved)].exposed.deposit; + cmd[i].details.save_array.data_saved[cmd[i].details.save_array.index].deposit = + cmd[cmd_find (cmd, cmd[i].details.save_array.label_save)].exposed.deposit; break; case PERF_TALER_MINTDB_TIME: - cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] = - cmd[cmd_find (cmd, cmd[i].details.save_array.label_saved)].exposed.time; + cmd[i].details.save_array.data_saved[cmd[i].details.save_array.index].time = + cmd[cmd_find (cmd, cmd[i].details.save_array.label_save)].exposed.time; break; default: break; } - cmd[cmd_find (cmd, cmd[i].details.save_array.label_saved)].exposed_use = 1; + cmd[cmd_find (cmd, cmd[i].details.save_array.label_save)].exposed_saved = 1; cmd[i].details.save_array.index++; } } @@ -268,23 +274,23 @@ interpret(struct TALER_MINTDB_Plugin *db_plugin, case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: { - int loop_index = cmd_find(cmd, cmd[i].details.load_array.loop); - int save_index = cmd_find(cmd, cmd[i].details.load_array.saved); - switch (cmd[i].details.load_array.loaded_type){ + int loop_index = cmd_find(cmd, cmd[i].details.load_array.label_loop); + int save_index = cmd_find(cmd, cmd[i].details.load_array.label_save); + switch (cmd[i].exposed_type){ case PERF_TALER_MINTDB_DEPOSIT: - cmd[i].exposed.deposit = cmd[save_index].details.save_array.saved_data.deposit[ + cmd[i].exposed.deposit = cmd[save_index].details.save_array.data_saved[ cmd[i].details.load_array.permutation[ cmd[loop_index].details.loop.curr_iteration ] - ]; + ].deposit; break; case PERF_TALER_MINTDB_TIME: - cmd[i].exposed.time = cmd[save_index].details.save_array.saved_data.time[ + cmd[i].exposed.time = cmd[save_index].details.save_array.data_saved[ cmd[i].details.load_array.permutation[ cmd[loop_index].details.loop.curr_iteration ] - ]; + ].time; break; default: @@ -302,16 +308,16 @@ interpret(struct TALER_MINTDB_Plugin *db_plugin, * Runs the commands given in @a cmd, working with * the database referenced by @a db_plugin */ - int -PERF_TALER_MINTDB_interprete(struct TALER_MINTDB_Plugin *db_plugin, - struct TALER_MINTDB_Session *session, - struct PERF_TALER_MINTDB_CMD cmd[]) +int +PERF_TALER_MINTDB_interpret(struct TALER_MINTDB_Plugin *db_plugin, + struct TALER_MINTDB_Session *session, + struct PERF_TALER_MINTDB_Cmd cmd[]) { // Initializing commands cmd_init(cmd); // Running the interpreter - interprete(db_plugin, session, cmd); + interpret(db_plugin, session, cmd); // Cleaning the memory cmd_clean(cmd); diff --git a/src/mintdb/perf_taler_mintdb_interpreter.h b/src/mintdb/perf_taler_mintdb_interpreter.h index 79327d995..cf2ca664f 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.h +++ b/src/mintdb/perf_taler_mintdb_interpreter.h @@ -23,9 +23,9 @@ #define __PERF_TALER_MINTDB_INTERPRETER_H__ #include -#include -#include "taler_mintdb_lib.h" -#include "taler_mintdb_plugin.h" +#include "../include/platform.h" +#include "../include/taler_mintdb_lib.h" +#include "../include/taler_mintdb_plugin.h" /** * Marks the end of the command chain @@ -172,6 +172,7 @@ enum PERF_TALER_MINTDB_Type PERF_TALER_MINTDB_TIME, }; + /** * Storage for a variety of data type */ @@ -181,6 +182,7 @@ union PERF_TALER_MINTDB_Data struct timespec time; }; + /** * Name of the command */ @@ -229,6 +231,7 @@ struct PERF_TALER_MINTDB_loop_details int curr_iteration; }; + struct PERF_TALER_MINTDB_loop_end_details { /** @@ -237,6 +240,7 @@ struct PERF_TALER_MINTDB_loop_end_details const char *label_loop; }; + /** * Details about the GAUGER command */ @@ -256,6 +260,7 @@ struct PERF_TALER_MINTDB_gauger_details const char *description; }; + /** * Contains details about a command */ @@ -280,13 +285,14 @@ struct PERF_TALER_MINTDB_save_array_details /** * Type of data saved */ - enum PERF_TALER_MINTDB_TYPE type_saved; + enum PERF_TALER_MINTDB_Type type_saved; /** * Array of data saved */ union PERF_TALER_MINTDB_Data *data_saved; }; + struct PERF_TALER_MINTDB_load_array_details { /** @@ -300,7 +306,7 @@ struct PERF_TALER_MINTDB_load_array_details /** * Label of the command where the items were saved */ - const char *label_saved; + const char *label_save; /** * A permutation array used to randomize the order the items are loaded in */ @@ -314,11 +320,12 @@ struct PERF_TALER_MINTDB_get_deposit_details union PERF_TALER_MINTDB_Details { - struct PERF_TALER_MINTDB_LOOP_DETAILS loop, - struct PERF_TALER_MINTDB_LOOP_END_DETAILS end_loop, - struct PERF_TALER_MINTDB_GAUGER_DETAILS gauger, - struct PERF_TALER_MINTDB_SAVE_ARRAY save_array, - struct PERF_TALER_MINTDB_LOAD_ARRAY_DETAILS load_array, + struct PERF_TALER_MINTDB_loop_details loop; + struct PERF_TALER_MINTDB_loop_end_details end_loop; + struct PERF_TALER_MINTDB_gauger_details gauger; + struct PERF_TALER_MINTDB_save_array_details save_array; + struct PERF_TALER_MINTDB_load_array_details load_array; + struct PERF_TALER_MINTDB_get_deposit_details get_deposit; }; @@ -357,7 +364,7 @@ int PERF_TALER_MINTDB_interpret( struct TALER_MINTDB_Plugin *db_plugin, struct TALER_MINTDB_Session *session, // add START_SESSION CMD - struct PERF_TALER_MINTDB_CMD cmd[]); + struct PERF_TALER_MINTDB_Cmd cmd[]); #endif