aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFournier Nicolas <nicolas.fournier@ensta-paristech.fr>2015-06-12 11:14:32 +0200
committerFournier Nicolas <nicolas.fournier@ensta-paristech.fr>2015-06-12 11:14:32 +0200
commitec56e47809783fde3adfe159af0ec8e828a1f385 (patch)
tree3f979da065e705087bf53f62698266c6601621e7
parent006c55b3de1262c390e2139798422ca0fb1e9c02 (diff)
Fix includes and more indentation
-rw-r--r--src/mintdb/perf_taler_mintdb.c29
-rw-r--r--src/mintdb/perf_taler_mintdb_init.c257
-rw-r--r--src/mintdb/perf_taler_mintdb_init.h13
-rw-r--r--src/mintdb/perf_taler_mintdb_interpreter.c136
-rw-r--r--src/mintdb/perf_taler_mintdb_interpreter.h12
5 files changed, 196 insertions, 251 deletions
diff --git a/src/mintdb/perf_taler_mintdb.c b/src/mintdb/perf_taler_mintdb.c
index 5d67b87e0..c7e8c3552 100644
--- a/src/mintdb/perf_taler_mintdb.c
+++ b/src/mintdb/perf_taler_mintdb.c
@@ -18,8 +18,8 @@
* @brief Mint database performance analysis
* @author Nicolas Fournier
*/
+#include "platform.h"
#include "perf_taler_mintdb_interpreter.h"
-#include "./perf_taler_mintdb_init.h"
#include "perf_taler_mintdb_values.h"
/**
@@ -29,18 +29,8 @@
int
main (int argc, char ** argv)
{
- struct GNUNET_CONFIGURATION_Handle *config =
- GNUNET_CONFIGURATION_create();
-
- GNUNET_CONFIGURATION_load(config, "./test-mint-db-postgres.conf");
-
- struct TALER_MINTDB_Plugin *plugin = TALER_MINTDB_plugin_load (config);
- GNUNET_CONFIGURATION_destroy(config);
-
- // creation of temporary tables
- plugin->create_tables (plugin->cls, GNUNET_YES);
-
-
+ struct TALER_MINTDB_Plugin *plugin;
+ struct GNUNET_CONFIGURATION_Handle *config;
struct PERF_TALER_MINTDB_Cmd test[] =
{
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit",100000),
@@ -48,14 +38,23 @@ main (int argc, char ** argv)
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("init_deposit_insert"),
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("endloop_init_deposit","loop_db_init_deposit"),
-
-
PERF_TALER_MINTDB_INIT_CMD_END("end")
};
+ config = GNUNET_CONFIGURATION_create();
+ GNUNET_CONFIGURATION_load(config, "./test-mint-db-postgres.conf");
+ GNUNET_assert (NULL !=
+ (plugin = TALER_MINTDB_plugin_load (config)));
+ plugin->create_tables (plugin->cls, GNUNET_YES);
PERF_TALER_MINTDB_interpret(plugin, test);
+ {
+ struct TALER_MINTDB_Session *session;
+ session = plugin->get_session (plugin->cls, GNUNET_YES);
+ plugin->drop_temporary (plugin->cls, session);
+ }
TALER_MINTDB_plugin_unload(plugin);
+ GNUNET_CONFIGURATION_destroy(config);
return GNUNET_OK;
}
diff --git a/src/mintdb/perf_taler_mintdb_init.c b/src/mintdb/perf_taler_mintdb_init.c
index 63c49da07..3ddf8abc2 100644
--- a/src/mintdb/perf_taler_mintdb_init.c
+++ b/src/mintdb/perf_taler_mintdb_init.c
@@ -34,66 +34,49 @@
struct TALER_MINTDB_CollectableBlindcoin *
collectable_blindcoin_init ()
{
+ uint32_t random_int;
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key;
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key;
- // indent by 2 spaces
- struct TALER_MINTDB_CollectableBlindcoin *coin =
- GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin);
+ struct {
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+ uint32_t data;
+ } unsigned_data;
+ struct TALER_MINTDB_CollectableBlindcoin *coin;
+
+ coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin);
GNUNET_assert (NULL !=
- (reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ())
- );
+ (reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()));
GNUNET_assert (NULL !=
- (denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512))
- );
+ (denomination_key = GNUNET_CRYPTO_rsa_private_key_create (512)));
GNUNET_assert (NULL ==
- (coin->denom_pub.rsa_public_key =
- GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key))
- );
-
+ (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);
-
+ &coin->reserve_pub.eddsa_pub);
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1",
- &coin->amount_with_fee));
-
+ TALER_string_to_amount (CURRENCY ":1.1",
+ &coin->amount_with_fee));
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1",
- &coin->withdraw_fee));
-
-
-
- uint32_t random_int =
+ TALER_string_to_amount (CURRENCY ":1.1",
+ &coin->withdraw_fee));
+ 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)
- ))
- );
-
+ (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;
-
+ &coin->h_coin_envelope);
+ unsigned_data.purpose.size = htonl (sizeof (unsigned_data));
+ unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
+ unsigned_data.data = htonl (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_eddsa_sign (reserve_sig_key,
+ (struct GNUNET_CRYPTO_EccSignaturePurpose *) &unsigned_data,
+ &coin->reserve_sig.eddsa_signature));
+ GNUNET_free (reserve_sig_key);
GNUNET_CRYPTO_rsa_private_key_free (denomination_key);
return coin;
}
@@ -106,11 +89,10 @@ collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin)
{
if (NULL == coin)
return GNUNET_OK;
+
GNUNET_CRYPTO_rsa_signature_free (coin->sig.rsa_signature);
GNUNET_CRYPTO_rsa_public_key_free (coin->denom_pub.rsa_public_key);
-
GNUNET_free (coin);
-
return GNUNET_OK;
}
@@ -121,28 +103,19 @@ collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin)
struct TALER_MINTDB_Reserve *
reserve_init ()
{
- struct TALER_MINTDB_Reserve *reserve ;
+ struct TALER_MINTDB_Reserve *reserve;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv;
GNUNET_assert (NULL !=
- (reserve = GNUNET_new (struct TALER_MINTDB_Reserve)
- ));
-
- struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv ;
-
+ (reserve = GNUNET_new (struct TALER_MINTDB_Reserve)));
GNUNET_assert (NULL !=
- (reserve_priv = GNUNET_CRYPTO_eddsa_key_create ()
- ));
-
+ (reserve_priv = GNUNET_CRYPTO_eddsa_key_create ()));
GNUNET_CRYPTO_eddsa_key_get_public (reserve_priv ,
- &reserve->pub.eddsa_pub);
-
+ &reserve->pub.eddsa_pub);
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1", &reserve->balance)
- );
-
+ TALER_string_to_amount (CURRENCY ":1.1", &reserve->balance));
reserve->expiry = GNUNET_TIME_absolute_get_forever_ ();
-
- GNUNET_CRYPTO_eddsa_key_clear (reserve_priv);
+ GNUNET_free (reserve_priv);
return reserve;
}
@@ -165,10 +138,9 @@ struct TALER_MINTDB_RefreshSession *
refresh_session_init ()
{
struct TALER_MINTDB_RefreshSession *refresh_session;
- GNUNET_assert (NULL !=
- (refresh_session = GNUNET_new (struct TALER_MINTDB_RefreshSession)
- ));
+ 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;
@@ -198,26 +170,20 @@ deposit_init ()
struct TALER_MINTDB_Deposit *deposit;
GNUNET_assert (NULL !=
- (deposit = GNUNET_new (struct TALER_MINTDB_Deposit)
- ));
+ (deposit = GNUNET_new (struct TALER_MINTDB_Deposit)));
deposit-> transaction_id = transaction_id;
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1", &deposit->amount_with_fee)
- );
-
+ 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)
- );
-
-
+ 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);
+ &deposit->h_contract);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- &deposit->h_wire);
-
+ &deposit->h_wire);
// Coin Spend Signature
{
struct u32_presign
@@ -225,81 +191,61 @@ deposit_init ()
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);
+ uint32_t random_int;
+ GNUNET_assert (NULL !=
+ (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
+ random_int = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ UINT32_MAX);
unsigned_data.purpose.size = htonl (sizeof (struct u32_presign));
unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
unsigned_data.data = random_int;
-
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (eddsa_prvt,
- &unsigned_data.purpose,
- &deposit->csig.eddsa_signature));
-
- GNUNET_CRYPTO_eddsa_key_clear (eddsa_prvt);
+ GNUNET_CRYPTO_eddsa_sign (eddsa_prvt,
+ &unsigned_data.purpose,
+ &deposit->csig.eddsa_signature));
+ // No need to clear as this is a dummy key
+ GNUNET_free (eddsa_prvt);
}
-
- printf("coin signed");
// Merchant Key
{
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv;
- GNUNET_assert(NULL !=
- (eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ()
- ));
+ 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);
+ eddsa_prv,
+ &deposit->merchant_pub.eddsa_pub);
+ GNUNET_free (eddsa_prv);
}
-
- printf("merchant ok");
// Coin
{
{
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
- GNUNET_assert (NULL !=
- (eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()
- ));
+ 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);
+ eddsa_prvt,
+ &deposit->coin.coin_pub.eddsa_pub);
+ GNUNET_free (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)
- ));
-
+ (rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (128)));
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)
- )
- ));
-
+ (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,
+ &deposit->coin.coin_pub.eddsa_pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))));
GNUNET_CRYPTO_rsa_private_key_free (rsa_prv);
}
}
@@ -317,7 +263,6 @@ deposit_free (struct TALER_MINTDB_Deposit *deposit)
return GNUNET_OK;
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;
@@ -336,46 +281,32 @@ denomination_init ()
struct TALER_Amount amount;
GNUNET_assert (NULL !=
- (dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation)
- ));
-
+ (dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation)));
GNUNET_assert (NULL !=
- (dki->denom_priv.rsa_private_key
- = GNUNET_CRYPTO_rsa_private_key_create (128)
- ));
+ (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)
- ));
-
+ (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);
GNUNET_assert (NULL !=
- (master_prvt = GNUNET_CRYPTO_eddsa_key_create ()
- ));
-
-
+ (master_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
GNUNET_CRYPTO_eddsa_key_get_public (master_prvt,
- &dki->issue.master.eddsa_pub);
-
+ &dki->issue.master.eddsa_pub);
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_ ()));
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1", &amount)
- );
-
+ 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);
@@ -383,14 +314,13 @@ denomination_init ()
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));
+ 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_key_clear (master_prvt);
+ GNUNET_CRYPTO_eddsa_sign (master_prvt,
+ &dki->issue.purpose,
+ &dki->issue.signature.eddsa_signature));
+ GNUNET_free (master_prvt);
return dki;
}
@@ -406,7 +336,6 @@ denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
return GNUNET_OK;
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);
return GNUNET_OK;
diff --git a/src/mintdb/perf_taler_mintdb_init.h b/src/mintdb/perf_taler_mintdb_init.h
index 1c8263b5d..6ecda8c61 100644
--- a/src/mintdb/perf_taler_mintdb_init.h
+++ b/src/mintdb/perf_taler_mintdb_init.h
@@ -40,7 +40,7 @@ reserve_init (void);
int
-reserve_free (struct TALER_MINTDB_Reserve);
+reserve_free (struct TALER_MINTDB_Reserve *reserve);
struct TALER_MINTDB_RefreshSession *
@@ -48,20 +48,19 @@ refresh_session_init (void);
struct TALER_MINTDB_Deposit *
-deposit_init (int transaction_id);
-
-
-struct TALER_MINTDB_DenominationKeyIssueInformation *
-init_denomination(void);
+deposit_init ();
int
deposit_free (struct TALER_MINTDB_Deposit *deposit);
+struct TALER_MINTDB_DenominationKeyIssueInformation *
+init_denomination(void);
+
+
int
denomination_free (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 fdfc6e9e8..899a040b7 100644
--- a/src/mintdb/perf_taler_mintdb_interpreter.c
+++ b/src/mintdb/perf_taler_mintdb_interpreter.c
@@ -18,9 +18,10 @@
* @brief Interpreter library for mint database performance analysis
* @author Nicolas Fournier
*/
+#include "platform.h"
#include "perf_taler_mintdb_interpreter.h"
#include "perf_taler_mintdb_init.h"
-#include "../include/gauger.h"
+#include "gauger.h"
/**
@@ -108,13 +109,15 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
// Creating the permutation array to randomize the data order
cmd[i].details.load_array.permutation =
GNUNET_CRYPTO_random_permute (
- GNUNET_CRYPTO_QUALITY_WEAK,
- cmd[cmd_find(cmd, cmd[i].details.load_array.label_save)].details.save_array.nb_saved);
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ cmd[cmd_find (cmd,
+ cmd[i].details.load_array.label_save)]
+ .details.save_array.nb_saved);
// 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;
+ cmd[i].exposed_type = cmd[cmd_find (cmd,
+ cmd[i].details.load_array.label_save)]
+ .details.save_array.type_saved;
break;
default:
@@ -142,7 +145,7 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
for (j = 0; j < cmd[i].details.save_array.nb_saved; j++)
{
data_free (&cmd[i].details.save_array.data_saved[j],
- cmd[i].details.save_array.type_saved);
+ cmd[i].details.save_array.type_saved);
}
GNUNET_free (cmd[i].details.save_array.data_saved);
@@ -173,9 +176,11 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
static void
interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
{
- int jump = cmd_find (state->cmd, state->cmd[state->i].details.end_loop.label_loop);
+ int jump = cmd_find (state->cmd,
+ state->cmd[state->i].details.end_loop.label_loop);
// If the loop is not finished
- if (state->cmd[jump].details.loop.max_iterations > state->cmd[jump].details.loop.curr_iteration)
+ if (state->cmd[jump].details.loop.max_iterations >
+ state->cmd[jump].details.loop.curr_iteration)
{
// jump back to the start
state->i = jump -1;
@@ -187,20 +192,18 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
int j;
for (j = jump; j < state->i; j++)
{
- // If the exposed variable has not been copied
- if ( 0 == state->cmd[j].exposed_saved)
- {
- // It is freed
+ // If the exposed variable has not been copied it is freed
+ if ( GNUNET_NO == state->cmd[j].exposed_saved)
data_free (&state->cmd[j].exposed, state->cmd[j].exposed_type);
- }
- state->cmd[j].exposed_saved = 0;
+ state->cmd[j].exposed_saved = GNUNET_NO;
}
}
/**
- * /TODO cut it into pieces
+ * Main interpreter loop.
+ *
*/
static int
interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
@@ -227,12 +230,16 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GAUGER:
{
- int start_index = cmd_find (state->cmd, state->cmd[state->i].details.gauger.label_start);
- int stop_index = cmd_find (state->cmd, state->cmd[state->i].details.gauger.label_stop);
- struct timespec start = state->cmd [start_index].exposed.time;
- struct timespec stop = state->cmd [stop_index].exposed.time;
-
- unsigned long elapsed_ms = (start.tv_sec - stop.tv_sec) * 1000 + (start.tv_nsec - stop.tv_nsec) / 1000000;
+ int start_index, stop_index;
+ struct timespec start, stop;
+ unsigned long elapsed_ms;
+ start_index = cmd_find (state->cmd,
+ state->cmd[state->i].details.gauger.label_start);
+ stop_index = cmd_find (state->cmd,
+ state->cmd[state->i].details.gauger.label_stop);
+ start = state->cmd [start_index].exposed.time;
+ stop = state->cmd [stop_index].exposed.time;
+ elapsed_ms = (start.tv_sec - stop.tv_sec) * 1000 + (start.tv_nsec - stop.tv_nsec) / 1000000;
GAUGER ("MINTDB", state->cmd[state->i].details.gauger.description, elapsed_ms, "milliseconds");
}
@@ -240,7 +247,6 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_NEW_SESSION:
state->session = state->plugin->get_session (state->plugin->cls, GNUNET_YES);
- // TODO what about the old session ?
break;
case PERF_TALER_MINTDB_CMD_START_TRANSACTION:
@@ -256,37 +262,42 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
{
+ int loop_index;
+ int proba;
+ int rnd;
// Array initialization on first loop iteration
// Alows for nested loops
- if (state->cmd[cmd_find (state->cmd, state->cmd[state->i].details.save_array.label_loop)].details.loop.curr_iteration == 0)
+ if (0 == state->cmd[cmd_find (state->cmd,
+ state->cmd[state->i].details.save_array.label_loop)]
+ .details.loop.curr_iteration)
{
state->cmd[state->i].details.save_array.index = 0;
}
-
- // TODO check the logic here. It probably can be improved
-
- int loop_index = cmd_find (state->cmd, state->cmd[state->i].details.save_array.label_loop);
- int proba = state->cmd[loop_index].details.loop.max_iterations / state->cmd[state->i].details.save_array.nb_saved;
- int rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, proba);
-
-
- /**
- * If the room available is equal to the remaining number of
+ loop_index = cmd_find (state->cmd,
+ state->cmd[state->i].details.save_array.label_loop);
+ // 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.
+ proba = state->cmd[loop_index].details.loop.max_iterations /
+ state->cmd[state->i].details.save_array.nb_saved;
+ rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, proba);
+ /*
+ * If the remaining sapce is equal to the remaining number of
* iterations, the item is automaticly saved.
*
* Else it is saved only if rdn is 0
*/
if ((state->cmd[loop_index].details.loop.max_iterations - state->cmd[loop_index].details.loop.curr_iteration ==
- state->cmd[state->i].details.save_array.nb_saved - state->cmd[state->i].details.save_array.index) ||
- (rnd == 0))
+ state->cmd[state->i].details.save_array.nb_saved - state->cmd[state->i].details.save_array.index) ||
+ (rnd == 0))
{
-
- union PERF_TALER_MINTDB_Data *save_location =
- &state->cmd[state->i].details.save_array.data_saved[state->cmd[state->i].details.save_array.index];
- union PERF_TALER_MINTDB_Data *item_saved =
- &state->cmd[cmd_find (state->cmd, state->cmd[state->i].details.save_array.label_save)].exposed;
-
-
+ union PERF_TALER_MINTDB_Data *save_location;
+ union PERF_TALER_MINTDB_Data *item_saved;
+
+ save_location = &state->cmd[state->i].details.save_array.data_saved[
+ state->cmd[state->i].details.save_array.index];
+ item_saved = &state->cmd[cmd_find (state->cmd,
+ state->cmd[state->i].details.save_array.label_save)]
+ .exposed;
switch (state->cmd[state->i].details.save_array.type_saved)
{
case PERF_TALER_MINTDB_DEPOSIT:
@@ -300,6 +311,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
default:
break;
}
+ state->cmd[cmd_find(state->cmd,
+ state->cmd[state->i].details.save_array.label_save)]
+ .exposed_saved = GNUNET_YES;
state->cmd[state->i].details.save_array.index++;
}
}
@@ -307,18 +321,18 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
{
- int loop_index = cmd_find (state->cmd, state->cmd[state->i].details.load_array.label_loop);
- int save_index = cmd_find (state->cmd, state->cmd[state->i].details.load_array.label_save);
-
+ int loop_index, save_index;
+ union PERF_TALER_MINTDB_Data loaded_data;
+ loop_index = cmd_find (state->cmd,
+ state->cmd[state->i].details.load_array.label_loop);
+ save_index = cmd_find (state->cmd,
+ state->cmd[state->i].details.load_array.label_save);
/* Extracting the data from the loop_indexth indice in save_index
* array.
*/
- union PERF_TALER_MINTDB_Data loaded_data =
- state->cmd[save_index].details.save_array.data_saved[
+ loaded_data = state->cmd[save_index].details.save_array.data_saved[
state->cmd[state->i].details.load_array.permutation[
- state->cmd[loop_index].details.loop.curr_iteration
- ]];
-
+ state->cmd[loop_index].details.loop.curr_iteration]];
switch (state->cmd[state->i].exposed_type)
{
@@ -339,16 +353,18 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
{
struct TALER_MINTDB_Deposit *deposit = deposit_init (-1);
- state->plugin->insert_deposit (state->plugin->cls, state->session, deposit);
+ state->plugin->insert_deposit (state->plugin->cls, state->session, deposit);
state->cmd[state->i].exposed.deposit = deposit;
}
break;
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
{
- int source_index = cmd_find (state->cmd, state->cmd[state->i].details.get_deposit.label_source); // Find the source location
- struct TALER_MINTDB_Deposit *deposit = state->cmd[source_index].exposed.deposit; // Get the deposit from the source
+ struct TALER_MINTDB_Deposit *deposit =
+ state->cmd[cmd_find (state->cmd,
+ state->cmd[state->i].details.get_deposit.label_source)]
+ .exposed.deposit; // Get the deposit from the source
state->plugin->have_deposit (state->plugin->cls, state->session, deposit);
}
break;
@@ -367,20 +383,16 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
*/
int
PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
- struct PERF_TALER_MINTDB_Cmd cmd[])
+ struct PERF_TALER_MINTDB_Cmd cmd[])
{
- // Initializing commands
- cmd_init (cmd);
+ struct PERF_TALER_MINTDB_interpreter_state state = {.i = 0, .cmd = cmd, .plugin = db_plugin};
+ // Initializing commands
+ cmd_init (state.cmd);
// Running the interpreter
- struct PERF_TALER_MINTDB_interpreter_state state =
- {.i = 0, .cmd = cmd, .plugin = db_plugin};
state.session = db_plugin->get_session (db_plugin->cls, GNUNET_YES);
-
interpret (&state);
-
// Cleaning the memory
cmd_clean (cmd);
-
return GNUNET_YES;
}
diff --git a/src/mintdb/perf_taler_mintdb_interpreter.h b/src/mintdb/perf_taler_mintdb_interpreter.h
index 12dec6d84..9556095c5 100644
--- a/src/mintdb/perf_taler_mintdb_interpreter.h
+++ b/src/mintdb/perf_taler_mintdb_interpreter.h
@@ -23,9 +23,7 @@
#define __PERF_TALER_MINTDB_INTERPRETER_H__
#include <sys/time.h>
-#include "../include/platform.h"
-#include "../include/taler_mintdb_lib.h"
-#include "../include/taler_mintdb_plugin.h"
+#include "taler_mintdb_plugin.h"
/**
* Marks the end of the command chain
@@ -389,10 +387,18 @@ struct PERF_TALER_MINTDB_Cmd
*/
union PERF_TALER_MINTDB_Data exposed;
+ /**
+ * GNUNET_YES if the exposed value hav been saved during last loop iteration
+ * GNUNET_NO if it hasn't
+ */
int exposed_saved;
};
+/**
+ * Runs the command array @a cmd
+ * using @a db_plugin to connect to the database
+ */
int
PERF_TALER_MINTDB_interpret(
struct TALER_MINTDB_Plugin *db_plugin,