Merge branch 'master' of git+ssh://taler.net/var/git/mint
This commit is contained in:
commit
d568358317
@ -33,40 +33,75 @@ main (int argc, char ** argv)
|
||||
struct GNUNET_CONFIGURATION_Handle *config;
|
||||
struct PERF_TALER_MINTDB_Cmd test[] =
|
||||
{
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit",
|
||||
// Denomination used to create coins
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("01 - denomination loop",
|
||||
PERF_TALER_MINTDB_NB_DENOMINATION_INIT),
|
||||
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("01 - start transaction"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION ("01 - denomination"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("01 - commit transaction"),
|
||||
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_INIT_CMD_END_LOOP ("01 - denomination loop end",
|
||||
"01 - denomination loop"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_DEBUG ("01 - init denomination complete"),
|
||||
// End of initialization
|
||||
// Reserve initialization
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("02 - init reserve loop",
|
||||
PERF_TALER_MINTDB_NB_RESERVE_INIT),
|
||||
PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE ("02 - reserve"),
|
||||
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_INIT_CMD_END_LOOP ("02 - init reserve end loop",
|
||||
"02 - init reserve loop"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_DEBUG ("02 - reserve init complete"),
|
||||
// End reserve init
|
||||
// Withdrawal initialization
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("03 - init withdraw loop",
|
||||
PERF_TALER_MINTDB_NB_WITHDRAW_INIT),
|
||||
// PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("03 - start transaction"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("03 - denomination load",
|
||||
"03 - init withdraw loop",
|
||||
"01 - save denomination"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("03 - reserve load",
|
||||
"03 - init withdraw loop",
|
||||
"02 - save reserve"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW ("03 - withdraw",
|
||||
"03 - denomination load",
|
||||
"03 - reserve load"),
|
||||
// PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("03 - commit transaction"),
|
||||
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_INIT_CMD_END_LOOP ("03 - withdraw init end loop",
|
||||
"03 - init withdraw loop"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_DEBUG ("03 - withdraw init complete"),
|
||||
//End of withdrawal initialization
|
||||
//Deposit initialization
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("04 - deposit init loop",
|
||||
PERF_TALER_MINTDB_NB_DEPOSIT_INIT),
|
||||
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_init"),
|
||||
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_SAVE_ARRAY ("array_depo",
|
||||
"loop_db_init_deposit",
|
||||
"init_deposit_insert",
|
||||
PERF_TALER_MINTDB_NB_DEPOSIT_GET,
|
||||
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("04 - start transaction"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("04 - deposit",
|
||||
"01 - denomination"),
|
||||
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_INIT_CMD_END_LOOP ("endloop_init_deposit",
|
||||
"loop_db_init_deposit"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_DEBUG("INIT_END"),
|
||||
// End of database initialization
|
||||
PERF_TALER_MINTDB_INIT_CMD_GET_TIME ("deposit_get_start"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_deposit_get",
|
||||
PERF_TALER_MINTDB_NB_DEPOSIT_GET),
|
||||
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_get"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("load deposit",
|
||||
"loop_deposit_get",
|
||||
"array_depo"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT ("get_deposit",
|
||||
"load_deposit"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("stop2", "loop_deposit_get"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_GET_TIME ("deposit_get_end"),
|
||||
PERF_TALER_MINTDB_INIT_CMD_GAUGER ("deposit_get_commit",
|
||||
"deposit_get_start",
|
||||
"deposit_get_end",
|
||||
"time per deposit check",
|
||||
PERF_TALER_MINTDB_NB_DEPOSIT_GET),
|
||||
PERF_TALER_MINTDB_INIT_CMD_END("end"),
|
||||
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"),
|
||||
// End of deposit initialization
|
||||
PERF_TALER_MINTDB_INIT_CMD_END ("end"),
|
||||
};
|
||||
// Plugin init
|
||||
|
||||
GNUNET_log_setup ("perf-taler-mintdb",
|
||||
"WARNING",
|
||||
|
@ -30,76 +30,115 @@
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
* Generate a dummy DenominationKeyInformation for testing purposes
|
||||
* @return a dummy denomination key
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init ()
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
PERF_TALER_MINTDB_denomination_init ()
|
||||
{
|
||||
uint32_t random_int;
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key;
|
||||
struct {
|
||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||
uint32_t data;
|
||||
} unsigned_data;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin;
|
||||
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 (PERF_TALER_MINTDB_RSA_SIZE)));
|
||||
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);
|
||||
GNUNET_assert (NULL !=
|
||||
(master_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (master_prvt,
|
||||
&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_ ()));
|
||||
dki->issue.expire_spend =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_ ()));
|
||||
dki->issue.expire_legal =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_ ()));
|
||||
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));
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_CRYPTO_eddsa_sign (master_prvt,
|
||||
&dki->issue.purpose,
|
||||
&dki->issue.signature.eddsa_signature));
|
||||
GNUNET_free (master_prvt);
|
||||
|
||||
coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin);
|
||||
GNUNET_assert (NULL !=
|
||||
(reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
GNUNET_assert (NULL !=
|
||||
(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)));
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (reserve_sig_key,
|
||||
&coin->reserve_pub.eddsa_pub);
|
||||
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->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))));
|
||||
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
&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_free (reserve_sig_key);
|
||||
GNUNET_CRYPTO_rsa_private_key_free (denomination_key);
|
||||
return coin;
|
||||
return dki;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Liberate memory of @a coin
|
||||
* Copies the given denomination
|
||||
* @param reserve the deposit copy
|
||||
* @return a copy of @a deposit; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
PERF_TALER_MINTDB_denomination_copy (const struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
|
||||
{
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *copy;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(copy = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation)));
|
||||
*copy = *dki;
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_private_key_encode (
|
||||
dki->denom_priv.rsa_private_key,
|
||||
&buffer)));
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->denom_priv.rsa_private_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_decode(buffer, size)));
|
||||
GNUNET_free (buffer);
|
||||
}
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key)));
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a DenominationKeyIssueInformation
|
||||
* @param dki pointer to the struct to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin)
|
||||
PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
|
||||
{
|
||||
if (NULL == coin)
|
||||
if (NULL ==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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated reserve
|
||||
* Generate a dummy reserve for testing
|
||||
* @return a reserve with 1000 EUR in it
|
||||
*/
|
||||
struct TALER_MINTDB_Reserve *
|
||||
PERF_TALER_MINTDB_reserve_init ()
|
||||
@ -114,58 +153,47 @@ PERF_TALER_MINTDB_reserve_init ()
|
||||
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));
|
||||
TALER_string_to_amount (CURRENCY ":1000", &reserve->balance));
|
||||
reserve->expiry = GNUNET_TIME_absolute_get_forever_ ();
|
||||
GNUNET_free (reserve_priv);
|
||||
return reserve;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the given reserve
|
||||
* @param reserve the reserve to copy
|
||||
* @return a copy of @a reserve; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_Reserve *
|
||||
PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve)
|
||||
{
|
||||
struct TALER_MINTDB_Reserve *copy;
|
||||
GNUNET_assert (NULL != (copy = GNUNET_new (struct TALER_MINTDB_Reserve)));
|
||||
*copy = *reserve;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory of a reserve
|
||||
* @param reserve pointer to the structure to be freed
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_reserve_free (struct TALER_MINTDB_Reserve *reserve)
|
||||
{
|
||||
if (NULL == reserve)
|
||||
return GNUNET_OK;
|
||||
GNUNET_free (reserve);
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated refresh session
|
||||
*/
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
PERF_TALER_MINTDB_refresh_session_init ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free a refresh session
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_refresh_session_free (struct TALER_MINTDB_RefreshSession *refresh_session)
|
||||
{
|
||||
GNUNET_free (refresh_session);
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a randomly generated deposit
|
||||
* Generate a dummy deposit for testing purposes
|
||||
* @param dki the denomination key used to sign the key
|
||||
*/
|
||||
struct TALER_MINTDB_Deposit *
|
||||
PERF_TALER_MINTDB_deposit_init ()
|
||||
PERF_TALER_MINTDB_deposit_init (const struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
|
||||
{
|
||||
struct TALER_MINTDB_Deposit *deposit;
|
||||
struct TALER_CoinPublicInfo coin;
|
||||
@ -189,24 +217,20 @@ PERF_TALER_MINTDB_deposit_init ()
|
||||
(deposit = GNUNET_malloc (sizeof (struct TALER_MINTDB_Deposit) + sizeof (wire))));
|
||||
{ // coin
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prvt;
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *rsa_prv;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(eddsa_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
GNUNET_assert (NULL !=
|
||||
(rsa_prv = GNUNET_CRYPTO_rsa_private_key_create (PERF_TALER_MINTDB_RSA_SIZE)));
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (eddsa_prvt,
|
||||
&coin.coin_pub.eddsa_pub);
|
||||
GNUNET_assert (NULL !=
|
||||
(coin.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_get_public (rsa_prv)));
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key)));
|
||||
GNUNET_assert (NULL !=
|
||||
(coin.denom_sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_sign (rsa_prv,
|
||||
GNUNET_CRYPTO_rsa_sign (dki->denom_priv.rsa_private_key,
|
||||
&coin.coin_pub.eddsa_pub,
|
||||
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))));
|
||||
|
||||
GNUNET_CRYPTO_rsa_private_key_free (rsa_prv);
|
||||
GNUNET_free (eddsa_prvt);
|
||||
}
|
||||
{ //csig
|
||||
@ -265,8 +289,41 @@ PERF_TALER_MINTDB_deposit_init ()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the given deposit
|
||||
* @param reserve the deposit copy
|
||||
* @return a copy of @a deposit; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_Deposit *
|
||||
PERF_TALER_MINTDB_deposit_copy (const struct TALER_MINTDB_Deposit *deposit)
|
||||
{
|
||||
struct TALER_MINTDB_Deposit *copy;
|
||||
|
||||
GNUNET_assert (NULL != (copy = GNUNET_new (struct TALER_MINTDB_Deposit)));
|
||||
*copy = *deposit;
|
||||
json_incref (copy->wire);
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->coin.denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (deposit->coin.denom_pub.rsa_public_key)));
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_signature_encode (
|
||||
deposit->coin.denom_sig.rsa_signature,
|
||||
&buffer)));
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->coin.denom_sig.rsa_signature =
|
||||
GNUNET_CRYPTO_rsa_signature_decode(buffer, size)));
|
||||
GNUNET_free (buffer);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a deposit
|
||||
* @param deposit pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit)
|
||||
@ -283,74 +340,150 @@ PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit)
|
||||
|
||||
|
||||
/**
|
||||
* Generate a randomly generate DenominationKeyInformation
|
||||
* Generate a CollectableBlindcoin for testing purpuses
|
||||
* @param dki denomination key used to sign the coin
|
||||
* @param reserve reserve providing the money for the coin
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
*/
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
PERF_TALER_MINTDB_denomination_init ()
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
|
||||
const struct TALER_MINTDB_Reserve *reserve)
|
||||
{
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt;
|
||||
struct GNUNET_TIME_Absolute anchor;
|
||||
struct TALER_Amount amount;
|
||||
uint32_t random_int;
|
||||
struct GNUNET_CRYPTO_rsa_PrivateKey *denomination_key;
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *reserve_sig_key;
|
||||
struct {
|
||||
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
|
||||
uint32_t data;
|
||||
} unsigned_data;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin;
|
||||
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(dki = GNUNET_new (struct TALER_MINTDB_DenominationKeyIssueInformation)));
|
||||
(coin = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin)));
|
||||
GNUNET_assert (NULL !=
|
||||
(dki->denom_priv.rsa_private_key
|
||||
= GNUNET_CRYPTO_rsa_private_key_create (PERF_TALER_MINTDB_RSA_SIZE)));
|
||||
(reserve_sig_key = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_private_key_encode (
|
||||
dki->denom_priv.rsa_private_key,
|
||||
&buffer)));
|
||||
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);
|
||||
GNUNET_assert (NULL !=
|
||||
(master_prvt = GNUNET_CRYPTO_eddsa_key_create ()));
|
||||
GNUNET_CRYPTO_eddsa_key_get_public (master_prvt,
|
||||
&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_ ()));
|
||||
dki->issue.expire_spend =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_ ()));
|
||||
dki->issue.expire_legal =
|
||||
GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_add (anchor,
|
||||
GNUNET_TIME_relative_get_hour_ ()));
|
||||
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));
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_CRYPTO_eddsa_sign (master_prvt,
|
||||
&dki->issue.purpose,
|
||||
&dki->issue.signature.eddsa_signature));
|
||||
GNUNET_free (master_prvt);
|
||||
(denomination_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_decode (buffer, size)));
|
||||
GNUNET_free (buffer);
|
||||
}
|
||||
|
||||
return dki;
|
||||
GNUNET_assert (NULL !=
|
||||
(coin->denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_private_key_get_public (denomination_key)));
|
||||
coin->reserve_pub.eddsa_pub = reserve->pub.eddsa_pub;
|
||||
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->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))));
|
||||
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
&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_free (reserve_sig_key);
|
||||
GNUNET_CRYPTO_rsa_private_key_free (denomination_key);
|
||||
return coin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free memory for a DenominationKeyIssueInformation
|
||||
* Copies the given coin
|
||||
* @param coin the coin to copy
|
||||
* @return a copy of coin; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_copy (const struct TALER_MINTDB_CollectableBlindcoin *coin)
|
||||
{
|
||||
struct TALER_MINTDB_CollectableBlindcoin *copy;
|
||||
|
||||
GNUNET_assert (NULL !=
|
||||
(copy = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin)));
|
||||
*copy = *coin;
|
||||
// No signature copy function found, Hacking it in
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int size;
|
||||
GNUNET_assert (0 <
|
||||
(size = GNUNET_CRYPTO_rsa_signature_encode (
|
||||
coin->sig.rsa_signature,
|
||||
&buffer)));
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_decode(
|
||||
buffer,
|
||||
size)));
|
||||
GNUNET_free (buffer);
|
||||
}
|
||||
GNUNET_assert (NULL !=
|
||||
(copy->denom_pub.rsa_public_key =
|
||||
GNUNET_CRYPTO_rsa_public_key_dup (coin->denom_pub.rsa_public_key)));
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liberate memory of @a coin
|
||||
* @param coin pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *coin)
|
||||
{
|
||||
if (NULL ==dki)
|
||||
if (NULL == coin)
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated refresh session
|
||||
*/
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
PERF_TALER_MINTDB_refresh_session_init ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free a refresh session
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_refresh_session_free (struct TALER_MINTDB_RefreshSession *refresh_session)
|
||||
{
|
||||
GNUNET_free (refresh_session);
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
@ -27,74 +27,114 @@
|
||||
#define CURRENCY "EUR"
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Liberate memory of @a coin
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (struct TALER_MINTDB_CollectableBlindcoin *NAME);
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated reserve
|
||||
*/
|
||||
struct TALER_MINTDB_Reserve *
|
||||
PERF_TALER_MINTDB_reserve_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a reserve
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_reserve_free (struct TALER_MINTDB_Reserve *reserve);
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated refresh session
|
||||
*/
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
PERF_TALER_MINTDB_refresh_session_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Frees memory of a refresh_session
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_refresh_session_free (struct TALER_MINTDB_RefreshSession *refresh_session);
|
||||
|
||||
|
||||
/**
|
||||
* Create a randomly generated deposit
|
||||
*/
|
||||
struct TALER_MINTDB_Deposit *
|
||||
PERF_TALER_MINTDB_deposit_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a deposit
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a randomly generate DenominationKeyInformation
|
||||
* Generate a dummy DenominationKeyInformation for testing purposes
|
||||
* @return a dummy denomination key
|
||||
*/
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
PERF_TALER_MINTDB_denomination_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory for a DenominationKeyIssueInformation
|
||||
* Copies the given denomination
|
||||
* @param reserve the deposit copy
|
||||
* @return a copy of @a deposit; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *
|
||||
PERF_TALER_MINTDB_denomination_copy (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a DenominationKeyIssueInformation
|
||||
* @param dki pointer to the struct to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||
PERF_TALER_MINTDB_denomination_free (
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a dummy reserve for testing
|
||||
* @return a reserve with 1000 EUR in it
|
||||
*/
|
||||
struct TALER_MINTDB_Reserve *
|
||||
PERF_TALER_MINTDB_reserve_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Copies the given reserve
|
||||
* @param reserve the reserve to copy
|
||||
* @return a copy of @a reserve; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_Reserve *
|
||||
PERF_TALER_MINTDB_reserve_copy (const struct TALER_MINTDB_Reserve *reserve);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a reserve
|
||||
* @param reserve pointer to the structure to be freed
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_reserve_free (struct TALER_MINTDB_Reserve *reserve);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a dummy deposit for testing purposes
|
||||
* @param dki the denomination key used to sign the key
|
||||
*/
|
||||
struct TALER_MINTDB_Deposit *
|
||||
PERF_TALER_MINTDB_deposit_init (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki);
|
||||
|
||||
|
||||
/**
|
||||
* Copies the given deposit
|
||||
* @param reserve the deposit copy
|
||||
* @return a copy of @a deposit; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_Deposit *
|
||||
PERF_TALER_MINTDB_deposit_copy (const struct TALER_MINTDB_Deposit *deposit);
|
||||
|
||||
|
||||
/**
|
||||
* Free memory of a deposit
|
||||
* @param deposit pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_deposit_free (struct TALER_MINTDB_Deposit *deposit);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a CollectableBlindcoin for testing purpuses
|
||||
* @param dki denomination key used to sign the coin
|
||||
* @param reserve reserve providing the money for the coin
|
||||
* @return a randomly generated CollectableBlindcoin
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
const struct TALER_MINTDB_DenominationKeyIssueInformation *dki,
|
||||
const struct TALER_MINTDB_Reserve *reserve);
|
||||
|
||||
|
||||
/**
|
||||
* Copies the given coin
|
||||
* @param coin the coin to copy
|
||||
* @return a copy of coin; NULL if error
|
||||
*/
|
||||
struct TALER_MINTDB_CollectableBlindcoin *
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_copy (
|
||||
const struct TALER_MINTDB_CollectableBlindcoin *coin);
|
||||
|
||||
|
||||
/**
|
||||
* Liberate memory of @a coin
|
||||
* @param coin pointer to the structure to free
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_free (
|
||||
struct TALER_MINTDB_CollectableBlindcoin *coin);
|
||||
|
||||
|
||||
/**
|
||||
@ -109,4 +149,19 @@ PERF_TALER_MINTDB_coin_public_info_init (void);
|
||||
*/
|
||||
int PERF_TALER_MINTDB_coin_public_info_free (struct TALER_CoinPublicInfo *cpi);
|
||||
|
||||
|
||||
/**
|
||||
* @return a randomly generated refresh session
|
||||
*/
|
||||
struct TALER_MINTDB_RefreshSession *
|
||||
PERF_TALER_MINTDB_refresh_session_init (void);
|
||||
|
||||
|
||||
/**
|
||||
* Frees memory of a refresh_session
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_refresh_session_free (
|
||||
struct TALER_MINTDB_RefreshSession *refresh_session);
|
||||
|
||||
#endif
|
||||
|
@ -129,19 +129,21 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||
// Creating the permutation array to randomize the data order
|
||||
{
|
||||
int save_index ;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_index = cmd_find (
|
||||
cmd,
|
||||
cmd[i].details.load_array.label_save)));
|
||||
GNUNET_assert (NULL !=
|
||||
(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)));
|
||||
|
||||
cmd[save_index].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[save_index].details.save_array.type_saved;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -200,16 +202,15 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
unsigned int i;
|
||||
union PERF_TALER_MINTDB_Data zero = {0};
|
||||
unsigned int jump = cmd_find (state->cmd,
|
||||
state->cmd[state->i].details.end_loop.label_loop);
|
||||
int jump;
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(jump = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.end_loop.label_loop)));
|
||||
// Cleaning up the memory in the loop
|
||||
for (i = jump; i < state->i; i++)
|
||||
{
|
||||
// If the exposed variable has not been copied it is freed
|
||||
if ( GNUNET_NO == state->cmd[i].exposed_saved)
|
||||
data_free (&state->cmd[i].exposed, state->cmd[i].exposed_type);
|
||||
state->cmd[i].exposed_saved = GNUNET_NO;
|
||||
// Anyway we need to make the data zero.
|
||||
state->cmd[i].exposed = zero;
|
||||
}
|
||||
|
||||
@ -234,20 +235,23 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
static void
|
||||
interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
unsigned int loop_index;
|
||||
int loop_index, save_index;
|
||||
unsigned int selection_chance;
|
||||
|
||||
// Array initialization on first loop iteration
|
||||
// Alows for nested loops
|
||||
if (0 == state->cmd[cmd_find (state->cmd,
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(loop_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.save_array.label_loop)]
|
||||
.details.loop.curr_iteration)
|
||||
.details.save_array.label_loop)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(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)
|
||||
{
|
||||
state->cmd[state->i].details.save_array.index = 0;
|
||||
}
|
||||
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.
|
||||
selection_chance = state->cmd[loop_index].details.loop.max_iterations /
|
||||
@ -272,10 +276,7 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
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;
|
||||
item_saved = &state->cmd[save_index].exposed;
|
||||
switch (state->cmd[state->i].details.save_array.type_saved)
|
||||
{
|
||||
case PERF_TALER_MINTDB_TIME:
|
||||
@ -283,19 +284,19 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_DEPOSIT:
|
||||
save_location->deposit = item_saved->deposit;
|
||||
save_location->deposit = PERF_TALER_MINTDB_deposit_copy (item_saved->deposit);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_BLINDCOIN:
|
||||
save_location->blindcoin = item_saved->blindcoin;
|
||||
save_location->blindcoin = PERF_TALER_MINTDB_collectable_blindcoin_copy (item_saved->blindcoin);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_RESERVE:
|
||||
save_location->reserve = item_saved->reserve;
|
||||
save_location->reserve = PERF_TALER_MINTDB_reserve_copy (item_saved->reserve);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_DENOMINATION_INFO:
|
||||
save_location->dki = item_saved->dki;
|
||||
save_location->dki = PERF_TALER_MINTDB_denomination_copy (item_saved->dki);
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_COIN_INFO:
|
||||
@ -305,9 +306,6 @@ interpret_save_array (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++;
|
||||
}
|
||||
}
|
||||
@ -316,21 +314,32 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
static void
|
||||
interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
unsigned int loop_index, save_index;
|
||||
unsigned int loop_iter;
|
||||
int loop_index, save_index;
|
||||
union PERF_TALER_MINTDB_Data zero = {0};
|
||||
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);
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(loop_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.load_array.label_loop)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.load_array.label_save)));
|
||||
loop_iter = state->cmd[loop_index].details.loop.curr_iteration;
|
||||
{
|
||||
int i, quotient;
|
||||
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++){
|
||||
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[
|
||||
state->cmd[state->i].details.load_array.permutation[
|
||||
state->cmd[loop_index].details.loop.curr_iteration]];
|
||||
|
||||
loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_index];
|
||||
switch (state->cmd[state->i].exposed_type)
|
||||
{
|
||||
case PERF_TALER_MINTDB_TIME:
|
||||
@ -392,14 +401,18 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GAUGER:
|
||||
{
|
||||
unsigned int start_index, stop_index;
|
||||
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);
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(start_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.gauger.label_start)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(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 +
|
||||
@ -437,8 +450,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
|
||||
{
|
||||
struct TALER_MINTDB_Deposit *deposit =
|
||||
PERF_TALER_MINTDB_deposit_init ();
|
||||
int dki_index;
|
||||
struct TALER_MINTDB_Deposit *deposit;
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(dki_index = cmd_find(state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.insert_deposit.label_dki)));
|
||||
GNUNET_assert (NULL !=
|
||||
(deposit = PERF_TALER_MINTDB_deposit_init (
|
||||
state->cmd[dki_index].exposed.dki)));
|
||||
|
||||
GNUNET_assert (
|
||||
state->plugin->insert_deposit (state->plugin->cls,
|
||||
@ -450,12 +470,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
|
||||
{
|
||||
struct TALER_MINTDB_Deposit *deposit =
|
||||
state->cmd[cmd_find (state->cmd,
|
||||
int source_index;
|
||||
struct TALER_MINTDB_Deposit *deposit;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(source_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_deposit.label_source)]
|
||||
.exposed.deposit; // Get the deposit from the source
|
||||
GNUNET_assert (NULL != deposit);
|
||||
.details.get_deposit.label_source)));
|
||||
GNUNET_assert (NULL !=
|
||||
(deposit = state->cmd[source_index].exposed.deposit));
|
||||
state->plugin->have_deposit (state->plugin->cls,
|
||||
state->session,
|
||||
deposit);
|
||||
@ -465,10 +488,12 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_RESERVE:
|
||||
{
|
||||
struct TALER_MINTDB_Reserve *reserve;
|
||||
json_t *details = json_pack ("si","justification",
|
||||
json_t *details = NULL;
|
||||
GNUNET_assert (NULL !=
|
||||
(details = json_pack ("{s:i}","justification",
|
||||
GNUNET_CRYPTO_random_u32 (
|
||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
UINT32_MAX));
|
||||
UINT32_MAX))));
|
||||
reserve = PERF_TALER_MINTDB_reserve_init ();
|
||||
state->plugin->reserves_in_insert (
|
||||
state->plugin->cls,
|
||||
@ -484,15 +509,19 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_RESERVE:
|
||||
{
|
||||
struct TALER_MINTDB_Reserve *reserve =
|
||||
state->cmd[cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_reserve.label_source)]
|
||||
.exposed.reserve; // Get the deposit from the source
|
||||
int source_index;
|
||||
struct TALER_MINTDB_Reserve *reserve;
|
||||
|
||||
state->plugin->reserve_get (state->plugin->cls,
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(source_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_reserve.label_source)));
|
||||
GNUNET_assert (NULL !=
|
||||
(reserve = state->cmd[source_index].exposed.reserve));
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
(state->plugin->reserve_get (state->plugin->cls,
|
||||
state->session,
|
||||
reserve);
|
||||
reserve)));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -511,11 +540,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DENOMINATION:
|
||||
{
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *dki =
|
||||
state->cmd[cmd_find (state->cmd,
|
||||
int source_index;
|
||||
struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(source_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_denomination.label_source)]
|
||||
.exposed.dki;
|
||||
.details.get_denomination.label_source)));
|
||||
GNUNET_assert (NULL !=
|
||||
(dki = state->cmd[source_index].exposed.dki));
|
||||
state->plugin->get_denomination_info (state->plugin->cls,
|
||||
state->session,
|
||||
&dki->denom_pub,
|
||||
@ -525,8 +558,22 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
|
||||
{
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin =
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init ();
|
||||
int dki_index, reserve_index;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin ;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(dki_index = cmd_find (
|
||||
state->cmd,
|
||||
state->cmd[state->i].details.insert_withdraw.label_dki)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(reserve_index = cmd_find (
|
||||
state->cmd,
|
||||
state->cmd[state->i].details.insert_withdraw.label_reserve)));
|
||||
GNUNET_assert (NULL !=
|
||||
(blindcoin =
|
||||
PERF_TALER_MINTDB_collectable_blindcoin_init (
|
||||
state->cmd[dki_index].exposed.dki,
|
||||
state->cmd[reserve_index].exposed.reserve)));
|
||||
|
||||
state->plugin->insert_withdraw_info (state->plugin->cls,
|
||||
state->session,
|
||||
@ -537,12 +584,15 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_WITHDRAW:
|
||||
{
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin =
|
||||
state->cmd[cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_denomination.label_source)]
|
||||
.exposed.blindcoin;
|
||||
int source_index;
|
||||
struct TALER_MINTDB_CollectableBlindcoin *blindcoin ;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(source_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.get_denomination.label_source)));
|
||||
GNUNET_assert (NULL !=
|
||||
(blindcoin = state->cmd[source_index].exposed.blindcoin));
|
||||
state->plugin->get_withdraw_info (state->plugin->cls,
|
||||
state->session,
|
||||
&blindcoin->h_coin_envelope,
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Prints @ _label to stdout
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_DEBUG(_label) \
|
||||
{ \
|
||||
@ -46,6 +46,7 @@
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_NONE \
|
||||
}
|
||||
|
||||
/**
|
||||
* The begining of a loop
|
||||
* @param _label the name of the loop
|
||||
@ -85,6 +86,10 @@
|
||||
/**
|
||||
* Commits the duration between @a _label_start and @a _label_stop
|
||||
* to Gauger with @a _description explaining
|
||||
* @param _label_start label of the start of the measurment
|
||||
* @param _label_stop label of the end of the measurment
|
||||
* @param _description description of the measure displayed in gauger
|
||||
* @param _divide number of measurments in the interval
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _description, _divide) \
|
||||
{ \
|
||||
@ -150,16 +155,65 @@
|
||||
.label_save = _label_save \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts informations about a denomination key in the database
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_DENOMINATION_INFO, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the database about informations regarding a specific denomination key
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GET_DENOMINATION(_label, _label_source) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GET_DENOMINATION, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
||||
.details.get_denomination.label_source = _label_source, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reserve in the database
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_RESERVE, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_RESERVE \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Polls the database for a secific reserve's details
|
||||
* @param _label_source Source for the reserve to poll
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE(_label, _label_source) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GET_RESERVE, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
||||
.details.get_reserve.label_source = _label_source \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a deposit into the database
|
||||
* @param _label_dki source to use for the denomination key
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label) \
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT(_label, _label_dki) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT,\
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_DEPOSIT, \
|
||||
.details.insert_deposit.label_dki = _label_dki, \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a deposit is in the database
|
||||
* @param _label_deposit Label of the deposit to use
|
||||
@ -172,39 +226,22 @@
|
||||
.details.get_deposit.label_source = _label_deposit \
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reserve in the database
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_RESERVE \
|
||||
.label = _label \
|
||||
.exposed_type = PERF_TALER_MINTDB_RESERVE \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Polls the database for a secific reserve's details
|
||||
* @param _label_source Source for the reserve to poll
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GET_RESERVE(_label, _label_source) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GET_RESERVE \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
||||
.details.get_reserve.label_source = _label_source \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inserts informations about a withdrawal in the database
|
||||
* @param _label_dki denomination key used to sign the coin
|
||||
* @param _label_reserve reserve used to emmit the coin
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label) \
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label, _label_dki, _label_reserve) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_BLINDCOIN, \
|
||||
}\
|
||||
.details.insert_withdraw = {\
|
||||
.label_dki = _label_dki, \
|
||||
.label_reserve = _label_reserve, \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -218,27 +255,6 @@
|
||||
.details.get_withdraw.label_source = _label_source, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts informations about a denomination key in the database
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_DENOMINATION_KEY, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the database about informations regarding a specific denomination key
|
||||
*/
|
||||
#define PERF_TALER_MINTDB_INIT_CMD_GET_DENOMINATION(_label, _label_source) \
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GET_DENOMINATION, \
|
||||
.label = _label, \
|
||||
.exposed_type = PERF_TALER_MINTDB_NONE, \
|
||||
.details.get_denomination.label_source = _label_source, \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The type of data stored
|
||||
@ -445,6 +461,18 @@ struct PERF_TALER_MINTDB_CMD_load_array_details
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Data used by the command insert_deposit
|
||||
*/
|
||||
struct PERF_TALER_MINTDB_CMD_insert_deposit_details
|
||||
{
|
||||
/**
|
||||
* Label of the source where the reserve used to create the coin is
|
||||
*/
|
||||
const char *label_dki;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Extra data requiered for the GET_DEPOSIT command
|
||||
*/
|
||||
@ -478,6 +506,22 @@ struct PERF_TALER_MINTDB_CMD_get_denomination_details
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Extra data related to the get withdraw command
|
||||
*/
|
||||
struct PERF_TALER_MINTDB_CMD_insert_withdraw_details
|
||||
{
|
||||
/**
|
||||
* label of the denomination key used to sign the coin
|
||||
*/
|
||||
const char *label_dki;
|
||||
|
||||
/**
|
||||
* label of the reserve the money to mint the coin comes from
|
||||
*/
|
||||
const char *label_reserve;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extra data requiered for refreshing coins
|
||||
*/
|
||||
@ -500,10 +544,12 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
struct PERF_TALER_MINTDB_CMD_gauger_details gauger;
|
||||
struct PERF_TALER_MINTDB_CMD_save_array_details save_array;
|
||||
struct PERF_TALER_MINTDB_CMD_load_array_details load_array;
|
||||
struct PERF_TALER_MINTDB_CMD_insert_deposit_details insert_deposit;
|
||||
struct PERF_TALER_MINTDB_CMD_get_deposit_details get_deposit;
|
||||
struct PERF_TALER_MINTDB_CMD_get_reserve_details get_reserve;
|
||||
struct PERF_TALER_MINTDB_CMD_get_denomination_details get_denomination;
|
||||
struct PERF_TALER_MINTDB_CMD_refresh_coin_details refresh;
|
||||
struct PERF_TALER_MINTDB_CMD_insert_withdraw_details insert_withdraw;
|
||||
};
|
||||
|
||||
|
||||
@ -536,12 +582,6 @@ struct PERF_TALER_MINTDB_Cmd
|
||||
* Data easily accessible
|
||||
*/
|
||||
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
|
||||
*/
|
||||
unsigned int exposed_saved;
|
||||
};
|
||||
|
||||
|
||||
|
@ -22,10 +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_DEPOSIT_INIT 100
|
||||
#define PERF_TALER_MINTDB_NB_DEPOSIT_GET 10
|
||||
#define PERF_TALER_MINTDB_NB_RESERVE_INIT 10000
|
||||
#define PERF_TALER_MINTDB_NB_RESERVE_SAVE 1000
|
||||
|
||||
|
||||
#define PERF_TALER_MINTDB_NB_DEPOSIT_INIT 100000
|
||||
#define PERF_TALER_MINTDB_NB_DEPOSIT_SAVE 1000
|
||||
|
||||
|
||||
#define PERF_TALER_MINTDB_NB_WITHDRAW_INIT 100000
|
||||
#define PERF_TALER_MINTDB_NB_WITHDRAW_SAVE 1000
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user