misc fakebank fixes
This commit is contained in:
parent
fdf095c6ef
commit
8c0492be71
@ -576,14 +576,17 @@ clean_transaction (struct TALER_FAKEBANK_Handle *h,
|
|||||||
t);
|
t);
|
||||||
GNUNET_assert (0 ==
|
GNUNET_assert (0 ==
|
||||||
pthread_mutex_unlock (&ca->lock));
|
pthread_mutex_unlock (&ca->lock));
|
||||||
GNUNET_assert (0 ==
|
if (T_DEBIT == t->type)
|
||||||
pthread_mutex_lock (&h->uuid_map_lock));
|
{
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_assert (0 ==
|
||||||
GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
|
pthread_mutex_lock (&h->uuid_map_lock));
|
||||||
&t->request_uid,
|
GNUNET_assert (GNUNET_OK ==
|
||||||
t));
|
GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
|
||||||
GNUNET_assert (0 ==
|
&t->request_uid,
|
||||||
pthread_mutex_unlock (&h->uuid_map_lock));
|
t));
|
||||||
|
GNUNET_assert (0 ==
|
||||||
|
pthread_mutex_unlock (&h->uuid_map_lock));
|
||||||
|
}
|
||||||
t->debit_account = NULL;
|
t->debit_account = NULL;
|
||||||
t->credit_account = NULL;
|
t->credit_account = NULL;
|
||||||
}
|
}
|
||||||
@ -671,8 +674,22 @@ post_transaction (struct Transaction *t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
/**
|
||||||
TALER_FAKEBANK_make_transfer (
|
* Tell the fakebank to create another wire transfer *from* an exchange.
|
||||||
|
*
|
||||||
|
* @param h fake bank handle
|
||||||
|
* @param debit_account account to debit
|
||||||
|
* @param credit_account account to credit
|
||||||
|
* @param amount amount to transfer
|
||||||
|
* @param subject wire transfer subject to use
|
||||||
|
* @param exchange_base_url exchange URL
|
||||||
|
* @param request_uid unique number to make the request unique, or NULL to create one
|
||||||
|
* @param[out] ret_row_id pointer to store the row ID of this transaction
|
||||||
|
* @return #GNUNET_YES if the transfer was successful,
|
||||||
|
* #GNUNET_SYSERR if the request_uid was reused for a different transfer
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
make_transfer (
|
||||||
struct TALER_FAKEBANK_Handle *h,
|
struct TALER_FAKEBANK_Handle *h,
|
||||||
const char *debit_account,
|
const char *debit_account,
|
||||||
const char *credit_account,
|
const char *credit_account,
|
||||||
@ -782,13 +799,27 @@ TALER_FAKEBANK_make_transfer (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t
|
/**
|
||||||
TALER_FAKEBANK_make_admin_transfer (
|
* Tell the fakebank to create another wire transfer *to* an exchange.
|
||||||
|
*
|
||||||
|
* @param h fake bank handle
|
||||||
|
* @param debit_account account to debit
|
||||||
|
* @param credit_account account to credit
|
||||||
|
* @param amount amount to transfer
|
||||||
|
* @param reserve_pub reserve public key to use in subject
|
||||||
|
* @param[out] serial_id of the transfer
|
||||||
|
* @param[out] timestamp when was the transfer made
|
||||||
|
* @return #GNUNET_OK on success
|
||||||
|
*/
|
||||||
|
static enum GNUNET_GenericReturnValue
|
||||||
|
make_admin_transfer (
|
||||||
struct TALER_FAKEBANK_Handle *h,
|
struct TALER_FAKEBANK_Handle *h,
|
||||||
const char *debit_account,
|
const char *debit_account,
|
||||||
const char *credit_account,
|
const char *credit_account,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub)
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
|
uint64_t *row_id,
|
||||||
|
struct GNUNET_TIME_Absolute *timestamp)
|
||||||
{
|
{
|
||||||
struct Transaction *t;
|
struct Transaction *t;
|
||||||
const struct GNUNET_PeerIdentity *pid;
|
const struct GNUNET_PeerIdentity *pid;
|
||||||
@ -824,11 +855,13 @@ TALER_FAKEBANK_make_admin_transfer (
|
|||||||
{
|
{
|
||||||
/* duplicate reserve public key not allowed */
|
/* duplicate reserve public key not allowed */
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
return 0;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = __sync_fetch_and_add (&h->serial_counter,
|
ret = __sync_fetch_and_add (&h->serial_counter,
|
||||||
1);
|
1);
|
||||||
|
if (NULL != row_id)
|
||||||
|
*row_id = ret;
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Making transfer from %s to %s over %s and subject %s at row %llu\n",
|
"Making transfer from %s to %s over %s and subject %s at row %llu\n",
|
||||||
debit_account,
|
debit_account,
|
||||||
@ -847,7 +880,9 @@ TALER_FAKEBANK_make_admin_transfer (
|
|||||||
t->amount = *amount;
|
t->amount = *amount;
|
||||||
t->row_id = ret;
|
t->row_id = ret;
|
||||||
t->date = GNUNET_TIME_absolute_get ();
|
t->date = GNUNET_TIME_absolute_get ();
|
||||||
GNUNET_TIME_round_abs (&t->date);
|
(void) GNUNET_TIME_round_abs (&t->date);
|
||||||
|
if (NULL != timestamp)
|
||||||
|
*timestamp = t->date;
|
||||||
t->type = T_CREDIT;
|
t->type = T_CREDIT;
|
||||||
t->subject.credit.reserve_pub = *reserve_pub;
|
t->subject.credit.reserve_pub = *reserve_pub;
|
||||||
post_transaction (t);
|
post_transaction (t);
|
||||||
@ -863,7 +898,7 @@ TALER_FAKEBANK_make_admin_transfer (
|
|||||||
pthread_mutex_unlock (&h->rpubs_lock));
|
pthread_mutex_unlock (&h->rpubs_lock));
|
||||||
GNUNET_assert (0 ==
|
GNUNET_assert (0 ==
|
||||||
pthread_mutex_unlock (&t->lock));
|
pthread_mutex_unlock (&t->lock));
|
||||||
return ret;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -992,6 +1027,8 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
|||||||
enum GNUNET_JSON_PostResult pr;
|
enum GNUNET_JSON_PostResult pr;
|
||||||
json_t *json;
|
json_t *json;
|
||||||
uint64_t row_id;
|
uint64_t row_id;
|
||||||
|
struct GNUNET_TIME_Absolute timestamp;
|
||||||
|
enum GNUNET_GenericReturnValue ret;
|
||||||
|
|
||||||
pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
|
pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
|
||||||
connection,
|
connection,
|
||||||
@ -1059,13 +1096,15 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
|||||||
account,
|
account,
|
||||||
TALER_B2S (&reserve_pub),
|
TALER_B2S (&reserve_pub),
|
||||||
TALER_amount2s (&amount));
|
TALER_amount2s (&amount));
|
||||||
row_id = TALER_FAKEBANK_make_admin_transfer (h,
|
ret = make_admin_transfer (h,
|
||||||
debit,
|
debit,
|
||||||
account,
|
account,
|
||||||
&amount,
|
&amount,
|
||||||
&reserve_pub);
|
&reserve_pub,
|
||||||
|
&row_id,
|
||||||
|
×tamp);
|
||||||
GNUNET_free (debit);
|
GNUNET_free (debit);
|
||||||
if (0 == row_id)
|
if (GNUNET_OK != ret)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Reserve public key not unique\n");
|
"Reserve public key not unique\n");
|
||||||
@ -1078,8 +1117,6 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
|||||||
}
|
}
|
||||||
json_decref (json);
|
json_decref (json);
|
||||||
|
|
||||||
// FIXME: timestamp without lock is unclean,
|
|
||||||
// return as part of TALER_FAKEBANK_make_admin_transfer instead!
|
|
||||||
/* Finally build response object */
|
/* Finally build response object */
|
||||||
return TALER_MHD_reply_json_pack (connection,
|
return TALER_MHD_reply_json_pack (connection,
|
||||||
MHD_HTTP_OK,
|
MHD_HTTP_OK,
|
||||||
@ -1087,8 +1124,7 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
|
|||||||
"row_id",
|
"row_id",
|
||||||
(json_int_t) row_id,
|
(json_int_t) row_id,
|
||||||
"timestamp",
|
"timestamp",
|
||||||
GNUNET_JSON_from_time_abs (
|
GNUNET_JSON_from_time_abs (timestamp));
|
||||||
h->transactions[row_id].date));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1172,14 +1208,14 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
credit = TALER_xtalerbank_account_from_payto (credit_account);
|
credit = TALER_xtalerbank_account_from_payto (credit_account);
|
||||||
ret = TALER_FAKEBANK_make_transfer (h,
|
ret = make_transfer (h,
|
||||||
account,
|
account,
|
||||||
credit,
|
credit,
|
||||||
&amount,
|
&amount,
|
||||||
&wtid,
|
&wtid,
|
||||||
base_url,
|
base_url,
|
||||||
&uuid,
|
&uuid,
|
||||||
&row_id);
|
&row_id);
|
||||||
if (GNUNET_OK != ret)
|
if (GNUNET_OK != ret)
|
||||||
{
|
{
|
||||||
MHD_RESULT res;
|
MHD_RESULT res;
|
||||||
@ -1393,7 +1429,7 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct Transaction *t = &h->transactions[ha.start_idx];
|
struct Transaction *t = &h->transactions[ha.start_idx % h->ram_limit];
|
||||||
|
|
||||||
GNUNET_assert (0 ==
|
GNUNET_assert (0 ==
|
||||||
pthread_mutex_lock (&t->lock));
|
pthread_mutex_lock (&t->lock));
|
||||||
@ -1508,7 +1544,7 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct Transaction *t = &h->transactions[ha.start_idx];
|
struct Transaction *t = &h->transactions[ha.start_idx % h->ram_limit];
|
||||||
|
|
||||||
GNUNET_assert (0 ==
|
GNUNET_assert (0 ==
|
||||||
pthread_mutex_lock (&t->lock));
|
pthread_mutex_lock (&t->lock));
|
||||||
|
@ -28,6 +28,11 @@ DB = postgres
|
|||||||
# exchange (or the twister) is actually listening.
|
# exchange (or the twister) is actually listening.
|
||||||
base_url = "http://localhost:8081/"
|
base_url = "http://localhost:8081/"
|
||||||
|
|
||||||
|
WIREWATCH_IDLE_SLEEP_INTERVAL = 5 ms
|
||||||
|
|
||||||
|
[exchange-offline]
|
||||||
|
MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
|
||||||
|
|
||||||
[auditor]
|
[auditor]
|
||||||
BASE_URL = "http://localhost:8083/"
|
BASE_URL = "http://localhost:8083/"
|
||||||
|
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
* @author Marcello Stanisci
|
* @author Marcello Stanisci
|
||||||
* @author Christian Grothoff
|
* @author Christian Grothoff
|
||||||
*/
|
*/
|
||||||
|
// TODO:
|
||||||
|
// - use more than one 'client' bank account
|
||||||
|
// - also add taler-exchange-transfer to simulate outgoing payments
|
||||||
|
// - improve reporting logic (currently not working)
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <gnunet/gnunet_util_lib.h>
|
#include <gnunet/gnunet_util_lib.h>
|
||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
@ -250,42 +254,39 @@ static void
|
|||||||
run (void *cls,
|
run (void *cls,
|
||||||
struct TALER_TESTING_Interpreter *is)
|
struct TALER_TESTING_Interpreter *is)
|
||||||
{
|
{
|
||||||
struct TALER_Amount total_reserve_amount;
|
char *total_reserve_amount;
|
||||||
char *user_payto_uri;
|
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
// FIXME: vary user accounts more...
|
// FIXME: vary user accounts more...
|
||||||
GNUNET_assert (GNUNET_OK ==
|
|
||||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
|
||||||
"benchmark",
|
|
||||||
"USER_PAYTO_URI",
|
|
||||||
&user_payto_uri));
|
|
||||||
all_commands = GNUNET_new_array (howmany_reserves
|
all_commands = GNUNET_new_array (howmany_reserves
|
||||||
+ 1 /* stat CMD */
|
+ 1 /* stat CMD */
|
||||||
+ 1 /* End CMD */,
|
+ 1 /* End CMD */,
|
||||||
struct TALER_TESTING_Command);
|
struct TALER_TESTING_Command);
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_asprintf (&total_reserve_amount,
|
||||||
TALER_amount_get_zero (currency,
|
"%s:5",
|
||||||
&total_reserve_amount));
|
currency);
|
||||||
total_reserve_amount.value = 5;
|
|
||||||
for (unsigned int j = 0; j < howmany_reserves; j++)
|
for (unsigned int j = 0; j < howmany_reserves; j++)
|
||||||
{
|
{
|
||||||
char create_reserve_label[32];
|
char *create_reserve_label;
|
||||||
|
char *user_payto_uri;
|
||||||
|
|
||||||
GNUNET_snprintf (create_reserve_label,
|
GNUNET_assert (GNUNET_OK ==
|
||||||
sizeof (create_reserve_label),
|
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||||
|
"benchmark",
|
||||||
|
"USER_PAYTO_URI",
|
||||||
|
&user_payto_uri));
|
||||||
|
GNUNET_asprintf (&create_reserve_label,
|
||||||
"createreserve-%u",
|
"createreserve-%u",
|
||||||
j);
|
j);
|
||||||
all_commands[j]
|
all_commands[j]
|
||||||
= TALER_TESTING_cmd_admin_add_incoming_retry (
|
= TALER_TESTING_cmd_admin_add_incoming_retry (
|
||||||
TALER_TESTING_cmd_admin_add_incoming (add_label (
|
TALER_TESTING_cmd_admin_add_incoming (add_label (
|
||||||
create_reserve_label),
|
create_reserve_label),
|
||||||
TALER_amount2s (
|
total_reserve_amount,
|
||||||
&total_reserve_amount),
|
|
||||||
&exchange_bank_account,
|
&exchange_bank_account,
|
||||||
user_payto_uri));
|
add_label (user_payto_uri)));
|
||||||
}
|
}
|
||||||
GNUNET_free (user_payto_uri);
|
GNUNET_free (total_reserve_amount);
|
||||||
all_commands[howmany_reserves]
|
all_commands[howmany_reserves]
|
||||||
= TALER_TESTING_cmd_stat (timings);
|
= TALER_TESTING_cmd_stat (timings);
|
||||||
all_commands[howmany_reserves + 1]
|
all_commands[howmany_reserves + 1]
|
||||||
@ -454,6 +455,20 @@ parallel_benchmark (void)
|
|||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct GNUNET_OS_Process *dbinit;
|
||||||
|
|
||||||
|
dbinit = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
"taler-exchange-dbinit",
|
||||||
|
"taler-exchange-dbinit",
|
||||||
|
"-c", cfg_filename,
|
||||||
|
"-r",
|
||||||
|
NULL);
|
||||||
|
GNUNET_break (GNUNET_OK ==
|
||||||
|
GNUNET_OS_process_wait (dbinit));
|
||||||
|
GNUNET_OS_process_destroy (dbinit);
|
||||||
|
}
|
||||||
/* start exchange wirewatch */
|
/* start exchange wirewatch */
|
||||||
wirewatch = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
|
wirewatch = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
@ -461,21 +476,27 @@ parallel_benchmark (void)
|
|||||||
"taler-exchange-wirewatch",
|
"taler-exchange-wirewatch",
|
||||||
"-c", cfg_filename,
|
"-c", cfg_filename,
|
||||||
NULL);
|
NULL);
|
||||||
if (-1 != fakebank)
|
if (NULL == wirewatch)
|
||||||
{
|
{
|
||||||
int wstatus;
|
if (-1 != fakebank)
|
||||||
|
{
|
||||||
|
int wstatus;
|
||||||
|
|
||||||
kill (fakebank,
|
kill (fakebank,
|
||||||
SIGTERM);
|
SIGTERM);
|
||||||
waitpid (fakebank,
|
waitpid (fakebank,
|
||||||
&wstatus,
|
&wstatus,
|
||||||
0);
|
0);
|
||||||
}
|
fakebank = -1;
|
||||||
if (NULL != bankd)
|
}
|
||||||
{
|
if (NULL != bankd)
|
||||||
GNUNET_OS_process_kill (bankd,
|
{
|
||||||
SIGTERM);
|
GNUNET_OS_process_kill (bankd,
|
||||||
GNUNET_OS_process_destroy (bankd);
|
SIGTERM);
|
||||||
|
GNUNET_OS_process_destroy (bankd);
|
||||||
|
bankd = NULL;
|
||||||
|
}
|
||||||
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +715,7 @@ main (int argc,
|
|||||||
howmany_reserves,
|
howmany_reserves,
|
||||||
howmany_clients,
|
howmany_clients,
|
||||||
GNUNET_STRINGS_relative_time_to_string (duration,
|
GNUNET_STRINGS_relative_time_to_string (duration,
|
||||||
GNUNET_NO));
|
GNUNET_YES));
|
||||||
fprintf (stdout,
|
fprintf (stdout,
|
||||||
"RAW: %04u %04u %16llu\n",
|
"RAW: %04u %04u %16llu\n",
|
||||||
howmany_reserves,
|
howmany_reserves,
|
||||||
|
@ -93,51 +93,6 @@ int
|
|||||||
TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
|
TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell the fakebank to create another wire transfer *from* an exchange.
|
|
||||||
*
|
|
||||||
* @param h fake bank handle
|
|
||||||
* @param debit_account account to debit
|
|
||||||
* @param credit_account account to credit
|
|
||||||
* @param amount amount to transfer
|
|
||||||
* @param subject wire transfer subject to use
|
|
||||||
* @param exchange_base_url exchange URL
|
|
||||||
* @param request_uid unique number to make the request unique, or NULL to create one
|
|
||||||
* @param[out] ret_row_id pointer to store the row ID of this transaction
|
|
||||||
* @return #GNUNET_YES if the transfer was successful,
|
|
||||||
* #GNUNET_SYSERR if the request_uid was reused for a different transfer
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
TALER_FAKEBANK_make_transfer (
|
|
||||||
struct TALER_FAKEBANK_Handle *h,
|
|
||||||
const char *debit_account,
|
|
||||||
const char *credit_account,
|
|
||||||
const struct TALER_Amount *amount,
|
|
||||||
const struct TALER_WireTransferIdentifierRawP *subject,
|
|
||||||
const char *exchange_base_url,
|
|
||||||
const struct GNUNET_HashCode *request_uid,
|
|
||||||
uint64_t *ret_row_id);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell the fakebank to create another wire transfer *to* an exchange.
|
|
||||||
*
|
|
||||||
* @param h fake bank handle
|
|
||||||
* @param debit_account account to debit
|
|
||||||
* @param credit_account account to credit
|
|
||||||
* @param amount amount to transfer
|
|
||||||
* @param reserve_pub reserve public key to use in subject
|
|
||||||
* @return serial_id of the transfer, 0 on error
|
|
||||||
*/
|
|
||||||
uint64_t
|
|
||||||
TALER_FAKEBANK_make_admin_transfer (
|
|
||||||
struct TALER_FAKEBANK_Handle *h,
|
|
||||||
const char *debit_account,
|
|
||||||
const char *credit_account,
|
|
||||||
const struct TALER_Amount *amount,
|
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the @a want_amount was transferred from the @a
|
* Check that the @a want_amount was transferred from the @a
|
||||||
* want_debit to the @a want_credit account. If so, set the @a subject
|
* want_debit to the @a want_credit account. If so, set the @a subject
|
||||||
|
Loading…
Reference in New Issue
Block a user