From d0a6b47099384e39e820687fe7b83628514a6382 Mon Sep 17 00:00:00 2001 From: Fournier Nicolas Date: Tue, 30 Jun 2015 18:18:31 +0200 Subject: [PATCH] Finished work on database initialization --- src/mintdb/perf_taler_mintdb.c | 18 ++--- src/mintdb/perf_taler_mintdb_init.c | 7 +- src/mintdb/perf_taler_mintdb_interpreter.c | 76 ++++++++++++++-------- src/mintdb/perf_taler_mintdb_interpreter.h | 3 +- src/mintdb/perf_taler_mintdb_values.h | 16 ++--- 5 files changed, 70 insertions(+), 50 deletions(-) diff --git a/src/mintdb/perf_taler_mintdb.c b/src/mintdb/perf_taler_mintdb.c index 49fe073aa..53c9a1c24 100644 --- a/src/mintdb/perf_taler_mintdb.c +++ b/src/mintdb/perf_taler_mintdb.c @@ -44,8 +44,7 @@ main (int argc, char ** argv) PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("01 - save denomination", "01 - denomination loop", "01 - denomination", - PERF_TALER_MINTDB_NB_DENOMINATION_SAVE, - PERF_TALER_MINTDB_BLINDCOIN), + PERF_TALER_MINTDB_NB_DENOMINATION_SAVE), PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("01 - denomination loop end", "01 - denomination loop"), PERF_TALER_MINTDB_INIT_CMD_DEBUG ("01 - init denomination complete"), @@ -57,8 +56,7 @@ main (int argc, char ** argv) PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("02 - save reserve", "02 - init reserve loop", "02 - reserve", - PERF_TALER_MINTDB_NB_RESERVE_SAVE, - PERF_TALER_MINTDB_RESERVE), + PERF_TALER_MINTDB_NB_RESERVE_SAVE), PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("02 - init reserve end loop", "02 - init reserve loop"), PERF_TALER_MINTDB_INIT_CMD_DEBUG ("02 - reserve init complete"), @@ -80,8 +78,7 @@ main (int argc, char ** argv) PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("03 - blindcoin array", "03 - init withdraw loop", "03 - withdraw", - PERF_TALER_MINTDB_NB_WITHDRAW_SAVE, - PERF_TALER_MINTDB_BLINDCOIN), + PERF_TALER_MINTDB_NB_WITHDRAW_SAVE), PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("03 - withdraw init end loop", "03 - init withdraw loop"), PERF_TALER_MINTDB_INIT_CMD_DEBUG ("03 - withdraw init complete"), @@ -90,14 +87,17 @@ main (int argc, char ** argv) PERF_TALER_MINTDB_INIT_CMD_LOOP ("04 - deposit init loop", PERF_TALER_MINTDB_NB_DEPOSIT_INIT), PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("04 - start transaction"), + PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("04 - denomination load", + "04 - deposit init loop", + "01 - save denomination"), + PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("04 - deposit", - "01 - denomination"), + "04 - denomination load"), PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("04 - commit transaction"), PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("04 - deposit array", "04 - deposit init loop", "04 - deposit", - PERF_TALER_MINTDB_NB_DEPOSIT_SAVE, - PERF_TALER_MINTDB_DEPOSIT), + PERF_TALER_MINTDB_NB_DEPOSIT_SAVE), PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("04 - deposit init loop end", "04 - deposit init loop"), PERF_TALER_MINTDB_INIT_CMD_DEBUG ("04 - deposit init complete"), diff --git a/src/mintdb/perf_taler_mintdb_init.c b/src/mintdb/perf_taler_mintdb_init.c index a0019f84c..ab55248ce 100644 --- a/src/mintdb/perf_taler_mintdb_init.c +++ b/src/mintdb/perf_taler_mintdb_init.c @@ -230,8 +230,6 @@ PERF_TALER_MINTDB_deposit_init (const struct TALER_MINTDB_DenominationKeyIssueIn GNUNET_CRYPTO_rsa_sign (dki->denom_priv.rsa_private_key, &coin.coin_pub.eddsa_pub, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))); - - GNUNET_free (eddsa_prvt); } { //csig struct u32_presign @@ -359,7 +357,6 @@ PERF_TALER_MINTDB_collectable_blindcoin_init ( } unsigned_data; struct TALER_MINTDB_CollectableBlindcoin *coin; - GNUNET_assert (NULL != (coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin))); GNUNET_assert (NULL != @@ -376,7 +373,6 @@ PERF_TALER_MINTDB_collectable_blindcoin_init ( GNUNET_CRYPTO_rsa_private_key_decode (buffer, size))); GNUNET_free (buffer); } - GNUNET_assert (NULL != (coin->denom_pub.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key))); @@ -394,6 +390,9 @@ PERF_TALER_MINTDB_collectable_blindcoin_init ( GNUNET_CRYPTO_rsa_sign (denomination_key, &random_int, sizeof (random_int)))); + char *buffer; + GNUNET_CRYPTO_rsa_signature_encode (coin->sig.rsa_signature, &buffer); + free (buffer); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &coin->h_coin_envelope); unsigned_data.purpose.size = htonl (sizeof (unsigned_data)); diff --git a/src/mintdb/perf_taler_mintdb_interpreter.c b/src/mintdb/perf_taler_mintdb_interpreter.c index 059070303..5a1ec2921 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.c +++ b/src/mintdb/perf_taler_mintdb_interpreter.c @@ -50,6 +50,7 @@ struct PERF_TALER_MINTDB_interpreter_state unsigned int i; }; + /** * Free the memory of @a data, with data of type @a type */ @@ -89,7 +90,6 @@ data_free (union PERF_TALER_MINTDB_Data *data, enum PERF_TALER_MINTDB_Type type) } - /** * Finds the first command in cmd with the name search * @@ -121,14 +121,25 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[]) switch (cmd[i].command) { case PERF_TALER_MINTDB_CMD_SAVE_ARRAY: - // Allocation of memory for saving data + { + int save_label; + + GNUNET_assert (GNUNET_SYSERR != + (save_label = cmd_find (cmd, + cmd[i].details.save_array.label_save))); + /* 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); + /* Getting the type saved from the given label */ + cmd[i].details.save_array.type_saved = + cmd[save_label].exposed_type; + } + break; case PERF_TALER_MINTDB_CMD_LOAD_ARRAY: - // Creating the permutation array to randomize the data order + /* Creating the permutation array to randomize the data order */ { int save_index ; @@ -141,7 +152,7 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[]) GNUNET_CRYPTO_random_permute ( GNUNET_CRYPTO_QUALITY_WEAK, cmd[save_index].details.save_array.nb_saved))); - // Initializing the type based on the type of the saved array + /* Initializing the type based on the type of the saved array */ cmd[i].exposed_type = cmd[save_index].details.save_array.type_saved; } break; @@ -215,14 +226,14 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state) } state->cmd[jump].details.loop.curr_iteration++; - // If the loop is not finished + /* If the loop is not finished */ if (state->cmd[jump].details.loop.max_iterations > state->cmd[jump].details.loop.curr_iteration) { - // jump back to the start + /* jump back to the start */ state->i = jump; }else{ - // Reset the loop counter and continue running + /* Reset the loop counter and continue running */ state->cmd[jump].details.loop.curr_iteration = 0; } } @@ -238,8 +249,6 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) int loop_index, save_index; unsigned int selection_chance; - // Array initialization on first loop iteration - // Alows for nested loops GNUNET_assert (GNUNET_SYSERR != (loop_index = cmd_find (state->cmd, state->cmd[state->i] @@ -248,19 +257,21 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) (save_index = cmd_find (state->cmd, state->cmd[state->i] .details.save_array.label_save))); - if (0 == state->cmd[loop_index].details.loop.curr_iteration) + /* Array initialization on first loop iteration + Alows for nested loops */ + if (0 == state->cmd[loop_index].details.loop.curr_iteration) { state->cmd[state->i].details.save_array.index = 0; } - // The probobility distribution of the saved items will be a little biased - // against the few last items but it should not be a big problem. + /* The probobility distribution of the saved items will be a little biased + against the few last items but it should not be a big problem. */ selection_chance = state->cmd[loop_index].details.loop.max_iterations / state->cmd[state->i].details.save_array.nb_saved; /* - * If the remaining sapce is equal to the remaining number of + * If the remaining space is equal to the remaining number of * iterations, the item is automaticly saved. * - * Else it is saved only if rdn is 0 + * Else it is saved only if the random numbre generated is 0 */ if ((0 < (state->cmd[state->i].details.save_array.nb_saved - state->cmd[state->i].details.save_array.index)) && @@ -311,14 +322,17 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state) } +/** + * Run when the current command is LOAD_ARRAY + * Get data from a SAVE_ARRAY and exposes a copy + */ static void interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state) { unsigned int loop_iter; int loop_index, save_index; - union PERF_TALER_MINTDB_Data zero = {0}; union PERF_TALER_MINTDB_Data *loaded_data; - + GNUNET_assert (GNUNET_SYSERR != (loop_index = cmd_find (state->cmd, state->cmd[state->i] @@ -330,16 +344,18 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state) loop_iter = state->cmd[loop_index].details.loop.curr_iteration; { int i, quotient; + + /* in case the iteration number is higher than the amount saved, + * the number is run several times in the permutation array */ quotient = loop_iter / state->cmd[save_index].details.save_array.nb_saved; loop_iter = loop_iter % state->cmd[save_index].details.save_array.nb_saved; - for (i=0; i<=quotient; i++){ + for (i=0; i<=quotient; i++) loop_iter = state->cmd[state->i].details.load_array.permutation[loop_iter]; - } } /* Extracting the data from the loop_indexth indice in save_index * array. */ - loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_index]; + loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_iter]; switch (state->cmd[state->i].exposed_type) { case PERF_TALER_MINTDB_TIME: @@ -347,26 +363,32 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state) break; case PERF_TALER_MINTDB_DEPOSIT: - state->cmd[state->i].exposed.deposit = loaded_data->deposit; + state->cmd[state->i].exposed.deposit = + PERF_TALER_MINTDB_deposit_copy (loaded_data->deposit); break; case PERF_TALER_MINTDB_BLINDCOIN: - state->cmd[state->i].exposed.blindcoin = loaded_data->blindcoin; + state->cmd[state->i].exposed.blindcoin = + PERF_TALER_MINTDB_collectable_blindcoin_copy (loaded_data->blindcoin); break; case PERF_TALER_MINTDB_RESERVE: - state->cmd[state->i].exposed.reserve = loaded_data->reserve; + state->cmd[state->i].exposed.reserve = + PERF_TALER_MINTDB_reserve_copy (loaded_data->reserve); break; case PERF_TALER_MINTDB_DENOMINATION_INFO: - state->cmd[state->i].exposed.dki = loaded_data->dki; + state->cmd[state->i].exposed.dki = + PERF_TALER_MINTDB_denomination_copy (loaded_data->dki); + break; case PERF_TALER_MINTDB_COIN_INFO: state->cmd[state->i].exposed.cpi = loaded_data->cpi; + break; + default: break; } - *loaded_data = zero; } /** @@ -472,7 +494,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) { int source_index; struct TALER_MINTDB_Deposit *deposit; - + GNUNET_assert (GNUNET_SYSERR != (source_index = cmd_find (state->cmd, state->cmd[state->i] @@ -511,7 +533,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) { int source_index; struct TALER_MINTDB_Reserve *reserve; - + GNUNET_assert (GNUNET_SYSERR != (source_index = cmd_find (state->cmd, state->cmd[state->i] @@ -560,7 +582,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state) { int dki_index, reserve_index; struct TALER_MINTDB_CollectableBlindcoin *blindcoin ; - + GNUNET_assert (GNUNET_SYSERR != (dki_index = cmd_find ( state->cmd, diff --git a/src/mintdb/perf_taler_mintdb_interpreter.h b/src/mintdb/perf_taler_mintdb_interpreter.h index b69e39ebe..1d64c3938 100644 --- a/src/mintdb/perf_taler_mintdb_interpreter.h +++ b/src/mintdb/perf_taler_mintdb_interpreter.h @@ -128,7 +128,7 @@ * Extracts @a _nb_saved items of type @a _save_type * from the command @a _label_save during the loop @a _label_loop */ -#define PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY(_label, _label_loop, _label_save, _nb_saved, _save_type) \ +#define PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY(_label, _label_loop, _label_save, _nb_saved) \ { \ .command = PERF_TALER_MINTDB_CMD_SAVE_ARRAY, \ .label = _label, \ @@ -137,7 +137,6 @@ .label_loop = _label_loop, \ .label_save = _label_save, \ .nb_saved = _nb_saved, \ - .type_saved = _save_type \ } \ } diff --git a/src/mintdb/perf_taler_mintdb_values.h b/src/mintdb/perf_taler_mintdb_values.h index f8a8fde0b..b3527224d 100644 --- a/src/mintdb/perf_taler_mintdb_values.h +++ b/src/mintdb/perf_taler_mintdb_values.h @@ -22,17 +22,17 @@ #define __PERF_TALER_MINTDB__VALUES_H__ -#define PERF_TALER_MINTDB_NB_DENOMINATION_INIT 100 -#define PERF_TALER_MINTDB_NB_DENOMINATION_SAVE 100 +#define PERF_TALER_MINTDB_NB_DENOMINATION_INIT 10 +#define PERF_TALER_MINTDB_NB_DENOMINATION_SAVE 10 -#define PERF_TALER_MINTDB_NB_RESERVE_INIT 10000 -#define PERF_TALER_MINTDB_NB_RESERVE_SAVE 1000 +#define PERF_TALER_MINTDB_NB_RESERVE_INIT 100 +#define PERF_TALER_MINTDB_NB_RESERVE_SAVE 10 -#define PERF_TALER_MINTDB_NB_DEPOSIT_INIT 100000 -#define PERF_TALER_MINTDB_NB_DEPOSIT_SAVE 1000 +#define PERF_TALER_MINTDB_NB_DEPOSIT_INIT 1000 +#define PERF_TALER_MINTDB_NB_DEPOSIT_SAVE 10 -#define PERF_TALER_MINTDB_NB_WITHDRAW_INIT 100000 -#define PERF_TALER_MINTDB_NB_WITHDRAW_SAVE 1000 +#define PERF_TALER_MINTDB_NB_WITHDRAW_INIT 100 +#define PERF_TALER_MINTDB_NB_WITHDRAW_SAVE 10 #endif