-commenting on code
This commit is contained in:
parent
d5f6b064f5
commit
4544a21cfb
@ -21,6 +21,14 @@
|
|||||||
#ifndef TALER_AMOUNT_LIB_H
|
#ifndef TALER_AMOUNT_LIB_H
|
||||||
#define TALER_AMOUNT_LIB_H
|
#define TALER_AMOUNT_LIB_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#if 0 /* keep Emacsens' auto-indent happy */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of characters (plus 1 for 0-termination) we use to
|
* @brief Number of characters (plus 1 for 0-termination) we use to
|
||||||
@ -249,5 +257,12 @@ TALER_amount_normalize (struct TALER_Amount *amount);
|
|||||||
char *
|
char *
|
||||||
TALER_amount_to_string (const struct TALER_Amount *amount);
|
TALER_amount_to_string (const struct TALER_Amount *amount);
|
||||||
|
|
||||||
|
#if 0 /* keep Emacsens' auto-indent happy */
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
#include "taler_crypto_lib.h"
|
#include "taler_crypto_lib.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#if 0 /* keep Emacsens' auto-indent happy */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Define logging functions */
|
/* Define logging functions */
|
||||||
#define TALER_LOG_DEBUG(...) \
|
#define TALER_LOG_DEBUG(...) \
|
||||||
@ -86,4 +94,12 @@ TALER_config_get_denom (struct GNUNET_CONFIGURATION_Handle *cfg,
|
|||||||
struct TALER_Amount *denom);
|
struct TALER_Amount *denom);
|
||||||
|
|
||||||
|
|
||||||
|
#if 0 /* keep Emacsens' auto-indent happy */
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,7 +59,7 @@ test_mintdb_deposits_LDADD = \
|
|||||||
$(top_srcdir)/src/pq/libtalerpq.la \
|
$(top_srcdir)/src/pq/libtalerpq.la \
|
||||||
-lgnunetutil \
|
-lgnunetutil \
|
||||||
-ljansson \
|
-ljansson \
|
||||||
-lpq
|
-lpq
|
||||||
|
|
||||||
test_mintdb_keyio_SOURCES = \
|
test_mintdb_keyio_SOURCES = \
|
||||||
test_mintdb_keyio.c
|
test_mintdb_keyio.c
|
||||||
@ -67,7 +67,7 @@ test_mintdb_keyio_LDADD = \
|
|||||||
libtalermintdb.la \
|
libtalermintdb.la \
|
||||||
$(top_srcdir)/src/util/libtalerutil.la \
|
$(top_srcdir)/src/util/libtalerutil.la \
|
||||||
$(top_srcdir)/src/pq/libtalerpq.la \
|
$(top_srcdir)/src/pq/libtalerpq.la \
|
||||||
-lgnunetutil
|
-lgnunetutil
|
||||||
|
|
||||||
test_mintdb_postgres_SOURCES = \
|
test_mintdb_postgres_SOURCES = \
|
||||||
test_mintdb.c
|
test_mintdb.c
|
||||||
|
@ -10,28 +10,35 @@
|
|||||||
#define CURRENCY "EUR\0\0\0\0\0\0\0\0"
|
#define CURRENCY "EUR\0\0\0\0\0\0\0\0"
|
||||||
|
|
||||||
struct TALER_MINTDB_CollectableBlindcoin *
|
struct TALER_MINTDB_CollectableBlindcoin *
|
||||||
init_CollectableBlindcoin(){
|
init_CollectableBlindcoin ()
|
||||||
struct TALER_MINTDB_CollectableBlindcoin *coin = GNUNET_malloc(sizeof(*coin));
|
{
|
||||||
|
// indent by 2 spaces
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create();
|
struct TALER_MINTDB_CollectableBlindcoin *coin = GNUNET_new (*coin);
|
||||||
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key = GNUNET_CRYPTO_rsa_private_key_create(512);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
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->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
|
//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));
|
||||||
|
|
||||||
coin->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY};
|
coin->amount_with_fee = (struct TALER_Amount) {1, 1, CURRENCY};
|
||||||
coin->withdraw_fee = (struct TALER_Amount) {0, 1, CURRENCY};
|
coin->withdraw_fee = (struct TALER_Amount) {0, 1, CURRENCY};
|
||||||
|
|
||||||
|
|
||||||
int random_int = rand();
|
int random_int = rand(); // GNUNET_CRYPTO_random_u32
|
||||||
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));
|
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &coin->h_coin_envelope);
|
||||||
|
|
||||||
void *purpose = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int));
|
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)->size = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(int);
|
||||||
((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->purpose = GNUNET_SIGNATURE_PURPOSE_TEST;
|
((struct GNUNET_CRYPTO_EccSignaturePurpose *)purpose)->purpose = GNUNET_SIGNATURE_PURPOSE_TEST;
|
||||||
*((int *)(purpose + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))) = random_int;
|
*((int *)(purpose + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))) = random_int;
|
||||||
@ -39,7 +46,7 @@ init_CollectableBlindcoin(){
|
|||||||
GNUNET_CRYPTO_eddsa_sign(reserve_sig_key, purpose, &coin->reserve_sig.eddsa_signature);
|
GNUNET_CRYPTO_eddsa_sign(reserve_sig_key, purpose, &coin->reserve_sig.eddsa_signature);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GNUNET_free(reserve_sig_key);
|
GNUNET_free(reserve_sig_key);
|
||||||
GNUNET_CRYPTO_rsa_private_key_free(denomination_key);
|
GNUNET_CRYPTO_rsa_private_key_free(denomination_key);
|
||||||
return coin;
|
return coin;
|
||||||
@ -52,11 +59,11 @@ init_Reserve(){
|
|||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv = GNUNET_CRYPTO_eddsa_key_create();
|
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_priv = GNUNET_CRYPTO_eddsa_key_create();
|
||||||
|
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public(reserve_priv , &(reserve->pub.eddsa_pub));
|
GNUNET_CRYPTO_eddsa_key_get_public(reserve_priv , &(reserve->pub.eddsa_pub));
|
||||||
|
|
||||||
|
|
||||||
reserve->balance = (struct TALER_Amount){1, 1, CURRENCY};
|
reserve->balance = (struct TALER_Amount){1, 1, CURRENCY};
|
||||||
reserve->expiry = GNUNET_TIME_absolute_get_forever_();
|
reserve->expiry = GNUNET_TIME_absolute_get_forever_();
|
||||||
|
|
||||||
GNUNET_free(reserve_priv);
|
GNUNET_free(reserve_priv);
|
||||||
return reserve;
|
return reserve;
|
||||||
}
|
}
|
||||||
@ -82,7 +89,7 @@ init_Deposit(){
|
|||||||
|
|
||||||
deposit-> transaction_id = transaction_id;
|
deposit-> transaction_id = transaction_id;
|
||||||
transaction_id++;
|
transaction_id++;
|
||||||
|
|
||||||
|
|
||||||
//TODO Randomize the amount that is deposited
|
//TODO Randomize the amount that is deposited
|
||||||
|
|
||||||
@ -94,11 +101,11 @@ init_Deposit(){
|
|||||||
|
|
||||||
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_contract);
|
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_contract);
|
||||||
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_wire);
|
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &deposit->h_wire);
|
||||||
|
|
||||||
// Coin Spend Signature
|
// Coin Spend Signature
|
||||||
{
|
{
|
||||||
struct GNUNET_CRYPTO_EddsaSignature sig;
|
struct GNUNET_CRYPTO_EddsaSignature sig;
|
||||||
|
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
||||||
void *prp = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int));
|
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};
|
*((struct GNUNET_CRYPTO_EccSignaturePurpose *)prp) =(struct GNUNET_CRYPTO_EccSignaturePurpose) {sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)+sizeof(int), GNUNET_SIGNATURE_PURPOSE_TEST};
|
||||||
@ -117,45 +124,45 @@ init_Deposit(){
|
|||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prv = GNUNET_CRYPTO_eddsa_key_create();
|
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prv = GNUNET_CRYPTO_eddsa_key_create();
|
||||||
|
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prv, &eddsa_pub);
|
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prv, &eddsa_pub);
|
||||||
|
|
||||||
deposit->merchant_pub.eddsa_pub = eddsa_pub;
|
deposit->merchant_pub.eddsa_pub = eddsa_pub;
|
||||||
|
|
||||||
GNUNET_free(p_eddsa_prv);
|
GNUNET_free(p_eddsa_prv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coin
|
// Coin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
|
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
|
||||||
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
struct GNUNET_CRYPTO_EddsaPrivateKey *p_eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create();
|
||||||
|
|
||||||
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prvt, &eddsa_pub);
|
GNUNET_CRYPTO_eddsa_key_get_public(p_eddsa_prvt, &eddsa_pub);
|
||||||
|
|
||||||
deposit->coin.coin_pub.eddsa_pub = eddsa_pub;
|
deposit->coin.coin_pub.eddsa_pub = eddsa_pub;
|
||||||
|
|
||||||
GNUNET_free(p_eddsa_prvt);
|
GNUNET_free(p_eddsa_prvt);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
struct GNUNET_CRYPTO_rsa_PrivateKey *p_rsa_prv = GNUNET_CRYPTO_rsa_private_key_create(128);
|
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);
|
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,
|
deposit->coin.denom_pub.rsa_public_key = p_rsa_pub;
|
||||||
(void *) &(deposit->coin.coin_pub.eddsa_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)));
|
sizeof(&(deposit->coin.coin_pub.eddsa_pub)));
|
||||||
|
|
||||||
GNUNET_CRYPTO_rsa_private_key_free(p_rsa_prv);
|
GNUNET_CRYPTO_rsa_private_key_free(p_rsa_prv);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return deposit;
|
return deposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +180,7 @@ init_denomination(){
|
|||||||
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_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 =
|
struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt =
|
||||||
GNUNET_CRYPTO_eddsa_key_create();
|
GNUNET_CRYPTO_eddsa_key_create();
|
||||||
|
|
||||||
struct GNUNET_CRYPTO_EddsaPublicKey master_pub;
|
struct GNUNET_CRYPTO_EddsaPublicKey master_pub;
|
||||||
@ -225,7 +232,7 @@ int
|
|||||||
free_deposit(struct TALER_MINTDB_Deposit *deposit){
|
free_deposit(struct TALER_MINTDB_Deposit *deposit){
|
||||||
GNUNET_free(deposit->coin.denom_pub.rsa_public_key);
|
GNUNET_free(deposit->coin.denom_pub.rsa_public_key);
|
||||||
GNUNET_free(deposit->coin.denom_sig.rsa_signature);
|
GNUNET_free(deposit->coin.denom_sig.rsa_signature);
|
||||||
|
|
||||||
GNUNET_free(deposit);
|
GNUNET_free(deposit);
|
||||||
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
@ -249,10 +256,6 @@ free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki){
|
|||||||
GNUNET_free(dki->denom_pub.rsa_public_key);
|
GNUNET_free(dki->denom_pub.rsa_public_key);
|
||||||
|
|
||||||
GNUNET_free(dki);
|
GNUNET_free(dki);
|
||||||
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,20 +8,20 @@
|
|||||||
#include <taler/taler_mintdb_plugin.h>
|
#include <taler/taler_mintdb_plugin.h>
|
||||||
|
|
||||||
|
|
||||||
#define CURRENCY "EUR\0\0\0\0\0\0\0\0"
|
#define CURRENCY "EUR"
|
||||||
|
|
||||||
|
|
||||||
struct TALER_MINTDB_CollectableBlindcoin *
|
struct TALER_MINTDB_CollectableBlindcoin *
|
||||||
init_collectableBlindcoin();
|
init_collectable_blindcoin(void);
|
||||||
|
|
||||||
struct TALER_MINTDB_RefreshSession *
|
struct TALER_MINTDB_RefreshSession *
|
||||||
init_refresh_session();
|
init_refresh_session(void);
|
||||||
|
|
||||||
struct TALER_MINTDB_Deposit *
|
struct TALER_MINTDB_Deposit *
|
||||||
init_deposit(int transaction_id);
|
init_deposit(int transaction_id);
|
||||||
|
|
||||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||||
init_denomination();
|
init_denomination(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -29,9 +29,9 @@ int
|
|||||||
free_deposit(struct TALER_MINTDB_Deposit *deposit);
|
free_deposit(struct TALER_MINTDB_Deposit *deposit);
|
||||||
|
|
||||||
int
|
int
|
||||||
free_collectableBlindcoin(struct TALER_MINTDB_CollectableBlindcoin);
|
free_collectable_blindcoin(struct TALER_MINTDB_CollectableBlindcoin *NAME);
|
||||||
|
|
||||||
int
|
int
|
||||||
free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
free_denomination(struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,26 +8,18 @@
|
|||||||
/**
|
/**
|
||||||
* Finds the first command in cmd with the name search
|
* Finds the first command in cmd with the name search
|
||||||
*
|
*
|
||||||
* \return the index of the first command with name search
|
* \return the index of the first command with name search
|
||||||
* GNUNET_SYSERR if none found
|
* GNUNET_SYSERR if none found
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
cmd_find(const struct PERF_TALER_MINTDB_CMD *cmd, const char *search)
|
cmd_find(const struct PERF_TALER_MINTDB_CMD *cmd, const char *search)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
while (0)
|
|
||||||
{
|
|
||||||
if (cmd[i].command == CMD_END)
|
|
||||||
{
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != strcmp(cmd[i].name, search))
|
for (i=0; CMD_END != cmd[i].command; i++)
|
||||||
{
|
if (0 == strcmp (cmd[i].name, search))
|
||||||
return i;
|
return i;
|
||||||
}
|
return GNUNET_SYSERR;
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -36,22 +28,21 @@ cmd_find(const struct PERF_TALER_MINTDB_CMD *cmd, const char *search)
|
|||||||
cmd_init(struct PERF_TALER_MINTDB_CMD cmd[])
|
cmd_init(struct PERF_TALER_MINTDB_CMD cmd[])
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (cmd[i].command != CMD_END)
|
while (CMD_END != cmd[i].command)
|
||||||
{
|
{
|
||||||
switch (cmd[i].command)
|
switch (cmd[i].command)
|
||||||
{
|
{
|
||||||
case CMD_SAVE_ARRAY:
|
case CMD_SAVE_ARRAY:
|
||||||
|
|
||||||
// Initialization is done differently depending of the type saved
|
// Initialization is done differently depending of the type saved
|
||||||
switch (cmd[i].details.save_array.saved_type)
|
switch (cmd[i].details.save_array.saved_type)
|
||||||
{
|
{
|
||||||
case DEPOSIT:
|
case DEPOSIT:
|
||||||
cmd[i].details.save_array.saved_data.deposit =
|
cmd[i].details.save_array.saved_data.deposit =
|
||||||
GNUNET_malloc(cmd[i].details.save_array.nb*
|
GNUNET_malloc(cmd[i].details.save_array.nb*
|
||||||
sizeof(*cmd[i].details.save_array.saved_data.deposit));
|
sizeof(*cmd[i].details.save_array.saved_data.deposit));
|
||||||
break;
|
break;
|
||||||
case TIME:
|
case TIME:
|
||||||
cmd[i].details.save_array.saved_data.time =
|
cmd[i].details.save_array.saved_data.time =
|
||||||
GNUNET_malloc(cmd[i].details.save_array.nb*
|
GNUNET_malloc(cmd[i].details.save_array.nb*
|
||||||
sizeof(*cmd[i].details.save_array.saved_data.time));
|
sizeof(*cmd[i].details.save_array.saved_data.time));
|
||||||
|
|
||||||
@ -61,9 +52,9 @@ cmd_init(struct PERF_TALER_MINTDB_CMD cmd[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LOAD_ARRAY:
|
case CMD_LOAD_ARRAY:
|
||||||
cmd[i].details.load_array.permutation =
|
cmd[i].details.load_array.permutation =
|
||||||
GNUNET_CRYPTO_random_permute(
|
GNUNET_CRYPTO_random_permute(
|
||||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
cmd[i].details.load_array.nb);
|
cmd[i].details.load_array.nb);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -129,7 +120,7 @@ cmd_clean(struct PERF_TALER_MINTDB_CMD cmd[])
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
||||||
@ -142,7 +133,6 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
{
|
{
|
||||||
case CMD_END:
|
case CMD_END:
|
||||||
return GNUNET_YES;
|
return GNUNET_YES;
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_LOOP:
|
case CMD_LOOP:
|
||||||
cmd[i].details.loop.curr_iteration++;
|
cmd[i].details.loop.curr_iteration++;
|
||||||
@ -171,7 +161,7 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +200,7 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
case CMD_INSERT_DEPOSIT:
|
case CMD_INSERT_DEPOSIT:
|
||||||
{
|
{
|
||||||
struct TALER_MINTDB_Deposit *deposit = init_deposit(0);
|
struct TALER_MINTDB_Deposit *deposit = init_deposit(0);
|
||||||
db_plugin->insert_deposit(db_plugin->cls, session, deposit);
|
db_plugin->insert_deposit(db_plugin->cls, session, deposit);
|
||||||
|
|
||||||
cmd[i].exposed.deposit = deposit;
|
cmd[i].exposed.deposit = deposit;
|
||||||
}
|
}
|
||||||
@ -238,8 +228,8 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
int proba = cmd[loop_index].details.loop.max_iterations / cmd[i].details.save_array.nb;
|
int proba = cmd[loop_index].details.loop.max_iterations / cmd[i].details.save_array.nb;
|
||||||
int rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, proba);
|
int rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, proba);
|
||||||
|
|
||||||
// If there is a lesser or equal number of iteration next than room remain in the array
|
// 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 <=
|
if ((cmd[loop_index].details.loop.max_iterations - cmd[loop_index].details.loop.curr_iteration <=
|
||||||
cmd[i].details.save_array.nb - cmd[i].details.save_array.index) ||
|
cmd[i].details.save_array.nb - cmd[i].details.save_array.index) ||
|
||||||
(rnd == 0 && cmd[i].details.save_array.index < cmd[i].details.save_array.nb))
|
(rnd == 0 && cmd[i].details.save_array.index < cmd[i].details.save_array.nb))
|
||||||
{
|
{
|
||||||
@ -247,11 +237,11 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
// We automaticly save the whatever we need to
|
// We automaticly save the whatever we need to
|
||||||
switch (cmd[i].details.save_array.saved_type){
|
switch (cmd[i].details.save_array.saved_type){
|
||||||
case DEPOSIT:
|
case DEPOSIT:
|
||||||
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
||||||
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
||||||
break;
|
break;
|
||||||
case TIME:
|
case TIME:
|
||||||
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
cmd[i].details.save_array.saved_data.deposit[cmd[i].details.save_array.index] =
|
||||||
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
cmd[cmd_find(cmd, cmd[i].details.save_array.saved)].exposed.deposit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -264,8 +254,8 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
case CMD_LOAD_ARRAY:
|
case CMD_LOAD_ARRAY:
|
||||||
{
|
{
|
||||||
|
|
||||||
int loop_index = cmd_find(cmd, cmd[i].details.load_array.loop);
|
int loop_index = cmd_find(cmd, cmd[i].details.load_array.loop);
|
||||||
int save_index = cmd_find(cmd, cmd[i].details.load_array.saved);
|
int save_index = cmd_find(cmd, cmd[i].details.load_array.saved);
|
||||||
switch (cmd[i].details.load_array.loaded_type){
|
switch (cmd[i].details.load_array.loaded_type){
|
||||||
case DEPOSIT:
|
case DEPOSIT:
|
||||||
cmd[i].exposed.deposit = cmd[save_index].details.save_array.saved_data.deposit[
|
cmd[i].exposed.deposit = cmd[save_index].details.save_array.saved_data.deposit[
|
||||||
@ -294,11 +284,11 @@ interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the commands given in cmd, working with
|
* Runs the commands given in @a cmd, working with
|
||||||
* the database referenced by db_plugin
|
* the database referenced by @a db_plugin
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
PERF_TALER_MINTDB_interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
PERF_TALER_MINTDB_interprete(struct TALER_MINTDB_Plugin *db_plugin,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
struct PERF_TALER_MINTDB_CMD cmd[])
|
struct PERF_TALER_MINTDB_CMD cmd[])
|
||||||
{
|
{
|
||||||
|
@ -8,12 +8,18 @@
|
|||||||
#include <taler/taler_mintdb_plugin.h>
|
#include <taler/taler_mintdb_plugin.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define INIT_CMD_END(label) {.command = CMD_END, .name = label}
|
||||||
|
|
||||||
#define INIT_CMD_LOOP(label, _iter) {.command = CMD_LOOP, .name = label, .details.loop = {.max_iterations = _iter, .curr_iteration = -1} }
|
#define INIT_CMD_LOOP(label, _iter) { \
|
||||||
|
.command = CMD_LOOP, \
|
||||||
|
.name = label, \
|
||||||
|
.details.loop = { \
|
||||||
|
.max_iterations = _iter, \
|
||||||
|
.curr_iteration = -1} \
|
||||||
|
}
|
||||||
|
|
||||||
#define INIT_CMD_END_LOOP(label, _loopname) {.command = CMD_END_LOOP, .name = label, .details.end_loop.loop_start = _loopname}
|
#define INIT_CMD_END_LOOP(label, _loopname) {.command = CMD_END_LOOP, .name = label, .details.end_loop.loop_start = _loopname}
|
||||||
|
|
||||||
#define INIT_CMD_END(label) {.command = CMD_END, .name = label}
|
|
||||||
|
|
||||||
#define INIT_CMD_GET_TIME(label) {.command = CMD_GET_TIME, .name = label}
|
#define INIT_CMD_GET_TIME(label) {.command = CMD_GET_TIME, .name = label}
|
||||||
|
|
||||||
@ -82,7 +88,7 @@ struct PERF_TALER_MINTDB_CMD{
|
|||||||
|
|
||||||
} command;
|
} command;
|
||||||
|
|
||||||
char name[40];
|
const char *name; // label!
|
||||||
|
|
||||||
// Contains command specific data.
|
// Contains command specific data.
|
||||||
union {
|
union {
|
||||||
@ -100,25 +106,28 @@ struct PERF_TALER_MINTDB_CMD{
|
|||||||
char stop_time[40];
|
char stop_time[40];
|
||||||
|
|
||||||
char description[40];
|
char description[40];
|
||||||
} gauger;
|
} gauger;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int nb; // Number of deposits to save
|
/**
|
||||||
int index; // The number of deposits already saved
|
* Comment!
|
||||||
|
*/
|
||||||
|
unsigned int nb; // Number of deposits to save
|
||||||
|
unsigned int index; // The number of deposits already saved
|
||||||
char loop[40]; // The loop from which the data will be extracted
|
char loop[40]; // The loop from which the data will be extracted
|
||||||
char saved[40]; // The deposit saved
|
char saved[40]; // The deposit saved
|
||||||
enum PERF_TALER_MINTDB_TYPE saved_type;
|
enum PERF_TALER_MINTDB_TYPE saved_type;
|
||||||
union {
|
union NAME_IT_TOP_LEVEL {
|
||||||
struct TALER_MINTDB_Deposit **deposit;
|
struct TALER_MINTDB_Deposit *deposit;
|
||||||
struct timespec *time;
|
struct timespec time;
|
||||||
} saved_data;
|
} *samples;
|
||||||
} save_array;
|
} save_array;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int nb; //the number of deposits to save
|
int nb; //the number of deposits to save
|
||||||
char loop[40];
|
char loop[40];
|
||||||
char saved[40]; // The command where the deposit were saved
|
char saved[40]; // The command where the deposit were saved
|
||||||
enum PERF_TALER_MINTDB_TYPE loaded_type;
|
enum PERF_TALER_MINTDB_TYPE loaded_type;
|
||||||
unsigned int *permutation; // A permutation array to randomize the order the deposits are loaded in
|
unsigned int *permutation; // A permutation array to randomize the order the deposits are loaded in
|
||||||
} load_array;
|
} load_array;
|
||||||
|
|
||||||
@ -128,10 +137,10 @@ struct PERF_TALER_MINTDB_CMD{
|
|||||||
|
|
||||||
|
|
||||||
} details;
|
} details;
|
||||||
union {
|
union NAME_IT_TOP_LEVEL {
|
||||||
struct TALER_MINTDB_Deposit *deposit;
|
struct TALER_MINTDB_Deposit *deposit;
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
} exposed;
|
} exposed;
|
||||||
|
|
||||||
int exposed_used;
|
int exposed_used;
|
||||||
};
|
};
|
||||||
@ -140,7 +149,7 @@ struct PERF_TALER_MINTDB_CMD{
|
|||||||
int
|
int
|
||||||
PERF_TALER_MINTDB_interprete(
|
PERF_TALER_MINTDB_interprete(
|
||||||
struct TALER_MINTDB_Plugin *db_plugin,
|
struct TALER_MINTDB_Plugin *db_plugin,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session, // add START_SESSION CMD
|
||||||
struct PERF_TALER_MINTDB_CMD cmd[]);
|
struct PERF_TALER_MINTDB_CMD cmd[]);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user