- calling exchange via GNUNET_OS_ interface
- getting currency via /keys - adding -c option (benchmark)
This commit is contained in:
parent
a7379930d2
commit
46c593f93e
@ -32,6 +32,16 @@
|
||||
*/
|
||||
static unsigned int pool_size = 100;
|
||||
|
||||
/**
|
||||
* Configuration file path
|
||||
*/
|
||||
static char *config_file;
|
||||
|
||||
/**
|
||||
* Configuation object (used to get BANK_URI)
|
||||
*/
|
||||
struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||
|
||||
/**
|
||||
* How many reservers ought to be created given the pool size
|
||||
*/
|
||||
@ -182,7 +192,7 @@ static struct TALER_MerchantPrivateKeyP merchant_priv;
|
||||
/**
|
||||
* URI under which the exchange is reachable during the benchmark.
|
||||
*/
|
||||
#define EXCHANGE_URI "http://localhost:8081"
|
||||
#define EXCHANGE_URI "http://localhost:8081/"
|
||||
|
||||
/**
|
||||
* How many coins (AKA withdraw operations) per reserve should be withdrawn
|
||||
@ -190,17 +200,21 @@ static struct TALER_MerchantPrivateKeyP merchant_priv;
|
||||
#define COINS_PER_RESERVE 12
|
||||
|
||||
/**
|
||||
* Used currency (to be preferably gotten via config file, together
|
||||
* exchange URI and other needed values)
|
||||
* Used currency (read from /keys' output)
|
||||
*/
|
||||
#define CURRENCY "PUDOS"
|
||||
|
||||
static char *currency;
|
||||
|
||||
/**
|
||||
* Large enough value to allow having 12 coins per reserve without parsing
|
||||
* /keys in the first place
|
||||
*/
|
||||
#define RESERVE_AMOUNT CURRENCY":1000"
|
||||
#define RESERVE_VALUE 1000
|
||||
|
||||
/**
|
||||
* The benchmark withdraws always the same denomination, since the calculation
|
||||
* for refreshing is statically done (at least in its very first version).
|
||||
*/
|
||||
#define COIN_VALUE 5
|
||||
|
||||
/**
|
||||
* Probability a coin can be spent
|
||||
@ -246,6 +260,7 @@ fail (const char *msg)
|
||||
"%s\n",
|
||||
msg);
|
||||
GNUNET_SCHEDULER_shutdown ();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -335,7 +350,6 @@ deposit_cb (void *cls,
|
||||
{
|
||||
/* TODO: all the refresh logic here */
|
||||
refreshed_once = GNUNET_YES;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -482,7 +496,8 @@ add_incoming_cb (void *cls,
|
||||
coin_index = reserve_index * COINS_PER_RESERVE + i;
|
||||
coins[coin_index].coin_priv.eddsa_priv = *coin_priv;
|
||||
coins[coin_index].reserve_index = reserve_index;
|
||||
TALER_string_to_amount (CURRENCY":5", &amount);
|
||||
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);
|
||||
coins[coin_index].wsh =
|
||||
@ -521,7 +536,8 @@ benchmark_run (void *cls)
|
||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
&blinding_key,
|
||||
sizeof (blinding_key));
|
||||
TALER_string_to_amount (RESERVE_AMOUNT, &reserve_amount);
|
||||
TALER_amount_get_zero (currency, &reserve_amount);
|
||||
reserve_amount.value = RESERVE_VALUE;
|
||||
sender_details = json_loads ("{ \"type\":\"test\", \"bank_uri\":\"https://bank.test.taler.net/\", \"account_number\":62}",
|
||||
JSON_REJECT_DUPLICATES,
|
||||
NULL);
|
||||
@ -530,9 +546,6 @@ benchmark_run (void *cls)
|
||||
|
||||
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",
|
||||
@ -600,6 +613,9 @@ cert_cb (void *cls,
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Certificate callback invoked, invoking benchmark_run()\n");
|
||||
keys = _keys;
|
||||
currency = _keys->denom_keys[0].value.currency;
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Using currency: %s\n", currency);
|
||||
benchmark_task = GNUNET_SCHEDULER_add_now (&benchmark_run,
|
||||
NULL);
|
||||
}
|
||||
@ -692,8 +708,26 @@ do_shutdown (void *cls)
|
||||
static void
|
||||
run (void *cls)
|
||||
{
|
||||
|
||||
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"running run()\n");
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"gotten pool_size of %d\n",
|
||||
pool_size);
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"config file: %s\n",
|
||||
config_file);
|
||||
if (NULL == config_file)
|
||||
fail ("-c option is mandatory\n");
|
||||
|
||||
/**
|
||||
* Read BANK_URI in here
|
||||
*/
|
||||
cfg = GNUNET_CONFIGURATION_create ();
|
||||
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, config_file))
|
||||
fail ("failed to parse configuration file\n");
|
||||
|
||||
GNUNET_array_append (spent_coins,
|
||||
spent_coins_size,
|
||||
1);
|
||||
@ -720,18 +754,96 @@ main (int argc,
|
||||
char * const *argv)
|
||||
{
|
||||
|
||||
struct GNUNET_OS_Process *proc;
|
||||
struct GNUNET_OS_Process *exchanged;
|
||||
unsigned int cnt;
|
||||
|
||||
GNUNET_log_setup ("taler-exchange-benchmark",
|
||||
"WARNING",
|
||||
NULL);
|
||||
const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
||||
{'s', "pool-size", NULL,
|
||||
"How many coins this benchmark should instantiate", GNUNET_YES,
|
||||
&GNUNET_GETOPT_set_uint, &pool_size}
|
||||
&GNUNET_GETOPT_set_uint, &pool_size},
|
||||
{'c', "config", NULL,
|
||||
"Configuration file", GNUNET_YES,
|
||||
&GNUNET_GETOPT_set_string, &config_file}
|
||||
};
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
GNUNET_GETOPT_run ("taler-exchange-benchmark",
|
||||
options, argc, argv));
|
||||
|
||||
proc = GNUNET_OS_start_process (GNUNET_NO,
|
||||
GNUNET_OS_INHERIT_STD_ALL,
|
||||
NULL, NULL, NULL,
|
||||
"taler-exchange-keyup",
|
||||
"taler-exchange-keyup",
|
||||
NULL);
|
||||
if (NULL == proc)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Failed to run taler-exchange-keyup. Check your PATH.\n");
|
||||
return 77;
|
||||
}
|
||||
|
||||
GNUNET_OS_process_wait (proc);
|
||||
GNUNET_OS_process_destroy (proc);
|
||||
|
||||
proc = GNUNET_OS_start_process (GNUNET_NO,
|
||||
GNUNET_OS_INHERIT_STD_ALL,
|
||||
NULL, NULL, NULL,
|
||||
"taler-exchange-dbinit",
|
||||
"taler-exchange-dbinit",
|
||||
"-r",
|
||||
NULL);
|
||||
|
||||
|
||||
if (NULL == proc)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Failed to run taler-exchange-dbinit. Check your PATH.\n");
|
||||
return 77;
|
||||
}
|
||||
GNUNET_OS_process_wait (proc);
|
||||
GNUNET_OS_process_destroy (proc);
|
||||
|
||||
exchanged = GNUNET_OS_start_process (GNUNET_NO,
|
||||
GNUNET_OS_INHERIT_STD_ALL,
|
||||
NULL, NULL, NULL,
|
||||
"taler-exchange-httpd",
|
||||
"taler-exchange-httpd",
|
||||
NULL);
|
||||
if (NULL == exchanged)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Failed to run taler-exchange-httpd. Check your PATH.\n");
|
||||
return 77;
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
do
|
||||
{
|
||||
fprintf (stderr, ".");
|
||||
sleep (1);
|
||||
cnt++;
|
||||
if (cnt > 60)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"\nFailed to start taler-exchange-httpd\n");
|
||||
GNUNET_OS_process_kill (exchanged,
|
||||
SIGKILL);
|
||||
GNUNET_OS_process_wait (exchanged);
|
||||
GNUNET_OS_process_destroy (exchanged);
|
||||
return 77;
|
||||
}
|
||||
}
|
||||
while (0 != system ("wget -q -t 1 -T 1 " EXCHANGE_URI "keys -o /dev/null -O /dev/null"));
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
GNUNET_SCHEDULER_run (&run, NULL);
|
||||
GNUNET_OS_process_wait (exchanged);
|
||||
GNUNET_OS_process_destroy (exchanged);
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
2
src/benchmark/taler-exchange-benchmark.conf
Normal file
2
src/benchmark/taler-exchange-benchmark.conf
Normal file
@ -0,0 +1,2 @@
|
||||
[benchmark]
|
||||
BANK_URI = https://bank.test.taler.net/
|
Loading…
Reference in New Issue
Block a user