merge refresh closure into struct Coin

This commit is contained in:
Christian Grothoff 2016-06-15 16:42:43 +02:00
parent e4b9a151a6
commit 3876b70eb4

View File

@ -18,6 +18,12 @@
* @brief exchange's benchmark * @brief exchange's benchmark
* @author Marcello Stanisci * @author Marcello Stanisci
* @author Christian Grothoff * @author Christian Grothoff
*
* TODO:
* - track state of reserve/coin with its struct
* - have global work-lists with available slots for
* admin, deposit and withdraw operations (and stats!)
* - implement the main loop of the benchmark
*/ */
#include "platform.h" #include "platform.h"
#include "taler_util.h" #include "taler_util.h"
@ -30,34 +36,6 @@
#include <jansson.h> #include <jansson.h>
/**
* Information needed by the /refresh/melt's callback
*/
struct RefreshRevealCls
{
/**
* The result of a #TALER_EXCHANGE_refresh_prepare() call
*/
const char *blob;
/**
* Size of @e blob
*/
size_t blob_size;
/**
* Which coin in the list are we melting
*/
unsigned int coin_index;
/**
* Array of denominations expected to get from melt
*/
struct TALER_Amount *denoms;
};
/** /**
* Needed information for a reserve. Other values are the same for all reserves, therefore defined in global variables * Needed information for a reserve. Other values are the same for all reserves, therefore defined in global variables
*/ */
@ -124,6 +102,21 @@ struct Coin
*/ */
struct TALER_EXCHANGE_DepositHandle *dh; struct TALER_EXCHANGE_DepositHandle *dh;
/**
* The result of a #TALER_EXCHANGE_refresh_prepare() call
*/
const char *blob;
/**
* Size of @e blob
*/
size_t blob_size;
/**
* Array of denominations expected to get from melt
*/
struct TALER_Amount *denoms;
/** /**
* Flag indicating if the coin is going to be refreshed * Flag indicating if the coin is going to be refreshed
*/ */
@ -431,7 +424,7 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys,
/** /**
* 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 `struct RefreshRevealCls *` * @param cls closure with the `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 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
@ -447,16 +440,13 @@ reveal_cb (void *cls,
const struct TALER_DenominationSignature *sigs, const struct TALER_DenominationSignature *sigs,
const json_t *full_response) const json_t *full_response)
{ {
struct RefreshRevealCls *rrcls = cls; struct Coin *coin = cls;
struct Coin *coin;
unsigned int i; unsigned int i;
const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_Keys *keys;
coin = &coins[rrcls->coin_index];
coin->rrh = NULL; coin->rrh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
GNUNET_free (rrcls);
json_dumpf (full_response, stderr, 0); json_dumpf (full_response, stderr, 0);
fail ("Not all coins correctly revealed"); fail ("Not all coins correctly revealed");
return; return;
@ -465,7 +455,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); coin->coin_index);
coin->left.value = 0; coin->left.value = 0;
} }
@ -475,7 +465,7 @@ reveal_cb (void *cls,
struct Coin fresh_coin; struct Coin fresh_coin;
char *revealed_str; char *revealed_str;
revealed_str = TALER_amount_to_string (&rrcls->denoms[i]); revealed_str = TALER_amount_to_string (&coin->denoms[i]);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"revealing %s # of coins after refresh: %d\n", "revealing %s # of coins after refresh: %d\n",
revealed_str, revealed_str,
@ -483,13 +473,13 @@ reveal_cb (void *cls,
GNUNET_free (revealed_str); GNUNET_free (revealed_str);
fresh_coin.reserve_index = coin->reserve_index; fresh_coin.reserve_index = coin->reserve_index;
fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]); fresh_coin.pk = find_pk (keys, &coin->denoms[i]);
fresh_coin.sig = sigs[i]; fresh_coin.sig = sigs[i];
// FIXME: yuck!
GNUNET_array_append (coins, GNUNET_array_append (coins,
ncoins, ncoins,
fresh_coin); fresh_coin);
} }
GNUNET_free (rrcls);
continue_master_task (); continue_master_task ();
} }
@ -497,7 +487,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 `struct RefreshRevealCls *` * @param cls closure with the `struct Coin *`
* @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,
@ -512,11 +502,8 @@ melt_cb (void *cls,
const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *full_response) const json_t *full_response)
{ {
/* free'd in `reveal_cb` */ struct Coin *coin = cls;
struct RefreshRevealCls *rrcls = cls;
struct Coin *coin;
coin = &coins[rrcls->coin_index];
coin->rmh = NULL; coin->rmh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
@ -527,11 +514,11 @@ melt_cb (void *cls,
coin->rrh coin->rrh
= TALER_EXCHANGE_refresh_reveal (exchange, = TALER_EXCHANGE_refresh_reveal (exchange,
rrcls->blob_size, coin->blob_size,
rrcls->blob, coin->blob,
noreveal_index, noreveal_index,
&reveal_cb, &reveal_cb,
rrcls); coin);
} }
@ -560,7 +547,6 @@ reserve_withdraw_cb (void *cls,
static void static void
refresh_coin (struct Coin *coin) refresh_coin (struct Coin *coin)
{ {
struct RefreshRevealCls *rrcls;
char *blob; char *blob;
size_t blob_size; size_t blob_size;
const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_Keys *keys;
@ -609,16 +595,14 @@ refresh_coin (struct Coin *coin)
"Prepared blob of size %d for refresh\n", "Prepared blob of size %d for refresh\n",
(unsigned int) blob_size); (unsigned int) blob_size);
rrcls = GNUNET_new (struct RefreshRevealCls); coin->blob = blob;
rrcls->blob = blob; coin->blob_size = blob_size;
rrcls->blob_size = blob_size; coin->denoms = denoms;
rrcls->coin_index = coin->coin_index;
rrcls->denoms = denoms;
coin->rmh = TALER_EXCHANGE_refresh_melt (exchange, coin->rmh = TALER_EXCHANGE_refresh_melt (exchange,
blob_size, blob_size,
blob, blob,
&melt_cb, &melt_cb,
rrcls); coin);
if (NULL == coin->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");