avoid passing int's as void*'s in benchmark logic

This commit is contained in:
Christian Grothoff 2016-06-15 16:04:29 +02:00
parent 7588f08238
commit b31c62039d
2 changed files with 159 additions and 113 deletions

View File

@ -17,6 +17,7 @@
* @file src/benchmark/taler-exchange-benchmark.c * @file src/benchmark/taler-exchange-benchmark.c
* @brief exchange's benchmark * @brief exchange's benchmark
* @author Marcello Stanisci * @author Marcello Stanisci
* @author Christian Grothoff
*/ */
#include "platform.h" #include "platform.h"
#include "taler_util.h" #include "taler_util.h"
@ -116,6 +117,11 @@ struct Reserve
*/ */
struct TALER_EXCHANGE_AdminAddIncomingHandle *aih; struct TALER_EXCHANGE_AdminAddIncomingHandle *aih;
/**
* Index of this reserve in the #reserves array.
*/
unsigned int reserve_index;
}; };
@ -189,6 +195,11 @@ struct Coin
*/ */
unsigned int reserve_index; unsigned int reserve_index;
/**
* Index of this coin in the #coins array.
*/
unsigned int coin_index;
/** /**
* If the coin has to be refreshed, this value indicates * If the coin has to be refreshed, this value indicates
* how much is left on this coin * how much is left on this coin
@ -237,6 +248,11 @@ static struct Coin *coins;
*/ */
static unsigned int transaction_id; static unsigned int transaction_id;
/**
* Transfer UUID counter, used in /admin/add/incoming
*/
static unsigned int transfer_uuid;
/** /**
* This key (usually provided by merchants) is needed when depositing coins, * This key (usually provided by merchants) is needed when depositing coins,
* even though there is no merchant acting in the benchmark * even though there is no merchant acting in the benchmark
@ -248,6 +264,12 @@ static struct TALER_MerchantPrivateKeyP merchant_priv;
*/ */
static char *exchange_uri; static char *exchange_uri;
/**
* URI under which the administrative exchange is reachable during the
* benchmark.
*/
static char *exchange_admin_uri;
/** /**
* How many coins (AKA withdraw operations) per reserve should be withdrawn * How many coins (AKA withdraw operations) per reserve should be withdrawn
*/ */
@ -389,10 +411,11 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys,
return NULL; return NULL;
} }
/** /**
* Function called with the result of the /refresh/reveal operation. * Function called with the result of the /refresh/reveal operation.
* *
* @param cls closure with the interpreter state * @param cls closure with the `struct RefreshRevealCls *`
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed * @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed
@ -409,10 +432,12 @@ reveal_cb (void *cls,
const json_t *full_response) const json_t *full_response)
{ {
struct RefreshRevealCls *rrcls = cls; struct RefreshRevealCls *rrcls = cls;
struct Coin *coin;
unsigned int i; unsigned int i;
const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_Keys *keys;
coins[rrcls->coin_index].rrh = NULL; coin = &coins[rrcls->coin_index];
coin->rrh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
GNUNET_free (rrcls); GNUNET_free (rrcls);
@ -425,7 +450,7 @@ reveal_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Coin #%d revealed!\n", "Coin #%d revealed!\n",
rrcls->coin_index); rrcls->coin_index);
coins[rrcls->coin_index].left.value = 0; coin->left.value = 0;
} }
keys = TALER_EXCHANGE_get_keys (exchange); keys = TALER_EXCHANGE_get_keys (exchange);
@ -440,12 +465,14 @@ reveal_cb (void *cls,
"# of coins after refresh: %d\n", "# of coins after refresh: %d\n",
revealed_str, revealed_str,
ncoins); ncoins);
GNUNET_free (revealed_str); GNUNET_free (revealed_str);
fresh_coin.reserve_index = coins[rrcls->coin_index].reserve_index;
fresh_coin.reserve_index = coin->reserve_index;
fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]); fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]);
fresh_coin.sig = sigs[i]; fresh_coin.sig = sigs[i];
GNUNET_array_append (coins, ncoins, fresh_coin); GNUNET_array_append (coins,
ncoins,
fresh_coin);
} }
GNUNET_free (rrcls); GNUNET_free (rrcls);
} }
@ -454,7 +481,7 @@ reveal_cb (void *cls,
/** /**
* Function called with the result of the /refresh/melt operation. * Function called with the result of the /refresh/melt operation.
* *
* @param cls closure with the interpreter state * @param cls closure with the `struct RefreshRevealCls *`
* @param http_status HTTP response code, never #MHD_HTTP_OK (200) as for successful intermediate response this callback is skipped. * @param http_status HTTP response code, never #MHD_HTTP_OK (200) as for successful intermediate response this callback is skipped.
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param noreveal_index choice by the exchange in the cut-and-choose protocol, * @param noreveal_index choice by the exchange in the cut-and-choose protocol,
@ -471,8 +498,10 @@ melt_cb (void *cls,
{ {
/* free'd in `reveal_cb` */ /* free'd in `reveal_cb` */
struct RefreshRevealCls *rrcls = cls; struct RefreshRevealCls *rrcls = cls;
struct Coin *coin;
coins[rrcls->coin_index].rmh = NULL; coin = &coins[rrcls->coin_index];
coin->rmh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
json_dumpf (full_response, stderr, 0); json_dumpf (full_response, stderr, 0);
@ -480,7 +509,7 @@ melt_cb (void *cls,
return; return;
} }
coins[rrcls->coin_index].rrh coin->rrh
= TALER_EXCHANGE_refresh_reveal (exchange, = TALER_EXCHANGE_refresh_reveal (exchange,
rrcls->blob_size, rrcls->blob_size,
rrcls->blob, rrcls->blob,
@ -494,7 +523,7 @@ melt_cb (void *cls,
* Function called upon completion of our /reserve/withdraw request. * Function called upon completion of our /reserve/withdraw request.
* This is merely the function which spends withdrawn coins * This is merely the function which spends withdrawn coins
* *
* @param cls closure with the interpreter state * @param cls closure with the `struct Coin` we are withdrawing
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param sig signature over the coin, NULL on error * @param sig signature over the coin, NULL on error
@ -510,7 +539,7 @@ reserve_withdraw_cb (void *cls,
/** /**
* Function called with the result of a /deposit operation. * Function called with the result of a /deposit operation.
* *
* @param cls closure with the interpreter state * @param cls closure with the `struct Coin` that we are processing
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit; * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit;
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param exchange_pub public key used by the exchange for signing * @param exchange_pub public key used by the exchange for signing
@ -523,9 +552,9 @@ deposit_cb (void *cls,
const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *obj) const json_t *obj)
{ {
unsigned int coin_index = (unsigned int) (long) cls; struct Coin *coin = cls;
coins[coin_index].dh = NULL; coin->dh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
json_dumpf (obj, stderr, 0); json_dumpf (obj, stderr, 0);
@ -534,8 +563,8 @@ deposit_cb (void *cls,
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Coin #%d correctly spent!\n", "Coin #%d correctly spent!\n",
coin_index); coin->coin_index);
if (GNUNET_YES == coins[coin_index].refresh) if (GNUNET_YES == coin->refresh)
{ {
struct RefreshRevealCls *rrcls; struct RefreshRevealCls *rrcls;
char *blob; char *blob;
@ -550,15 +579,15 @@ deposit_cb (void *cls,
unsigned long long acc_value; unsigned long long acc_value;
TALER_amount_get_zero (currency, &curr); TALER_amount_get_zero (currency, &curr);
curr.value = COIN_VALUE >> 1;
acc_value = 0; acc_value = 0;
keys = TALER_EXCHANGE_get_keys (exchange); keys = TALER_EXCHANGE_get_keys (exchange);
for (; curr.value > 0; curr.value = curr.value >> 1) for (curr.value = COIN_VALUE >> 1; curr.value > 0; curr.value = curr.value >> 1)
{ {
if (acc_value + curr.value <= coins[coin_index].left.value) if (acc_value + curr.value <= coin->left.value)
{ {
GNUNET_array_append (denoms, ndenoms, curr); GNUNET_array_append (denoms,
ndenoms,
curr);
GNUNET_assert (NULL != (curr_dpk = find_pk (keys, &curr))); GNUNET_assert (NULL != (curr_dpk = find_pk (keys, &curr)));
GNUNET_array_append (dpks, ndenoms2, *curr_dpk); GNUNET_array_append (dpks, ndenoms2, *curr_dpk);
acc_value += curr.value; acc_value += curr.value;
@ -567,10 +596,10 @@ deposit_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"# of coins to get in melt: %d\n", "# of coins to get in melt: %d\n",
ndenoms2); ndenoms2);
blob = TALER_EXCHANGE_refresh_prepare (&coins[coin_index].coin_priv, blob = TALER_EXCHANGE_refresh_prepare (&coin->coin_priv,
&coins[coin_index].left, &coin->left,
&coins[coin_index].sig, &coin->sig,
coins[coin_index].pk, coin->pk,
GNUNET_YES, GNUNET_YES,
ndenoms2, ndenoms2,
dpks, dpks,
@ -588,14 +617,14 @@ deposit_cb (void *cls,
rrcls = GNUNET_new (struct RefreshRevealCls); rrcls = GNUNET_new (struct RefreshRevealCls);
rrcls->blob = blob; rrcls->blob = blob;
rrcls->blob_size = blob_size; rrcls->blob_size = blob_size;
rrcls->coin_index = coin_index; rrcls->coin_index = coin->coin_index;
rrcls->denoms = denoms; rrcls->denoms = denoms;
coins[coin_index].rmh = TALER_EXCHANGE_refresh_melt (exchange, coin->rmh = TALER_EXCHANGE_refresh_melt (exchange,
blob_size, blob_size,
blob, blob,
&melt_cb, &melt_cb,
rrcls); rrcls);
if (NULL == coins[coin_index].rmh) if (NULL == coin->rmh)
{ {
fail ("Impossible to issue a melt request to the exchange"); fail ("Impossible to issue a melt request to the exchange");
return; return;
@ -604,17 +633,18 @@ deposit_cb (void *cls,
else else
{ /* re-withdraw */ { /* re-withdraw */
struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv; struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv;
coin_priv = GNUNET_CRYPTO_eddsa_key_create (); coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
coins[coin_index].coin_priv.eddsa_priv = *coin_priv; coin->coin_priv.eddsa_priv = *coin_priv;
GNUNET_free (coin_priv); GNUNET_free (coin_priv);
coins[coin_index].wsh = coin->wsh =
TALER_EXCHANGE_reserve_withdraw (exchange, TALER_EXCHANGE_reserve_withdraw (exchange,
coins[coin_index].pk, coin->pk,
&reserves[coins[coin_index].reserve_index].reserve_priv, &reserves[coin->reserve_index].reserve_priv,
&coins[coin_index].coin_priv, &coin->coin_priv,
&blinding_key, &blinding_key,
reserve_withdraw_cb, &reserve_withdraw_cb,
(void *) (long) coin_index); coin);
} }
} }
@ -624,7 +654,7 @@ deposit_cb (void *cls,
* This is merely the function which spends withdrawn coins. For each * This is merely the function which spends withdrawn coins. For each
* spent coin, ti either refresh it or re-withdraw it. * spent coin, ti either refresh it or re-withdraw it.
* *
* @param cls closure with the interpreter state * @param cls closure with our `struct Coin`
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param sig signature over the coin, NULL on error * @param sig signature over the coin, NULL on error
@ -636,10 +666,9 @@ reserve_withdraw_cb (void *cls,
const struct TALER_DenominationSignature *sig, const struct TALER_DenominationSignature *sig,
const json_t *full_response) const json_t *full_response)
{ {
struct Coin *coin = cls;
unsigned int coin_index = (unsigned int) (long) cls; coin->wsh = NULL;
coins[coin_index].wsh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
json_dumpf (full_response, stderr, 0); json_dumpf (full_response, stderr, 0);
@ -648,8 +677,8 @@ reserve_withdraw_cb (void *cls,
} }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%d-th coin withdrawn\n", "%d-th coin withdrawn\n",
coin_index); coin->coin_index);
coins[coin_index].sig.rsa_signature = coin->sig.rsa_signature =
GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature); GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature);
if (GNUNET_OK == eval_probability (SPEND_PROBABILITY)) if (GNUNET_OK == eval_probability (SPEND_PROBABILITY))
{ {
@ -663,44 +692,49 @@ reserve_withdraw_cb (void *cls,
struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_CoinSpendSignatureP coin_sig; struct TALER_CoinSpendSignatureP coin_sig;
GNUNET_CRYPTO_eddsa_key_get_public (&coins[coin_index].coin_priv.eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&coin->coin_priv.eddsa_priv,
&coin_pub.eddsa_pub); &coin_pub.eddsa_pub);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&h_contract, &h_contract,
sizeof (h_contract)); sizeof (h_contract));
timestamp = GNUNET_TIME_absolute_get (); timestamp = GNUNET_TIME_absolute_get ();
wire_deadline = GNUNET_TIME_absolute_add (timestamp, GNUNET_TIME_UNIT_WEEKS); wire_deadline = GNUNET_TIME_absolute_add (timestamp,
refund_deadline = GNUNET_TIME_absolute_add (timestamp, GNUNET_TIME_UNIT_DAYS); GNUNET_TIME_UNIT_WEEKS);
refund_deadline = GNUNET_TIME_absolute_add (timestamp,
GNUNET_TIME_UNIT_DAYS);
GNUNET_TIME_round_abs (&timestamp); GNUNET_TIME_round_abs (&timestamp);
GNUNET_TIME_round_abs (&wire_deadline); GNUNET_TIME_round_abs (&wire_deadline);
GNUNET_TIME_round_abs (&refund_deadline); GNUNET_TIME_round_abs (&refund_deadline);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Spending %d-th coin\n", coin_index); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Spending %d-th coin\n",
coin->coin_index);
if (GNUNET_YES == eval_probability (REFRESH_PROBABILITY) if ( (GNUNET_YES == eval_probability (REFRESH_PROBABILITY)) &&
&& GNUNET_NO == refreshed_once) (GNUNET_NO == refreshed_once) )
{ {
/** /**
* Always spending 1 out of 8 KUDOS. To be improved by randomly * Always spending 1 out of 8 KUDOS. To be improved by randomly
* picking the spent amount * picking the spent amount
*/ */
struct TALER_Amount one; struct TALER_Amount one;
TALER_amount_get_zero (currency, &one); TALER_amount_get_zero (currency, &one);
one.value = 1; one.value = 1;
TALER_amount_subtract (&amount, TALER_amount_subtract (&amount,
&one, &one,
&coins[coin_index].pk->fee_deposit); &coin->pk->fee_deposit);
TALER_amount_subtract (&coins[coin_index].left, TALER_amount_subtract (&coin->left,
&coins[coin_index].pk->value, &coin->pk->value,
&one); &one);
coins[coin_index].refresh = GNUNET_YES; coin->refresh = GNUNET_YES;
refreshed_once = GNUNET_YES; refreshed_once = GNUNET_YES;
} }
else else
{ {
TALER_amount_subtract (&amount, TALER_amount_subtract (&amount,
&coins[coin_index].pk->value, &coin->pk->value,
&coins[coin_index].pk->fee_deposit); &coin->pk->fee_deposit);
} }
memset (&dr, 0, sizeof (dr)); memset (&dr, 0, sizeof (dr));
dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS));
@ -716,33 +750,33 @@ reserve_withdraw_cb (void *cls,
TALER_amount_hton (&dr.amount_with_fee, TALER_amount_hton (&dr.amount_with_fee,
&amount); &amount);
TALER_amount_hton (&dr.deposit_fee, TALER_amount_hton (&dr.deposit_fee,
&coins[coin_index].pk->fee_deposit); &coin->pk->fee_deposit);
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
&merchant_pub.eddsa_pub); &merchant_pub.eddsa_pub);
dr.merchant = merchant_pub; dr.merchant = merchant_pub;
dr.coin_pub = coin_pub; dr.coin_pub = coin_pub;
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_sign (&coins[coin_index].coin_priv.eddsa_priv, GNUNET_CRYPTO_eddsa_sign (&coin->coin_priv.eddsa_priv,
&dr.purpose, &dr.purpose,
&coin_sig.eddsa_signature)); &coin_sig.eddsa_signature));
coins[coin_index].dh = TALER_EXCHANGE_deposit (exchange, coin->dh = TALER_EXCHANGE_deposit (exchange,
&amount, &amount,
wire_deadline, wire_deadline,
merchant_details, merchant_details,
&h_contract, &h_contract,
&coin_pub, &coin_pub,
&coins[coin_index].sig, &coin->sig,
&coins[coin_index].pk->key, &coin->pk->key,
timestamp, timestamp,
transaction_id, transaction_id,
&merchant_pub, &merchant_pub,
refund_deadline, refund_deadline,
&coin_sig, &coin_sig,
&deposit_cb, &deposit_cb,
(void *) (long) coin_index); coin);
if (NULL == coins[coin_index].dh) if (NULL == coin->dh)
{ {
json_decref (merchant_details); json_decref (merchant_details);
fail ("An error occurred while calling deposit API"); fail ("An error occurred while calling deposit API");
@ -757,7 +791,7 @@ reserve_withdraw_cb (void *cls,
* Function called upon completion of our /admin/add/incoming request. * Function called upon completion of our /admin/add/incoming request.
* Its duty is withdrawing coins on the freshly created reserve. * Its duty is withdrawing coins on the freshly created reserve.
* *
* @param cls closure with the interpreter state * @param cls closure with the `struct Reserve *`
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
* 0 if the exchange's reply is bogus (fails to follow the protocol) * 0 if the exchange's reply is bogus (fails to follow the protocol)
* @param full_response full response from the exchange (for logging, in case of errors) * @param full_response full response from the exchange (for logging, in case of errors)
@ -767,18 +801,17 @@ add_incoming_cb (void *cls,
unsigned int http_status, unsigned int http_status,
const json_t *full_response) const json_t *full_response)
{ {
unsigned int reserve_index = (unsigned int) (long) cls; struct Reserve *r = cls;
struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv; struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv;
unsigned int i; unsigned int i;
unsigned int coin_index; unsigned int coin_index;
struct TALER_Amount amount; struct TALER_Amount amount;
const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_Keys *keys;
keys = TALER_EXCHANGE_get_keys (exchange); r->aih = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"/admin/add/incoming callback called on %d-th reserve\n", "/admin/add/incoming callback called on %d-th reserve\n",
reserve_index); r->reserve_index);
reserves[reserve_index].aih = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
json_dumpf (full_response, stderr, 0); json_dumpf (full_response, stderr, 0);
@ -786,24 +819,30 @@ add_incoming_cb (void *cls,
return; return;
} }
keys = TALER_EXCHANGE_get_keys (exchange);
for (i=0; i < COINS_PER_RESERVE; i++) for (i=0; i < COINS_PER_RESERVE; i++)
{ {
struct Coin *coin;
coin_index = r->reserve_index * COINS_PER_RESERVE + i;
coin = &coins[coin_index];
coin->coin_index = coin_index;
coin_priv = GNUNET_CRYPTO_eddsa_key_create (); coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
coin_index = reserve_index * COINS_PER_RESERVE + i; coin->coin_priv.eddsa_priv = *coin_priv;
coins[coin_index].coin_priv.eddsa_priv = *coin_priv;
coins[coin_index].reserve_index = reserve_index;
TALER_amount_get_zero (currency, &amount);
amount.value = COIN_VALUE;
GNUNET_assert (NULL != (coins[coin_index].pk = find_pk (keys, &amount)));
GNUNET_free (coin_priv); GNUNET_free (coin_priv);
coins[coin_index].wsh = coin->reserve_index = r->reserve_index;
TALER_amount_get_zero (currency,
&amount);
amount.value = COIN_VALUE;
GNUNET_assert (NULL != (coin->pk = find_pk (keys, &amount)));
coin->wsh =
TALER_EXCHANGE_reserve_withdraw (exchange, TALER_EXCHANGE_reserve_withdraw (exchange,
coins[coin_index].pk, coin->pk,
&reserves[reserve_index].reserve_priv, &r->reserve_priv,
&coins[coin_index].coin_priv, &coin->coin_priv,
&blinding_key, &blinding_key,
reserve_withdraw_cb, &reserve_withdraw_cb,
(void *) (long) coin_index); coin);
} }
} }
@ -819,7 +858,6 @@ benchmark_run (void *cls)
unsigned int i; unsigned int i;
struct GNUNET_CRYPTO_EddsaPrivateKey *priv; struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
json_t *transfer_details; json_t *transfer_details;
char *uuid;
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Absolute execution_date; struct GNUNET_TIME_Absolute execution_date;
struct TALER_Amount reserve_amount; struct TALER_Amount reserve_amount;
@ -849,26 +887,27 @@ benchmark_run (void *cls)
for (i=0;i < nreserves;i++) for (i=0;i < nreserves;i++)
{ {
priv = GNUNET_CRYPTO_eddsa_key_create (); struct Reserve *r = &reserves[i];
reserves[i].reserve_priv.eddsa_priv = *priv;
GNUNET_free (priv);
// FIXME: avoid use of JSON parser
GNUNET_asprintf (&uuid, "{ \"uuid\":%d}", i);
transfer_details = json_loads (uuid, JSON_REJECT_DUPLICATES, NULL);
GNUNET_free (uuid);
GNUNET_CRYPTO_eddsa_key_get_public (&reserves[i].reserve_priv.eddsa_priv,
&reserve_pub.eddsa_pub);
reserves[i].aih = TALER_EXCHANGE_admin_add_incoming (exchange, priv = GNUNET_CRYPTO_eddsa_key_create ();
"http://localhost:18080/", r->reserve_priv.eddsa_priv = *priv;
&reserve_pub, GNUNET_free (priv);
&reserve_amount, r->reserve_index = i;
execution_date, transfer_details = json_pack ("{s:I}",
bank_details, "uuid", (json_int_t) transfer_uuid++);
transfer_details, GNUNET_assert (NULL != transfer_details);
&add_incoming_cb, GNUNET_CRYPTO_eddsa_key_get_public (&r->reserve_priv.eddsa_priv,
(void *) (long) i); &reserve_pub.eddsa_pub);
GNUNET_assert (NULL != reserves[i].aih); r->aih = TALER_EXCHANGE_admin_add_incoming (exchange,
exchange_admin_uri,
&reserve_pub,
&reserve_amount,
execution_date,
bank_details,
transfer_details,
&add_incoming_cb,
r);
GNUNET_assert (NULL != r->aih);
json_decref (transfer_details); json_decref (transfer_details);
} }
json_decref (bank_details); json_decref (bank_details);
@ -1187,7 +1226,11 @@ main (int argc,
&GNUNET_GETOPT_set_uint, &pool_size}, &GNUNET_GETOPT_set_uint, &pool_size},
{'e', "exchange-uri", "URI", {'e', "exchange-uri", "URI",
"URI of the exchange", GNUNET_YES, "URI of the exchange", GNUNET_YES,
&GNUNET_GETOPT_set_string, &exchange_uri} &GNUNET_GETOPT_set_string, &exchange_uri},
{'E', "exchange-admin-uri", "URI",
"URI of the administrative interface of the exchange", GNUNET_YES,
&GNUNET_GETOPT_set_string, &exchange_admin_uri},
GNUNET_GETOPT_OPTION_END
}; };
GNUNET_log_setup ("taler-exchange-benchmark", GNUNET_log_setup ("taler-exchange-benchmark",
@ -1198,6 +1241,8 @@ main (int argc,
options, argc, argv)); options, argc, argv));
if (NULL == exchange_uri) if (NULL == exchange_uri)
exchange_uri = GNUNET_strdup ("http://localhost:8081/"); exchange_uri = GNUNET_strdup ("http://localhost:8081/");
if (NULL == exchange_admin_uri)
exchange_admin_uri = GNUNET_strdup ("http://localhost:18080/");
if (run_exchange) if (run_exchange)
{ {
char *wget; char *wget;

View File

@ -283,6 +283,7 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
"merchant_pub", GNUNET_JSON_from_data_auto (&rr.merchant), "merchant_pub", GNUNET_JSON_from_data_auto (&rr.merchant),
"merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig) "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig)
); );
GNUNET_assert (NULL != refund_obj);
rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle); rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle);
rh->exchange = exchange; rh->exchange = exchange;