2016-05-30 15:08:12 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2014, 2015, 2016 GNUnet e.V. and INRIA
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU Lesser General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2.1, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along with
|
|
|
|
TALER; see the file COPYING.LGPL. If not, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file src/benchmark/taler-exchange-benchmark.c
|
|
|
|
* @brief exchange's benchmark
|
|
|
|
* @author Marcello Stanisci
|
2016-06-15 16:04:29 +02:00
|
|
|
* @author Christian Grothoff
|
2016-05-30 15:08:12 +02:00
|
|
|
*/
|
|
|
|
#include "platform.h"
|
2016-06-03 14:18:42 +02:00
|
|
|
#include "taler_util.h"
|
|
|
|
#include "taler_signatures.h"
|
|
|
|
#include "taler_exchange_service.h"
|
|
|
|
#include "taler_json_lib.h"
|
2016-05-30 15:08:12 +02:00
|
|
|
#include <gnunet/gnunet_util_lib.h>
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include <microhttpd.h>
|
2016-06-08 17:11:33 +02:00
|
|
|
#include <jansson.h>
|
2016-05-30 15:08:12 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
/**
|
|
|
|
* Should we initialize and start the exchange, if #GNUNET_NO,
|
|
|
|
* we expect one to be already up and running.
|
|
|
|
*/
|
|
|
|
static int run_exchange;
|
2016-06-09 17:22:15 +02:00
|
|
|
|
2016-05-30 18:45:57 +02:00
|
|
|
/**
|
|
|
|
* How many coins the benchmark should operate on
|
|
|
|
*/
|
2016-06-03 01:23:16 +02:00
|
|
|
static unsigned int pool_size = 100;
|
|
|
|
|
2016-06-08 16:12:31 +02:00
|
|
|
/**
|
|
|
|
* Configuration file path
|
|
|
|
*/
|
|
|
|
static char *config_file;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuation object (used to get BANK_URI)
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static struct GNUNET_CONFIGURATION_Handle *cfg;
|
2016-06-08 16:12:31 +02:00
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
2016-06-09 17:22:15 +02:00
|
|
|
* How many reserves ought to be created given the pool size
|
2016-06-03 01:23:16 +02:00
|
|
|
*/
|
|
|
|
static unsigned int nreserves;
|
|
|
|
|
2016-06-11 18:01:57 +02:00
|
|
|
/**
|
2016-06-15 15:09:57 +02:00
|
|
|
* How many coins are in the #coins array. This is needed
|
|
|
|
* as the number of coins is not always #nreserves * #COINS_PER_RESERVE
|
2016-06-11 18:01:57 +02:00
|
|
|
* due to refresh operations
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static unsigned int ncoins;
|
2016-06-11 18:01:57 +02:00
|
|
|
|
2016-06-08 17:11:33 +02:00
|
|
|
/**
|
|
|
|
* Bank details of who creates reserves
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static json_t *bank_details;
|
2016-06-08 17:11:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bank details of who deposits coins
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static json_t *merchant_details;
|
|
|
|
|
2016-06-08 17:11:33 +02:00
|
|
|
|
2016-06-10 16:04:03 +02:00
|
|
|
/**
|
|
|
|
* Information needed by the /refresh/melt's callback
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
struct RefreshRevealCls
|
|
|
|
{
|
2016-06-10 16:04:03 +02:00
|
|
|
|
|
|
|
/**
|
2016-06-15 15:09:57 +02:00
|
|
|
* The result of a #TALER_EXCHANGE_refresh_prepare() call
|
2016-06-10 16:04:03 +02:00
|
|
|
*/
|
|
|
|
const char *blob;
|
|
|
|
|
|
|
|
/**
|
2016-06-15 15:09:57 +02:00
|
|
|
* Size of @e blob
|
2016-06-10 16:04:03 +02:00
|
|
|
*/
|
|
|
|
size_t blob_size;
|
2016-06-10 16:06:27 +02:00
|
|
|
|
2016-06-10 16:04:03 +02:00
|
|
|
/**
|
|
|
|
* Which coin in the list are we melting
|
|
|
|
*/
|
|
|
|
unsigned int coin_index;
|
2016-06-14 15:51:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of denominations expected to get from melt
|
|
|
|
*/
|
|
|
|
struct TALER_Amount *denoms;
|
2016-06-10 16:04:03 +02:00
|
|
|
};
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
|
|
|
* Needed information for a reserve. Other values are the same for all reserves, therefore defined in global variables
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
struct Reserve
|
|
|
|
{
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
|
|
|
* Set (by the interpreter) to the reserve's private key
|
|
|
|
* we used to fill the reserve.
|
|
|
|
*/
|
|
|
|
struct TALER_ReservePrivateKeyP reserve_priv;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to the API's handle during the operation.
|
|
|
|
*/
|
|
|
|
struct TALER_EXCHANGE_AdminAddIncomingHandle *aih;
|
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
/**
|
|
|
|
* Index of this reserve in the #reserves array.
|
|
|
|
*/
|
|
|
|
unsigned int reserve_index;
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
};
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
|
2016-06-09 23:35:05 +02:00
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* Array of denomination keys needed to perform the refresh operation
|
2016-06-09 23:35:05 +02:00
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static struct TALER_EXCHANGE_DenomPublicKey *refresh_pk;
|
2016-06-09 23:35:05 +02:00
|
|
|
|
|
|
|
/**
|
2016-06-15 15:09:57 +02:00
|
|
|
* Size of #refresh_pk
|
2016-06-09 23:35:05 +02:00
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static unsigned int refresh_pk_len;
|
2016-06-03 19:39:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same blinding key for all coins
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static struct TALER_DenominationBlindingKeyP blinding_key;
|
2016-06-03 19:39:04 +02:00
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
2016-06-04 01:29:42 +02:00
|
|
|
* Information regarding a coin
|
2016-06-03 01:23:16 +02:00
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
struct Coin
|
|
|
|
{
|
2016-06-03 01:23:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set (by the interpreter) to the exchange's signature over the
|
|
|
|
* coin's public key.
|
|
|
|
*/
|
|
|
|
struct TALER_DenominationSignature sig;
|
|
|
|
|
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* Set to the coin's private key.
|
2016-06-03 01:23:16 +02:00
|
|
|
*/
|
|
|
|
struct TALER_CoinSpendPrivateKeyP coin_priv;
|
|
|
|
|
2016-06-15 15:41:17 +02:00
|
|
|
/**
|
|
|
|
* This specifies the denomination key to use.
|
|
|
|
*/
|
|
|
|
const struct TALER_EXCHANGE_DenomPublicKey *pk;
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
|
|
|
* Withdraw handle (while operation is running).
|
|
|
|
*/
|
|
|
|
struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh;
|
|
|
|
|
2016-06-15 15:41:17 +02:00
|
|
|
/**
|
|
|
|
* Refresh melt handle
|
|
|
|
*/
|
|
|
|
struct TALER_EXCHANGE_RefreshMeltHandle *rmh;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh reveal handle
|
|
|
|
*/
|
|
|
|
struct TALER_EXCHANGE_RefreshRevealHandle *rrh;
|
|
|
|
|
2016-06-06 16:53:42 +02:00
|
|
|
/**
|
|
|
|
* Deposit handle (while operation is running).
|
|
|
|
*/
|
|
|
|
struct TALER_EXCHANGE_DepositHandle *dh;
|
|
|
|
|
2016-06-09 23:35:05 +02:00
|
|
|
/**
|
|
|
|
* Flag indicating if the coin is going to be refreshed
|
|
|
|
*/
|
|
|
|
unsigned int refresh;
|
|
|
|
|
2016-06-13 23:40:00 +02:00
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* Index in the reserve's global array indicating which
|
|
|
|
* reserve this coin is to be retrieved. If the coin comes
|
|
|
|
* from a refresh, then this value is set to the melted coin's
|
|
|
|
* reserve index
|
2016-06-07 16:58:55 +02:00
|
|
|
*/
|
2016-06-15 15:41:17 +02:00
|
|
|
unsigned int reserve_index;
|
2016-06-07 16:58:55 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
/**
|
|
|
|
* Index of this coin in the #coins array.
|
|
|
|
*/
|
|
|
|
unsigned int coin_index;
|
|
|
|
|
2016-06-07 16:58:55 +02:00
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* If the coin has to be refreshed, this value indicates
|
|
|
|
* how much is left on this coin
|
2016-06-07 16:58:55 +02:00
|
|
|
*/
|
2016-06-15 15:41:17 +02:00
|
|
|
struct TALER_Amount left;
|
2016-06-07 16:58:55 +02:00
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
};
|
2016-05-30 17:16:01 +02:00
|
|
|
|
2016-06-11 16:31:33 +02:00
|
|
|
/**
|
|
|
|
* Handle to the exchange's process
|
|
|
|
*/
|
|
|
|
static struct GNUNET_OS_Process *exchanged;
|
|
|
|
|
2016-05-30 18:45:57 +02:00
|
|
|
/**
|
|
|
|
* Context for running the #ctx's event loop.
|
|
|
|
*/
|
|
|
|
static struct GNUNET_CURL_RescheduleContext *rc;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Benchmark's task
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static struct GNUNET_SCHEDULER_Task *benchmark_task;
|
2016-05-30 18:45:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Main execution context for the main loop of the exchange.
|
|
|
|
*/
|
|
|
|
static struct GNUNET_CURL_Context *ctx;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle to access the exchange.
|
|
|
|
*/
|
|
|
|
static struct TALER_EXCHANGE_Handle *exchange;
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* The array of all reserves, of length #nreserves.
|
2016-06-03 01:23:16 +02:00
|
|
|
*/
|
|
|
|
static struct Reserve *reserves;
|
|
|
|
|
|
|
|
/**
|
2016-06-15 15:41:17 +02:00
|
|
|
* The array of all coins, of length #ncoins.
|
2016-06-03 01:23:16 +02:00
|
|
|
*/
|
|
|
|
static struct Coin *coins;
|
|
|
|
|
2016-06-06 16:53:42 +02:00
|
|
|
/**
|
2016-06-13 15:42:08 +02:00
|
|
|
* Transaction id counter, used in /deposit's
|
2016-06-06 16:53:42 +02:00
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static unsigned int transaction_id;
|
2016-06-06 16:53:42 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
/**
|
|
|
|
* Transfer UUID counter, used in /admin/add/incoming
|
|
|
|
*/
|
|
|
|
static unsigned int transfer_uuid;
|
|
|
|
|
2016-06-06 16:53:42 +02:00
|
|
|
/**
|
|
|
|
* This key (usually provided by merchants) is needed when depositing coins,
|
|
|
|
* even though there is no merchant acting in the benchmark
|
|
|
|
*/
|
|
|
|
static struct TALER_MerchantPrivateKeyP merchant_priv;
|
2016-06-03 01:23:16 +02:00
|
|
|
|
2016-05-30 15:08:12 +02:00
|
|
|
/**
|
|
|
|
* URI under which the exchange is reachable during the benchmark.
|
|
|
|
*/
|
2016-06-15 15:41:17 +02:00
|
|
|
static char *exchange_uri;
|
2016-05-30 18:45:57 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
/**
|
|
|
|
* URI under which the administrative exchange is reachable during the
|
|
|
|
* benchmark.
|
|
|
|
*/
|
|
|
|
static char *exchange_admin_uri;
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
|
|
|
* How many coins (AKA withdraw operations) per reserve should be withdrawn
|
|
|
|
*/
|
|
|
|
#define COINS_PER_RESERVE 12
|
|
|
|
|
2016-06-07 16:58:55 +02:00
|
|
|
/**
|
2016-06-08 16:12:31 +02:00
|
|
|
* Used currency (read from /keys' output)
|
2016-06-07 16:58:55 +02:00
|
|
|
*/
|
2016-06-08 16:12:31 +02:00
|
|
|
static char *currency;
|
2016-06-07 16:58:55 +02:00
|
|
|
|
2016-06-04 01:29:42 +02:00
|
|
|
/**
|
|
|
|
* Large enough value to allow having 12 coins per reserve without parsing
|
|
|
|
* /keys in the first place
|
|
|
|
*/
|
2016-06-08 16:12:31 +02:00
|
|
|
#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).
|
|
|
|
*/
|
2016-06-10 15:22:32 +02:00
|
|
|
#define COIN_VALUE 8
|
2016-06-04 01:29:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Probability a coin can be spent
|
|
|
|
*/
|
|
|
|
#define SPEND_PROBABILITY 0.1
|
|
|
|
|
2016-06-07 16:58:55 +02:00
|
|
|
/**
|
|
|
|
* Probability a coin can be refreshed
|
|
|
|
*/
|
2016-06-13 15:42:08 +02:00
|
|
|
#define REFRESH_PROBABILITY 0.4
|
2016-06-07 16:58:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Refreshed once. For each batch of deposits, only one
|
|
|
|
* coin will be refreshed, according to #REFRESH_PROBABILITY
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static unsigned int refreshed_once;
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-11 17:35:15 +02:00
|
|
|
/**
|
|
|
|
* List of coins to get in return to a melt operation. Just a
|
|
|
|
* static list for now as every melt operation is carried out
|
|
|
|
* on a 8 KUDOS coin whose only 1 KUDOS has been spent, thus
|
|
|
|
* 7 KUDOS melted. This structure must be changed with one holding
|
|
|
|
* TALER_Amount structs, as every time it's needed it requires
|
|
|
|
* too many operations before getting the desired TALER_Amount.
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
static const char *refresh_denoms[] = {
|
2016-06-11 17:35:15 +02:00
|
|
|
"4",
|
|
|
|
"2",
|
|
|
|
"1",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Throw a weighted coin with @a probability.
|
|
|
|
*
|
|
|
|
* @reurn #GNUNET_OK with @a probability, #GNUNET_NO with 1 - @a probability
|
|
|
|
*/
|
2016-06-04 01:29:42 +02:00
|
|
|
static unsigned int
|
|
|
|
eval_probability (float probability)
|
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
uint64_t random;
|
2016-06-04 01:29:42 +02:00
|
|
|
float random_01;
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
random = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
UINT64_MAX);
|
|
|
|
random_01 = (double) random / UINT64_MAX;
|
|
|
|
return (random_01 <= probability) ? GNUNET_OK : GNUNET_NO;
|
2016-06-04 01:29:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-04 01:29:42 +02:00
|
|
|
/**
|
|
|
|
* Shutdown benchmark in case of errors
|
|
|
|
*
|
|
|
|
* @param msg error message to print in logs
|
|
|
|
*/
|
2016-06-03 01:23:16 +02:00
|
|
|
static void
|
2016-06-06 23:53:54 +02:00
|
|
|
fail (const char *msg)
|
2016-06-04 01:29:42 +02:00
|
|
|
{
|
2016-06-10 22:35:38 +02:00
|
|
|
if (NULL != msg)
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"%s\n",
|
|
|
|
msg);
|
2016-06-04 01:29:42 +02:00
|
|
|
GNUNET_SCHEDULER_shutdown ();
|
|
|
|
}
|
2016-06-03 01:23:16 +02:00
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-07 16:58:55 +02:00
|
|
|
/**
|
|
|
|
* Find denomination key matching the given amount.
|
|
|
|
*
|
|
|
|
* @param keys array of keys to search
|
|
|
|
* @param amount coin value to look for
|
|
|
|
* @return NULL if no matching key was found
|
|
|
|
*/
|
|
|
|
static const struct TALER_EXCHANGE_DenomPublicKey *
|
|
|
|
find_pk (const struct TALER_EXCHANGE_Keys *keys,
|
|
|
|
const struct TALER_Amount *amount)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct GNUNET_TIME_Absolute now;
|
|
|
|
struct TALER_EXCHANGE_DenomPublicKey *pk;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
now = GNUNET_TIME_absolute_get ();
|
|
|
|
for (i=0;i<keys->num_denom_keys;i++)
|
|
|
|
{
|
|
|
|
pk = &keys->denom_keys[i];
|
|
|
|
if ( (0 == TALER_amount_cmp (amount,
|
|
|
|
&pk->value)) &&
|
|
|
|
(now.abs_value_us >= pk->valid_from.abs_value_us) &&
|
|
|
|
(now.abs_value_us < pk->withdraw_valid_until.abs_value_us) )
|
|
|
|
return pk;
|
|
|
|
}
|
|
|
|
/* do 2nd pass to check if expiration times are to blame for failure */
|
|
|
|
str = TALER_amount_to_string (amount);
|
|
|
|
for (i=0;i<keys->num_denom_keys;i++)
|
|
|
|
{
|
|
|
|
pk = &keys->denom_keys[i];
|
|
|
|
if ( (0 == TALER_amount_cmp (amount,
|
|
|
|
&pk->value)) &&
|
|
|
|
( (now.abs_value_us < pk->valid_from.abs_value_us) ||
|
|
|
|
(now.abs_value_us > pk->withdraw_valid_until.abs_value_us) ) )
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
|
|
|
"Have denomination key for `%s', but with wrong expiration range %llu vs [%llu,%llu)\n",
|
|
|
|
str,
|
|
|
|
(unsigned long long) now.abs_value_us,
|
|
|
|
(unsigned long long) pk->valid_from.abs_value_us,
|
|
|
|
(unsigned long long) pk->withdraw_valid_until.abs_value_us);
|
|
|
|
GNUNET_free (str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
|
|
|
"No denomination key for amount %s found\n",
|
|
|
|
str);
|
|
|
|
GNUNET_free (str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
|
2016-06-10 16:04:03 +02:00
|
|
|
/**
|
|
|
|
* Function called with the result of the /refresh/reveal operation.
|
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with the `struct RefreshRevealCls *`
|
2016-06-10 16:04:03 +02:00
|
|
|
* @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)
|
|
|
|
* @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed
|
|
|
|
* @param coin_privs array of @a num_coins private keys for the coins that were created, NULL on error
|
|
|
|
* @param sigs array of signature over @a num_coins coins, NULL on error
|
|
|
|
* @param full_response full response from the exchange (for logging, in case of errors)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reveal_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
|
|
|
unsigned int num_coins,
|
|
|
|
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
|
|
|
|
const struct TALER_DenominationSignature *sigs,
|
|
|
|
const json_t *full_response)
|
|
|
|
{
|
2016-06-11 17:35:15 +02:00
|
|
|
struct RefreshRevealCls *rrcls = cls;
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Coin *coin;
|
2016-06-11 17:35:15 +02:00
|
|
|
unsigned int i;
|
|
|
|
const struct TALER_EXCHANGE_Keys *keys;
|
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin = &coins[rrcls->coin_index];
|
|
|
|
coin->rrh = NULL;
|
2016-06-11 17:35:15 +02:00
|
|
|
if (MHD_HTTP_OK != http_status)
|
|
|
|
{
|
2016-06-13 15:42:08 +02:00
|
|
|
GNUNET_free (rrcls);
|
|
|
|
json_dumpf (full_response, stderr, 0);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Not all coins correctly revealed");
|
2016-06-11 17:35:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2016-06-14 15:58:25 +02:00
|
|
|
{
|
2016-06-11 17:35:15 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
2016-06-13 15:42:08 +02:00
|
|
|
"Coin #%d revealed!\n",
|
|
|
|
rrcls->coin_index);
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->left.value = 0;
|
2016-06-14 15:58:25 +02:00
|
|
|
}
|
|
|
|
|
2016-06-11 17:35:15 +02:00
|
|
|
keys = TALER_EXCHANGE_get_keys (exchange);
|
|
|
|
for (i=0; i<num_coins; i++)
|
|
|
|
{
|
|
|
|
struct Coin fresh_coin;
|
2016-06-14 15:51:58 +02:00
|
|
|
char *revealed_str;
|
|
|
|
|
|
|
|
revealed_str = TALER_amount_to_string (&rrcls->denoms[i]);
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"revealing %s "
|
|
|
|
"# of coins after refresh: %d\n",
|
|
|
|
revealed_str,
|
|
|
|
ncoins);
|
|
|
|
GNUNET_free (revealed_str);
|
2016-06-15 16:04:29 +02:00
|
|
|
|
|
|
|
fresh_coin.reserve_index = coin->reserve_index;
|
2016-06-14 15:51:58 +02:00
|
|
|
fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]);
|
2016-06-11 17:35:15 +02:00
|
|
|
fresh_coin.sig = sigs[i];
|
2016-06-15 16:04:29 +02:00
|
|
|
GNUNET_array_append (coins,
|
|
|
|
ncoins,
|
|
|
|
fresh_coin);
|
2016-06-11 17:35:15 +02:00
|
|
|
}
|
2016-06-11 18:01:57 +02:00
|
|
|
GNUNET_free (rrcls);
|
2016-06-10 16:04:03 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
|
2016-06-10 15:22:32 +02:00
|
|
|
/**
|
|
|
|
* Function called with the result of the /refresh/melt operation.
|
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with the `struct RefreshRevealCls *`
|
2016-06-10 15:22:32 +02:00
|
|
|
* @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)
|
|
|
|
* @param noreveal_index choice by the exchange in the cut-and-choose protocol,
|
|
|
|
* UINT16_MAX on error
|
|
|
|
* @param exchange_pub public key the exchange used for signing
|
|
|
|
* @param full_response full response from the exchange (for logging, in case of errors)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
melt_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
|
|
|
uint16_t noreveal_index,
|
|
|
|
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
|
|
|
const json_t *full_response)
|
|
|
|
{
|
2016-06-14 15:51:58 +02:00
|
|
|
/* free'd in `reveal_cb` */
|
2016-06-10 16:06:27 +02:00
|
|
|
struct RefreshRevealCls *rrcls = cls;
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Coin *coin;
|
2016-06-10 16:04:03 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin = &coins[rrcls->coin_index];
|
|
|
|
coin->rmh = NULL;
|
2016-06-10 16:04:03 +02:00
|
|
|
if (MHD_HTTP_OK != http_status)
|
|
|
|
{
|
2016-06-10 16:07:51 +02:00
|
|
|
json_dumpf (full_response, stderr, 0);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Coin not correctly melted!");
|
2016-06-10 16:06:27 +02:00
|
|
|
return;
|
2016-06-10 16:04:03 +02:00
|
|
|
}
|
2016-06-14 15:51:58 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->rrh
|
2016-06-10 16:06:27 +02:00
|
|
|
= TALER_EXCHANGE_refresh_reveal (exchange,
|
|
|
|
rrcls->blob_size,
|
|
|
|
rrcls->blob,
|
|
|
|
noreveal_index,
|
2016-06-14 15:51:58 +02:00
|
|
|
&reveal_cb,
|
2016-06-11 17:35:15 +02:00
|
|
|
rrcls);
|
2016-06-10 15:22:32 +02:00
|
|
|
}
|
2016-06-07 16:58:55 +02:00
|
|
|
|
2016-06-13 15:42:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called upon completion of our /reserve/withdraw request.
|
|
|
|
* This is merely the function which spends withdrawn coins
|
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with the `struct Coin` we are withdrawing
|
2016-06-13 15:42:08 +02:00
|
|
|
* @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)
|
|
|
|
* @param sig signature over the coin, NULL on error
|
|
|
|
* @param full_response full response from the exchange (for logging, in case of errors)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reserve_withdraw_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
|
|
|
const struct TALER_DenominationSignature *sig,
|
|
|
|
const json_t *full_response);
|
|
|
|
|
|
|
|
|
2016-06-06 16:53:42 +02:00
|
|
|
/**
|
|
|
|
* Function called with the result of a /deposit operation.
|
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with the `struct Coin` that we are processing
|
2016-06-06 16:53:42 +02:00
|
|
|
* @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)
|
2016-06-07 15:14:44 +02:00
|
|
|
* @param exchange_pub public key used by the exchange for signing
|
2016-06-06 16:53:42 +02:00
|
|
|
* @param obj the received JSON reply, should be kept as proof (and, in case of errors,
|
|
|
|
* be forwarded to the customer)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
deposit_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
2016-06-07 15:14:44 +02:00
|
|
|
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
2016-06-06 16:53:42 +02:00
|
|
|
const json_t *obj)
|
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Coin *coin = cls;
|
2016-06-06 16:53:42 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->dh = NULL;
|
2016-06-06 16:53:42 +02:00
|
|
|
if (MHD_HTTP_OK != http_status)
|
|
|
|
{
|
2016-06-13 15:42:08 +02:00
|
|
|
json_dumpf (obj, stderr, 0);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("At least one coin has not been deposited, status: %d");
|
2016-06-06 16:53:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-14 15:51:58 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Coin #%d correctly spent!\n",
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->coin_index);
|
|
|
|
if (GNUNET_YES == coin->refresh)
|
2016-06-07 16:58:55 +02:00
|
|
|
{
|
2016-06-10 16:04:03 +02:00
|
|
|
struct RefreshRevealCls *rrcls;
|
2016-06-10 01:04:09 +02:00
|
|
|
char *blob;
|
|
|
|
size_t blob_size;
|
2016-06-14 15:51:58 +02:00
|
|
|
const struct TALER_EXCHANGE_Keys *keys;
|
|
|
|
struct TALER_Amount *denoms = NULL;
|
|
|
|
struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL;
|
|
|
|
const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk;
|
|
|
|
struct TALER_Amount curr;
|
|
|
|
unsigned int ndenoms = 0;
|
|
|
|
unsigned int ndenoms2 = 0;
|
|
|
|
unsigned long long acc_value;
|
|
|
|
|
|
|
|
TALER_amount_get_zero (currency, &curr);
|
|
|
|
acc_value = 0;
|
|
|
|
keys = TALER_EXCHANGE_get_keys (exchange);
|
2016-06-15 16:04:29 +02:00
|
|
|
for (curr.value = COIN_VALUE >> 1; curr.value > 0; curr.value = curr.value >> 1)
|
2016-06-14 15:51:58 +02:00
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
if (acc_value + curr.value <= coin->left.value)
|
2016-06-14 15:51:58 +02:00
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
GNUNET_array_append (denoms,
|
|
|
|
ndenoms,
|
|
|
|
curr);
|
2016-06-14 15:51:58 +02:00
|
|
|
GNUNET_assert (NULL != (curr_dpk = find_pk (keys, &curr)));
|
|
|
|
GNUNET_array_append (dpks, ndenoms2, *curr_dpk);
|
|
|
|
acc_value += curr.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"# of coins to get in melt: %d\n",
|
|
|
|
ndenoms2);
|
2016-06-15 16:04:29 +02:00
|
|
|
blob = TALER_EXCHANGE_refresh_prepare (&coin->coin_priv,
|
|
|
|
&coin->left,
|
|
|
|
&coin->sig,
|
|
|
|
coin->pk,
|
2016-06-10 01:04:09 +02:00
|
|
|
GNUNET_YES,
|
2016-06-14 15:51:58 +02:00
|
|
|
ndenoms2,
|
|
|
|
dpks,
|
2016-06-10 01:04:09 +02:00
|
|
|
&blob_size);
|
|
|
|
if (NULL == blob)
|
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Failed to prepare refresh");
|
2016-06-10 01:04:09 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-13 15:42:08 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
2016-06-10 01:04:09 +02:00
|
|
|
"prepared blob %d\n",
|
2016-06-11 14:33:52 +02:00
|
|
|
(unsigned int) blob_size);
|
2016-06-07 16:58:55 +02:00
|
|
|
refreshed_once = GNUNET_YES;
|
2016-06-10 15:22:32 +02:00
|
|
|
|
2016-06-10 16:04:03 +02:00
|
|
|
rrcls = GNUNET_new (struct RefreshRevealCls);
|
|
|
|
rrcls->blob = blob;
|
|
|
|
rrcls->blob_size = blob_size;
|
2016-06-15 16:04:29 +02:00
|
|
|
rrcls->coin_index = coin->coin_index;
|
2016-06-14 15:51:58 +02:00
|
|
|
rrcls->denoms = denoms;
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->rmh = TALER_EXCHANGE_refresh_melt (exchange,
|
|
|
|
blob_size,
|
|
|
|
blob,
|
|
|
|
&melt_cb,
|
|
|
|
rrcls);
|
|
|
|
if (NULL == coin->rmh)
|
2016-06-10 15:22:32 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Impossible to issue a melt request to the exchange");
|
2016-06-10 15:22:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-10 16:06:27 +02:00
|
|
|
}
|
2016-06-13 15:42:08 +02:00
|
|
|
else
|
|
|
|
{ /* re-withdraw */
|
|
|
|
struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv;
|
2016-06-15 16:04:29 +02:00
|
|
|
|
2016-06-13 15:42:08 +02:00
|
|
|
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->coin_priv.eddsa_priv = *coin_priv;
|
2016-06-13 15:42:08 +02:00
|
|
|
GNUNET_free (coin_priv);
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->wsh =
|
2016-06-13 15:42:08 +02:00
|
|
|
TALER_EXCHANGE_reserve_withdraw (exchange,
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->pk,
|
|
|
|
&reserves[coin->reserve_index].reserve_priv,
|
|
|
|
&coin->coin_priv,
|
2016-06-13 15:42:08 +02:00
|
|
|
&blinding_key,
|
2016-06-15 16:04:29 +02:00
|
|
|
&reserve_withdraw_cb,
|
|
|
|
coin);
|
2016-06-13 15:42:08 +02:00
|
|
|
}
|
2016-06-06 16:53:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-13 15:42:08 +02:00
|
|
|
|
2016-06-04 01:29:42 +02:00
|
|
|
/**
|
|
|
|
* Function called upon completion of our /reserve/withdraw request.
|
2016-06-14 15:53:48 +02:00
|
|
|
* This is merely the function which spends withdrawn coins. For each
|
|
|
|
* spent coin, ti either refresh it or re-withdraw it.
|
2016-06-04 01:29:42 +02:00
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with our `struct Coin`
|
2016-06-04 01:29:42 +02:00
|
|
|
* @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)
|
|
|
|
* @param sig signature over the coin, NULL on error
|
|
|
|
* @param full_response full response from the exchange (for logging, in case of errors)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
reserve_withdraw_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
|
|
|
const struct TALER_DenominationSignature *sig,
|
|
|
|
const json_t *full_response)
|
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Coin *coin = cls;
|
2016-06-04 01:29:42 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->wsh = NULL;
|
2016-06-04 01:29:42 +02:00
|
|
|
if (MHD_HTTP_OK != http_status)
|
2016-06-09 17:22:15 +02:00
|
|
|
{
|
2016-06-13 15:42:08 +02:00
|
|
|
json_dumpf (full_response, stderr, 0);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("At least one coin has not correctly been withdrawn");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-14 15:51:58 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
2016-06-06 23:53:54 +02:00
|
|
|
"%d-th coin withdrawn\n",
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->coin_index);
|
|
|
|
coin->sig.rsa_signature =
|
2016-06-04 01:29:42 +02:00
|
|
|
GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature);
|
|
|
|
if (GNUNET_OK == eval_probability (SPEND_PROBABILITY))
|
|
|
|
{
|
2016-06-06 16:53:42 +02:00
|
|
|
struct TALER_Amount amount;
|
|
|
|
struct GNUNET_TIME_Absolute wire_deadline;
|
|
|
|
struct GNUNET_TIME_Absolute timestamp;
|
|
|
|
struct GNUNET_TIME_Absolute refund_deadline;
|
|
|
|
struct GNUNET_HashCode h_contract;
|
|
|
|
struct TALER_CoinSpendPublicKeyP coin_pub;
|
|
|
|
struct TALER_DepositRequestPS dr;
|
|
|
|
struct TALER_MerchantPublicKeyP merchant_pub;
|
|
|
|
struct TALER_CoinSpendSignatureP coin_sig;
|
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&coin->coin_priv.eddsa_priv,
|
2016-06-06 16:53:42 +02:00
|
|
|
&coin_pub.eddsa_pub);
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
&h_contract,
|
|
|
|
sizeof (h_contract));
|
2016-06-06 23:55:31 +02:00
|
|
|
timestamp = GNUNET_TIME_absolute_get ();
|
2016-06-15 16:04:29 +02:00
|
|
|
wire_deadline = GNUNET_TIME_absolute_add (timestamp,
|
|
|
|
GNUNET_TIME_UNIT_WEEKS);
|
|
|
|
refund_deadline = GNUNET_TIME_absolute_add (timestamp,
|
|
|
|
GNUNET_TIME_UNIT_DAYS);
|
2016-06-06 16:53:42 +02:00
|
|
|
GNUNET_TIME_round_abs (×tamp);
|
|
|
|
GNUNET_TIME_round_abs (&wire_deadline);
|
|
|
|
GNUNET_TIME_round_abs (&refund_deadline);
|
2016-06-15 16:04:29 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
|
|
"Spending %d-th coin\n",
|
|
|
|
coin->coin_index);
|
2016-06-09 23:35:05 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
if ( (GNUNET_YES == eval_probability (REFRESH_PROBABILITY)) &&
|
|
|
|
(GNUNET_NO == refreshed_once) )
|
2016-06-09 23:35:05 +02:00
|
|
|
{
|
2016-06-14 15:51:58 +02:00
|
|
|
/**
|
|
|
|
* Always spending 1 out of 8 KUDOS. To be improved by randomly
|
|
|
|
* picking the spent amount
|
|
|
|
*/
|
2016-06-09 23:35:05 +02:00
|
|
|
struct TALER_Amount one;
|
2016-06-15 16:04:29 +02:00
|
|
|
|
2016-06-09 23:35:05 +02:00
|
|
|
TALER_amount_get_zero (currency, &one);
|
|
|
|
one.value = 1;
|
|
|
|
|
|
|
|
TALER_amount_subtract (&amount,
|
|
|
|
&one,
|
2016-06-15 16:04:29 +02:00
|
|
|
&coin->pk->fee_deposit);
|
|
|
|
TALER_amount_subtract (&coin->left,
|
|
|
|
&coin->pk->value,
|
2016-06-14 15:51:58 +02:00
|
|
|
&one);
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->refresh = GNUNET_YES;
|
2016-06-09 23:35:05 +02:00
|
|
|
refreshed_once = GNUNET_YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TALER_amount_subtract (&amount,
|
2016-06-15 16:04:29 +02:00
|
|
|
&coin->pk->value,
|
|
|
|
&coin->pk->fee_deposit);
|
2016-06-09 23:35:05 +02:00
|
|
|
}
|
2016-06-06 16:53:42 +02:00
|
|
|
memset (&dr, 0, sizeof (dr));
|
|
|
|
dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS));
|
|
|
|
dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT);
|
|
|
|
dr.h_contract = h_contract;
|
|
|
|
TALER_JSON_hash (merchant_details,
|
|
|
|
&dr.h_wire);
|
|
|
|
|
|
|
|
dr.timestamp = GNUNET_TIME_absolute_hton (timestamp);
|
|
|
|
dr.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
|
|
|
|
dr.transaction_id = GNUNET_htonll (transaction_id);
|
|
|
|
|
|
|
|
TALER_amount_hton (&dr.amount_with_fee,
|
|
|
|
&amount);
|
|
|
|
TALER_amount_hton (&dr.deposit_fee,
|
2016-06-15 16:04:29 +02:00
|
|
|
&coin->pk->fee_deposit);
|
2016-06-06 16:53:42 +02:00
|
|
|
|
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
|
|
|
|
&merchant_pub.eddsa_pub);
|
|
|
|
dr.merchant = merchant_pub;
|
|
|
|
dr.coin_pub = coin_pub;
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
2016-06-15 16:04:29 +02:00
|
|
|
GNUNET_CRYPTO_eddsa_sign (&coin->coin_priv.eddsa_priv,
|
2016-06-06 16:53:42 +02:00
|
|
|
&dr.purpose,
|
|
|
|
&coin_sig.eddsa_signature));
|
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->dh = TALER_EXCHANGE_deposit (exchange,
|
|
|
|
&amount,
|
|
|
|
wire_deadline,
|
|
|
|
merchant_details,
|
|
|
|
&h_contract,
|
|
|
|
&coin_pub,
|
|
|
|
&coin->sig,
|
|
|
|
&coin->pk->key,
|
|
|
|
timestamp,
|
|
|
|
transaction_id,
|
|
|
|
&merchant_pub,
|
|
|
|
refund_deadline,
|
|
|
|
&coin_sig,
|
|
|
|
&deposit_cb,
|
|
|
|
coin);
|
|
|
|
if (NULL == coin->dh)
|
2016-06-06 16:53:42 +02:00
|
|
|
{
|
|
|
|
json_decref (merchant_details);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("An error occurred while calling deposit API");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
2016-06-06 16:53:42 +02:00
|
|
|
}
|
|
|
|
transaction_id++;
|
2016-06-04 01:29:42 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-06 23:53:54 +02:00
|
|
|
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
/**
|
|
|
|
* Function called upon completion of our /admin/add/incoming request.
|
2016-06-07 16:58:55 +02:00
|
|
|
* Its duty is withdrawing coins on the freshly created reserve.
|
2016-06-03 01:23:16 +02:00
|
|
|
*
|
2016-06-15 16:04:29 +02:00
|
|
|
* @param cls closure with the `struct Reserve *`
|
2016-06-03 01:23:16 +02:00
|
|
|
* @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)
|
|
|
|
* @param full_response full response from the exchange (for logging, in case of errors)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_incoming_cb (void *cls,
|
|
|
|
unsigned int http_status,
|
|
|
|
const json_t *full_response)
|
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Reserve *r = cls;
|
2016-06-04 01:29:42 +02:00
|
|
|
struct GNUNET_CRYPTO_EddsaPrivateKey *coin_priv;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int coin_index;
|
2016-06-07 16:58:55 +02:00
|
|
|
struct TALER_Amount amount;
|
2016-06-09 23:35:05 +02:00
|
|
|
const struct TALER_EXCHANGE_Keys *keys;
|
2016-06-04 01:29:42 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
r->aih = NULL;
|
2016-06-04 01:29:42 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
|
|
"/admin/add/incoming callback called on %d-th reserve\n",
|
2016-06-15 16:04:29 +02:00
|
|
|
r->reserve_index);
|
2016-06-04 01:29:42 +02:00
|
|
|
if (MHD_HTTP_OK != http_status)
|
2016-06-13 15:42:08 +02:00
|
|
|
{
|
|
|
|
json_dumpf (full_response, stderr, 0);
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("At least one reserve failed in being created");
|
|
|
|
return;
|
2016-06-13 15:42:08 +02:00
|
|
|
}
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-15 16:04:29 +02:00
|
|
|
keys = TALER_EXCHANGE_get_keys (exchange);
|
2016-06-04 01:29:42 +02:00
|
|
|
for (i=0; i < COINS_PER_RESERVE; i++)
|
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Coin *coin;
|
|
|
|
|
|
|
|
coin_index = r->reserve_index * COINS_PER_RESERVE + i;
|
|
|
|
coin = &coins[coin_index];
|
|
|
|
coin->coin_index = coin_index;
|
2016-06-04 01:29:42 +02:00
|
|
|
coin_priv = GNUNET_CRYPTO_eddsa_key_create ();
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->coin_priv.eddsa_priv = *coin_priv;
|
2016-06-04 01:29:42 +02:00
|
|
|
GNUNET_free (coin_priv);
|
2016-06-15 16:04:29 +02:00
|
|
|
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 =
|
2016-06-04 01:29:42 +02:00
|
|
|
TALER_EXCHANGE_reserve_withdraw (exchange,
|
2016-06-15 16:04:29 +02:00
|
|
|
coin->pk,
|
|
|
|
&r->reserve_priv,
|
|
|
|
&coin->coin_priv,
|
2016-06-04 01:29:42 +02:00
|
|
|
&blinding_key,
|
2016-06-15 16:04:29 +02:00
|
|
|
&reserve_withdraw_cb,
|
|
|
|
coin);
|
2016-06-04 01:29:42 +02:00
|
|
|
}
|
2016-06-03 01:23:16 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-05-30 18:45:57 +02:00
|
|
|
/**
|
2016-06-15 15:09:57 +02:00
|
|
|
* Main task for the benchmark.
|
2016-05-30 18:45:57 +02:00
|
|
|
*
|
2016-06-15 15:09:57 +02:00
|
|
|
* @param cls NULL
|
2016-05-30 18:45:57 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
benchmark_run (void *cls)
|
|
|
|
{
|
2016-06-03 01:23:16 +02:00
|
|
|
unsigned int i;
|
|
|
|
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
|
|
|
|
json_t *transfer_details;
|
|
|
|
struct TALER_ReservePublicKeyP reserve_pub;
|
|
|
|
struct GNUNET_TIME_Absolute execution_date;
|
|
|
|
struct TALER_Amount reserve_amount;
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
benchmark_task = NULL;
|
2016-06-06 16:53:42 +02:00
|
|
|
priv = GNUNET_CRYPTO_eddsa_key_create ();
|
|
|
|
merchant_priv.eddsa_priv = *priv;
|
|
|
|
GNUNET_free (priv);
|
|
|
|
|
2016-06-03 19:39:04 +02:00
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
|
|
&blinding_key,
|
|
|
|
sizeof (blinding_key));
|
2016-06-08 16:12:31 +02:00
|
|
|
TALER_amount_get_zero (currency, &reserve_amount);
|
|
|
|
reserve_amount.value = RESERVE_VALUE;
|
2016-06-03 01:23:16 +02:00
|
|
|
execution_date = GNUNET_TIME_absolute_get ();
|
|
|
|
GNUNET_TIME_round_abs (&execution_date);
|
|
|
|
nreserves = pool_size / COINS_PER_RESERVE;
|
2016-06-09 17:22:15 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
2016-06-15 15:09:57 +02:00
|
|
|
"Creating %d reserves\n",
|
2016-06-06 23:53:54 +02:00
|
|
|
nreserves);
|
2016-06-03 01:23:16 +02:00
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
reserves = GNUNET_new_array (nreserves,
|
|
|
|
struct Reserve);
|
2016-06-11 18:01:57 +02:00
|
|
|
ncoins = COINS_PER_RESERVE * nreserves;
|
|
|
|
coins = GNUNET_new_array (ncoins,
|
2016-06-06 23:53:54 +02:00
|
|
|
struct Coin);
|
2016-05-30 18:57:16 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
for (i=0;i < nreserves;i++)
|
2016-06-03 01:23:16 +02:00
|
|
|
{
|
2016-06-15 16:04:29 +02:00
|
|
|
struct Reserve *r = &reserves[i];
|
|
|
|
|
2016-06-03 01:23:16 +02:00
|
|
|
priv = GNUNET_CRYPTO_eddsa_key_create ();
|
2016-06-15 16:04:29 +02:00
|
|
|
r->reserve_priv.eddsa_priv = *priv;
|
2016-06-03 01:23:16 +02:00
|
|
|
GNUNET_free (priv);
|
2016-06-15 16:04:29 +02:00
|
|
|
r->reserve_index = i;
|
|
|
|
transfer_details = json_pack ("{s:I}",
|
|
|
|
"uuid", (json_int_t) transfer_uuid++);
|
|
|
|
GNUNET_assert (NULL != transfer_details);
|
|
|
|
GNUNET_CRYPTO_eddsa_key_get_public (&r->reserve_priv.eddsa_priv,
|
2016-06-03 01:23:16 +02:00
|
|
|
&reserve_pub.eddsa_pub);
|
2016-06-15 16:04:29 +02:00
|
|
|
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);
|
2016-06-03 01:23:16 +02:00
|
|
|
json_decref (transfer_details);
|
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
json_decref (bank_details);
|
|
|
|
bank_details = NULL;
|
2016-06-13 23:40:00 +02:00
|
|
|
transfer_details = NULL;
|
2016-05-30 18:45:57 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
|
2016-06-09 23:35:05 +02:00
|
|
|
/**
|
2016-06-10 16:06:27 +02:00
|
|
|
* Populates the global array of denominations which will
|
2016-06-15 15:09:57 +02:00
|
|
|
* be withdrawn in a refresh operation. It sums up 4 #currency units,
|
2016-06-09 23:35:05 +02:00
|
|
|
* since that is the only amount refreshed so far by the benchmark
|
|
|
|
*
|
|
|
|
* @param NULL-terminated array of value.fraction pairs
|
2016-06-13 16:36:10 +02:00
|
|
|
* @return #GNUNET_OK if the array is correctly built, #GNUNET_SYSERR
|
2016-06-10 22:35:38 +02:00
|
|
|
* otherwise
|
2016-06-09 23:35:05 +02:00
|
|
|
*/
|
2016-06-10 22:35:38 +02:00
|
|
|
static unsigned int
|
2016-06-15 15:09:57 +02:00
|
|
|
build_refresh (const char *const*list)
|
2016-06-09 23:35:05 +02:00
|
|
|
{
|
|
|
|
char *amount_str;
|
|
|
|
struct TALER_Amount amount;
|
|
|
|
unsigned int i;
|
|
|
|
const struct TALER_EXCHANGE_DenomPublicKey *picked_denom;
|
|
|
|
const struct TALER_EXCHANGE_Keys *keys;
|
|
|
|
|
|
|
|
keys = TALER_EXCHANGE_get_keys (exchange);
|
2016-06-15 15:09:57 +02:00
|
|
|
for (i=0; NULL != list[i]; i++)
|
2016-06-09 23:35:05 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_asprintf (&amount_str,
|
|
|
|
"%s:%s",
|
|
|
|
currency,
|
|
|
|
list[i]);
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_string_to_amount (amount_str,
|
|
|
|
&amount));
|
|
|
|
picked_denom = find_pk (keys,
|
|
|
|
&amount);
|
2016-06-10 22:35:38 +02:00
|
|
|
if (NULL == picked_denom)
|
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_break (0);
|
|
|
|
GNUNET_free (amount_str);
|
2016-06-10 22:35:38 +02:00
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_array_append (refresh_pk,
|
|
|
|
refresh_pk_len,
|
|
|
|
*picked_denom);
|
2016-06-09 23:35:05 +02:00
|
|
|
GNUNET_free (amount_str);
|
|
|
|
}
|
2016-06-10 22:35:38 +02:00
|
|
|
return GNUNET_OK;
|
2016-06-09 23:35:05 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-05-30 18:45:57 +02:00
|
|
|
/**
|
|
|
|
* Functions of this type are called to provide the retrieved signing and
|
|
|
|
* denomination keys of the exchange. No TALER_EXCHANGE_*() functions should be called
|
|
|
|
* in this callback.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
2016-06-09 23:35:05 +02:00
|
|
|
* @param _keys information about keys of the exchange
|
2016-05-30 18:45:57 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cert_cb (void *cls,
|
2016-06-04 01:29:42 +02:00
|
|
|
const struct TALER_EXCHANGE_Keys *_keys)
|
2016-05-30 18:45:57 +02:00
|
|
|
{
|
|
|
|
/* check that keys is OK */
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL == _keys)
|
|
|
|
{
|
|
|
|
fail ("Exchange returned no keys!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( (0 == _keys->num_sign_keys) ||
|
|
|
|
(0 == _keys->num_denom_keys) )
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
fail ("Bad /keys response");
|
|
|
|
return;
|
|
|
|
}
|
2016-05-30 18:45:57 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
2016-06-15 15:09:57 +02:00
|
|
|
"Read %u signing keys and %u denomination keys\n",
|
2016-06-15 15:41:17 +02:00
|
|
|
_keys->num_sign_keys,
|
2016-06-04 01:29:42 +02:00
|
|
|
_keys->num_denom_keys);
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL != currency)
|
|
|
|
return; /* we've been here before... */
|
2016-06-10 01:04:09 +02:00
|
|
|
currency = GNUNET_strdup (_keys->denom_keys[0].value.currency);
|
2016-06-08 16:12:31 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
2016-06-15 15:09:57 +02:00
|
|
|
"Using currency: %s\n",
|
|
|
|
currency);
|
|
|
|
if (GNUNET_SYSERR ==
|
|
|
|
build_refresh (refresh_denoms))
|
2016-06-10 22:35:38 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Initializing denominations failed");
|
2016-06-10 22:35:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-30 18:45:57 +02:00
|
|
|
benchmark_task = GNUNET_SCHEDULER_add_now (&benchmark_run,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-05-30 18:45:57 +02:00
|
|
|
/**
|
2016-06-07 16:58:55 +02:00
|
|
|
* Function run when the benchmark terminates (good or bad).
|
2016-05-30 18:45:57 +02:00
|
|
|
* Cleans up our state.
|
|
|
|
*
|
|
|
|
* @param cls the interpreter state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
do_shutdown (void *cls)
|
|
|
|
{
|
2016-06-03 02:28:57 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Shutting down...\n");
|
2016-06-03 02:28:57 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL != benchmark_task)
|
|
|
|
{
|
|
|
|
GNUNET_SCHEDULER_cancel (benchmark_task);
|
|
|
|
benchmark_task = NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-03 02:28:57 +02:00
|
|
|
/**
|
|
|
|
* WARNING: all the non NULL handles must correspond to non completed
|
|
|
|
* calls (AKA calls for which the callback function has not been called).
|
|
|
|
* If not, it segfaults
|
|
|
|
*/
|
2016-06-15 15:09:57 +02:00
|
|
|
for (i=0; i<nreserves; i++)
|
2016-06-03 02:28:57 +02:00
|
|
|
{
|
|
|
|
if (NULL != reserves[i].aih)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Cancelling %d-th reserve\n",
|
|
|
|
i);
|
2016-06-03 02:28:57 +02:00
|
|
|
TALER_EXCHANGE_admin_add_incoming_cancel(reserves[i].aih);
|
|
|
|
reserves[i].aih = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
for (i=0; i<COINS_PER_RESERVE * nreserves; i++)
|
2016-06-03 02:28:57 +02:00
|
|
|
{
|
|
|
|
if (NULL != coins[i].wsh)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Cancelling %d-th coin withdraw handle\n",
|
|
|
|
i);
|
2016-06-03 02:28:57 +02:00
|
|
|
TALER_EXCHANGE_reserve_withdraw_cancel(coins[i].wsh);
|
|
|
|
coins[i].wsh = NULL;
|
2016-06-06 23:55:31 +02:00
|
|
|
}
|
2016-06-06 16:53:42 +02:00
|
|
|
if (NULL != coins[i].dh)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Cancelling %d-th coin deposit handle\n",
|
|
|
|
i);
|
2016-06-06 16:53:42 +02:00
|
|
|
TALER_EXCHANGE_deposit_cancel(coins[i].dh);
|
|
|
|
coins[i].dh = NULL;
|
2016-06-06 23:53:54 +02:00
|
|
|
}
|
2016-06-07 16:58:55 +02:00
|
|
|
if (NULL != coins[i].rmh)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Cancelling %d-th coin melt handle\n",
|
|
|
|
i);
|
2016-06-07 16:58:55 +02:00
|
|
|
TALER_EXCHANGE_refresh_melt_cancel(coins[i].rmh);
|
2016-06-10 16:06:27 +02:00
|
|
|
coins[i].rmh = NULL;
|
2016-06-07 16:58:55 +02:00
|
|
|
}
|
|
|
|
if (NULL != coins[i].rrh)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Cancelling %d-th coin reveal handle\n",
|
|
|
|
i);
|
2016-06-07 16:58:55 +02:00
|
|
|
TALER_EXCHANGE_refresh_reveal_cancel(coins[i].rrh);
|
2016-06-10 16:06:27 +02:00
|
|
|
coins[i].rmh = NULL;
|
2016-06-07 16:58:55 +02:00
|
|
|
}
|
2016-06-03 02:28:57 +02:00
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL != bank_details)
|
|
|
|
{
|
|
|
|
json_decref (bank_details);
|
|
|
|
bank_details = NULL;
|
|
|
|
}
|
2016-06-08 17:34:46 +02:00
|
|
|
if (NULL != merchant_details)
|
2016-06-15 15:09:57 +02:00
|
|
|
{
|
2016-06-09 23:35:05 +02:00
|
|
|
json_decref (merchant_details);
|
2016-06-15 15:09:57 +02:00
|
|
|
merchant_details = NULL;
|
|
|
|
}
|
2016-06-03 01:23:16 +02:00
|
|
|
GNUNET_free_non_null (reserves);
|
|
|
|
GNUNET_free_non_null (coins);
|
2016-06-10 01:04:09 +02:00
|
|
|
GNUNET_free_non_null (currency);
|
2016-06-06 22:40:33 +02:00
|
|
|
|
|
|
|
if (NULL != exchange)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Disconnecting from exchange\n");
|
2016-06-06 22:40:33 +02:00
|
|
|
TALER_EXCHANGE_disconnect (exchange);
|
|
|
|
exchange = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != ctx)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Invoking GNUNET_CURL_fini()\n");
|
2016-06-06 22:40:33 +02:00
|
|
|
GNUNET_CURL_fini (ctx);
|
|
|
|
ctx = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != rc)
|
|
|
|
{
|
2016-06-11 14:33:52 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"Invoking GNUNET_CURL_gnunet_rc_destroy()\n");
|
2016-06-06 22:40:33 +02:00
|
|
|
GNUNET_CURL_gnunet_rc_destroy (rc);
|
|
|
|
rc = NULL;
|
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_CONFIGURATION_destroy (cfg);
|
|
|
|
cfg = NULL;
|
2016-05-30 18:45:57 +02:00
|
|
|
}
|
2016-05-30 15:08:12 +02:00
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-05-30 17:16:01 +02:00
|
|
|
/**
|
|
|
|
* Main function that will be run by the scheduler.
|
2016-05-30 15:08:12 +02:00
|
|
|
*
|
2016-05-30 17:16:01 +02:00
|
|
|
* @param cls closure
|
2016-05-30 15:08:12 +02:00
|
|
|
*/
|
2016-05-30 17:16:01 +02:00
|
|
|
static void
|
|
|
|
run (void *cls)
|
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
char *bank_details_filename;
|
2016-06-08 17:11:33 +02:00
|
|
|
char *merchant_details_filename;
|
2016-06-08 16:12:31 +02:00
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
|
|
|
"running run()\n");
|
2016-06-08 16:12:31 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
|
|
|
"gotten pool_size of %d\n",
|
|
|
|
pool_size);
|
|
|
|
if (NULL == config_file)
|
2016-06-09 17:22:15 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("-c option is mandatory");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-08 16:12:31 +02:00
|
|
|
|
|
|
|
cfg = GNUNET_CONFIGURATION_create ();
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
|
|
|
|
NULL);
|
|
|
|
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg,
|
|
|
|
config_file))
|
2016-06-09 17:22:15 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Failed to parse configuration file");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-15 15:09:57 +02:00
|
|
|
if (GNUNET_SYSERR ==
|
|
|
|
GNUNET_CONFIGURATION_get_value_filename (cfg,
|
|
|
|
"benchmark",
|
|
|
|
"bank_details",
|
|
|
|
&bank_details_filename))
|
2016-06-09 17:22:15 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"benchmark",
|
|
|
|
"bank_details");
|
|
|
|
fail ("Failed to get BANK_DETAILS value");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-08 17:11:33 +02:00
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
bank_details = json_load_file (bank_details_filename,
|
|
|
|
JSON_REJECT_DUPLICATES,
|
|
|
|
NULL);
|
|
|
|
if (NULL == bank_details)
|
2016-06-09 17:22:15 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fail ("Failed to parse file with BANK_DETAILS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (GNUNET_SYSERR ==
|
|
|
|
GNUNET_CONFIGURATION_get_value_filename (cfg,
|
|
|
|
"benchmark",
|
|
|
|
"merchant_details",
|
|
|
|
&merchant_details_filename))
|
|
|
|
{
|
|
|
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"benchmark",
|
|
|
|
"merchant_details");
|
|
|
|
fail ("Failed to get MERCHANT_DETAILS value");
|
2016-06-09 17:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-08 17:11:33 +02:00
|
|
|
merchant_details = json_load_file (merchant_details_filename,
|
|
|
|
JSON_REJECT_DUPLICATES,
|
|
|
|
NULL);
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL == merchant_details)
|
|
|
|
{
|
|
|
|
fail ("Failed to parse file with MERCHANT_DETAILS");
|
|
|
|
return;
|
|
|
|
}
|
2016-06-03 01:23:16 +02:00
|
|
|
reserves = NULL;
|
|
|
|
coins = NULL;
|
2016-05-30 18:45:57 +02:00
|
|
|
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
|
|
|
|
&rc);
|
|
|
|
GNUNET_assert (NULL != ctx);
|
|
|
|
rc = GNUNET_CURL_gnunet_rc_create (ctx);
|
2016-06-15 15:09:57 +02:00
|
|
|
GNUNET_assert (NULL != rc);
|
2016-05-30 18:45:57 +02:00
|
|
|
exchange = TALER_EXCHANGE_connect (ctx,
|
2016-06-15 15:41:17 +02:00
|
|
|
exchange_uri,
|
2016-05-30 18:45:57 +02:00
|
|
|
&cert_cb, NULL,
|
|
|
|
TALER_EXCHANGE_OPTION_END);
|
2016-06-15 15:09:57 +02:00
|
|
|
if (NULL == exchange)
|
|
|
|
{
|
|
|
|
fail ("Failed to connect to the exchange!");
|
|
|
|
return;
|
|
|
|
}
|
2016-05-30 17:16:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 23:53:54 +02:00
|
|
|
|
2016-05-30 15:08:12 +02:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char * const *argv)
|
|
|
|
{
|
2016-06-08 16:12:31 +02:00
|
|
|
struct GNUNET_OS_Process *proc;
|
|
|
|
unsigned int cnt;
|
2016-05-30 17:16:01 +02:00
|
|
|
const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
2016-06-15 15:41:17 +02:00
|
|
|
{'a', "automate", NULL,
|
|
|
|
"Initialize and start the bank and exchange", GNUNET_NO,
|
|
|
|
&GNUNET_GETOPT_set_one, &run_exchange},
|
|
|
|
GNUNET_GETOPT_OPTION_CFG_FILE (&config_file),
|
|
|
|
GNUNET_GETOPT_OPTION_HELP ("tool to benchmark the Taler exchange"),
|
|
|
|
{'s', "pool-size", "SIZE",
|
2016-05-30 17:16:01 +02:00
|
|
|
"How many coins this benchmark should instantiate", GNUNET_YES,
|
2016-06-08 16:12:31 +02:00
|
|
|
&GNUNET_GETOPT_set_uint, &pool_size},
|
2016-06-15 15:41:17 +02:00
|
|
|
{'e', "exchange-uri", "URI",
|
|
|
|
"URI of the exchange", GNUNET_YES,
|
2016-06-15 16:04:29 +02:00
|
|
|
&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
|
2016-06-15 15:09:57 +02:00
|
|
|
};
|
2016-05-30 17:16:01 +02:00
|
|
|
|
2016-06-15 15:41:17 +02:00
|
|
|
GNUNET_log_setup ("taler-exchange-benchmark",
|
|
|
|
"WARNING",
|
|
|
|
NULL);
|
2016-05-30 18:45:57 +02:00
|
|
|
GNUNET_assert (GNUNET_SYSERR !=
|
2016-06-15 15:41:17 +02:00
|
|
|
GNUNET_GETOPT_run ("taler-exchange-benchmark",
|
|
|
|
options, argc, argv));
|
|
|
|
if (NULL == exchange_uri)
|
|
|
|
exchange_uri = GNUNET_strdup ("http://localhost:8081/");
|
2016-06-15 16:04:29 +02:00
|
|
|
if (NULL == exchange_admin_uri)
|
|
|
|
exchange_admin_uri = GNUNET_strdup ("http://localhost:18080/");
|
2016-06-15 15:09:57 +02:00
|
|
|
if (run_exchange)
|
2016-06-08 16:12:31 +02:00
|
|
|
{
|
2016-06-15 15:41:17 +02:00
|
|
|
char *wget;
|
|
|
|
|
2016-06-15 15:09:57 +02:00
|
|
|
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)
|
2016-06-08 16:12:31 +02:00
|
|
|
{
|
2016-06-15 15:09:57 +02:00
|
|
|
fprintf (stderr,
|
|
|
|
"Failed to run taler-exchange-httpd. Check your PATH.\n");
|
|
|
|
return 77;
|
|
|
|
}
|
2016-06-15 15:41:17 +02:00
|
|
|
|
|
|
|
GNUNET_asprintf (&wget,
|
|
|
|
"wget -q -t 1 -T 1 %s keys -o /dev/null -O /dev/null",
|
|
|
|
exchange_uri);
|
2016-06-15 15:09:57 +02:00
|
|
|
cnt = 0;
|
|
|
|
do {
|
2016-06-08 16:12:31 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 15:41:17 +02:00
|
|
|
while (0 != system (wget));
|
|
|
|
GNUNET_free (wget);
|
2016-06-15 15:09:57 +02:00
|
|
|
fprintf (stderr, "\n");
|
|
|
|
}
|
2016-05-30 17:16:01 +02:00
|
|
|
GNUNET_SCHEDULER_run (&run, NULL);
|
2016-06-15 15:09:57 +02:00
|
|
|
if (run_exchange)
|
|
|
|
{
|
|
|
|
GNUNET_OS_process_kill (exchanged,
|
|
|
|
SIGTERM);
|
|
|
|
GNUNET_OS_process_wait (exchanged);
|
|
|
|
GNUNET_OS_process_destroy (exchanged);
|
|
|
|
}
|
|
|
|
return 0;
|
2016-05-30 15:08:12 +02:00
|
|
|
}
|
2016-06-15 15:41:17 +02:00
|
|
|
|
|
|
|
/* end of taler-exchange-benchmark.c */
|