aboutsummaryrefslogtreecommitdiff
path: root/src/benchmark/taler-exchange-benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmark/taler-exchange-benchmark.c')
-rw-r--r--src/benchmark/taler-exchange-benchmark.c79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index 5b4f1f5ef..7e19d8318 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -184,31 +184,38 @@ static struct TALER_MerchantPrivateKeyP merchant_priv;
*/
#define SPEND_PROBABILITY 0.1
+
static unsigned int
eval_probability (float probability)
{
unsigned int random;
float random_01;
+
random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
random_01 = (float) random / UINT32_MAX;
return random_01 <= probability ? GNUNET_OK : GNUNET_NO;
}
+
static void
do_shutdown (void *cls);
+
/**
* Shutdown benchmark in case of errors
*
* @param msg error message to print in logs
*/
static void
-fail (char *msg)
+fail (const char *msg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s\n",
+ msg);
GNUNET_SCHEDULER_shutdown ();
}
+
/**
* Function called with the result of a /deposit operation.
*
@@ -223,8 +230,7 @@ deposit_cb (void *cls,
unsigned int http_status,
const json_t *obj)
{
- unsigned int coin_index = (unsigned int) cls;
-
+ unsigned int coin_index = (unsigned int) (long) cls;
coins[coin_index].dh = NULL;
if (MHD_HTTP_OK != http_status)
@@ -254,12 +260,14 @@ reserve_withdraw_cb (void *cls,
const json_t *full_response)
{
- unsigned int coin_index = (unsigned int) cls;
+ unsigned int coin_index = (unsigned int) (long) cls;
coins[coin_index].wsh = NULL;
if (MHD_HTTP_OK != http_status)
fail ("At least one coin has not correctly been withdrawn\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d-th coin withdrawn\n", coin_index);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%d-th coin withdrawn\n",
+ coin_index);
coins[coin_index].sig.rsa_signature =
GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature);
if (GNUNET_OK == eval_probability (SPEND_PROBABILITY))
@@ -280,7 +288,7 @@ reserve_withdraw_cb (void *cls,
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&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);
refund_deadline = GNUNET_TIME_absolute_add (timestamp, GNUNET_TIME_UNIT_DAYS);
GNUNET_TIME_round_abs (&timestamp);
@@ -333,7 +341,7 @@ reserve_withdraw_cb (void *cls,
refund_deadline,
&coin_sig,
&deposit_cb,
- (void *) coin_index);
+ (void *) (long) coin_index);
if (NULL == coins[coin_index].dh)
{
json_decref (merchant_details);
@@ -341,10 +349,10 @@ reserve_withdraw_cb (void *cls,
}
json_decref (merchant_details);
transaction_id++;
-
}
-
}
+
+
/**
* Function called upon completion of our /admin/add/incoming request.
*
@@ -358,19 +366,18 @@ add_incoming_cb (void *cls,
unsigned int http_status,
const json_t *full_response)
{
-
+ unsigned int reserve_index = (unsigned int) (long) cls;
struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv;
unsigned int i;
unsigned int coin_index;
- unsigned int reserve_index = (unsigned int) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"/admin/add/incoming callback called on %d-th reserve\n",
reserve_index);
reserves[reserve_index].aih = NULL;
if (MHD_HTTP_OK != http_status)
fail ("At least one reserve failed in being created\n");
-
+
for (i=0; i < COINS_PER_RESERVE; i++)
{
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
@@ -387,11 +394,11 @@ add_incoming_cb (void *cls,
&coins[coin_index].coin_priv,
&blinding_key,
reserve_withdraw_cb,
- (void *) coin_index);
+ (void *) (long) coin_index);
}
-
}
+
/**
* Run the main interpreter loop that performs exchange operations.
*
@@ -408,7 +415,7 @@ benchmark_run (void *cls)
struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Absolute execution_date;
struct TALER_Amount reserve_amount;
-
+
priv = GNUNET_CRYPTO_eddsa_key_create ();
merchant_priv.eddsa_priv = *priv;
GNUNET_free (priv);
@@ -423,13 +430,20 @@ benchmark_run (void *cls)
execution_date = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&execution_date);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "benchmark_run() invoked\n");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gotten pool_size of %d\n", pool_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "benchmark_run() invoked\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "gotten pool_size of %d\n",
+ pool_size);
nreserves = pool_size / COINS_PER_RESERVE;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating %d reserves\n", nreserves);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "creating %d reserves\n",
+ nreserves);
- reserves = GNUNET_malloc (nreserves * sizeof (struct Reserve));
- coins = GNUNET_malloc (COINS_PER_RESERVE * nreserves * sizeof (struct Coin));
+ reserves = GNUNET_new_array (nreserves,
+ struct Reserve);
+ coins = GNUNET_new_array (COINS_PER_RESERVE * nreserves,
+ struct Coin);
/* reserves */
for (i=0;i < nreserves && 0 < nreserves;i++)
@@ -450,15 +464,16 @@ benchmark_run (void *cls)
sender_details,
transfer_details,
&add_incoming_cb,
- (void *) i);
- GNUNET_assert (NULL != reserves[i].aih);
+ (void *) (long) i);
+ GNUNET_assert (NULL != reserves[i].aih);
json_decref (transfer_details);
}
json_decref (sender_details);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "benchmark_run() returns\n");
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "benchmark_run() returns\n");
}
+
/**
* Functions of this type are called to provide the retrieved signing and
* denomination keys of the exchange. No TALER_EXCHANGE_*() functions should be called
@@ -493,6 +508,7 @@ cert_cb (void *cls,
NULL);
}
+
/**
* Function run when the test terminates (good or bad).
* Cleans up our state.
@@ -527,13 +543,11 @@ do_shutdown (void *cls)
{
TALER_EXCHANGE_reserve_withdraw_cancel(coins[i].wsh);
coins[i].wsh = NULL;
-
- }
+ }
if (NULL != coins[i].dh)
{
TALER_EXCHANGE_deposit_cancel(coins[i].dh);
coins[i].dh = NULL;
-
}
}
@@ -560,6 +574,7 @@ do_shutdown (void *cls)
}
+
/**
* Main function that will be run by the scheduler.
*
@@ -568,8 +583,11 @@ do_shutdown (void *cls)
static void
run (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running run()\n");
- GNUNET_array_append (spent_coins, spent_coins_size, 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "running run()\n");
+ GNUNET_array_append (spent_coins,
+ spent_coins_size,
+ 1);
spent_coins_size++;
reserves = NULL;
@@ -587,6 +605,7 @@ run (void *cls)
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
+
int
main (int argc,
char * const *argv)