-implement exchange URL suggestion

This commit is contained in:
Christian Grothoff 2022-08-16 13:34:33 +02:00
parent dfc3d89c5a
commit ab7266fc1c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 42 additions and 3 deletions

View File

@ -447,6 +447,12 @@ struct TALER_FAKEBANK_Handle
*/ */
struct GNUNET_CONTAINER_MultiShortmap *wops; struct GNUNET_CONTAINER_MultiShortmap *wops;
/**
* (Base) URL to suggest for the exchange. Can
* be NULL if there is no suggestion to be made.
*/
char *exchange_url;
/** /**
* Lock for accessing @a rpubs map. * Lock for accessing @a rpubs map.
*/ */
@ -1539,6 +1545,7 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
GNUNET_free (h->transactions); GNUNET_free (h->transactions);
GNUNET_free (h->my_baseurl); GNUNET_free (h->my_baseurl);
GNUNET_free (h->currency); GNUNET_free (h->currency);
GNUNET_free (h->exchange_url);
GNUNET_free (h->hostname); GNUNET_free (h->hostname);
GNUNET_free (h); GNUNET_free (h);
} }
@ -2669,7 +2676,7 @@ serve (struct TALER_FAKEBANK_Handle *h,
/** /**
* Handle GET /withdrawal-operation/ request. * Handle GET /withdrawal-operation/{wopid} request.
* *
* @param h the handle * @param h the handle
* @param connection the connection * @param connection the connection
@ -2723,6 +2730,9 @@ get_withdrawal_operation (struct TALER_FAKEBANK_Handle *h,
wo->selection_done), wo->selection_done),
GNUNET_JSON_pack_bool ("transfer_done", GNUNET_JSON_pack_bool ("transfer_done",
wo->confirmation_done), wo->confirmation_done),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("suggested_exchange",
h->exchange_url)),
TALER_JSON_pack_amount ("amount", TALER_JSON_pack_amount ("amount",
&wo->amount), &wo->amount),
GNUNET_JSON_pack_array_steal ("wire_types", GNUNET_JSON_pack_array_steal ("wire_types",
@ -4036,6 +4046,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
{ {
return TALER_FAKEBANK_start3 ("localhost", return TALER_FAKEBANK_start3 ("localhost",
port, port,
NULL,
currency, currency,
ram_limit, ram_limit,
num_threads); num_threads);
@ -4045,6 +4056,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
struct TALER_FAKEBANK_Handle * struct TALER_FAKEBANK_Handle *
TALER_FAKEBANK_start3 (const char *hostname, TALER_FAKEBANK_start3 (const char *hostname,
uint16_t port, uint16_t port,
const char *exchange_url,
const char *currency, const char *currency,
uint64_t ram_limit, uint64_t ram_limit,
unsigned int num_threads) unsigned int num_threads)
@ -4060,6 +4072,8 @@ TALER_FAKEBANK_start3 (const char *hostname,
} }
GNUNET_assert (strlen (currency) < TALER_CURRENCY_LEN); GNUNET_assert (strlen (currency) < TALER_CURRENCY_LEN);
h = GNUNET_new (struct TALER_FAKEBANK_Handle); h = GNUNET_new (struct TALER_FAKEBANK_Handle);
if (NULL != exchange_url)
h->exchange_url = GNUNET_strdup (exchange_url);
#ifdef __linux__ #ifdef __linux__
h->lp_event = -1; h->lp_event = -1;
#else #else

View File

@ -103,6 +103,8 @@ run (void *cls,
unsigned long long port = 8082; unsigned long long port = 8082;
unsigned long long ram = 1024 * 128; /* 128 k entries */ unsigned long long ram = 1024 * 128; /* 128 k entries */
char *currency_string; char *currency_string;
char *hostname;
char *exchange_url;
(void) cls; (void) cls;
(void) args; (void) args;
@ -124,6 +126,23 @@ run (void *cls,
"Listening on default port %llu\n", "Listening on default port %llu\n",
port); port);
} }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"bank",
"SUGGESTED_EXCHANGE",
&exchange_url))
{
/* no suggested exchange */
exchange_url = NULL;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"bank",
"HOSTNAME",
&hostname))
{
hostname = GNUNET_strdup ("localhost");
}
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, GNUNET_CONFIGURATION_get_value_number (cfg,
"bank", "bank",
@ -142,17 +161,21 @@ run (void *cls,
go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE; go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
TALER_MHD_setup (go); TALER_MHD_setup (go);
} }
fb = TALER_FAKEBANK_start2 ((uint16_t) port, fb = TALER_FAKEBANK_start3 (hostname,
(uint16_t) port,
exchange_url,
currency_string, currency_string,
ram, ram,
num_threads); num_threads);
GNUNET_free (hostname);
GNUNET_free (exchange_url);
GNUNET_free (currency_string);
if (NULL == fb) if (NULL == fb)
{ {
GNUNET_break (0); GNUNET_break (0);
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
return; return;
} }
GNUNET_free (currency_string);
keepalive = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, keepalive = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&keepalive_task, &keepalive_task,
NULL); NULL);

View File

@ -87,6 +87,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
* *
* @param hostname hostname to use in URLs and URIs. * @param hostname hostname to use in URLs and URIs.
* @param port port to listen to * @param port port to listen to
* @param exchange_url suggested exchange base URL
* @param currency which currency should the bank offer * @param currency which currency should the bank offer
* @param ram_limit how much memory do we use at most * @param ram_limit how much memory do we use at most
* @param num_threads size of the thread pool, 0 to use the GNUnet scheduler * @param num_threads size of the thread pool, 0 to use the GNUnet scheduler
@ -95,6 +96,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
struct TALER_FAKEBANK_Handle * struct TALER_FAKEBANK_Handle *
TALER_FAKEBANK_start3 (const char *hostname, TALER_FAKEBANK_start3 (const char *hostname,
uint16_t port, uint16_t port,
const char *exchange_url,
const char *currency, const char *currency,
uint64_t ram_limit, uint64_t ram_limit,
unsigned int num_threads); unsigned int num_threads);