fixing compiler warnings, indentation, etc.

This commit is contained in:
Christian Grothoff 2016-06-06 23:53:54 +02:00
parent 0fef44159a
commit 7d281b63be

View File

@ -169,31 +169,38 @@ static unsigned int spent_coins_size = 0;
*/ */
#define SPEND_PROBABILITY 0.1 #define SPEND_PROBABILITY 0.1
static unsigned int static unsigned int
eval_probability (float probability) eval_probability (float probability)
{ {
unsigned int random; unsigned int random;
float random_01; float random_01;
random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
random_01 = (float) random / UINT32_MAX; random_01 = (float) random / UINT32_MAX;
return random_01 <= probability ? GNUNET_OK : GNUNET_NO; return random_01 <= probability ? GNUNET_OK : GNUNET_NO;
} }
static void static void
do_shutdown (void *cls); do_shutdown (void *cls);
/** /**
* Shutdown benchmark in case of errors * Shutdown benchmark in case of errors
* *
* @param msg error message to print in logs * @param msg error message to print in logs
*/ */
static void 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 (); GNUNET_SCHEDULER_shutdown ();
} }
/** /**
* Function called upon completion of our /reserve/withdraw request. * Function called upon completion of our /reserve/withdraw request.
* *
@ -210,25 +217,34 @@ reserve_withdraw_cb (void *cls,
const json_t *full_response) const json_t *full_response)
{ {
unsigned int coin_index = (unsigned int) cls; unsigned int coin_index = (unsigned int) (long) cls;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
fail ("At least one coin has not correctly been withdrawn\n"); 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 = coins[coin_index].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))
{ {
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_index);
/* FIXME: the following operation must be done once the coins has *actually* /* FIXME: the following operation must be done once the coins has *actually*
* been spent * been spent
*/ */
GNUNET_array_append (spent_coins, spent_coins_size, coin_index); GNUNET_array_append (spent_coins,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "picked! = %d\n", spent_coins[spent_coins_size-1]); spent_coins_size,
coin_index);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"picked! = %d\n",
spent_coins[spent_coins_size-1]);
spent_coins_size++; spent_coins_size++;
} }
} }
/** /**
* Function called upon completion of our /admin/add/incoming request. * Function called upon completion of our /admin/add/incoming request.
* *
@ -242,12 +258,11 @@ 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 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;
unsigned int reserve_index = (unsigned int) cls;
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); reserve_index);
@ -271,10 +286,10 @@ add_incoming_cb (void *cls,
&coins[coin_index].coin_priv, &coins[coin_index].coin_priv,
&blinding_key, &blinding_key,
reserve_withdraw_cb, reserve_withdraw_cb,
(void *) coin_index); (void *) (long) coin_index);
}
} }
}
/** /**
* Run the main interpreter loop that performs exchange operations. * Run the main interpreter loop that performs exchange operations.
@ -304,13 +319,20 @@ benchmark_run (void *cls)
execution_date = GNUNET_TIME_absolute_get (); execution_date = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&execution_date); GNUNET_TIME_round_abs (&execution_date);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "benchmark_run() invoked\n"); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gotten pool_size of %d\n", pool_size); "benchmark_run() invoked\n");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"gotten pool_size of %d\n",
pool_size);
nreserves = pool_size / COINS_PER_RESERVE; 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)); reserves = GNUNET_new_array (nreserves,
coins = GNUNET_malloc (COINS_PER_RESERVE * nreserves * sizeof (struct Coin)); struct Reserve);
coins = GNUNET_new_array (COINS_PER_RESERVE * nreserves,
struct Coin);
/* reserves */ /* reserves */
for (i=0;i < nreserves && 0 < nreserves;i++) for (i=0;i < nreserves && 0 < nreserves;i++)
@ -331,15 +353,16 @@ benchmark_run (void *cls)
sender_details, sender_details,
transfer_details, transfer_details,
&add_incoming_cb, &add_incoming_cb,
(void *) i); (void *) (long) i);
GNUNET_assert (NULL != reserves[i].aih); GNUNET_assert (NULL != reserves[i].aih);
json_decref (transfer_details); json_decref (transfer_details);
} }
json_decref (sender_details); json_decref (sender_details);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "benchmark_run() returns\n"); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
return; "benchmark_run() returns\n");
} }
/** /**
* Functions of this type are called to provide the retrieved signing and * Functions of this type are called to provide the retrieved signing and
* denomination keys of the exchange. No TALER_EXCHANGE_*() functions should be called * denomination keys of the exchange. No TALER_EXCHANGE_*() functions should be called
@ -374,6 +397,7 @@ cert_cb (void *cls,
NULL); NULL);
} }
/** /**
* Function run when the test terminates (good or bad). * Function run when the test terminates (good or bad).
* Cleans up our state. * Cleans up our state.
@ -431,6 +455,7 @@ do_shutdown (void *cls)
GNUNET_free_non_null (spent_coins); GNUNET_free_non_null (spent_coins);
} }
/** /**
* Main function that will be run by the scheduler. * Main function that will be run by the scheduler.
* *
@ -439,8 +464,11 @@ do_shutdown (void *cls)
static void static void
run (void *cls) run (void *cls)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "running run()\n"); GNUNET_log (GNUNET_ERROR_TYPE_INFO,
GNUNET_array_append (spent_coins, spent_coins_size, 1); "running run()\n");
GNUNET_array_append (spent_coins,
spent_coins_size,
1);
spent_coins_size++; spent_coins_size++;
reserves = NULL; reserves = NULL;
@ -458,6 +486,7 @@ run (void *cls)
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
} }
int int
main (int argc, main (int argc,
char * const *argv) char * const *argv)