From 17789253e9194c66bb9ddb081425a35212ac7bf3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 21 Jun 2023 07:53:17 +0200 Subject: ensure forward-compatibility for auditor C API --- src/lib/exchange_api_handle.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 20bac43a..7b815f28 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -168,19 +168,20 @@ struct KeysRequest void -TEAH_acc_confirmation_cb (void *cls, - const struct TALER_AUDITOR_HttpResponse *hr) +TEAH_acc_confirmation_cb ( + void *cls, + const struct TALER_AUDITOR_DepositConfirmationResponse *dcr) { struct TEAH_AuditorInteractionEntry *aie = cls; struct TEAH_AuditorListEntry *ale = aie->ale; - if (MHD_HTTP_OK != hr->http_status) + if (MHD_HTTP_OK != dcr->hr.http_status) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n", ale->auditor_url, - hr->http_status, - hr->ec); + dcr->hr.http_status, + dcr->hr.ec); } GNUNET_CONTAINER_DLL_remove (ale->ai_head, ale->ai_tail, @@ -579,21 +580,17 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf, * auditor as 'up'. * * @param cls closure, a `struct TEAH_AuditorListEntry *` - * @param hr http response from the auditor - * @param vi basic information about the auditor - * @param compat protocol compatibility information + * @param vr response from the auditor */ static void auditor_version_cb ( void *cls, - const struct TALER_AUDITOR_HttpResponse *hr, - const struct TALER_AUDITOR_VersionInformation *vi, - enum TALER_AUDITOR_VersionCompatibility compat) + const struct TALER_AUDITOR_VersionResponse *vr) { struct TEAH_AuditorListEntry *ale = cls; + enum TALER_AUDITOR_VersionCompatibility compat; - (void) hr; - if (NULL == vi) + if (MHD_HTTP_OK != vr->hr.http_status) { /* In this case, we don't mark the auditor as 'up' */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -601,7 +598,7 @@ auditor_version_cb ( ale->auditor_url); return; } - + compat = vr->details.ok.compat; if (0 != (TALER_AUDITOR_VC_INCOMPATIBLE & compat)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, -- cgit v1.2.3 From af77a2a178a818abe851e4e25e768e2c1963b49c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 21 Jun 2023 08:15:06 +0200 Subject: -more auditor API atomization --- src/include/taler_auditor_service.h | 6 ++- src/lib/auditor_api_deposit_confirmation.c | 19 ++------ src/lib/exchange_api_batch_deposit.c | 25 ++++++---- src/lib/exchange_api_deposit.c | 27 ++++++----- src/lib/exchange_api_handle.c | 2 +- src/lib/exchange_api_handle.h | 4 +- .../testing_api_cmd_auditor_deposit_confirmation.c | 53 ++++++++++++---------- 7 files changed, 73 insertions(+), 63 deletions(-) (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/include/taler_auditor_service.h b/src/include/taler_auditor_service.h index 5ee41c3b..2c6685c1 100644 --- a/src/include/taler_auditor_service.h +++ b/src/include/taler_auditor_service.h @@ -277,7 +277,8 @@ typedef void * finished processing the /version reply). If either check fails, we do * NOT initiate the transaction with the auditor and instead return NULL. * - * @param auditor the auditor handle; the auditor must be ready to operate + * @param ctx the context for CURL requests + * @param url HTTP base URL for the auditor * @param h_wire hash of merchant wire details * @param h_policy hash over the policy, if any * @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the auditor) @@ -301,7 +302,8 @@ typedef void */ struct TALER_AUDITOR_DepositConfirmationHandle * TALER_AUDITOR_deposit_confirmation ( - struct TALER_AUDITOR_Handle *auditor, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_MerchantWireHashP *h_wire, const struct TALER_ExtensionPolicyHashP *h_policy, const struct TALER_PrivateContractHashP *h_contract_terms, diff --git a/src/lib/auditor_api_deposit_confirmation.c b/src/lib/auditor_api_deposit_confirmation.c index 93cdaed9..21479c10 100644 --- a/src/lib/auditor_api_deposit_confirmation.c +++ b/src/lib/auditor_api_deposit_confirmation.c @@ -38,11 +38,6 @@ struct TALER_AUDITOR_DepositConfirmationHandle { - /** - * The connection to auditor this request handle will use - */ - struct TALER_AUDITOR_Handle *auditor; - /** * The url for this request. */ @@ -237,7 +232,8 @@ verify_signatures (const struct TALER_MerchantWireHashP *h_wire, struct TALER_AUDITOR_DepositConfirmationHandle * TALER_AUDITOR_deposit_confirmation ( - struct TALER_AUDITOR_Handle *auditor, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_MerchantWireHashP *h_wire, const struct TALER_ExtensionPolicyHashP *h_policy, const struct TALER_PrivateContractHashP *h_contract_terms, @@ -258,12 +254,9 @@ TALER_AUDITOR_deposit_confirmation ( void *cb_cls) { struct TALER_AUDITOR_DepositConfirmationHandle *dh; - struct GNUNET_CURL_Context *ctx; json_t *deposit_confirmation_obj; CURL *eh; - GNUNET_assert (GNUNET_YES == - TALER_AUDITOR_handle_is_ready_ (auditor)); if (GNUNET_OK != verify_signatures (h_wire, h_policy, @@ -322,18 +315,17 @@ TALER_AUDITOR_deposit_confirmation ( GNUNET_JSON_pack_data_auto ("exchange_pub", exchange_pub)); dh = GNUNET_new (struct TALER_AUDITOR_DepositConfirmationHandle); - dh->auditor = auditor; dh->cb = cb; dh->cb_cls = cb_cls; - dh->url = TALER_AUDITOR_path_to_url_ (auditor, - "/deposit-confirmation"); + dh->url = TALER_url_join (url, + "deposit-confirmation", + NULL); if (NULL == dh->url) { GNUNET_free (dh); return NULL; } eh = TALER_AUDITOR_curl_easy_get_ (dh->url); - if ( (NULL == eh) || (CURLE_OK != curl_easy_setopt (eh, @@ -356,7 +348,6 @@ TALER_AUDITOR_deposit_confirmation ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for deposit-confirmation: `%s'\n", dh->url); - ctx = TALER_AUDITOR_handle_to_context_ (auditor); dh->job = GNUNET_CURL_job_add2 (ctx, eh, dh->ctx.headers, diff --git a/src/lib/exchange_api_batch_deposit.c b/src/lib/exchange_api_batch_deposit.c index 544407a3..bb17737f 100644 --- a/src/lib/exchange_api_batch_deposit.c +++ b/src/lib/exchange_api_batch_deposit.c @@ -55,6 +55,11 @@ struct TALER_EXCHANGE_BatchDepositHandle */ struct TALER_EXCHANGE_Handle *exchange; + /** + * Context for our curl request(s). + */ + struct GNUNET_CURL_Context *ctx; + /** * The url for this request. */ @@ -64,7 +69,7 @@ struct TALER_EXCHANGE_BatchDepositHandle * Context for #TEH_curl_easy_post(). Keeps the data that must * persist for Curl to make the upload. */ - struct TALER_CURL_PostContext ctx; + struct TALER_CURL_PostContext post_ctx; /** * Handle for the request. @@ -136,13 +141,13 @@ struct TALER_EXCHANGE_BatchDepositHandle * launch a deposit confirmation interaction. * * @param cls closure - * @param ah handle to the auditor + * @param auditor_url base URL of the auditor * @param auditor_pub public key of the auditor * @return NULL if no deposit confirmation interaction was launched */ static struct TEAH_AuditorInteractionEntry * auditor_cb (void *cls, - struct TALER_AUDITOR_Handle *ah, + const char *auditor_url, const struct TALER_AuditorPublicKeyP *auditor_pub) { struct TALER_EXCHANGE_BatchDepositHandle *dh = cls; @@ -183,7 +188,8 @@ auditor_cb (void *cls, &dki->fees.deposit)); aie = GNUNET_new (struct TEAH_AuditorInteractionEntry); aie->dch = TALER_AUDITOR_deposit_confirmation ( - ah, + dh->ctx, + auditor_url, &dh->h_wire, &dh->h_policy, &dh->dcd.h_contract_terms, @@ -464,7 +470,6 @@ TALER_EXCHANGE_batch_deposit ( { const struct TALER_EXCHANGE_Keys *key_state; struct TALER_EXCHANGE_BatchDepositHandle *dh; - struct GNUNET_CURL_Context *ctx; json_t *deposit_obj; json_t *deposits; CURL *eh; @@ -600,7 +605,7 @@ TALER_EXCHANGE_batch_deposit ( eh = TALER_EXCHANGE_curl_easy_get_ (dh->url); if ( (NULL == eh) || (GNUNET_OK != - TALER_curl_easy_post (&dh->ctx, + TALER_curl_easy_post (&dh->post_ctx, eh, deposit_obj)) ) { @@ -618,10 +623,10 @@ TALER_EXCHANGE_batch_deposit ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for deposit: `%s'\n", dh->url); - ctx = TEAH_handle_to_context (exchange); - dh->job = GNUNET_CURL_job_add2 (ctx, + dh->ctx = TEAH_handle_to_context (exchange); + dh->job = GNUNET_CURL_job_add2 (dh->ctx, eh, - dh->ctx.headers, + dh->post_ctx.headers, &handle_deposit_finished, dh); return dh; @@ -648,7 +653,7 @@ TALER_EXCHANGE_batch_deposit_cancel ( GNUNET_free (deposit->url); GNUNET_free (deposit->cdds); GNUNET_free (deposit->exchange_sigs); - TALER_curl_easy_post_finished (&deposit->ctx); + TALER_curl_easy_post_finished (&deposit->post_ctx); GNUNET_free (deposit); } diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 5a0073f3..6f8d348f 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2021 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -55,6 +55,11 @@ struct TALER_EXCHANGE_DepositHandle */ struct TALER_EXCHANGE_Handle *exchange; + /** + * Our CURL context. + */ + struct GNUNET_CURL_Context *ctx; + /** * The url for this request. */ @@ -64,7 +69,7 @@ struct TALER_EXCHANGE_DepositHandle * Context for #TEH_curl_easy_post(). Keeps the data that must * persist for Curl to make the upload. */ - struct TALER_CURL_PostContext ctx; + struct TALER_CURL_PostContext post_ctx; /** * Handle for the request. @@ -131,13 +136,13 @@ struct TALER_EXCHANGE_DepositHandle * launch a deposit confirmation interaction. * * @param cls closure - * @param ah handle to the auditor + * @param auditor_url base URL of the auditor * @param auditor_pub public key of the auditor * @return NULL if no deposit confirmation interaction was launched */ static struct TEAH_AuditorInteractionEntry * auditor_cb (void *cls, - struct TALER_AUDITOR_Handle *ah, + const char *auditor_url, const struct TALER_AuditorPublicKeyP *auditor_pub) { struct TALER_EXCHANGE_DepositHandle *dh = cls; @@ -175,7 +180,8 @@ auditor_cb (void *cls, &dki->fees.deposit)); aie = GNUNET_new (struct TEAH_AuditorInteractionEntry); aie->dch = TALER_AUDITOR_deposit_confirmation ( - ah, + dh->ctx, + auditor_url, &dh->h_wire, &dh->h_policy, &dh->dcd.h_contract_terms, @@ -389,7 +395,6 @@ TALER_EXCHANGE_deposit ( { const struct TALER_EXCHANGE_Keys *key_state; struct TALER_EXCHANGE_DepositHandle *dh; - struct GNUNET_CURL_Context *ctx; json_t *deposit_obj; CURL *eh; const struct TALER_EXCHANGE_DenomPublicKey *dki; @@ -506,7 +511,7 @@ TALER_EXCHANGE_deposit ( eh = TALER_EXCHANGE_curl_easy_get_ (dh->url); if ( (NULL == eh) || (GNUNET_OK != - TALER_curl_easy_post (&dh->ctx, + TALER_curl_easy_post (&dh->post_ctx, eh, deposit_obj)) ) { @@ -523,10 +528,10 @@ TALER_EXCHANGE_deposit ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for deposit: `%s'\n", dh->url); - ctx = TEAH_handle_to_context (exchange); - dh->job = GNUNET_CURL_job_add2 (ctx, + dh->ctx = TEAH_handle_to_context (exchange); + dh->job = GNUNET_CURL_job_add2 (dh->ctx, eh, - dh->ctx.headers, + dh->post_ctx.headers, &handle_deposit_finished, dh); return dh; @@ -549,7 +554,7 @@ TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit) deposit->job = NULL; } GNUNET_free (deposit->url); - TALER_curl_easy_post_finished (&deposit->ctx); + TALER_curl_easy_post_finished (&deposit->post_ctx); GNUNET_free (deposit); } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 7b815f28..0d9bf041 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -211,7 +211,7 @@ TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h, if (! ale->is_up) continue; aie = ac (ac_cls, - ale->ah, + ale->auditor_url, &ale->auditor_pub); if (NULL != aie) { diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h index 47be99d4..8e3b1065 100644 --- a/src/lib/exchange_api_handle.h +++ b/src/lib/exchange_api_handle.h @@ -178,13 +178,13 @@ struct TALER_EXCHANGE_Handle * launch a deposit confirmation interaction. * * @param cls closure - * @param ah handle to the auditor + * @param auditor_url base URL of the auditor * @param auditor_pub public key of the auditor * @return NULL if no deposit confirmation interaction was launched */ typedef struct TEAH_AuditorInteractionEntry * (*TEAH_AuditorCallback)(void *cls, - struct TALER_AUDITOR_Handle *ah, + const char *auditor_url, const struct TALER_AuditorPublicKeyP *auditor_pub); diff --git a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c index c2a4bcc2..5c7b76a3 100644 --- a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c +++ b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c @@ -210,7 +210,7 @@ deposit_confirmation_run (void *cls, const struct TALER_CoinSpendPrivateKeyP *coin_priv; const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_SigningPublicKey *spk; - struct TALER_AUDITOR_Handle *auditor; + const char *auditor_url; struct TALER_EXCHANGE_Handle *exchange = TALER_TESTING_get_exchange (is); @@ -231,9 +231,14 @@ deposit_confirmation_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } - GNUNET_assert (GNUNET_OK == - TALER_TESTING_get_trait_auditor (auditor_cmd, - &auditor)); + if (GNUNET_OK != + TALER_TESTING_get_trait_auditor_url (auditor_cmd, + &auditor_url)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } } deposit_cmd = TALER_TESTING_interpreter_lookup_command (is, @@ -319,25 +324,27 @@ deposit_confirmation_run (void *cls, if (GNUNET_TIME_absolute_is_zero (refund_deadline.abs_time)) refund_deadline = timestamp; } - dcs->dc = TALER_AUDITOR_deposit_confirmation (auditor, - &h_wire, - &no_h_policy, - &h_contract_terms, - *exchange_timestamp, - *wire_deadline, - refund_deadline, - &amount_without_fee, - &coin_pub, - &merchant_pub, - exchange_pub, - exchange_sig, - &keys->master_pub, - spk->valid_from, - spk->valid_until, - spk->valid_legal, - &spk->master_sig, - &deposit_confirmation_cb, - dcs); + dcs->dc = TALER_AUDITOR_deposit_confirmation ( + TALER_TESTING_interpreter_get_context (is), + auditor_url, + &h_wire, + &no_h_policy, + &h_contract_terms, + *exchange_timestamp, + *wire_deadline, + refund_deadline, + &amount_without_fee, + &coin_pub, + &merchant_pub, + exchange_pub, + exchange_sig, + &keys->master_pub, + spk->valid_from, + spk->valid_until, + spk->valid_legal, + &spk->master_sig, + &deposit_confirmation_cb, + dcs); if (NULL == dcs->dc) { -- cgit v1.2.3 From f5ce22ddf6da6aae6a9077dba122013c1dbc55d9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 21 Jun 2023 09:00:58 +0200 Subject: -more clean up of auditor api: atomization complete --- src/include/taler_auditor_service.h | 55 ++-- src/include/taler_testing_lib.h | 1 - src/lib/Makefile.am | 2 +- src/lib/auditor_api_deposit_confirmation.c | 3 +- src/lib/auditor_api_exchanges.c | 3 +- src/lib/auditor_api_get_config.c | 288 +++++++++++++++++++ src/lib/auditor_api_handle.c | 438 ----------------------------- src/lib/auditor_api_handle.h | 59 ---- src/lib/exchange_api_handle.c | 23 +- src/testing/test_auditor_api_version.c | 19 +- src/testing/testing_api_cmd_get_auditor.c | 27 +- 11 files changed, 363 insertions(+), 555 deletions(-) create mode 100644 src/lib/auditor_api_get_config.c delete mode 100644 src/lib/auditor_api_handle.c delete mode 100644 src/lib/auditor_api_handle.h (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/include/taler_auditor_service.h b/src/include/taler_auditor_service.h index 2c6685c1..3d8ca9ef 100644 --- a/src/include/taler_auditor_service.h +++ b/src/include/taler_auditor_service.h @@ -28,12 +28,12 @@ #include -/* ********************* /version *********************** */ +/* ********************* /config *********************** */ /** - * @brief Information we get from the auditor about auditors. + * @brief Information we get from the auditor about itself. */ -struct TALER_AUDITOR_VersionInformation +struct TALER_AUDITOR_ConfigInformation { /** * Public key of the auditing institution. Wallets and merchants @@ -147,9 +147,9 @@ struct TALER_AUDITOR_HttpResponse /** - * Response to /version request. + * Response to /config request. */ -struct TALER_AUDITOR_VersionResponse +struct TALER_AUDITOR_ConfigResponse { /** * HTTP response. @@ -174,11 +174,12 @@ struct TALER_AUDITOR_VersionResponse enum TALER_AUDITOR_VersionCompatibility compat; /** - * Version data returned by /config. + * Config data returned by /config. */ - struct TALER_AUDITOR_VersionInformation vi; + struct TALER_AUDITOR_ConfigInformation vi; } ok; + } details; }; @@ -191,46 +192,45 @@ struct TALER_AUDITOR_VersionResponse * @param vr response data */ typedef void -(*TALER_AUDITOR_VersionCallback) ( +(*TALER_AUDITOR_ConfigCallback) ( void *cls, - const struct TALER_AUDITOR_VersionResponse *vr); + const struct TALER_AUDITOR_ConfigResponse *vr); /** * @brief Handle to the auditor. This is where we interact with * a particular auditor and keep the per-auditor information. */ -struct TALER_AUDITOR_Handle; +struct TALER_AUDITOR_GetConfigHandle; /** - * Initialise a connection to the auditor. Will connect to the + * Obtain meta data about an auditor. Will connect to the * auditor and obtain information about the auditor's master public * key and the auditor's auditor. The respective information will - * be passed to the @a version_cb once available, and all future - * interactions with the auditor will be checked to be signed - * (where appropriate) by the respective master key. + * be passed to the @a config_cb once available. * * @param ctx the context for CURL requests * @param url HTTP base URL for the auditor - * @param version_cb function to call with the auditor's version information - * @param version_cb_cls closure for @a version_cb + * @param config_cb function to call with the auditor's config information + * @param config_cb_cls closure for @a config_cb * @return the auditor handle; NULL upon error */ -struct TALER_AUDITOR_Handle * -TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx, - const char *url, - TALER_AUDITOR_VersionCallback version_cb, - void *version_cb_cls); +struct TALER_AUDITOR_GetConfigHandle * +TALER_AUDITOR_get_config (struct GNUNET_CURL_Context *ctx, + const char *url, + TALER_AUDITOR_ConfigCallback config_cb, + void *config_cb_cls); /** - * Disconnect from the auditor. + * Cancel auditor config request. * * @param auditor the auditor handle */ void -TALER_AUDITOR_disconnect (struct TALER_AUDITOR_Handle *auditor); +TALER_AUDITOR_get_config_cancel (struct + TALER_AUDITOR_GetConfigHandle *auditor); /** @@ -271,11 +271,10 @@ typedef void * that the response is well-formed. If the auditor's reply is not * well-formed, we return an HTTP status code of zero to @a cb. * - * We also verify that the @a exchange_sig is valid for this deposit-confirmation - * request, and that the @a master_sig is a valid signature for @a - * exchange_pub. Also, the @a auditor must be ready to operate (i.e. have - * finished processing the /version reply). If either check fails, we do - * NOT initiate the transaction with the auditor and instead return NULL. + * We also verify that the @a exchange_sig is valid for this + * deposit-confirmation request, and that the @a master_sig is a valid + * signature for @a exchange_pub. If the check fails, we do NOT initiate the + * transaction with the auditor and instead return NULL. * * @param ctx the context for CURL requests * @param url HTTP base URL for the auditor diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 175d25e6..2c9f5859 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2692,7 +2692,6 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, op (fresh_coins, const struct TALER_TESTING_FreshCoinData *) \ op (claim_token, const struct TALER_ClaimTokenP) \ op (relative_time, const struct GNUNET_TIME_Relative) \ - op (auditor, struct TALER_AUDITOR_Handle) \ op (exchange, struct TALER_EXCHANGE_Handle) \ op (fakebank, struct TALER_FAKEBANK_Handle) \ op (process, struct GNUNET_OS_Process *) diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 529a2d01..2c903142 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -96,7 +96,7 @@ libtalerauditor_la_LDFLAGS = \ -no-undefined libtalerauditor_la_SOURCES = \ auditor_api_curl_defaults.c auditor_api_curl_defaults.h \ - auditor_api_handle.c auditor_api_handle.h \ + auditor_api_get_config.c \ auditor_api_deposit_confirmation.c \ auditor_api_exchanges.c libtalerauditor_la_LIBADD = \ diff --git a/src/lib/auditor_api_deposit_confirmation.c b/src/lib/auditor_api_deposit_confirmation.c index 21479c10..0b0f4dd4 100644 --- a/src/lib/auditor_api_deposit_confirmation.c +++ b/src/lib/auditor_api_deposit_confirmation.c @@ -25,9 +25,10 @@ #include #include #include +#include "taler_util.h" +#include "taler_curl_lib.h" #include "taler_json_lib.h" #include "taler_auditor_service.h" -#include "auditor_api_handle.h" #include "taler_signatures.h" #include "auditor_api_curl_defaults.h" diff --git a/src/lib/auditor_api_exchanges.c b/src/lib/auditor_api_exchanges.c index 8acf5946..897dfe60 100644 --- a/src/lib/auditor_api_exchanges.c +++ b/src/lib/auditor_api_exchanges.c @@ -27,7 +27,8 @@ #include #include "taler_json_lib.h" #include "taler_auditor_service.h" -#include "auditor_api_handle.h" +#include "taler_util.h" +#include "taler_curl_lib.h" #include "taler_signatures.h" #include "auditor_api_curl_defaults.h" diff --git a/src/lib/auditor_api_get_config.c b/src/lib/auditor_api_get_config.c new file mode 100644 index 00000000..ede702a0 --- /dev/null +++ b/src/lib/auditor_api_get_config.c @@ -0,0 +1,288 @@ +/* + This file is part of TALER + Copyright (C) 2014-2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see + +*/ +/** + * @file lib/auditor_api_get_config.c + * @brief Implementation of /config for the auditor's HTTP API + * @author Sree Harsha Totakura + * @author Christian Grothoff + */ +#include "platform.h" +#include +#include +#include "taler_json_lib.h" +#include "taler_auditor_service.h" +#include "taler_signatures.h" +#include "auditor_api_curl_defaults.h" + + +/** + * Which revision of the Taler auditor protocol is implemented + * by this library? Used to determine compatibility. + */ +#define TALER_PROTOCOL_CURRENT 0 + +/** + * How many revisions back are we compatible to? + */ +#define TALER_PROTOCOL_AGE 0 + + +/** + * Log error related to CURL operations. + * + * @param type log level + * @param function which function failed to run + * @param code what was the curl error code + */ +#define CURL_STRERROR(type, function, code) \ + GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \ + function, __FILE__, __LINE__, curl_easy_strerror (code)); + + +/** + * Handle for the get config request. + */ +struct TALER_AUDITOR_GetConfigHandle +{ + /** + * The context of this handle + */ + struct GNUNET_CURL_Context *ctx; + + /** + * Function to call with the auditor's certification data, + * NULL if this has already been done. + */ + TALER_AUDITOR_ConfigCallback config_cb; + + /** + * Closure to pass to @e config_cb. + */ + void *config_cb_cls; + + /** + * Data for the request to get the /config of a auditor, + * NULL once we are past stage #MHS_INIT. + */ + struct GNUNET_CURL_Job *vr; + + /** + * The url for the @e vr job. + */ + char *vr_url; + +}; + + +/* ***************** Internal /config fetching ************* */ + +/** + * Decode the JSON in @a resp_obj from the /config response and store the data + * in the @a key_data. + * + * @param[in] resp_obj JSON object to parse + * @param[in,out] auditor where to store the results we decoded + * @param[out] vc where to store config compatibility data + * @return #TALER_EC_NONE on success + */ +static enum TALER_ErrorCode +decode_config_json (const json_t *resp_obj, + struct TALER_AUDITOR_ConfigInformation *vi, + enum TALER_AUDITOR_VersionCompatibility *vc) +{ + unsigned int age; + unsigned int revision; + unsigned int current; + char dummy; + const char *ver; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("version", + &ver), + GNUNET_JSON_spec_fixed_auto ("auditor_public_key", + &vi->auditor_pub), + GNUNET_JSON_spec_end () + }; + + if (JSON_OBJECT != json_typeof (resp_obj)) + { + GNUNET_break_op (0); + return TALER_EC_GENERIC_JSON_INVALID; + } + /* check the config */ + if (GNUNET_OK != + GNUNET_JSON_parse (resp_obj, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + return TALER_EC_GENERIC_JSON_INVALID; + } + if (3 != sscanf (ver, + "%u:%u:%u%c", + ¤t, + &revision, + &age, + &dummy)) + { + GNUNET_break_op (0); + return TALER_EC_GENERIC_VERSION_MALFORMED; + } + vi->version = ver; + *vc = TALER_AUDITOR_VC_MATCH; + if (TALER_PROTOCOL_CURRENT < current) + { + *vc |= TALER_AUDITOR_VC_NEWER; + if (TALER_PROTOCOL_CURRENT < current - age) + *vc |= TALER_AUDITOR_VC_INCOMPATIBLE; + } + if (TALER_PROTOCOL_CURRENT > current) + { + *vc |= TALER_AUDITOR_VC_OLDER; + if (TALER_PROTOCOL_CURRENT - TALER_PROTOCOL_AGE > current) + *vc |= TALER_AUDITOR_VC_INCOMPATIBLE; + } + return TALER_EC_NONE; +} + + +/** + * Callback used when downloading the reply to a /config request + * is complete. + * + * @param cls the `struct TALER_AUDITOR_GetConfigHandle` + * @param response_code HTTP response code, 0 on error + * @param gresp_obj parsed JSON result, NULL on error, must be a `const json_t *` + */ +static void +config_completed_cb (void *cls, + long response_code, + const void *gresp_obj) +{ + struct TALER_AUDITOR_GetConfigHandle *auditor = cls; + const json_t *resp_obj = gresp_obj; + struct TALER_AUDITOR_ConfigResponse vr = { + .hr.reply = resp_obj, + .hr.http_status = (unsigned int) response_code + }; + + auditor->vr = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received config from URL `%s' with status %ld.\n", + auditor->vr_url, + response_code); + switch (response_code) + { + case 0: + GNUNET_break_op (0); + vr.hr.ec = TALER_EC_INVALID; + break; + case MHD_HTTP_OK: + if (NULL == resp_obj) + { + GNUNET_break_op (0); + vr.hr.http_status = 0; + vr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; + } + vr.hr.ec = decode_config_json (resp_obj, + &vr.details.ok.vi, + &vr.details.ok.compat); + if (TALER_EC_NONE != vr.hr.ec) + { + GNUNET_break_op (0); + vr.hr.http_status = 0; + break; + } + break; + case MHD_HTTP_INTERNAL_SERVER_ERROR: + vr.hr.ec = TALER_JSON_get_error_code (resp_obj); + vr.hr.hint = TALER_JSON_get_error_hint (resp_obj); + break; + default: + vr.hr.ec = TALER_JSON_get_error_code (resp_obj); + vr.hr.hint = TALER_JSON_get_error_hint (resp_obj); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) vr.hr.ec); + break; + } + auditor->config_cb (auditor->config_cb_cls, + &vr); + TALER_AUDITOR_get_config_cancel (auditor); +} + + +struct TALER_AUDITOR_GetConfigHandle * +TALER_AUDITOR_get_config (struct GNUNET_CURL_Context *ctx, + const char *url, + TALER_AUDITOR_ConfigCallback config_cb, + void *config_cb_cls) +{ + struct TALER_AUDITOR_GetConfigHandle *auditor; + CURL *eh; + + auditor = GNUNET_new (struct TALER_AUDITOR_GetConfigHandle); + auditor->config_cb = config_cb; + auditor->config_cb_cls = config_cb_cls; + auditor->ctx = ctx; + auditor->vr_url = TALER_url_join (url, + "config", + NULL); + if (NULL == auditor->vr_url) + { + GNUNET_break (0); + GNUNET_free (auditor->vr_url); + GNUNET_free (auditor); + return NULL; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Requesting auditor config with URL `%s'.\n", + auditor->vr_url); + eh = TALER_AUDITOR_curl_easy_get_ (auditor->vr_url); + if (NULL == eh) + { + GNUNET_break (0); + TALER_AUDITOR_get_config_cancel (auditor); + return NULL; + } + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT, + (long) 300)); + auditor->vr = GNUNET_CURL_job_add (auditor->ctx, + eh, + &config_completed_cb, + auditor); + return auditor; +} + + +void +TALER_AUDITOR_get_config_cancel (struct TALER_AUDITOR_GetConfigHandle *auditor) +{ + if (NULL != auditor->vr) + { + GNUNET_CURL_job_cancel (auditor->vr); + auditor->vr = NULL; + } + GNUNET_free (auditor->vr_url); + GNUNET_free (auditor); +} + + +/* end of auditor_api_get_config.c */ diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c deleted file mode 100644 index 318b63f9..00000000 --- a/src/lib/auditor_api_handle.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see - -*/ -/** - * @file lib/auditor_api_handle.c - * @brief Implementation of the "handle" component of the auditor's HTTP API - * @author Sree Harsha Totakura - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include "taler_json_lib.h" -#include "taler_auditor_service.h" -#include "taler_signatures.h" -#include "auditor_api_handle.h" -#include "auditor_api_curl_defaults.h" -#include "backoff.h" - -/** - * Which revision of the Taler auditor protocol is implemented - * by this library? Used to determine compatibility. - */ -#define TALER_PROTOCOL_CURRENT 0 - -/** - * How many revisions back are we compatible to? - */ -#define TALER_PROTOCOL_AGE 0 - - -/** - * Log error related to CURL operations. - * - * @param type log level - * @param function which function failed to run - * @param code what was the curl error code - */ -#define CURL_STRERROR(type, function, code) \ - GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \ - function, __FILE__, __LINE__, curl_easy_strerror (code)); - -/** - * Stages of initialization for the `struct TALER_AUDITOR_Handle` - */ -enum AuditorHandleState -{ - /** - * Just allocated. - */ - MHS_INIT = 0, - - /** - * Obtained the auditor's versioning data and version. - */ - MHS_VERSION = 1, - - /** - * Failed to initialize (fatal). - */ - MHS_FAILED = 2 -}; - - -/** - * Handle to the auditor - */ -struct TALER_AUDITOR_Handle -{ - /** - * The context of this handle - */ - struct GNUNET_CURL_Context *ctx; - - /** - * The URL of the auditor (i.e. "http://auditor.taler.net/") - */ - char *url; - - /** - * Function to call with the auditor's certification data, - * NULL if this has already been done. - */ - TALER_AUDITOR_VersionCallback version_cb; - - /** - * Closure to pass to @e version_cb. - */ - void *version_cb_cls; - - /** - * Data for the request to get the /config of a auditor, - * NULL once we are past stage #MHS_INIT. - */ - struct GNUNET_CURL_Job *vr; - - /** - * The url for the @e vr job. - */ - char *vr_url; - - /** - * Task for retrying /config request. - */ - struct GNUNET_SCHEDULER_Task *retry_task; - - /** - * /config data of the auditor, only valid if - * @e handshake_complete is past stage #MHS_VERSION. - */ - char *version; - - /** - * Version information for the callback. - */ - struct TALER_AUDITOR_VersionInformation vi; - - /** - * Retry /config frequency. - */ - struct GNUNET_TIME_Relative retry_delay; - - /** - * Stage of the auditor's initialization routines. - */ - enum AuditorHandleState state; - -}; - - -/* ***************** Internal /config fetching ************* */ - -/** - * Decode the JSON in @a resp_obj from the /config response and store the data - * in the @a key_data. - * - * @param[in] resp_obj JSON object to parse - * @param[in,out] auditor where to store the results we decoded - * @param[out] vc where to store version compatibility data - * @return #TALER_EC_NONE on success - */ -static enum TALER_ErrorCode -decode_version_json (const json_t *resp_obj, - struct TALER_AUDITOR_Handle *auditor, - enum TALER_AUDITOR_VersionCompatibility *vc) -{ - struct TALER_AUDITOR_VersionInformation *vi = &auditor->vi; - unsigned int age; - unsigned int revision; - unsigned int current; - char dummy; - const char *ver; - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("version", - &ver), - GNUNET_JSON_spec_fixed_auto ("auditor_public_key", - &vi->auditor_pub), - GNUNET_JSON_spec_end () - }; - - if (JSON_OBJECT != json_typeof (resp_obj)) - { - GNUNET_break_op (0); - return TALER_EC_GENERIC_JSON_INVALID; - } - /* check the version */ - if (GNUNET_OK != - GNUNET_JSON_parse (resp_obj, - spec, - NULL, NULL)) - { - GNUNET_break_op (0); - return TALER_EC_GENERIC_JSON_INVALID; - } - if (3 != sscanf (ver, - "%u:%u:%u%c", - ¤t, - &revision, - &age, - &dummy)) - { - GNUNET_break_op (0); - return TALER_EC_GENERIC_VERSION_MALFORMED; - } - GNUNET_free (auditor->version); - auditor->version = GNUNET_strdup (ver); - vi->version = auditor->version; - *vc = TALER_AUDITOR_VC_MATCH; - if (TALER_PROTOCOL_CURRENT < current) - { - *vc |= TALER_AUDITOR_VC_NEWER; - if (TALER_PROTOCOL_CURRENT < current - age) - *vc |= TALER_AUDITOR_VC_INCOMPATIBLE; - } - if (TALER_PROTOCOL_CURRENT > current) - { - *vc |= TALER_AUDITOR_VC_OLDER; - if (TALER_PROTOCOL_CURRENT - TALER_PROTOCOL_AGE > current) - *vc |= TALER_AUDITOR_VC_INCOMPATIBLE; - } - return TALER_EC_NONE; -} - - -/** - * Initiate download of /config from the auditor. - * - * @param cls auditor where to download /config from - */ -static void -request_version (void *cls); - - -/** - * Callback used when downloading the reply to a /config request - * is complete. - * - * @param cls the `struct TALER_AUDITOR_Handle` - * @param response_code HTTP response code, 0 on error - * @param gresp_obj parsed JSON result, NULL on error, must be a `const json_t *` - */ -static void -version_completed_cb (void *cls, - long response_code, - const void *gresp_obj) -{ - struct TALER_AUDITOR_Handle *auditor = cls; - const json_t *resp_obj = gresp_obj; - struct TALER_AUDITOR_VersionResponse vr = { - .hr.reply = resp_obj, - .hr.http_status = (unsigned int) response_code - }; - - auditor->vr = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received version from URL `%s' with status %ld.\n", - auditor->url, - response_code); - switch (response_code) - { - case 0: - case MHD_HTTP_INTERNAL_SERVER_ERROR: - /* NOTE: this design is debatable. We MAY want to throw this error at the - client. We may then still additionally internally re-try. */ - GNUNET_assert (NULL == auditor->retry_task); - auditor->retry_delay = EXCHANGE_LIB_BACKOFF (auditor->retry_delay); - auditor->retry_task = GNUNET_SCHEDULER_add_delayed (auditor->retry_delay, - &request_version, - auditor); - return; - case MHD_HTTP_OK: - if (NULL == resp_obj) - { - GNUNET_break_op (0); - TALER_LOG_WARNING ("NULL body for a 200-OK /config\n"); - vr.hr.http_status = 0; - vr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - break; - } - vr.hr.ec = decode_version_json (resp_obj, - auditor, - &vr.details.ok.compat); - if (TALER_EC_NONE != vr.hr.ec) - { - GNUNET_break_op (0); - vr.hr.http_status = 0; - break; - } - auditor->state = MHS_VERSION; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Auditor %s is ready!\n", - auditor->url); - vr.details.ok.vi = auditor->vi; - auditor->retry_delay = GNUNET_TIME_UNIT_ZERO; /* restart quickly */ - break; - default: - vr.hr.ec = TALER_JSON_get_error_code (resp_obj); - vr.hr.hint = TALER_JSON_get_error_hint (resp_obj); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u/%d\n", - (unsigned int) response_code, - (int) vr.hr.ec); - break; - } - if (MHD_HTTP_OK != response_code) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "/config failed for auditor %s: %u!\n", - auditor->url, - (unsigned int) response_code); - auditor->state = MHS_FAILED; - } - auditor->version_cb (auditor->version_cb_cls, - &vr); -} - - -/** - * Initiate download of /config from the auditor. - * - * @param cls auditor where to download /config from - */ -static void -request_version (void *cls) -{ - struct TALER_AUDITOR_Handle *auditor = cls; - CURL *eh; - - auditor->retry_task = NULL; - GNUNET_assert (NULL == auditor->vr); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Requesting auditor version with URL `%s'.\n", - auditor->vr_url); - eh = TALER_AUDITOR_curl_easy_get_ (auditor->vr_url); - if (NULL == eh) - { - GNUNET_break (0); - auditor->retry_delay = EXCHANGE_LIB_BACKOFF (auditor->retry_delay); - auditor->retry_task = GNUNET_SCHEDULER_add_delayed (auditor->retry_delay, - &request_version, - auditor); - return; - } - GNUNET_break (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_TIMEOUT, - (long) 300)); - auditor->vr = GNUNET_CURL_job_add (auditor->ctx, - eh, - &version_completed_cb, - auditor); -} - - -/* ********************* library internal API ********* */ - - -struct GNUNET_CURL_Context * -TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h) -{ - return h->ctx; -} - - -enum GNUNET_GenericReturnValue -TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Checking if auditor at `%s` is now ready: %s\n", - h->url, - (MHD_VERSION == h->state) ? "yes" : "no"); - return (MHS_VERSION == h->state) ? GNUNET_YES : GNUNET_NO; -} - - -char * -TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h, - const char *path) -{ - GNUNET_assert ('/' == path[0]); - return TALER_url_join (h->url, - path + 1, - NULL); -} - - -/* ********************* public API ******************* */ - - -struct TALER_AUDITOR_Handle * -TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx, - const char *url, - TALER_AUDITOR_VersionCallback version_cb, - void *version_cb_cls) -{ - struct TALER_AUDITOR_Handle *auditor; - - auditor = GNUNET_new (struct TALER_AUDITOR_Handle); - auditor->version_cb = version_cb; - auditor->version_cb_cls = version_cb_cls; - auditor->retry_delay = GNUNET_TIME_UNIT_SECONDS; /* start slowly */ - auditor->ctx = ctx; - auditor->url = GNUNET_strdup (url); - auditor->vr_url = TALER_AUDITOR_path_to_url_ (auditor, - "/config"); - if (NULL == auditor->vr_url) - { - GNUNET_break (0); - GNUNET_free (auditor->url); - GNUNET_free (auditor); - return NULL; - } - auditor->retry_task = GNUNET_SCHEDULER_add_now (&request_version, - auditor); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Connecting to auditor at URL `%s'.\n", - url); - return auditor; -} - - -void -TALER_AUDITOR_disconnect (struct TALER_AUDITOR_Handle *auditor) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Disconnecting from auditor at URL `%s'.\n", - auditor->url); - if (NULL != auditor->vr) - { - GNUNET_CURL_job_cancel (auditor->vr); - auditor->vr = NULL; - } - if (NULL != auditor->retry_task) - { - GNUNET_SCHEDULER_cancel (auditor->retry_task); - auditor->retry_task = NULL; - } - GNUNET_free (auditor->version); - GNUNET_free (auditor->vr_url); - GNUNET_free (auditor->url); - GNUNET_free (auditor); -} - - -/* end of auditor_api_handle.c */ diff --git a/src/lib/auditor_api_handle.h b/src/lib/auditor_api_handle.h deleted file mode 100644 index 7ff5bfcd..00000000 --- a/src/lib/auditor_api_handle.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014, 2015 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see - -*/ -/** - * @file lib/auditor_api_handle.h - * @brief Internal interface to the handle part of the auditor's HTTP API - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include "taler_auditor_service.h" -#include "taler_curl_lib.h" - -/** - * Get the context of a auditor. - * - * @param h the auditor handle to query - * @return ctx context to execute jobs in - */ -struct GNUNET_CURL_Context * -TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h); - - -/** - * Check if the handle is ready to process requests. - * - * @param h the auditor handle to query - * @return #GNUNET_YES if we are ready, #GNUNET_NO if not - */ -int -TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h); - - -/** - * Obtain the URL to use for an API request. - * - * @param h the auditor handle to query - * @param path Taler API path (i.e. "/deposit-confirmation") - * @return the full URL to use with cURL - */ -char * -TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h, - const char *path); - - -/* end of auditor_api_handle.h */ diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 0d9bf041..4d245b07 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -110,7 +110,7 @@ struct TEAH_AuditorListEntry /** * Handle to the auditor. */ - struct TALER_AUDITOR_Handle *ah; + struct TALER_AUDITOR_GetConfigHandle *ah; /** * Head of DLL of interactions with this auditor. @@ -583,13 +583,14 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf, * @param vr response from the auditor */ static void -auditor_version_cb ( +auditor_config_cb ( void *cls, - const struct TALER_AUDITOR_VersionResponse *vr) + const struct TALER_AUDITOR_ConfigResponse *vr) { struct TEAH_AuditorListEntry *ale = cls; enum TALER_AUDITOR_VersionCompatibility compat; + ale->ah = NULL; if (MHD_HTTP_OK != vr->hr.http_status) { /* In this case, we don't mark the auditor as 'up' */ @@ -664,10 +665,10 @@ update_auditors (struct TALER_EXCHANGE_Handle *exchange) GNUNET_CONTAINER_DLL_insert (exchange->auditors_head, exchange->auditors_tail, ale); - ale->ah = TALER_AUDITOR_connect (exchange->ctx, - ale->auditor_url, - &auditor_version_cb, - ale); + ale->ah = TALER_AUDITOR_get_config (exchange->ctx, + ale->auditor_url, + &auditor_config_cb, + ale); } } @@ -2137,9 +2138,11 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange) GNUNET_CONTAINER_DLL_remove (exchange->auditors_head, exchange->auditors_tail, ale); - TALER_LOG_DEBUG ("Disconnecting the auditor `%s'\n", - ale->auditor_url); - TALER_AUDITOR_disconnect (ale->ah); + if (NULL != ale->ah) + { + TALER_AUDITOR_get_config_cancel (ale->ah); + ale->ah = NULL; + } GNUNET_free (ale->auditor_url); GNUNET_free (ale); } diff --git a/src/testing/test_auditor_api_version.c b/src/testing/test_auditor_api_version.c index 1b4f2b17..dcd542ad 100644 --- a/src/testing/test_auditor_api_version.c +++ b/src/testing/test_auditor_api_version.c @@ -41,7 +41,7 @@ */ #define CONFIG_FILE "test_auditor_api-rsa.conf" -static struct TALER_AUDITOR_Handle *ah; +static struct TALER_AUDITOR_GetConfigHandle *ah; static struct GNUNET_CURL_Context *ctx; @@ -62,7 +62,11 @@ do_shutdown (void *cls) GNUNET_SCHEDULER_cancel (tt); tt = NULL; } - TALER_AUDITOR_disconnect (ah); + if (NULL != ah) + { + TALER_AUDITOR_get_config_cancel (ah); + ah = NULL; + } GNUNET_CURL_fini (ctx); GNUNET_CURL_gnunet_rc_destroy (rc); } @@ -86,9 +90,10 @@ do_timeout (void *cls) */ static void version_cb (void *cls, - const struct TALER_AUDITOR_VersionResponse *vr) + const struct TALER_AUDITOR_ConfigResponse *vr) { (void) cls; + ah = NULL; if ( (MHD_HTTP_OK == vr->hr.http_status) && (TALER_AUDITOR_VC_MATCH == vr->details.ok.compat) ) global_ret = 0; @@ -113,10 +118,10 @@ run (void *cls) ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, &rc); rc = GNUNET_CURL_gnunet_rc_create (ctx); - ah = TALER_AUDITOR_connect (ctx, - auditor_url, - &version_cb, - NULL); + ah = TALER_AUDITOR_get_config (ctx, + auditor_url, + &version_cb, + NULL); GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, diff --git a/src/testing/testing_api_cmd_get_auditor.c b/src/testing/testing_api_cmd_get_auditor.c index 2e9961c3..e1ae8ba5 100644 --- a/src/testing/testing_api_cmd_get_auditor.c +++ b/src/testing/testing_api_cmd_get_auditor.c @@ -49,9 +49,9 @@ struct GetAuditorState struct TALER_TESTING_Interpreter *is; /** - * Auditor handle we produced. + * Auditor handle used to get the configuration. */ - struct TALER_AUDITOR_Handle *auditor; + struct TALER_AUDITOR_GetConfigHandle *auditor; /** * URL of the auditor. @@ -75,16 +75,25 @@ struct GetAuditorState static void version_cb ( void *cls, - const struct TALER_AUDITOR_VersionResponse *vr) + const struct TALER_AUDITOR_ConfigResponse *vr) { struct GetAuditorState *gas = cls; + gas->auditor = NULL; if (MHD_HTTP_OK != vr->hr.http_status) { TALER_TESTING_unexpected_status (gas->is, vr->hr.http_status); return; } + if ( (NULL != gas->priv_file) && + (0 != GNUNET_memcmp (&gas->auditor_pub, + &vr->details.ok.vi.auditor_pub)) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (gas->is); + return; + } TALER_TESTING_interpreter_next (gas->is); } @@ -126,10 +135,10 @@ get_auditor_run (void *cls, } gas->is = is; gas->auditor - = TALER_AUDITOR_connect (TALER_TESTING_interpreter_get_context (is), - gas->auditor_url, - &version_cb, - gas); + = TALER_AUDITOR_get_config (TALER_TESTING_interpreter_get_context (is), + gas->auditor_url, + &version_cb, + gas); if (NULL == gas->auditor) { GNUNET_break (0); @@ -153,7 +162,8 @@ get_auditor_cleanup (void *cls, if (NULL != gas->auditor) { - TALER_AUDITOR_disconnect (gas->auditor); + GNUNET_break (0); + TALER_AUDITOR_get_config_cancel (gas->auditor); gas->auditor = NULL; } GNUNET_free (gas->priv_file); @@ -182,7 +192,6 @@ get_auditor_traits (void *cls, struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_auditor_priv (&gas->auditor_priv), TALER_TESTING_make_trait_auditor_pub (&gas->auditor_pub), - TALER_TESTING_make_trait_auditor (gas->auditor), TALER_TESTING_make_trait_auditor_url (gas->auditor_url), TALER_TESTING_trait_end () }; -- cgit v1.2.3 From 75733ee00efc6d5342ed8b4fccd637efaebdce06 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jun 2023 13:59:47 +0200 Subject: more work on atomizing exchange API: deposit --- contrib/gana | 2 +- src/auditor/taler-auditor-httpd.c | 2 + src/include/taler_exchange_service.h | 159 +++--------- src/include/taler_testing_lib.h | 12 + src/lib/Makefile.am | 1 - src/lib/exchange_api_batch_deposit.c | 267 +++++++++++++++------ src/lib/exchange_api_handle.c | 93 ++----- src/lib/exchange_api_handle.h | 46 +--- src/testing/test_exchange_api.conf | 2 +- .../taler/auditor/offline-keys/auditor.priv | 1 + src/testing/testing_api_cmd_batch_deposit.c | 26 +- src/testing/testing_api_cmd_deposit.c | 34 ++- src/testing/testing_api_cmd_get_exchange.c | 3 +- src/testing/testing_api_traits.c | 28 +++ 14 files changed, 327 insertions(+), 349 deletions(-) create mode 100644 src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv (limited to 'src/lib/exchange_api_handle.c') diff --git a/contrib/gana b/contrib/gana index 3e5591a7..5f377301 160000 --- a/contrib/gana +++ b/contrib/gana @@ -1 +1 @@ -Subproject commit 3e5591a7e3fd93ba46fc2b538c63f0c16336283d +Subproject commit 5f377301db4d94c485422ecda277fe850e29504a diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index 68316082..a59ce3de 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -157,6 +157,8 @@ handle_config (struct TAH_RequestHandler *rh, if (NULL == ver) { ver = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("name", + "taler-auditor"), GNUNET_JSON_pack_string ("version", AUDITOR_PROTOCOL_VERSION), GNUNET_JSON_pack_string ("currency", diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 065c2dcd..9cb5f083 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -573,10 +573,30 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange); * @param exchange the exchange handle * @return the exchange's key set */ -const struct TALER_EXCHANGE_Keys * +struct TALER_EXCHANGE_Keys * TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange); +/** + * Increment reference counter for @a keys + * + * @param[in,out] keys object to increment reference counter for + * @return keys, with incremented reference counter + */ +struct TALER_EXCHANGE_Keys * +TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys); + + +/** + * Deccrement reference counter for @a keys. + * Frees @a keys if reference counter becomes zero. + * + * @param[in,out] keys object to decrement reference counter for + */ +void +TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys); + + /** * Let the user set the last valid denomination time manually. * @@ -1151,135 +1171,6 @@ struct TALER_EXCHANGE_DepositContractDetail }; -/** - * @brief A Deposit Handle - */ -struct TALER_EXCHANGE_DepositHandle; - - -/** - * Structure with information about a deposit - * operation's result. - */ -struct TALER_EXCHANGE_DepositResult -{ - /** - * HTTP response data - */ - struct TALER_EXCHANGE_HttpResponse hr; - - union - { - - /** - * Information returned if the HTTP status is - * #MHD_HTTP_OK. - */ - struct - { - /** - * Time when the exchange generated the deposit confirmation - */ - struct GNUNET_TIME_Timestamp deposit_timestamp; - - /** - * signature provided by the exchange - */ - const struct TALER_ExchangeSignatureP *exchange_sig; - - /** - * exchange key used to sign @a exchange_sig. - */ - const struct TALER_ExchangePublicKeyP *exchange_pub; - - /** - * Base URL for looking up wire transfers, or - * NULL to use the default base URL. - */ - const char *transaction_base_url; - - } ok; - - /** - * Information returned if the HTTP status is - * #MHD_HTTP_CONFLICT. - */ - struct - { - /* TODO: returning full details is not implemented */ - } conflict; - - } details; -}; - - -/** - * Callbacks of this type are used to serve the result of submitting a - * deposit permission request to a exchange. - * - * @param cls closure - * @param dr deposit response details - */ -typedef void -(*TALER_EXCHANGE_DepositResultCallback) ( - void *cls, - const struct TALER_EXCHANGE_DepositResult *dr); - - -/** - * Submit a deposit permission to the exchange and get the exchange's - * response. This API is typically used by a merchant. Note that - * while we return the response verbatim to the caller for further - * processing, we do already verify that the response is well-formed - * (i.e. that signatures included in the response are all valid). If - * the exchange's reply is not well-formed, we return an HTTP status code - * of zero to @a cb. - * - * We also verify that the @a cdd.coin_sig is valid for this deposit - * request, and that the @a cdd.ub_sig is a valid signature for @a - * coin_pub. Also, the @a exchange must be ready to operate (i.e. have - * finished processing the /keys reply). If either check fails, we do - * NOT initiate the transaction with the exchange and instead return NULL. - * - * @param exchange the exchange handle; the exchange must be ready to operate - * @param dcd details about the contract the deposit is for - * @param cdd details about the coin to be deposited - * @param cb the callback to call when a reply for this request is available - * @param cb_cls closure for the above callback - * @param[out] ec if NULL is returned, set to the error code explaining why the operation failed - * @return a handle for this request; NULL if the inputs are invalid (i.e. - * signatures fail to verify). In this case, the callback is not called. - */ -struct TALER_EXCHANGE_DepositHandle * -TALER_EXCHANGE_deposit ( - struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_EXCHANGE_DepositContractDetail *dcd, - const struct TALER_EXCHANGE_CoinDepositDetail *cdd, - TALER_EXCHANGE_DepositResultCallback cb, - void *cb_cls, - enum TALER_ErrorCode *ec); - - -/** - * Change the chance that our deposit confirmation will be given to the - * auditor to 100%. - * - * @param deposit the deposit permission request handle - */ -void -TALER_EXCHANGE_deposit_force_dc (struct TALER_EXCHANGE_DepositHandle *deposit); - - -/** - * Cancel a deposit permission request. This function cannot be used - * on a request handle if a response is already served for it. - * - * @param deposit the deposit permission request handle - */ -void -TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit); - - /** * @brief A Batch Deposit Handle */ @@ -1374,7 +1265,9 @@ typedef void * finished processing the /keys reply). If either check fails, we do * NOT initiate the transaction with the exchange and instead return NULL. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param dcd details about the contract the deposit is for * @param num_cdds length of the @a cdds array * @param cdds array with details about the coins to be deposited @@ -1386,7 +1279,9 @@ typedef void */ struct TALER_EXCHANGE_BatchDepositHandle * TALER_EXCHANGE_batch_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_EXCHANGE_DepositContractDetail *dcd, unsigned int num_cdds, const struct TALER_EXCHANGE_CoinDepositDetail *cdds, diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 6554bc95..2ef7ef60 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2694,6 +2694,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, op (relative_time, const struct GNUNET_TIME_Relative) \ op (exchange, struct TALER_EXCHANGE_Handle) \ op (fakebank, struct TALER_FAKEBANK_Handle) \ + op (keys, struct TALER_EXCHANGE_Keys) \ op (process, struct GNUNET_OS_Process *) @@ -2751,4 +2752,15 @@ TALER_TESTING_get_exchange_url ( struct TALER_TESTING_Interpreter *is); +/** + * Get exchange keys from interpreter. Convenience function. + * + * @param is interpreter state. + * @return the exchange keys, or NULL on error + */ +struct TALER_EXCHANGE_Keys * +TALER_TESTING_get_keys ( + struct TALER_TESTING_Interpreter *is); + + #endif diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 2c903142..53190bc5 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -32,7 +32,6 @@ libtalerexchange_la_SOURCES = \ exchange_api_csr_melt.c \ exchange_api_csr_withdraw.c \ exchange_api_handle.c exchange_api_handle.h \ - exchange_api_deposit.c \ exchange_api_deposits_get.c \ exchange_api_kyc_check.c \ exchange_api_kyc_proof.c \ diff --git a/src/lib/exchange_api_batch_deposit.c b/src/lib/exchange_api_batch_deposit.c index bb17737f..22ae2d58 100644 --- a/src/lib/exchange_api_batch_deposit.c +++ b/src/lib/exchange_api_batch_deposit.c @@ -44,6 +44,39 @@ */ #define AUDITOR_CHANCE 20 + +/** + * Entry in list of ongoing interactions with an auditor. + */ +struct TEAH_AuditorInteractionEntry +{ + /** + * DLL entry. + */ + struct TEAH_AuditorInteractionEntry *next; + + /** + * DLL entry. + */ + struct TEAH_AuditorInteractionEntry *prev; + + /** + * URL of our auditor. For logging. + */ + const char *auditor_url; + + /** + * Interaction state. + */ + struct TALER_AUDITOR_DepositConfirmationHandle *dch; + + /** + * Batch deposit this is for. + */ + struct TALER_EXCHANGE_BatchDepositHandle *dh; +}; + + /** * @brief A Deposit Handle */ @@ -51,9 +84,9 @@ struct TALER_EXCHANGE_BatchDepositHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange. */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * Context for our curl request(s). @@ -117,11 +150,31 @@ struct TALER_EXCHANGE_BatchDepositHandle */ struct TALER_ExchangeSignatureP *exchange_sigs; + /** + * Head of DLL of interactions with this auditor. + */ + struct TEAH_AuditorInteractionEntry *ai_head; + + /** + * Tail of DLL of interactions with this auditor. + */ + struct TEAH_AuditorInteractionEntry *ai_tail; + + /** + * Result to return to the application once @e ai_head is empty. + */ + struct TALER_EXCHANGE_BatchDepositResult dr; + /** * Exchange signing public key, set for #auditor_cb. */ struct TALER_ExchangePublicKeyP exchange_pub; + /** + * Response object to free at the end. + */ + json_t *response; + /** * Chance that we will inform the auditor about the deposit * is 1:n, where the value of this field is "n". @@ -136,6 +189,52 @@ struct TALER_EXCHANGE_BatchDepositHandle }; +/** + * Finish batch deposit operation by calling the callback. + * + * @param[in] dh handle to finished batch deposit operation + */ +static void +finish_dh (struct TALER_EXCHANGE_BatchDepositHandle *dh) +{ + dh->cb (dh->cb_cls, + &dh->dr); + TALER_EXCHANGE_batch_deposit_cancel (dh); +} + + +/** + * Function called with the result from our call to the + * auditor's /deposit-confirmation handler. + * + * @param cls closure of type `struct TEAH_AuditorInteractionEntry *` + * @param dcr response + */ +static void +acc_confirmation_cb ( + void *cls, + const struct TALER_AUDITOR_DepositConfirmationResponse *dcr) +{ + struct TEAH_AuditorInteractionEntry *aie = cls; + struct TALER_EXCHANGE_BatchDepositHandle *dh = aie->dh; + + if (MHD_HTTP_OK != dcr->hr.http_status) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n", + aie->auditor_url, + dcr->hr.http_status, + dcr->hr.ec); + } + GNUNET_CONTAINER_DLL_remove (dh->ai_head, + dh->ai_tail, + aie); + GNUNET_free (aie); + if (NULL == dh->ai_head) + finish_dh (dh); +} + + /** * Function called for each auditor to give us a chance to possibly * launch a deposit confirmation interaction. @@ -143,15 +242,13 @@ struct TALER_EXCHANGE_BatchDepositHandle * @param cls closure * @param auditor_url base URL of the auditor * @param auditor_pub public key of the auditor - * @return NULL if no deposit confirmation interaction was launched */ -static struct TEAH_AuditorInteractionEntry * +static void auditor_cb (void *cls, const char *auditor_url, const struct TALER_AuditorPublicKeyP *auditor_pub) { struct TALER_EXCHANGE_BatchDepositHandle *dh = cls; - const struct TALER_EXCHANGE_Keys *key_state; const struct TALER_EXCHANGE_SigningPublicKey *spk; struct TEAH_AuditorInteractionEntry *aie; struct TALER_Amount amount_without_fee; @@ -164,29 +261,30 @@ auditor_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Not providing deposit confirmation to auditor\n"); - return NULL; + return; } coin = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, dh->num_cdds); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Will provide deposit confirmation to auditor `%s'\n", TALER_B2S (auditor_pub)); - key_state = TALER_EXCHANGE_get_keys (dh->exchange); - dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + dki = TALER_EXCHANGE_get_denomination_key_by_hash (dh->keys, &dh->cdds[coin].h_denom_pub); GNUNET_assert (NULL != dki); - spk = TALER_EXCHANGE_get_signing_key_info (key_state, + spk = TALER_EXCHANGE_get_signing_key_info (dh->keys, &dh->exchange_pub); if (NULL == spk) { GNUNET_break_op (0); - return NULL; + return; } GNUNET_assert (0 <= TALER_amount_subtract (&amount_without_fee, &dh->cdds[coin].amount, &dki->fees.deposit)); aie = GNUNET_new (struct TEAH_AuditorInteractionEntry); + aie->dh = dh; + aie->auditor_url = auditor_url; aie->dch = TALER_AUDITOR_deposit_confirmation ( dh->ctx, auditor_url, @@ -201,14 +299,16 @@ auditor_cb (void *cls, &dh->dcd.merchant_pub, &dh->exchange_pub, &dh->exchange_sigs[coin], - &key_state->master_pub, + &dh->keys->master_pub, spk->valid_from, spk->valid_until, spk->valid_legal, &spk->master_sig, - &TEAH_acc_confirmation_cb, + &acc_confirmation_cb, aie); - return aie; + GNUNET_CONTAINER_DLL_insert (dh->ai_head, + dh->ai_tail, + aie); } @@ -227,22 +327,19 @@ handle_deposit_finished (void *cls, { struct TALER_EXCHANGE_BatchDepositHandle *dh = cls; const json_t *j = response; - struct TALER_EXCHANGE_BatchDepositResult dr = { - .hr.reply = j, - .hr.http_status = (unsigned int) response_code - }; - const struct TALER_EXCHANGE_Keys *keys; + struct TALER_EXCHANGE_BatchDepositResult *dr = &dh->dr; dh->job = NULL; - keys = TALER_EXCHANGE_get_keys (dh->exchange); + dh->response = json_incref ((json_t*) j); + dr->hr.reply = dh->response; + dr->hr.http_status = (unsigned int) response_code; switch (response_code) { case 0: - dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + dr->hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { - const struct TALER_EXCHANGE_Keys *key_state; const json_t *sigs; json_t *sig; unsigned int idx; @@ -253,7 +350,7 @@ handle_deposit_finished (void *cls, &dh->exchange_pub), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("transaction_base_url", - &dr.details.ok.transaction_base_url), + &dr->details.ok.transaction_base_url), NULL), GNUNET_JSON_spec_timestamp ("exchange_timestamp", &dh->exchange_timestamp), @@ -266,27 +363,26 @@ handle_deposit_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } if (json_array_size (sigs) != dh->num_cdds) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } dh->exchange_sigs = GNUNET_new_array (dh->num_cdds, struct TALER_ExchangeSignatureP); - key_state = TALER_EXCHANGE_get_keys (dh->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (dh->keys, &dh->exchange_pub)) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; break; } json_array_foreach (sigs, idx, sig) @@ -305,11 +401,11 @@ handle_deposit_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + dki = TALER_EXCHANGE_get_denomination_key_by_hash (dh->keys, &dh->cdds[idx]. h_denom_pub); GNUNET_assert (NULL != dki); @@ -333,42 +429,41 @@ handle_deposit_finished (void *cls, &dh->exchange_sigs[idx])) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; break; } } - TEAH_get_auditors_for_dc (dh->exchange, + TEAH_get_auditors_for_dc (dh->keys, &auditor_cb, dh); } - dr.details.ok.exchange_sigs = dh->exchange_sigs; - dr.details.ok.exchange_pub = &dh->exchange_pub; - dr.details.ok.deposit_timestamp = dh->exchange_timestamp; - dr.details.ok.num_signatures = dh->num_cdds; + dr->details.ok.exchange_sigs = dh->exchange_sigs; + dr->details.ok.exchange_pub = &dh->exchange_pub; + dr->details.ok.deposit_timestamp = dh->exchange_timestamp; + dr->details.ok.num_signatures = dh->num_cdds; break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); /* Nothing really to verify, exchange says one of the signatures is invalid; as we checked them, this should never happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_NOT_FOUND: - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_CONFLICT: { - const struct TALER_EXCHANGE_Keys *key_state; struct TALER_CoinSpendPublicKeyP coin_pub; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("coin_pub", @@ -384,8 +479,8 @@ handle_deposit_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } for (unsigned int i = 0; inum_cdds; i++) @@ -394,14 +489,13 @@ handle_deposit_finished (void *cls, GNUNET_memcmp (&coin_pub, &dh->cdds[i].coin_pub)) continue; - key_state = TALER_EXCHANGE_get_keys (dh->exchange); - dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + dki = TALER_EXCHANGE_get_denomination_key_by_hash (dh->keys, &dh->cdds[i]. h_denom_pub); GNUNET_assert (NULL != dki); if (GNUNET_OK != TALER_EXCHANGE_check_coin_conflict_ ( - keys, + dh->keys, j, dki, &dh->cdds[i].coin_pub, @@ -409,8 +503,8 @@ handle_deposit_finished (void *cls, &dh->cdds[i].amount)) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } found = true; @@ -419,12 +513,12 @@ handle_deposit_finished (void *cls, if (! found) { GNUNET_break_op (0); - dr.hr.http_status = 0; - dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr->hr.http_status = 0; + dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); } break; case MHD_HTTP_GONE: @@ -432,35 +526,37 @@ handle_deposit_finished (void *cls, /* Note: one might want to check /keys for revocation signature here, alas tricky in case our /keys is outdated => left to clients */ - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); /* Server had an internal issue; we should retry, but this API leaves this to the application */ break; default: /* unexpected response code */ - dr.hr.ec = TALER_JSON_get_error_code (j); - dr.hr.hint = TALER_JSON_get_error_hint (j); + dr->hr.ec = TALER_JSON_get_error_code (j); + dr->hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange deposit\n", (unsigned int) response_code, - dr.hr.ec); + dr->hr.ec); GNUNET_break_op (0); break; } - dh->cb (dh->cb_cls, - &dr); - TALER_EXCHANGE_batch_deposit_cancel (dh); + if (NULL != dh->ai_head) + return; + finish_dh (dh); } struct TALER_EXCHANGE_BatchDepositHandle * TALER_EXCHANGE_batch_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_EXCHANGE_DepositContractDetail *dcd, unsigned int num_cdds, const struct TALER_EXCHANGE_CoinDepositDetail *cdds, @@ -468,15 +564,12 @@ TALER_EXCHANGE_batch_deposit ( void *cb_cls, enum TALER_ErrorCode *ec) { - const struct TALER_EXCHANGE_Keys *key_state; struct TALER_EXCHANGE_BatchDepositHandle *dh; json_t *deposit_obj; json_t *deposits; CURL *eh; struct TALER_Amount amount_without_fee; - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); if (GNUNET_TIME_timestamp_cmp (dcd->refund_deadline, >, dcd->wire_deadline)) @@ -485,10 +578,8 @@ TALER_EXCHANGE_batch_deposit ( *ec = TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE; return NULL; } - key_state = TALER_EXCHANGE_get_keys (exchange); dh = GNUNET_new (struct TALER_EXCHANGE_BatchDepositHandle); dh->auditor_chance = AUDITOR_CHANCE; - dh->exchange = exchange; dh->cb = cb; dh->cb_cls = cb_cls; dh->cdds = GNUNET_memdup (cdds, @@ -509,7 +600,7 @@ TALER_EXCHANGE_batch_deposit ( const struct TALER_EXCHANGE_CoinDepositDetail *cdd = &cdds[i]; const struct TALER_EXCHANGE_DenomPublicKey *dki; - dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, + dki = TALER_EXCHANGE_get_denomination_key_by_hash (keys, &cdd->h_denom_pub); if (NULL == dki) { @@ -568,8 +659,9 @@ TALER_EXCHANGE_batch_deposit ( &cdd->coin_sig) ))); } - dh->url = TEAH_path_to_url (exchange, - "/batch-deposit"); + dh->url = TALER_url_join (url, + "batch-deposit", + NULL); if (NULL == dh->url) { GNUNET_break (0); @@ -623,8 +715,9 @@ TALER_EXCHANGE_batch_deposit ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for deposit: `%s'\n", dh->url); - dh->ctx = TEAH_handle_to_context (exchange); - dh->job = GNUNET_CURL_job_add2 (dh->ctx, + dh->ctx = ctx; + dh->keys = TALER_EXCHANGE_keys_incref (keys); + dh->job = GNUNET_CURL_job_add2 (ctx, eh, dh->post_ctx.headers, &handle_deposit_finished, @@ -645,15 +738,31 @@ void TALER_EXCHANGE_batch_deposit_cancel ( struct TALER_EXCHANGE_BatchDepositHandle *deposit) { + struct TEAH_AuditorInteractionEntry *aie; + + while (NULL != (aie = deposit->ai_head)) + { + GNUNET_assert (aie->dh == deposit); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Not sending deposit confirmation to auditor `%s' due to cancellation\n", + aie->auditor_url); + TALER_AUDITOR_deposit_confirmation_cancel (aie->dch); + GNUNET_CONTAINER_DLL_remove (deposit->ai_head, + deposit->ai_tail, + aie); + GNUNET_free (aie); + } if (NULL != deposit->job) { GNUNET_CURL_job_cancel (deposit->job); deposit->job = NULL; } + TALER_EXCHANGE_keys_decref (deposit->keys); GNUNET_free (deposit->url); GNUNET_free (deposit->cdds); GNUNET_free (deposit->exchange_sigs); TALER_curl_easy_post_finished (&deposit->post_ctx); + json_decref (deposit->response); GNUNET_free (deposit); } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 4d245b07..7e302112 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -112,16 +112,6 @@ struct TEAH_AuditorListEntry */ struct TALER_AUDITOR_GetConfigHandle *ah; - /** - * Head of DLL of interactions with this auditor. - */ - struct TEAH_AuditorInteractionEntry *ai_head; - - /** - * Tail of DLL of interactions with this auditor. - */ - struct TEAH_AuditorInteractionEntry *ai_tail; - /** * Public key of the auditor. */ @@ -168,58 +158,24 @@ struct KeysRequest void -TEAH_acc_confirmation_cb ( - void *cls, - const struct TALER_AUDITOR_DepositConfirmationResponse *dcr) -{ - struct TEAH_AuditorInteractionEntry *aie = cls; - struct TEAH_AuditorListEntry *ale = aie->ale; - - if (MHD_HTTP_OK != dcr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n", - ale->auditor_url, - dcr->hr.http_status, - dcr->hr.ec); - } - GNUNET_CONTAINER_DLL_remove (ale->ai_head, - ale->ai_tail, - aie); - GNUNET_free (aie); -} - - -void -TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h, +TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Keys *keys, TEAH_AuditorCallback ac, void *ac_cls) { - if (NULL == h->auditors_head) + if (0 == keys->num_auditors) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "No auditor available for exchange `%s'. Not submitting deposit confirmations.\n", - h->url); + "No auditor available. Not submitting deposit confirmations.\n"); return; } - for (struct TEAH_AuditorListEntry *ale = h->auditors_head; - NULL != ale; - ale = ale->next) + for (unsigned int i = 0; inum_auditors; i++) { - struct TEAH_AuditorInteractionEntry *aie; + const struct TALER_EXCHANGE_AuditorInformation *auditor + = &keys->auditors[i]; - if (! ale->is_up) - continue; - aie = ac (ac_cls, - ale->auditor_url, - &ale->auditor_pub); - if (NULL != aie) - { - aie->ale = ale; - GNUNET_CONTAINER_DLL_insert (ale->ai_head, - ale->ai_tail, - aie); - } + ac (ac_cls, + auditor->auditor_url, + &auditor->auditor_pub); } } @@ -2121,20 +2077,6 @@ TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange) while (NULL != (ale = exchange->auditors_head)) { - struct TEAH_AuditorInteractionEntry *aie; - - while (NULL != (aie = ale->ai_head)) - { - GNUNET_assert (aie->ale == ale); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Not sending deposit confirmation to auditor `%s' due to exchange disconnect\n", - ale->auditor_url); - TALER_AUDITOR_deposit_confirmation_cancel (aie->dch); - GNUNET_CONTAINER_DLL_remove (ale->ai_head, - ale->ai_tail, - aie); - GNUNET_free (aie); - } GNUNET_CONTAINER_DLL_remove (exchange->auditors_head, exchange->auditors_tail, ale); @@ -2275,7 +2217,7 @@ TALER_EXCHANGE_get_denomination_key_by_hash ( } -const struct TALER_EXCHANGE_Keys * +struct TALER_EXCHANGE_Keys * TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange) { (void) TALER_EXCHANGE_check_keys_current (exchange, @@ -2297,4 +2239,19 @@ TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange) } +struct TALER_EXCHANGE_Keys * +TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys) +{ + // FIXME + return keys; +} + + +void +TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys) +{ + // FIXME +} + + /* end of exchange_api_handle.c */ diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h index 8e3b1065..6b96e21e 100644 --- a/src/lib/exchange_api_handle.h +++ b/src/lib/exchange_api_handle.h @@ -34,32 +34,6 @@ struct TEAH_AuditorListEntry; -/** - * Entry in list of ongoing interactions with an auditor. - */ -struct TEAH_AuditorInteractionEntry -{ - /** - * DLL entry. - */ - struct TEAH_AuditorInteractionEntry *next; - - /** - * DLL entry. - */ - struct TEAH_AuditorInteractionEntry *prev; - - /** - * Which auditor is this action associated with? - */ - struct TEAH_AuditorListEntry *ale; - - /** - * Interaction state. - */ - struct TALER_AUDITOR_DepositConfirmationHandle *dch; -}; - /** * Stages of initialization for the `struct TALER_EXCHANGE_Handle` */ @@ -180,38 +154,24 @@ struct TALER_EXCHANGE_Handle * @param cls closure * @param auditor_url base URL of the auditor * @param auditor_pub public key of the auditor - * @return NULL if no deposit confirmation interaction was launched */ -typedef struct TEAH_AuditorInteractionEntry * +typedef void (*TEAH_AuditorCallback)(void *cls, const char *auditor_url, const struct TALER_AuditorPublicKeyP *auditor_pub); -/** - * Signature of functions called with the result from our call to the - * auditor's /deposit-confirmation handler. - * - * @param cls closure of type `struct TEAH_AuditorInteractionEntry *` - * @param dcr response - */ -void -TEAH_acc_confirmation_cb ( - void *cls, - const struct TALER_AUDITOR_DepositConfirmationResponse *dcr); - - /** * Iterate over all available auditors for @a h, calling * @a ac and giving it a chance to start a deposit * confirmation interaction. * - * @param h exchange to go over auditors for + * @param keys the keys to go over auditors for * @param ac function to call per auditor * @param ac_cls closure for @a ac */ void -TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h, +TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Keys *keys, TEAH_AuditorCallback ac, void *ac_cls); diff --git a/src/testing/test_exchange_api.conf b/src/testing/test_exchange_api.conf index 9ed12412..b7f8c5c6 100644 --- a/src/testing/test_exchange_api.conf +++ b/src/testing/test_exchange_api.conf @@ -11,7 +11,7 @@ CURRENCY_ROUND_UNIT = EUR:0.01 [auditor] BASE_URL = "http://localhost:8083/" PORT = 8083 -PUBLIC_KEY = SA7JVMCW3MMN7SYAWJ9AB0BGJDX6MP3PNN2JWQ3T8233MDSQC7Z0 +PUBLIC_KEY = T0XJ9QZ59YDN7QG3RE40SB2HY7W0ASR1EKF4WZDGZ1G159RSQC80 TINY_AMOUNT = EUR:0.01 [auditordb-postgres] diff --git a/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv b/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv new file mode 100644 index 00000000..7e712e48 --- /dev/null +++ b/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv @@ -0,0 +1 @@ +·G,U²†{ ~#ræ-½Hê ‘¶ÒÆÏâÿñ \ No newline at end of file diff --git a/src/testing/testing_api_cmd_batch_deposit.c b/src/testing/testing_api_cmd_batch_deposit.c index 6a05071a..0a4fbd25 100644 --- a/src/testing/testing_api_cmd_batch_deposit.c +++ b/src/testing/testing_api_cmd_batch_deposit.c @@ -251,12 +251,15 @@ batch_deposit_run (void *cls, &wire_salt), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url + = TALER_TESTING_get_exchange_url (is); (void) cmd; - if (NULL == exchange) + if (NULL == exchange_url) + { + GNUNET_break (0); return; + } memset (cdds, 0, sizeof (cdds)); @@ -383,13 +386,16 @@ batch_deposit_run (void *cls, .refund_deadline = ds->refund_deadline }; - ds->dh = TALER_EXCHANGE_batch_deposit (exchange, - &dcd, - ds->num_coins, - cdds, - &batch_deposit_cb, - ds, - &ec); + ds->dh = TALER_EXCHANGE_batch_deposit ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + TALER_TESTING_get_keys (is), + &dcd, + ds->num_coins, + cdds, + &batch_deposit_cb, + ds, + &ec); } if (NULL == ds->dh) { diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 3d5c00ab..f2a3a269 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -98,7 +98,7 @@ struct DepositState /** * Deposit handle while operation is running. */ - struct TALER_EXCHANGE_DepositHandle *dh; + struct TALER_EXCHANGE_BatchDepositHandle *dh; /** * Timestamp of the /deposit operation in the wallet (contract signing time). @@ -215,7 +215,7 @@ do_retry (void *cls) */ static void deposit_cb (void *cls, - const struct TALER_EXCHANGE_DepositResult *dr) + const struct TALER_EXCHANGE_BatchDepositResult *dr) { struct DepositState *ds = cls; @@ -254,10 +254,11 @@ deposit_cb (void *cls, } if (MHD_HTTP_OK == dr->hr.http_status) { + GNUNET_assert (1 == dr->details.ok.num_signatures); ds->deposit_succeeded = GNUNET_YES; ds->exchange_timestamp = dr->details.ok.deposit_timestamp; ds->exchange_pub = *dr->details.ok.exchange_pub; - ds->exchange_sig = *dr->details.ok.exchange_sig; + ds->exchange_sig = dr->details.ok.exchange_sigs[0]; } TALER_TESTING_interpreter_next (ds->is); } @@ -296,12 +297,15 @@ deposit_run (void *cls, &wire_salt), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); + const char *exchange_url + = TALER_TESTING_get_exchange_url (is); (void) cmd; - if (NULL == exchange) + if (NULL == exchange_url) + { + GNUNET_break (0); return; + } ds->is = is; if (NULL != ds->deposit_reference) { @@ -469,12 +473,16 @@ deposit_run (void *cls, .refund_deadline = ds->refund_deadline }; - ds->dh = TALER_EXCHANGE_deposit (exchange, - &dcd, - &cdd, - &deposit_cb, - ds, - &ec); + ds->dh = TALER_EXCHANGE_batch_deposit ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + TALER_TESTING_get_keys (is), + &dcd, + 1, + &cdd, + &deposit_cb, + ds, + &ec); } if (NULL == ds->dh) { @@ -505,7 +513,7 @@ deposit_cleanup (void *cls, { TALER_TESTING_command_incomplete (ds->is, cmd->label); - TALER_EXCHANGE_deposit_cancel (ds->dh); + TALER_EXCHANGE_batch_deposit_cancel (ds->dh); ds->dh = NULL; } if (NULL != ds->retry_task) diff --git a/src/testing/testing_api_cmd_get_exchange.c b/src/testing/testing_api_cmd_get_exchange.c index 2fc8ba77..2822616c 100644 --- a/src/testing/testing_api_cmd_get_exchange.c +++ b/src/testing/testing_api_cmd_get_exchange.c @@ -189,7 +189,7 @@ get_exchange_traits (void *cls, { struct GetExchangeState *ges = cls; unsigned int off = (NULL == ges->master_priv_file) ? 1 : 0; - const struct TALER_EXCHANGE_Keys *keys + struct TALER_EXCHANGE_Keys *keys = TALER_EXCHANGE_get_keys (ges->exchange); if (NULL != keys) @@ -198,6 +198,7 @@ get_exchange_traits (void *cls, TALER_TESTING_make_trait_master_priv (&ges->master_priv), TALER_TESTING_make_trait_master_pub (&keys->master_pub), TALER_TESTING_make_trait_exchange (ges->exchange), + TALER_TESTING_make_trait_keys (keys), TALER_TESTING_make_trait_exchange_url (ges->exchange_url), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c index 27eef5a5..d00a8d8c 100644 --- a/src/testing/testing_api_traits.c +++ b/src/testing/testing_api_traits.c @@ -129,4 +129,32 @@ TALER_TESTING_get_exchange_url (struct TALER_TESTING_Interpreter *is) } +struct TALER_EXCHANGE_Keys * +TALER_TESTING_get_keys ( + struct TALER_TESTING_Interpreter *is) +{ + struct TALER_EXCHANGE_Keys *keys; + const struct TALER_TESTING_Command *exchange_cmd; + + exchange_cmd + = TALER_TESTING_interpreter_get_command (is, + "exchange"); + if (NULL == exchange_cmd) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return NULL; + } + if (GNUNET_OK != + TALER_TESTING_get_trait_keys (exchange_cmd, + &keys)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return NULL; + } + return keys; +} + + /* end of testing_api_traits.c */ -- cgit v1.2.3 From 421129a32ed88fee49108c76e67c16b60f95116b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jun 2023 19:10:26 +0200 Subject: next round of exchange API atomization --- contrib/gana | 2 +- src/include/taler_exchange_service.h | 230 ++++++++++++++------- src/lib/exchange_api_batch_withdraw2.c | 17 +- src/lib/exchange_api_common.c | 14 +- src/lib/exchange_api_csr_melt.c | 26 +-- src/lib/exchange_api_deposits_get.c | 29 ++- src/lib/exchange_api_handle.c | 14 ++ src/lib/exchange_api_melt.c | 57 +++-- src/lib/exchange_api_purse_create_with_deposit.c | 45 ++-- src/lib/exchange_api_purse_create_with_merge.c | 41 ++-- src/lib/exchange_api_purse_deposit.c | 30 ++- src/lib/exchange_api_purse_merge.c | 30 ++- src/lib/exchange_api_purses_get.c | 34 ++- src/lib/exchange_api_recoup.c | 41 ++-- src/lib/exchange_api_recoup_refresh.c | 30 ++- src/lib/exchange_api_refreshes_reveal.c | 34 +-- src/lib/exchange_api_refund.c | 28 ++- src/lib/exchange_api_reserves_close.c | 26 +-- src/lib/exchange_api_reserves_history.c | 40 ++-- src/lib/exchange_api_reserves_open.c | 45 ++-- src/lib/exchange_api_reserves_status.c | 30 ++- src/lib/exchange_api_transfers_get.c | 31 ++- src/lib/exchange_api_withdraw2.c | 3 +- src/testing/testing_api_cmd_deposits_get.c | 23 +-- src/testing/testing_api_cmd_purse_create_deposit.c | 8 +- src/testing/testing_api_cmd_purse_deposit.c | 8 +- src/testing/testing_api_cmd_purse_get.c | 19 +- src/testing/testing_api_cmd_purse_merge.c | 8 +- src/testing/testing_api_cmd_recoup.c | 21 +- src/testing/testing_api_cmd_recoup_refresh.c | 25 ++- src/testing/testing_api_cmd_refresh.c | 52 ++--- src/testing/testing_api_cmd_refund.c | 27 +-- src/testing/testing_api_cmd_reserve_close.c | 16 +- src/testing/testing_api_cmd_reserve_history.c | 11 +- src/testing/testing_api_cmd_reserve_open.c | 4 +- src/testing/testing_api_cmd_reserve_purse.c | 4 +- src/testing/testing_api_cmd_reserve_status.c | 11 +- src/testing/testing_api_cmd_transfer_get.c | 11 +- 38 files changed, 576 insertions(+), 549 deletions(-) (limited to 'src/lib/exchange_api_handle.c') diff --git a/contrib/gana b/contrib/gana index 5f377301..3e5591a7 160000 --- a/contrib/gana +++ b/contrib/gana @@ -1 +1 @@ -Subproject commit 5f377301db4d94c485422ecda277fe850e29504a +Subproject commit 3e5591a7e3fd93ba46fc2b538c63f0c16336283d diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 9cb5f083..bc6a230b 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -604,8 +604,9 @@ TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys); * @param last_denom_new new last denomination time. */ void -TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange, - struct GNUNET_TIME_Timestamp last_denom_new); +TALER_EXCHANGE_set_last_denom ( + struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_TIME_Timestamp last_denom_new); /** @@ -653,10 +654,11 @@ enum TALER_EXCHANGE_CheckKeysFlags * @return until when the existing response is current, 0 if we are re-downloading now */ struct GNUNET_TIME_Timestamp -TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange, - enum TALER_EXCHANGE_CheckKeysFlags flags, - TALER_EXCHANGE_CertificationCallback cb, - void *cb_cls); +TALER_EXCHANGE_check_keys_current ( + struct TALER_EXCHANGE_Handle *exchange, + enum TALER_EXCHANGE_CheckKeysFlags flags, + TALER_EXCHANGE_CertificationCallback cb, + void *cb_cls); /** @@ -669,6 +671,16 @@ json_t * TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange); +/** + * Obtain the keys from the exchange in the raw JSON format. + * + * @param keys the keys structure + * @return the keys in raw JSON + */ +json_t * +TALER_EXCHANGE_keys_to_json (struct TALER_EXCHANGE_Keys *keys); + + /** * Test if the given @a pub is a the current signing key from the exchange * according to @a keys. @@ -1055,9 +1067,10 @@ struct TALER_EXCHANGE_WireHandle; * @return a handle for this request */ struct TALER_EXCHANGE_WireHandle * -TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange, - TALER_EXCHANGE_WireCallback wire_cb, - void *wire_cb_cls); +TALER_EXCHANGE_wire ( + struct TALER_EXCHANGE_Handle *exchange, + TALER_EXCHANGE_WireCallback wire_cb, + void *wire_cb_cls); /** @@ -1377,7 +1390,9 @@ typedef void * finished processing the /keys reply). If this check fails, we do * NOT initiate the transaction with the exchange and instead return NULL. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param amount the amount to be refunded; must be larger than the refund fee * (as that fee is still being subtracted), and smaller than the amount * (with deposit fee) of the original deposit contribution of this coin @@ -1395,7 +1410,9 @@ typedef void */ struct TALER_EXCHANGE_RefundHandle * TALER_EXCHANGE_refund ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_Amount *amount, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_CoinSpendPublicKeyP *coin_pub, @@ -1504,7 +1521,8 @@ struct TALER_EXCHANGE_NonceKey /** * Get a set of CS R values using a /csr-melt request. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL * @param rms master key used for the derivation of the CS values * @param nks_len length of the @a nks array * @param nks array of denominations and nonces @@ -1515,12 +1533,14 @@ struct TALER_EXCHANGE_NonceKey * In this case, the callback is not called. */ struct TALER_EXCHANGE_CsRMeltHandle * -TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_RefreshMasterSecretP *rms, - unsigned int nks_len, - struct TALER_EXCHANGE_NonceKey *nks, - TALER_EXCHANGE_CsRMeltCallback res_cb, - void *res_cb_cls); +TALER_EXCHANGE_csr_melt ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_RefreshMasterSecretP *rms, + unsigned int nks_len, + struct TALER_EXCHANGE_NonceKey *nks, + TALER_EXCHANGE_CsRMeltCallback res_cb, + void *res_cb_cls); /** @@ -1608,11 +1628,12 @@ typedef void * In this case, the callback is not called. */ struct TALER_EXCHANGE_CsRWithdrawHandle * -TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_EXCHANGE_DenomPublicKey *pk, - const struct TALER_CsNonce *nonce, - TALER_EXCHANGE_CsRWithdrawCallback res_cb, - void *res_cb_cls); +TALER_EXCHANGE_csr_withdraw ( + struct TALER_EXCHANGE_Handle *exchange, + const struct TALER_EXCHANGE_DenomPublicKey *pk, + const struct TALER_CsNonce *nonce, + TALER_EXCHANGE_CsRWithdrawCallback res_cb, + void *res_cb_cls); /** @@ -2132,7 +2153,9 @@ typedef void /** * Submit a request to obtain the reserve status. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param reserve_priv private key of the reserve to inspect * @param cb the callback to call when a reply for this request is available * @param cb_cls closure for the above callback @@ -2141,7 +2164,9 @@ typedef void */ struct TALER_EXCHANGE_ReservesStatusHandle * TALER_EXCHANGE_reserves_status ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, TALER_EXCHANGE_ReservesStatusCallback cb, void *cb_cls); @@ -2250,7 +2275,9 @@ typedef void /** * Submit a request to obtain the reserve history. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param reserve_priv private key of the reserve to inspect * @param cb the callback to call when a reply for this request is available * @param cb_cls closure for the above callback @@ -2259,7 +2286,9 @@ typedef void */ struct TALER_EXCHANGE_ReservesHistoryHandle * TALER_EXCHANGE_reserves_history ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, TALER_EXCHANGE_ReservesHistoryCallback cb, void *cb_cls); @@ -2649,11 +2678,12 @@ struct TALER_EXCHANGE_Withdraw2Handle; * In this case, the callback is not called. */ struct TALER_EXCHANGE_Withdraw2Handle * -TALER_EXCHANGE_withdraw2 (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_PlanchetDetail *pd, - const struct TALER_ReservePrivateKeyP *reserve_priv, - TALER_EXCHANGE_Withdraw2Callback res_cb, - void *res_cb_cls); +TALER_EXCHANGE_withdraw2 ( + struct TALER_EXCHANGE_Handle *exchange, + const struct TALER_PlanchetDetail *pd, + const struct TALER_ReservePrivateKeyP *reserve_priv, + TALER_EXCHANGE_Withdraw2Callback res_cb, + void *res_cb_cls); /** @@ -2911,7 +2941,9 @@ typedef void * argument @a rd should be committed to persistent storage * prior to calling this function. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param rms the fresh secret that defines the refresh operation * @param rd the refresh data specifying the characteristics of the operation * @param melt_cb the callback to call with the result @@ -2920,11 +2952,14 @@ typedef void * In this case, neither callback will be called. */ struct TALER_EXCHANGE_MeltHandle * -TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_RefreshMasterSecretP *rms, - const struct TALER_EXCHANGE_RefreshData *rd, - TALER_EXCHANGE_MeltCallback melt_cb, - void *melt_cb_cls); +TALER_EXCHANGE_melt ( + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, + const struct TALER_RefreshMasterSecretP *rms, + const struct TALER_EXCHANGE_RefreshData *rd, + TALER_EXCHANGE_MeltCallback melt_cb, + void *melt_cb_cls); /** @@ -3044,7 +3079,9 @@ struct TALER_EXCHANGE_RefreshesRevealHandle; * arguments should have been committed to persistent storage * prior to calling this function. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param rms the fresh secret that defines the refresh operation * @param rd the refresh data that characterizes the refresh operation * @param num_coins number of fresh coins to be created, length of the @a exchange_vals array, must match value in @a rd @@ -3059,7 +3096,8 @@ struct TALER_EXCHANGE_RefreshesRevealHandle; */ struct TALER_EXCHANGE_RefreshesRevealHandle * TALER_EXCHANGE_refreshes_reveal ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_RefreshMasterSecretP *rms, const struct TALER_EXCHANGE_RefreshData *rd, unsigned int num_coins, @@ -3311,7 +3349,9 @@ typedef void * Query the exchange about which transactions were combined * to create a wire transfer. * - * @param exchange exchange to query + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param wtid raw wire transfer identifier to get information about * @param cb callback to call * @param cb_cls closure for @a cb @@ -3319,7 +3359,9 @@ typedef void */ struct TALER_EXCHANGE_TransfersGetHandle * TALER_EXCHANGE_transfers_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_EXCHANGE_TransfersGetCallback cb, void *cb_cls); @@ -3449,7 +3491,9 @@ typedef void * which aggregate wire transfer the deposit operation identified by @a coin_pub, * @a merchant_priv and @a h_contract_terms contributed to. * - * @param exchange the exchange to query + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param merchant_priv the merchant's private key * @param h_wire hash of merchant's wire transfer details * @param h_contract_terms hash of the proposal data @@ -3461,7 +3505,9 @@ typedef void */ struct TALER_EXCHANGE_DepositGetHandle * TALER_EXCHANGE_deposits_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_MerchantPrivateKeyP *merchant_priv, const struct TALER_MerchantWireHashP *h_wire, const struct TALER_PrivateContractHashP *h_contract_terms, @@ -3504,7 +3550,7 @@ TALER_EXCHANGE_verify_coin_history ( * Parse history given in JSON format and return it in binary * format. * - * @param exchange connection to the exchange we can use + * @param keys exchange keys * @param history JSON array with the history * @param reserve_pub public key of the reserve to inspect * @param currency currency we expect the balance to be in @@ -3519,7 +3565,7 @@ TALER_EXCHANGE_verify_coin_history ( */ enum GNUNET_GenericReturnValue TALER_EXCHANGE_parse_reserve_history ( - struct TALER_EXCHANGE_Handle *exchange, + struct TALER_EXCHANGE_Keys *keys, const json_t *history, const struct TALER_ReservePublicKeyP *reserve_pub, const char *currency, @@ -3601,7 +3647,9 @@ typedef void * the emergency recoup protocol for a given denomination. The value * of the coin will be refunded to the original customer (without fees). * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param pk kind of coin to pay back * @param denom_sig signature over the coin by the exchange using @a pk * @param exchange_vals contribution from the exchange on the withdraw @@ -3613,13 +3661,16 @@ typedef void * In this case, the callback is not called. */ struct TALER_EXCHANGE_RecoupHandle * -TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_EXCHANGE_DenomPublicKey *pk, - const struct TALER_DenominationSignature *denom_sig, - const struct TALER_ExchangeWithdrawValues *exchange_vals, - const struct TALER_PlanchetMasterSecretP *ps, - TALER_EXCHANGE_RecoupResultCallback recoup_cb, - void *recoup_cb_cls); +TALER_EXCHANGE_recoup ( + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, + const struct TALER_EXCHANGE_DenomPublicKey *pk, + const struct TALER_DenominationSignature *denom_sig, + const struct TALER_ExchangeWithdrawValues *exchange_vals, + const struct TALER_PlanchetMasterSecretP *ps, + TALER_EXCHANGE_RecoupResultCallback recoup_cb, + void *recoup_cb_cls); /** @@ -3692,7 +3743,9 @@ typedef void * revoked coin was refreshed from. The original coin is then * considered a zombie. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param pk kind of coin to pay back * @param denom_sig signature over the coin by the exchange using @a pk * @param exchange_vals contribution from the exchange on the withdraw @@ -3707,7 +3760,9 @@ typedef void */ struct TALER_EXCHANGE_RecoupRefreshHandle * TALER_EXCHANGE_recoup_refresh ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_DenominationSignature *denom_sig, const struct TALER_ExchangeWithdrawValues *exchange_vals, @@ -4258,10 +4313,11 @@ struct TALER_EXCHANGE_ManagementGetKeysHandle; * @return the request handle; NULL upon error */ struct TALER_EXCHANGE_ManagementGetKeysHandle * -TALER_EXCHANGE_get_management_keys (struct GNUNET_CURL_Context *ctx, - const char *url, - TALER_EXCHANGE_ManagementGetKeysCallback cb, - void *cb_cls); +TALER_EXCHANGE_get_management_keys ( + struct GNUNET_CURL_Context *ctx, + const char *url, + TALER_EXCHANGE_ManagementGetKeysCallback cb, + void *cb_cls); /** @@ -5787,7 +5843,9 @@ struct TALER_EXCHANGE_PurseGetHandle; /** * Request information about a purse from the exchange. * - * @param exchange exchange handle + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param purse_pub public key of the purse * @param timeout how long to wait for a change to happen * @param wait_for_merge true to wait for a merge event, otherwise wait for a deposit event @@ -5797,7 +5855,9 @@ struct TALER_EXCHANGE_PurseGetHandle; */ struct TALER_EXCHANGE_PurseGetHandle * TALER_EXCHANGE_purse_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_PurseContractPublicKeyP *purse_pub, struct GNUNET_TIME_Relative timeout, bool wait_for_merge, @@ -5911,7 +5971,9 @@ struct TALER_EXCHANGE_PurseDeposit * Inform the exchange that a purse should be created * and coins deposited into it. * - * @param exchange the exchange to interact with + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param purse_priv private key of the purse * @param merge_priv the merge credential * @param contract_priv key needed to obtain and decrypt the contract @@ -5927,7 +5989,9 @@ struct TALER_EXCHANGE_PurseDeposit */ struct TALER_EXCHANGE_PurseCreateDepositHandle * TALER_EXCHANGE_purse_create_with_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_PurseContractPrivateKeyP *purse_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv, const struct TALER_ContractDiffiePrivateP *contract_priv, @@ -6091,7 +6155,9 @@ struct TALER_EXCHANGE_AccountMergeHandle; * Inform the exchange that a purse should be merged * with a reserve. * - * @param exchange the exchange hosting the purse + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param reserve_exchange_url base URL of the exchange with the reserve * @param reserve_priv private key of the reserve to merge into * @param purse_pub public key of the purse to merge @@ -6107,7 +6173,9 @@ struct TALER_EXCHANGE_AccountMergeHandle; */ struct TALER_EXCHANGE_AccountMergeHandle * TALER_EXCHANGE_account_merge ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const char *reserve_exchange_url, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPublicKeyP *purse_pub, @@ -6199,7 +6267,9 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle; * Inform the exchange that a purse should be created * and merged with a reserve. * - * @param exchange the exchange hosting the reserve + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param reserve_priv private key of the reserve * @param purse_priv private key of the purse * @param merge_priv private key of the merge capability @@ -6214,7 +6284,9 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle; */ struct TALER_EXCHANGE_PurseCreateMergeHandle * TALER_EXCHANGE_purse_create_with_merge ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPrivateKeyP *purse_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv, @@ -6306,7 +6378,9 @@ struct TALER_EXCHANGE_PurseDepositHandle; * Inform the exchange that a deposit should be made into * a purse. * - * @param exchange the exchange that issued the coins + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param purse_exchange_url base URL of the exchange hosting the purse * @param purse_pub public key of the purse to merge * @param min_age minimum age we need to prove for the purse @@ -6318,7 +6392,9 @@ struct TALER_EXCHANGE_PurseDepositHandle; */ struct TALER_EXCHANGE_PurseDepositHandle * TALER_EXCHANGE_purse_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const char *purse_exchange_url, const struct TALER_PurseContractPublicKeyP *purse_pub, uint8_t min_age, @@ -6442,7 +6518,9 @@ typedef void /** * Submit a request to open a reserve. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL + * @param keys exchange keys * @param reserve_priv private key of the reserve to open * @param reserve_contribution amount to pay from the reserve's balance for the operation * @param coin_payments_length length of the @a coin_payments array @@ -6456,7 +6534,9 @@ typedef void */ struct TALER_EXCHANGE_ReservesOpenHandle * TALER_EXCHANGE_reserves_open ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_Amount *reserve_contribution, unsigned int coin_payments_length, @@ -6760,7 +6840,8 @@ typedef void /** * Submit a request to close a reserve. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param ctx curl context + * @param url exchange base URL * @param reserve_priv private key of the reserve to close * @param target_payto_uri where to send the payment, NULL to send to reserve origin * @param cb the callback to call when a reply for this request is available @@ -6770,7 +6851,8 @@ typedef void */ struct TALER_EXCHANGE_ReservesCloseHandle * TALER_EXCHANGE_reserves_close ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_ReservePrivateKeyP *reserve_priv, const char *target_payto_uri, TALER_EXCHANGE_ReservesCloseCallback cb, diff --git a/src/lib/exchange_api_batch_withdraw2.c b/src/lib/exchange_api_batch_withdraw2.c index 04c2c010..6dd421ce 100644 --- a/src/lib/exchange_api_batch_withdraw2.c +++ b/src/lib/exchange_api_batch_withdraw2.c @@ -218,14 +218,15 @@ reserve_batch_withdraw_payment_required ( } if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (wh->exchange, - history, - &wh->reserve_pub, - balance.currency, - &total_in_from_history, - &total_out_from_history, - len, - rhistory)) + TALER_EXCHANGE_parse_reserve_history ( + TALER_EXCHANGE_get_keys (wh->exchange), + history, + &wh->reserve_pub, + balance.currency, + &total_in_from_history, + &total_out_from_history, + len, + rhistory)) { GNUNET_break_op (0); TALER_EXCHANGE_free_reserve_history (rhistory, diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 8bbc6c47..f43673d7 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -34,9 +34,9 @@ struct HistoryParseContext { /** - * Exchange we use. + * Keys of the exchange we use. */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * Our reserve public key. @@ -187,7 +187,7 @@ parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, const struct TALER_EXCHANGE_Keys *key_state; const struct TALER_EXCHANGE_DenomPublicKey *dki; - key_state = TALER_EXCHANGE_get_keys (uc->exchange); + key_state = uc->keys; dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, &h_denom_pub); if ( (GNUNET_YES != @@ -275,7 +275,7 @@ parse_recoup (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, GNUNET_break_op (0); return GNUNET_SYSERR; } - key_state = TALER_EXCHANGE_get_keys (uc->exchange); + key_state = uc->keys; if (GNUNET_OK != TALER_EXCHANGE_test_signing_key (key_state, &rh->details. @@ -349,7 +349,7 @@ parse_closing (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, GNUNET_break_op (0); return GNUNET_SYSERR; } - key_state = TALER_EXCHANGE_get_keys (uc->exchange); + key_state = uc->keys; if (GNUNET_OK != TALER_EXCHANGE_test_signing_key ( key_state, @@ -647,7 +647,7 @@ parse_close (struct TALER_EXCHANGE_ReserveHistoryEntry *rh, enum GNUNET_GenericReturnValue TALER_EXCHANGE_parse_reserve_history ( - struct TALER_EXCHANGE_Handle *exchange, + struct TALER_EXCHANGE_Keys *keys, const json_t *history, const struct TALER_ReservePublicKeyP *reserve_pub, const char *currency, @@ -673,7 +673,7 @@ TALER_EXCHANGE_parse_reserve_history ( }; struct GNUNET_HashCode uuid[history_length]; struct HistoryParseContext uc = { - .exchange = exchange, + .keys = keys, .reserve_pub = reserve_pub, .uuids = uuid, .total_in = total_in, diff --git a/src/lib/exchange_api_csr_melt.c b/src/lib/exchange_api_csr_melt.c index 67b1a9b7..da6c392a 100644 --- a/src/lib/exchange_api_csr_melt.c +++ b/src/lib/exchange_api_csr_melt.c @@ -38,10 +38,6 @@ */ struct TALER_EXCHANGE_CsRMeltHandle { - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; /** * Function to call with the result. @@ -220,12 +216,14 @@ handle_csr_finished (void *cls, struct TALER_EXCHANGE_CsRMeltHandle * -TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_RefreshMasterSecretP *rms, - unsigned int nks_len, - struct TALER_EXCHANGE_NonceKey *nks, - TALER_EXCHANGE_CsRMeltCallback res_cb, - void *res_cb_cls) +TALER_EXCHANGE_csr_melt ( + struct GNUNET_CURL_Context *ctx, + const char *url, + const struct TALER_RefreshMasterSecretP *rms, + unsigned int nks_len, + struct TALER_EXCHANGE_NonceKey *nks, + TALER_EXCHANGE_CsRMeltCallback res_cb, + void *res_cb_cls) { struct TALER_EXCHANGE_CsRMeltHandle *csrh; json_t *csr_arr; @@ -242,7 +240,6 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, return NULL; } csrh = GNUNET_new (struct TALER_EXCHANGE_CsRMeltHandle); - csrh->exchange = exchange; csrh->cb = res_cb; csrh->cb_cls = res_cb_cls; csr_arr = json_array (); @@ -262,8 +259,9 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, json_array_append_new (csr_arr, csr_obj)); } - csrh->url = TEAH_path_to_url (exchange, - "/csr-melt"); + csrh->url = TALER_url_join (url, + "csr-melt", + NULL); if (NULL == csrh->url) { json_decref (csr_arr); @@ -272,7 +270,6 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, } { CURL *eh; - struct GNUNET_CURL_Context *ctx; json_t *req; req = GNUNET_JSON_PACK ( @@ -280,7 +277,6 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange, rms), GNUNET_JSON_pack_array_steal ("nks", csr_arr)); - ctx = TEAH_handle_to_context (exchange); eh = TALER_EXCHANGE_curl_easy_get_ (csrh->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c index 9ec25e45..8b145dab 100644 --- a/src/lib/exchange_api_deposits_get.c +++ b/src/lib/exchange_api_deposits_get.c @@ -39,9 +39,9 @@ struct TALER_EXCHANGE_DepositGetHandle { /** - * The connection to exchange this request handle will use + * The keys of the this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -131,7 +131,7 @@ handle_deposit_wtid_finished (void *cls, }; const struct TALER_EXCHANGE_Keys *key_state; - key_state = TALER_EXCHANGE_get_keys (dwh->exchange); + key_state = dwh->keys; GNUNET_assert (NULL != key_state); if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -255,7 +255,9 @@ handle_deposit_wtid_finished (void *cls, struct TALER_EXCHANGE_DepositGetHandle * TALER_EXCHANGE_deposits_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_MerchantPrivateKeyP *merchant_priv, const struct TALER_MerchantWireHashP *h_wire, const struct TALER_PrivateContractHashP *h_contract_terms, @@ -267,7 +269,6 @@ TALER_EXCHANGE_deposits_get ( struct TALER_MerchantPublicKeyP merchant; struct TALER_MerchantSignatureP merchant_sig; struct TALER_EXCHANGE_DepositGetHandle *dwh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[(sizeof (struct TALER_CoinSpendPublicKeyP) + sizeof (struct TALER_MerchantWireHashP) @@ -275,12 +276,6 @@ TALER_EXCHANGE_deposits_get ( + sizeof (struct TALER_PrivateContractHashP) + sizeof (struct TALER_MerchantSignatureP)) * 2 + 48]; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv, &merchant.eddsa_pub); TALER_merchant_deposit_sign (h_contract_terms, @@ -339,7 +334,7 @@ TALER_EXCHANGE_deposits_get ( GNUNET_snprintf (arg_str, sizeof (arg_str), - "/deposits/%s/%s/%s/%s?merchant_sig=%s%s%s", + "deposits/%s/%s/%s/%s?merchant_sig=%s%s%s", whash_str, mpub_str, chash_str, @@ -352,11 +347,11 @@ TALER_EXCHANGE_deposits_get ( } dwh = GNUNET_new (struct TALER_EXCHANGE_DepositGetHandle); - dwh->exchange = exchange; dwh->cb = cb; dwh->cb_cls = cb_cls; - dwh->url = TEAH_path_to_url (exchange, - arg_str); + dwh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == dwh->url) { GNUNET_free (dwh); @@ -365,7 +360,6 @@ TALER_EXCHANGE_deposits_get ( dwh->h_wire = *h_wire; dwh->h_contract_terms = *h_contract_terms; dwh->coin_pub = *coin_pub; - eh = TALER_EXCHANGE_curl_easy_get_ (dwh->url); if (NULL == eh) { @@ -374,11 +368,11 @@ TALER_EXCHANGE_deposits_get ( GNUNET_free (dwh); return NULL; } - ctx = TEAH_handle_to_context (exchange); dwh->job = GNUNET_CURL_job_add (ctx, eh, &handle_deposit_wtid_finished, dwh); + dwh->keys = TALER_EXCHANGE_keys_incref (keys); return dwh; } @@ -393,6 +387,7 @@ TALER_EXCHANGE_deposits_get_cancel (struct TALER_EXCHANGE_DepositGetHandle *dwh) } GNUNET_free (dwh->url); TALER_curl_easy_post_finished (&dwh->ctx); + TALER_EXCHANGE_keys_decref (dwh->keys); GNUNET_free (dwh); } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 7e302112..fe73f050 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -2239,6 +2239,20 @@ TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange) } +/** + * Obtain the keys from the exchange in the raw JSON format. + * + * @param keys the keys structure + * @return the keys in raw JSON + */ +json_t * +TALER_EXCHANGE_keys_to_json (struct TALER_EXCHANGE_Keys *keys) +{ + // FIXME! + return NULL; +} + + struct TALER_EXCHANGE_Keys * TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys) { diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c index 3a8144a3..1da4184d 100644 --- a/src/lib/exchange_api_melt.c +++ b/src/lib/exchange_api_melt.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015-2022 Taler Systems SA + Copyright (C) 2015-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -41,15 +41,25 @@ struct TALER_EXCHANGE_MeltHandle { /** - * The connection to exchange this request handle will use + * The keys of the this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. */ char *url; + /** + * The exchange base url. + */ + char *exchange_url; + + /** + * Curl context. + */ + struct GNUNET_CURL_Context *cctx; + /** * Context for #TEH_curl_easy_post(). Keeps the data that must * persist for Curl to make the upload. @@ -159,7 +169,7 @@ verify_melt_signature_ok (struct TALER_EXCHANGE_MeltHandle *mh, return GNUNET_SYSERR; } /* check that exchange signing key is permitted */ - key_state = TALER_EXCHANGE_get_keys (mh->exchange); + key_state = mh->keys; if (GNUNET_OK != TALER_EXCHANGE_test_signing_key (key_state, exchange_pub)) @@ -211,7 +221,7 @@ handle_melt_finished (void *cls, const struct TALER_EXCHANGE_Keys *keys; mh->job = NULL; - keys = TALER_EXCHANGE_get_keys (mh->exchange); + keys = mh->keys; switch (response_code) { case 0: @@ -309,7 +319,6 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh) const struct TALER_EXCHANGE_Keys *key_state; json_t *melt_obj; CURL *eh; - struct GNUNET_CURL_Context *ctx; char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32]; struct TALER_DenominationHashP h_denom_pub; struct TALER_ExchangeWithdrawValues alg_values[mh->rd->fresh_pks_len]; @@ -371,19 +380,19 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh) *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/melt", + "coins/%s/melt", pub_str); } - ctx = TEAH_handle_to_context (mh->exchange); - key_state = TALER_EXCHANGE_get_keys (mh->exchange); + key_state = mh->keys; mh->dki = TALER_EXCHANGE_get_denomination_key (key_state, &mh->md.melted_coin.pub_key); /* and now we can at last begin the actual request handling */ - mh->url = TEAH_path_to_url (mh->exchange, - arg_str); + mh->url = TALER_url_join (mh->exchange_url, + arg_str, + NULL); if (NULL == mh->url) { json_decref (melt_obj); @@ -403,7 +412,7 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh) return GNUNET_SYSERR; } json_decref (melt_obj); - mh->job = GNUNET_CURL_job_add2 (ctx, + mh->job = GNUNET_CURL_job_add2 (mh->cctx, eh, mh->ctx.headers, &handle_melt_finished, @@ -496,11 +505,14 @@ csr_cb (void *cls, struct TALER_EXCHANGE_MeltHandle * -TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_RefreshMasterSecretP *rms, - const struct TALER_EXCHANGE_RefreshData *rd, - TALER_EXCHANGE_MeltCallback melt_cb, - void *melt_cb_cls) +TALER_EXCHANGE_melt ( + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, + const struct TALER_RefreshMasterSecretP *rms, + const struct TALER_EXCHANGE_RefreshData *rd, + TALER_EXCHANGE_MeltCallback melt_cb, + void *melt_cb_cls) { struct TALER_EXCHANGE_NonceKey nks[GNUNET_NZL (rd->fresh_pks_len)]; unsigned int nks_off = 0; @@ -511,11 +523,10 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, GNUNET_break (0); return NULL; } - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); mh = GNUNET_new (struct TALER_EXCHANGE_MeltHandle); mh->noreveal_index = TALER_CNC_KAPPA; /* invalid value */ - mh->exchange = exchange; + mh->cctx = ctx; + mh->exchange_url = GNUNET_strdup (url); mh->rd = rd; mh->rms = *rms; mh->melt_cb = melt_cb; @@ -545,9 +556,11 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange, break; } } + mh->keys = TALER_EXCHANGE_keys_incref (keys); if (0 != nks_off) { - mh->csr = TALER_EXCHANGE_csr_melt (exchange, + mh->csr = TALER_EXCHANGE_csr_melt (ctx, + url, rms, nks_off, nks, @@ -588,7 +601,9 @@ TALER_EXCHANGE_melt_cancel (struct TALER_EXCHANGE_MeltHandle *mh) TALER_EXCHANGE_free_melt_data_ (&mh->md); /* does not free 'md' itself */ GNUNET_free (mh->mbds); GNUNET_free (mh->url); + GNUNET_free (mh->exchange_url); TALER_curl_easy_post_finished (&mh->ctx); + TALER_EXCHANGE_keys_decref (mh->keys); GNUNET_free (mh); } diff --git a/src/lib/exchange_api_purse_create_with_deposit.c b/src/lib/exchange_api_purse_create_with_deposit.c index a2618d63..af05bf92 100644 --- a/src/lib/exchange_api_purse_create_with_deposit.c +++ b/src/lib/exchange_api_purse_create_with_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -73,15 +73,20 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. */ char *url; + /** + * The base URL of the exchange. + */ + char *exchange_url; + /** * Context for #TEH_curl_easy_post(). Keeps the data that must * persist for Curl to make the upload. @@ -170,10 +175,9 @@ handle_purse_create_deposit_finished (void *cls, .hr.reply = j, .hr.http_status = (unsigned int) response_code }; - const struct TALER_EXCHANGE_Keys *keys; + const struct TALER_EXCHANGE_Keys *keys = pch->keys; pch->job = NULL; - keys = TALER_EXCHANGE_get_keys (pch->exchange); switch (response_code) { case 0: @@ -181,7 +185,6 @@ handle_purse_create_deposit_finished (void *cls, break; case MHD_HTTP_OK: { - const struct TALER_EXCHANGE_Keys *key_state; struct GNUNET_TIME_Timestamp etime; struct TALER_Amount total_deposited; struct TALER_ExchangeSignatureP exchange_sig; @@ -209,9 +212,8 @@ handle_purse_create_deposit_finished (void *cls, dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - key_state = TALER_EXCHANGE_get_keys (pch->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (keys, &exchange_pub)) { GNUNET_break_op (0); @@ -387,7 +389,7 @@ handle_purse_create_deposit_finished (void *cls, if (GNUNET_OK != TALER_EXCHANGE_check_purse_coin_conflict_ ( &pch->purse_pub, - pch->exchange->url, + pch->exchange_url, j, &h_denom_pub, &phac, @@ -496,7 +498,9 @@ handle_purse_create_deposit_finished (void *cls, struct TALER_EXCHANGE_PurseCreateDepositHandle * TALER_EXCHANGE_purse_create_with_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_PurseContractPrivateKeyP *purse_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv, const struct TALER_ContractDiffiePrivateP *contract_priv, @@ -508,16 +512,13 @@ TALER_EXCHANGE_purse_create_with_deposit ( void *cb_cls) { struct TALER_EXCHANGE_PurseCreateDepositHandle *pch; - struct GNUNET_CURL_Context *ctx; json_t *create_obj; json_t *deposit_arr; CURL *eh; char arg_str[sizeof (pch->purse_pub) * 2 + 32]; - char *url; uint32_t min_age = 0; pch = GNUNET_new (struct TALER_EXCHANGE_PurseCreateDepositHandle); - pch->exchange = exchange; pch->cb = cb; pch->cb_cls = cb_cls; { @@ -542,8 +543,6 @@ TALER_EXCHANGE_purse_create_with_deposit ( return NULL; } } - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); if (GNUNET_OK != TALER_JSON_contract_hash (contract_terms, &pch->h_contract_terms)) @@ -565,13 +564,14 @@ TALER_EXCHANGE_purse_create_with_deposit ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/purses/%s/create", + "purses/%s/create", pub_str); } GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv, &pch->merge_pub.eddsa_pub); - pch->url = TEAH_path_to_url (exchange, - arg_str); + pch->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == pch->url) { GNUNET_break (0); @@ -583,8 +583,6 @@ TALER_EXCHANGE_purse_create_with_deposit ( struct Deposit); deposit_arr = json_array (); GNUNET_assert (NULL != deposit_arr); - url = TEAH_path_to_url (exchange, - "/"); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Signing with URL `%s'\n", url); @@ -610,7 +608,6 @@ TALER_EXCHANGE_purse_create_with_deposit ( { GNUNET_break (0); json_decref (deposit_arr); - GNUNET_free (url); GNUNET_free (pch); return NULL; } @@ -648,7 +645,6 @@ TALER_EXCHANGE_purse_create_with_deposit ( json_array_append_new (deposit_arr, jdeposit)); } - GNUNET_free (url); TALER_wallet_purse_create_sign (pch->purse_expiration, &pch->h_contract_terms, &pch->merge_pub, @@ -714,7 +710,8 @@ TALER_EXCHANGE_purse_create_with_deposit ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for purse create with deposit: `%s'\n", pch->url); - ctx = TEAH_handle_to_context (exchange); + pch->keys = TALER_EXCHANGE_keys_incref (keys); + pch->exchange_url = GNUNET_strdup (url); pch->job = GNUNET_CURL_job_add2 (ctx, eh, pch->ctx.headers, @@ -734,8 +731,10 @@ TALER_EXCHANGE_purse_create_with_deposit_cancel ( pch->job = NULL; } GNUNET_free (pch->econtract.econtract); + GNUNET_free (pch->exchange_url); GNUNET_free (pch->url); GNUNET_free (pch->deposits); + TALER_EXCHANGE_keys_decref (pch->keys); TALER_curl_easy_post_finished (&pch->ctx); GNUNET_free (pch); } diff --git a/src/lib/exchange_api_purse_create_with_merge.c b/src/lib/exchange_api_purse_create_with_merge.c index 460239fc..0c887834 100644 --- a/src/lib/exchange_api_purse_create_with_merge.c +++ b/src/lib/exchange_api_purse_create_with_merge.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -41,15 +41,20 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. */ char *url; + /** + * The exchange base URL. + */ + char *exchange_url; + /** * Context for #TEH_curl_easy_post(). Keeps the data that must * persist for Curl to make the upload. @@ -157,7 +162,6 @@ handle_purse_create_with_merge_finished (void *cls, break; case MHD_HTTP_OK: { - const struct TALER_EXCHANGE_Keys *key_state; struct GNUNET_TIME_Timestamp etime; struct TALER_Amount total_deposited; struct TALER_ExchangeSignatureP exchange_sig; @@ -184,9 +188,8 @@ handle_purse_create_with_merge_finished (void *cls, dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - key_state = TALER_EXCHANGE_get_keys (pcm->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (pcm->keys, &exchange_pub)) { GNUNET_break_op (0); @@ -253,7 +256,7 @@ handle_purse_create_with_merge_finished (void *cls, &pcm->merge_sig, &pcm->merge_pub, &pcm->purse_pub, - pcm->exchange->url, + pcm->exchange_url, j)) { GNUNET_break_op (0); @@ -340,7 +343,9 @@ handle_purse_create_with_merge_finished (void *cls, struct TALER_EXCHANGE_PurseCreateMergeHandle * TALER_EXCHANGE_purse_create_with_merge ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPrivateKeyP *purse_priv, const struct TALER_PurseMergePrivateKeyP *merge_priv, @@ -353,7 +358,6 @@ TALER_EXCHANGE_purse_create_with_merge ( void *cb_cls) { struct TALER_EXCHANGE_PurseCreateMergeHandle *pcm; - struct GNUNET_CURL_Context *ctx; json_t *create_with_merge_obj; CURL *eh; char arg_str[sizeof (pcm->reserve_pub) * 2 + 32]; @@ -362,7 +366,6 @@ TALER_EXCHANGE_purse_create_with_merge ( enum TALER_WalletAccountMergeFlags flags; pcm = GNUNET_new (struct TALER_EXCHANGE_PurseCreateMergeHandle); - pcm->exchange = exchange; pcm->cb = cb; pcm->cb_cls = cb_cls; if (GNUNET_OK != @@ -409,7 +412,7 @@ TALER_EXCHANGE_purse_create_with_merge ( const struct TALER_EXCHANGE_GlobalFee *gf; gf = TALER_EXCHANGE_get_global_fee ( - TALER_EXCHANGE_get_keys (exchange), + keys, GNUNET_TIME_timestamp_get ()); purse_fee = gf->fees.purse; flags = TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE; @@ -422,8 +425,6 @@ TALER_EXCHANGE_purse_create_with_merge ( flags = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA; } - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); { char pub_str[sizeof (pcm->reserve_pub) * 2]; char *end; @@ -436,11 +437,12 @@ TALER_EXCHANGE_purse_create_with_merge ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves/%s/purse", + "reserves/%s/purse", pub_str); } - pcm->url = TEAH_path_to_url (exchange, - arg_str); + pcm->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == pcm->url) { GNUNET_break (0); @@ -457,7 +459,7 @@ TALER_EXCHANGE_purse_create_with_merge ( { char *payto_uri; - payto_uri = TALER_reserve_make_payto (exchange->url, + payto_uri = TALER_reserve_make_payto (url, &pcm->reserve_pub); TALER_wallet_purse_merge_sign (payto_uri, merge_timestamp, @@ -546,7 +548,8 @@ TALER_EXCHANGE_purse_create_with_merge ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for purse create_with_merge: `%s'\n", pcm->url); - ctx = TEAH_handle_to_context (exchange); + pcm->keys = TALER_EXCHANGE_keys_incref (keys); + pcm->exchange_url = GNUNET_strdup (url); pcm->job = GNUNET_CURL_job_add2 (ctx, eh, pcm->ctx.headers, @@ -566,7 +569,9 @@ TALER_EXCHANGE_purse_create_with_merge_cancel ( pcm->job = NULL; } GNUNET_free (pcm->url); + GNUNET_free (pcm->exchange_url); TALER_curl_easy_post_finished (&pcm->ctx); + TALER_EXCHANGE_keys_decref (pcm->keys); GNUNET_free (pcm->econtract.econtract); GNUNET_free (pcm); } diff --git a/src/lib/exchange_api_purse_deposit.c b/src/lib/exchange_api_purse_deposit.c index f88d2329..e1d38d16 100644 --- a/src/lib/exchange_api_purse_deposit.c +++ b/src/lib/exchange_api_purse_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -73,9 +73,9 @@ struct TALER_EXCHANGE_PurseDepositHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -144,10 +144,9 @@ handle_purse_deposit_finished (void *cls, .hr.reply = j, .hr.http_status = (unsigned int) response_code }; - const struct TALER_EXCHANGE_Keys *keys; + const struct TALER_EXCHANGE_Keys *keys = pch->keys; pch->job = NULL; - keys = TALER_EXCHANGE_get_keys (pch->exchange); switch (response_code) { case 0: @@ -447,7 +446,9 @@ handle_purse_deposit_finished (void *cls, struct TALER_EXCHANGE_PurseDepositHandle * TALER_EXCHANGE_purse_deposit ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const char *purse_exchange_url, const struct TALER_PurseContractPublicKeyP *purse_pub, uint8_t min_age, @@ -457,7 +458,6 @@ TALER_EXCHANGE_purse_deposit ( void *cb_cls) { struct TALER_EXCHANGE_PurseDepositHandle *pch; - struct GNUNET_CURL_Context *ctx; json_t *create_obj; json_t *deposit_arr; CURL *eh; @@ -470,11 +470,8 @@ TALER_EXCHANGE_purse_deposit ( GNUNET_break (0); return NULL; } - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); pch = GNUNET_new (struct TALER_EXCHANGE_PurseDepositHandle); pch->purse_pub = *purse_pub; - pch->exchange = exchange; pch->cb = cb; pch->cb_cls = cb_cls; { @@ -489,11 +486,12 @@ TALER_EXCHANGE_purse_deposit ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/purses/%s/deposit", + "purses/%s/deposit", pub_str); } - pch->url = TEAH_path_to_url (exchange, - arg_str); + pch->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == pch->url) { GNUNET_break (0); @@ -502,8 +500,7 @@ TALER_EXCHANGE_purse_deposit ( } deposit_arr = json_array (); GNUNET_assert (NULL != deposit_arr); - pch->base_url = TEAH_path_to_url (exchange, - "/"); + pch->base_url = GNUNET_strdup (url); pch->num_deposits = num_deposits; pch->coins = GNUNET_new_array (num_deposits, struct Coin); @@ -594,7 +591,7 @@ TALER_EXCHANGE_purse_deposit ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for purse deposit: `%s'\n", pch->url); - ctx = TEAH_handle_to_context (exchange); + pch->keys = TALER_EXCHANGE_keys_incref (keys); pch->job = GNUNET_CURL_job_add2 (ctx, eh, pch->ctx.headers, @@ -616,6 +613,7 @@ TALER_EXCHANGE_purse_deposit_cancel ( GNUNET_free (pch->base_url); GNUNET_free (pch->url); GNUNET_free (pch->coins); + TALER_EXCHANGE_keys_decref (pch->keys); TALER_curl_easy_post_finished (&pch->ctx); GNUNET_free (pch); } diff --git a/src/lib/exchange_api_purse_merge.c b/src/lib/exchange_api_purse_merge.c index 6e1995e0..8fd95251 100644 --- a/src/lib/exchange_api_purse_merge.c +++ b/src/lib/exchange_api_purse_merge.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -41,9 +41,9 @@ struct TALER_EXCHANGE_AccountMergeHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -148,7 +148,6 @@ handle_purse_merge_finished (void *cls, break; case MHD_HTTP_OK: { - const struct TALER_EXCHANGE_Keys *key_state; struct TALER_Amount total_deposited; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("exchange_sig", @@ -173,9 +172,8 @@ handle_purse_merge_finished (void *cls, dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - key_state = TALER_EXCHANGE_get_keys (pch->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (pch->keys, &dr.details.ok.exchange_pub)) { GNUNET_break_op (0); @@ -302,7 +300,9 @@ handle_purse_merge_finished (void *cls, struct TALER_EXCHANGE_AccountMergeHandle * TALER_EXCHANGE_account_merge ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const char *reserve_exchange_url, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PurseContractPublicKeyP *purse_pub, @@ -316,14 +316,12 @@ TALER_EXCHANGE_account_merge ( void *cb_cls) { struct TALER_EXCHANGE_AccountMergeHandle *pch; - struct GNUNET_CURL_Context *ctx; json_t *merge_obj; CURL *eh; char arg_str[sizeof (pch->purse_pub) * 2 + 32]; char *reserve_url; pch = GNUNET_new (struct TALER_EXCHANGE_AccountMergeHandle); - pch->exchange = exchange; pch->merge_priv = *merge_priv; pch->cb = cb; pch->cb_cls = cb_cls; @@ -332,14 +330,12 @@ TALER_EXCHANGE_account_merge ( pch->purse_expiration = purse_expiration; pch->purse_value_after_fees = *purse_value_after_fees; if (NULL == reserve_exchange_url) - pch->provider_url = GNUNET_strdup (exchange->url); + pch->provider_url = GNUNET_strdup (url); else pch->provider_url = GNUNET_strdup (reserve_exchange_url); GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, &pch->reserve_pub.eddsa_pub); - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); { char pub_str[sizeof (*purse_pub) * 2]; char *end; @@ -352,7 +348,7 @@ TALER_EXCHANGE_account_merge ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/purses/%s/merge", + "purses/%s/merge", pub_str); } reserve_url = TALER_reserve_make_payto (pch->provider_url, @@ -364,8 +360,9 @@ TALER_EXCHANGE_account_merge ( GNUNET_free (pch); return NULL; } - pch->url = TEAH_path_to_url (exchange, - arg_str); + pch->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == pch->url) { GNUNET_break (0); @@ -426,7 +423,7 @@ TALER_EXCHANGE_account_merge ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for purse merge: `%s'\n", pch->url); - ctx = TEAH_handle_to_context (exchange); + pch->keys = TALER_EXCHANGE_keys_incref (keys); pch->job = GNUNET_CURL_job_add2 (ctx, eh, pch->ctx.headers, @@ -448,6 +445,7 @@ TALER_EXCHANGE_account_merge_cancel ( GNUNET_free (pch->url); GNUNET_free (pch->provider_url); TALER_curl_easy_post_finished (&pch->ctx); + TALER_EXCHANGE_keys_decref (pch->keys); GNUNET_free (pch); } diff --git a/src/lib/exchange_api_purses_get.c b/src/lib/exchange_api_purses_get.c index 4c2fdd79..7a6b2707 100644 --- a/src/lib/exchange_api_purses_get.c +++ b/src/lib/exchange_api_purses_get.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,9 +39,9 @@ struct TALER_EXCHANGE_PurseGetHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -117,7 +117,6 @@ handle_purse_get_finished (void *cls, &exchange_sig), GNUNET_JSON_spec_end () }; - const struct TALER_EXCHANGE_Keys *key_state; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -130,9 +129,8 @@ handle_purse_get_finished (void *cls, break; } - key_state = TALER_EXCHANGE_get_keys (pgh->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (pgh->keys, &exchange_pub)) { GNUNET_break_op (0); @@ -207,7 +205,9 @@ handle_purse_get_finished (void *cls, struct TALER_EXCHANGE_PurseGetHandle * TALER_EXCHANGE_purse_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_PurseContractPublicKeyP *purse_pub, struct GNUNET_TIME_Relative timeout, bool wait_for_merge, @@ -218,14 +218,7 @@ TALER_EXCHANGE_purse_get ( CURL *eh; char arg_str[sizeof (*purse_pub) * 2 + 64]; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } pgh = GNUNET_new (struct TALER_EXCHANGE_PurseGetHandle); - pgh->exchange = exchange; pgh->cb = cb; pgh->cb_cls = cb_cls; { @@ -247,19 +240,20 @@ TALER_EXCHANGE_purse_get ( if (GNUNET_TIME_relative_is_zero (timeout)) GNUNET_snprintf (arg_str, sizeof (arg_str), - "/purses/%s/%s", + "purses/%s/%s", cpub_str, wait_for_merge ? "merge" : "deposit"); else GNUNET_snprintf (arg_str, sizeof (arg_str), - "/purses/%s/%s?timeout_ms=%s", + "purses/%s/%s?timeout_ms=%s", cpub_str, wait_for_merge ? "merge" : "deposit", timeout_str); } - pgh->url = TEAH_path_to_url (exchange, - arg_str); + pgh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == pgh->url) { GNUNET_free (pgh); @@ -273,10 +267,11 @@ TALER_EXCHANGE_purse_get ( GNUNET_free (pgh); return NULL; } - pgh->job = GNUNET_CURL_job_add (TEAH_handle_to_context (exchange), + pgh->job = GNUNET_CURL_job_add (ctx, eh, &handle_purse_get_finished, pgh); + pgh->keys = TALER_EXCHANGE_keys_incref (keys); return pgh; } @@ -291,6 +286,7 @@ TALER_EXCHANGE_purse_get_cancel ( pgh->job = NULL; } GNUNET_free (pgh->url); + TALER_EXCHANGE_keys_decref (pgh->keys); GNUNET_free (pgh); } diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c index b89bda8b..e7daff16 100644 --- a/src/lib/exchange_api_recoup.c +++ b/src/lib/exchange_api_recoup.c @@ -40,9 +40,9 @@ struct TALER_EXCHANGE_RecoupHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -143,10 +143,8 @@ handle_recoup_finished (void *cls, .hr.reply = j, .hr.http_status = (unsigned int) response_code }; - const struct TALER_EXCHANGE_Keys *keys; ph->job = NULL; - keys = TALER_EXCHANGE_get_keys (ph->exchange); switch (response_code) { case 0: @@ -177,7 +175,7 @@ handle_recoup_finished (void *cls, rr.hr.ec = TALER_JSON_get_error_code (j); rr.hr.hint = TALER_JSON_get_error_hint (j); if (GNUNET_OK != - TALER_EXCHANGE_get_min_denomination_ (keys, + TALER_EXCHANGE_get_min_denomination_ (ph->keys, &min_key)) { GNUNET_break (0); @@ -187,7 +185,7 @@ handle_recoup_finished (void *cls, } if (GNUNET_OK != TALER_EXCHANGE_check_coin_conflict_ ( - keys, + ph->keys, j, &ph->pk, &ph->coin_pub, @@ -244,16 +242,18 @@ handle_recoup_finished (void *cls, struct TALER_EXCHANGE_RecoupHandle * -TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange, - const struct TALER_EXCHANGE_DenomPublicKey *pk, - const struct TALER_DenominationSignature *denom_sig, - const struct TALER_ExchangeWithdrawValues *exchange_vals, - const struct TALER_PlanchetMasterSecretP *ps, - TALER_EXCHANGE_RecoupResultCallback recoup_cb, - void *recoup_cb_cls) +TALER_EXCHANGE_recoup ( + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, + const struct TALER_EXCHANGE_DenomPublicKey *pk, + const struct TALER_DenominationSignature *denom_sig, + const struct TALER_ExchangeWithdrawValues *exchange_vals, + const struct TALER_PlanchetMasterSecretP *ps, + TALER_EXCHANGE_RecoupResultCallback recoup_cb, + void *recoup_cb_cls) { struct TALER_EXCHANGE_RecoupHandle *ph; - struct GNUNET_CURL_Context *ctx; struct TALER_DenominationHashP h_denom_pub; json_t *recoup_obj; CURL *eh; @@ -261,8 +261,6 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange, struct TALER_CoinSpendPrivateKeyP coin_priv; union TALER_DenominationBlindingKeyP bks; - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); ph = GNUNET_new (struct TALER_EXCHANGE_RecoupHandle); TALER_planchet_setup_coin_priv (ps, exchange_vals, @@ -319,19 +317,19 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange, *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/recoup", + "coins/%s/recoup", pub_str); } - ph->exchange = exchange; ph->pk = *pk; memset (&ph->pk.key, 0, sizeof (ph->pk.key)); /* zero out, as lifetime cannot be warranted */ ph->cb = recoup_cb; ph->cb_cls = recoup_cb_cls; - ph->url = TEAH_path_to_url (exchange, - arg_str); + ph->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == ph->url) { json_decref (recoup_obj); @@ -357,7 +355,7 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for recoup: `%s'\n", ph->url); - ctx = TEAH_handle_to_context (exchange); + ph->keys = TALER_EXCHANGE_keys_incref (keys); ph->job = GNUNET_CURL_job_add2 (ctx, eh, ph->ctx.headers, @@ -377,6 +375,7 @@ TALER_EXCHANGE_recoup_cancel (struct TALER_EXCHANGE_RecoupHandle *ph) } GNUNET_free (ph->url); TALER_curl_easy_post_finished (&ph->ctx); + TALER_EXCHANGE_keys_decref (ph->keys); GNUNET_free (ph); } diff --git a/src/lib/exchange_api_recoup_refresh.c b/src/lib/exchange_api_recoup_refresh.c index 7b42aa7e..f5745deb 100644 --- a/src/lib/exchange_api_recoup_refresh.c +++ b/src/lib/exchange_api_recoup_refresh.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2017-2022 Taler Systems SA + Copyright (C) 2017-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -40,9 +40,9 @@ struct TALER_EXCHANGE_RecoupRefreshHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -144,10 +144,8 @@ handle_recoup_refresh_finished (void *cls, .hr.reply = j, .hr.http_status = (unsigned int) response_code }; - const struct TALER_EXCHANGE_Keys *keys; ph->job = NULL; - keys = TALER_EXCHANGE_get_keys (ph->exchange); switch (response_code) { case 0: @@ -191,7 +189,7 @@ handle_recoup_refresh_finished (void *cls, rrr.hr.ec = TALER_JSON_get_error_code (j); rrr.hr.hint = TALER_JSON_get_error_hint (j); if (GNUNET_OK != - TALER_EXCHANGE_get_min_denomination_ (keys, + TALER_EXCHANGE_get_min_denomination_ (ph->keys, &min_key)) { GNUNET_break (0); @@ -201,7 +199,7 @@ handle_recoup_refresh_finished (void *cls, } if (GNUNET_OK != TALER_EXCHANGE_check_coin_conflict_ ( - keys, + ph->keys, j, &ph->pk, &ph->coin_pub, @@ -246,7 +244,9 @@ handle_recoup_refresh_finished (void *cls, struct TALER_EXCHANGE_RecoupRefreshHandle * TALER_EXCHANGE_recoup_refresh ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_DenominationSignature *denom_sig, const struct TALER_ExchangeWithdrawValues *exchange_vals, @@ -257,7 +257,6 @@ TALER_EXCHANGE_recoup_refresh ( void *recoup_cb_cls) { struct TALER_EXCHANGE_RecoupRefreshHandle *ph; - struct GNUNET_CURL_Context *ctx; struct TALER_DenominationHashP h_denom_pub; json_t *recoup_obj; CURL *eh; @@ -266,10 +265,7 @@ TALER_EXCHANGE_recoup_refresh ( union TALER_DenominationBlindingKeyP bks; GNUNET_assert (NULL != recoup_cb); - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); ph = GNUNET_new (struct TALER_EXCHANGE_RecoupRefreshHandle); - ph->exchange = exchange; ph->pk = *pk; memset (&ph->pk.key, 0, @@ -333,12 +329,13 @@ TALER_EXCHANGE_recoup_refresh ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/recoup-refresh", + "coins/%s/recoup-refresh", pub_str); } - ph->url = TEAH_path_to_url (exchange, - arg_str); + ph->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == ph->url) { json_decref (recoup_obj); @@ -364,7 +361,7 @@ TALER_EXCHANGE_recoup_refresh ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for recoup-refresh: `%s'\n", ph->url); - ctx = TEAH_handle_to_context (exchange); + ph->keys = TALER_EXCHANGE_keys_incref (keys); ph->job = GNUNET_CURL_job_add2 (ctx, eh, ph->ctx.headers, @@ -385,6 +382,7 @@ TALER_EXCHANGE_recoup_refresh_cancel ( } GNUNET_free (ph->url); TALER_curl_easy_post_finished (&ph->ctx); + TALER_EXCHANGE_keys_decref (ph->keys); GNUNET_free (ph); } diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 50de7681..9b6f9b19 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015-2022 Taler Systems SA + Copyright (C) 2015-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,11 +39,6 @@ struct TALER_EXCHANGE_RefreshesRevealHandle { - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * The url for this request. */ @@ -310,7 +305,8 @@ handle_refresh_reveal_finished (void *cls, struct TALER_EXCHANGE_RefreshesRevealHandle * TALER_EXCHANGE_refreshes_reveal ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_RefreshMasterSecretP *rms, const struct TALER_EXCHANGE_RefreshData *rd, unsigned int num_coins, @@ -327,7 +323,6 @@ TALER_EXCHANGE_refreshes_reveal ( json_t *link_sigs; json_t *old_age_commitment = NULL; CURL *eh; - struct GNUNET_CURL_Context *ctx; struct MeltData md; char arg_str[sizeof (struct TALER_RefreshCommitmentP) * 2 + 32]; bool send_rms = false; @@ -342,12 +337,6 @@ TALER_EXCHANGE_refreshes_reveal ( GNUNET_break (0); return NULL; } - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } if (GNUNET_OK != TALER_EXCHANGE_get_melt_data_ (rms, rd, @@ -467,22 +456,22 @@ TALER_EXCHANGE_refreshes_reveal ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/refreshes/%s/reveal", + "refreshes/%s/reveal", pub_str); } /* finally, we can actually issue the request */ rrh = GNUNET_new (struct TALER_EXCHANGE_RefreshesRevealHandle); - rrh->exchange = exchange; rrh->noreveal_index = noreveal_index; rrh->reveal_cb = reveal_cb; rrh->reveal_cb_cls = reveal_cb_cls; rrh->md = md; - rrh->alg_values = GNUNET_memdup (alg_values, - md.num_fresh_coins - * sizeof (struct - TALER_ExchangeWithdrawValues)); - rrh->url = TEAH_path_to_url (rrh->exchange, - arg_str); + rrh->alg_values + = GNUNET_memdup (alg_values, + md.num_fresh_coins + * sizeof (struct TALER_ExchangeWithdrawValues)); + rrh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rrh->url) { json_decref (reveal_obj); @@ -510,7 +499,6 @@ TALER_EXCHANGE_refreshes_reveal ( return NULL; } json_decref (reveal_obj); - ctx = TEAH_handle_to_context (rrh->exchange); rrh->job = GNUNET_CURL_job_add2 (ctx, eh, rrh->ctx.headers, diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c index 35524ca4..83f9612d 100644 --- a/src/lib/exchange_api_refund.c +++ b/src/lib/exchange_api_refund.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,9 +39,9 @@ struct TALER_EXCHANGE_RefundHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -117,7 +117,6 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh, struct TALER_ExchangePublicKeyP *exchange_pub, struct TALER_ExchangeSignatureP *exchange_sig) { - const struct TALER_EXCHANGE_Keys *key_state; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("exchange_sig", exchange_sig), @@ -134,9 +133,8 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh, GNUNET_break_op (0); return GNUNET_SYSERR; } - key_state = TALER_EXCHANGE_get_keys (rh->exchange); if (GNUNET_OK != - TALER_EXCHANGE_test_signing_key (key_state, + TALER_EXCHANGE_test_signing_key (rh->keys, exchange_pub)) { GNUNET_break_op (0); @@ -672,7 +670,9 @@ handle_refund_finished (void *cls, struct TALER_EXCHANGE_RefundHandle * TALER_EXCHANGE_refund ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_Amount *amount, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_CoinSpendPublicKeyP *coin_pub, @@ -684,13 +684,10 @@ TALER_EXCHANGE_refund ( struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_MerchantSignatureP merchant_sig; struct TALER_EXCHANGE_RefundHandle *rh; - struct GNUNET_CURL_Context *ctx; json_t *refund_obj; CURL *eh; char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32]; - GNUNET_assert (GNUNET_YES == - TEAH_handle_is_ready (exchange)); GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv, &merchant_pub.eddsa_pub); TALER_merchant_refund_sign (coin_pub, @@ -711,7 +708,7 @@ TALER_EXCHANGE_refund ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/coins/%s/refund", + "coins/%s/refund", pub_str); } refund_obj = GNUNET_JSON_PACK ( @@ -726,11 +723,11 @@ TALER_EXCHANGE_refund ( GNUNET_JSON_pack_data_auto ("merchant_sig", &merchant_sig)); rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle); - rh->exchange = exchange; rh->cb = cb; rh->cb_cls = cb_cls; - rh->url = TEAH_path_to_url (exchange, - arg_str); + rh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rh->url) { json_decref (refund_obj); @@ -761,7 +758,7 @@ TALER_EXCHANGE_refund ( GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URL for refund: `%s'\n", rh->url); - ctx = TEAH_handle_to_context (exchange); + rh->keys = TALER_EXCHANGE_keys_incref (keys); rh->job = GNUNET_CURL_job_add2 (ctx, eh, rh->ctx.headers, @@ -781,6 +778,7 @@ TALER_EXCHANGE_refund_cancel (struct TALER_EXCHANGE_RefundHandle *refund) } GNUNET_free (refund->url); TALER_curl_easy_post_finished (&refund->ctx); + TALER_EXCHANGE_keys_decref (refund->keys); GNUNET_free (refund); } diff --git a/src/lib/exchange_api_reserves_close.c b/src/lib/exchange_api_reserves_close.c index 278d1310..a3769a22 100644 --- a/src/lib/exchange_api_reserves_close.c +++ b/src/lib/exchange_api_reserves_close.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -38,11 +38,6 @@ struct TALER_EXCHANGE_ReservesCloseHandle { - /** - * The connection to exchange this request handle will use - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * The url for this request. */ @@ -269,26 +264,19 @@ handle_reserves_close_finished (void *cls, struct TALER_EXCHANGE_ReservesCloseHandle * TALER_EXCHANGE_reserves_close ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, const struct TALER_ReservePrivateKeyP *reserve_priv, const char *target_payto_uri, TALER_EXCHANGE_ReservesCloseCallback cb, void *cb_cls) { struct TALER_EXCHANGE_ReservesCloseHandle *rch; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; struct TALER_PaytoHashP h_payto; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } rch = GNUNET_new (struct TALER_EXCHANGE_ReservesCloseHandle); - rch->exchange = exchange; rch->cb = cb; rch->cb_cls = cb_cls; rch->ts = GNUNET_TIME_timestamp_get (); @@ -306,11 +294,12 @@ TALER_EXCHANGE_reserves_close ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves/%s/close", + "reserves/%s/close", pub_str); } - rch->url = TEAH_path_to_url (exchange, - arg_str); + rch->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rch->url) { GNUNET_free (rch); @@ -357,7 +346,6 @@ TALER_EXCHANGE_reserves_close ( } json_decref (close_obj); } - ctx = TEAH_handle_to_context (exchange); rch->job = GNUNET_CURL_job_add2 (ctx, eh, rch->post_ctx.headers, diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c index ccc11a27..a48e0c08 100644 --- a/src/lib/exchange_api_reserves_history.c +++ b/src/lib/exchange_api_reserves_history.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,9 +39,9 @@ struct TALER_EXCHANGE_ReservesHistoryHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -131,7 +131,7 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, rhistory = GNUNET_new_array (len, struct TALER_EXCHANGE_ReserveHistoryEntry); if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rsh->exchange, + TALER_EXCHANGE_parse_reserve_history (rsh->keys, history, &rsh->reserve_pub, rs.details.ok.balance.currency, @@ -250,26 +250,19 @@ handle_reserves_history_finished (void *cls, struct TALER_EXCHANGE_ReservesHistoryHandle * TALER_EXCHANGE_reserves_history ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, TALER_EXCHANGE_ReservesHistoryCallback cb, void *cb_cls) { struct TALER_EXCHANGE_ReservesHistoryHandle *rsh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; - const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_GlobalFee *gf; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesHistoryHandle); - rsh->exchange = exchange; rsh->cb = cb; rsh->cb_cls = cb_cls; rsh->ts = GNUNET_TIME_timestamp_get (); @@ -287,11 +280,12 @@ TALER_EXCHANGE_reserves_history ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves/%s/history", + "reserves/%s/history", pub_str); } - rsh->url = TEAH_path_to_url (exchange, - arg_str); + rsh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rsh->url) { GNUNET_free (rsh); @@ -305,15 +299,6 @@ TALER_EXCHANGE_reserves_history ( GNUNET_free (rsh); return NULL; } - keys = TALER_EXCHANGE_get_keys (exchange); - if (NULL == keys) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - GNUNET_free (rsh->url); - GNUNET_free (rsh); - return NULL; - } gf = TALER_EXCHANGE_get_global_fee (keys, rsh->ts); if (NULL == gf) @@ -349,7 +334,7 @@ TALER_EXCHANGE_reserves_history ( } json_decref (history_obj); } - ctx = TEAH_handle_to_context (exchange); + rsh->keys = TALER_EXCHANGE_keys_incref (keys); rsh->job = GNUNET_CURL_job_add2 (ctx, eh, rsh->post_ctx.headers, @@ -370,6 +355,7 @@ TALER_EXCHANGE_reserves_history_cancel ( } TALER_curl_easy_post_finished (&rsh->post_ctx); GNUNET_free (rsh->url); + TALER_EXCHANGE_keys_decref (rsh->keys); GNUNET_free (rsh); } diff --git a/src/lib/exchange_api_reserves_open.c b/src/lib/exchange_api_reserves_open.c index 2b7ef0d9..b28333d5 100644 --- a/src/lib/exchange_api_reserves_open.c +++ b/src/lib/exchange_api_reserves_open.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -67,9 +67,9 @@ struct TALER_EXCHANGE_ReservesOpenHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -321,7 +321,6 @@ handle_reserves_open_finished (void *cls, break; case MHD_HTTP_CONFLICT: { - const struct TALER_EXCHANGE_Keys *keys; const struct CoinData *cd = NULL; struct TALER_CoinSpendPublicKeyP coin_pub; const struct TALER_EXCHANGE_DenomPublicKey *dk; @@ -331,8 +330,6 @@ handle_reserves_open_finished (void *cls, GNUNET_JSON_spec_end () }; - keys = TALER_EXCHANGE_get_keys (roh->exchange); - GNUNET_assert (NULL != keys); if (GNUNET_OK != GNUNET_JSON_parse (j, spec, @@ -362,7 +359,7 @@ handle_reserves_open_finished (void *cls, rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - dk = TALER_EXCHANGE_get_denomination_key_by_hash (keys, + dk = TALER_EXCHANGE_get_denomination_key_by_hash (roh->keys, &cd->h_denom_pub); if (NULL == dk) { @@ -372,7 +369,7 @@ handle_reserves_open_finished (void *cls, break; } if (GNUNET_OK != - TALER_EXCHANGE_check_coin_conflict_ (keys, + TALER_EXCHANGE_check_coin_conflict_ (roh->keys, j, dk, &coin_pub, @@ -427,7 +424,9 @@ handle_reserves_open_finished (void *cls, struct TALER_EXCHANGE_ReservesOpenHandle * TALER_EXCHANGE_reserves_open ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_Amount *reserve_contribution, unsigned int coin_payments_length, @@ -438,20 +437,11 @@ TALER_EXCHANGE_reserves_open ( void *cb_cls) { struct TALER_EXCHANGE_ReservesOpenHandle *roh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; - const struct TALER_EXCHANGE_Keys *keys; json_t *cpa; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } roh = GNUNET_new (struct TALER_EXCHANGE_ReservesOpenHandle); - roh->exchange = exchange; roh->cb = cb; roh->cb_cls = cb_cls; roh->ts = GNUNET_TIME_timestamp_get (); @@ -469,11 +459,12 @@ TALER_EXCHANGE_reserves_open ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves/%s/open", + "reserves/%s/open", pub_str); } - roh->url = TEAH_path_to_url (exchange, - arg_str); + roh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == roh->url) { GNUNET_free (roh); @@ -487,15 +478,6 @@ TALER_EXCHANGE_reserves_open ( GNUNET_free (roh); return NULL; } - keys = TALER_EXCHANGE_get_keys (exchange); - if (NULL == keys) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - GNUNET_free (roh->url); - GNUNET_free (roh); - return NULL; - } TALER_wallet_reserve_open_sign (reserve_contribution, roh->ts, expiration_time, @@ -578,7 +560,7 @@ TALER_EXCHANGE_reserves_open ( } json_decref (open_obj); } - ctx = TEAH_handle_to_context (exchange); + roh->keys = TALER_EXCHANGE_keys_incref (keys); roh->job = GNUNET_CURL_job_add2 (ctx, eh, roh->post_ctx.headers, @@ -600,6 +582,7 @@ TALER_EXCHANGE_reserves_open_cancel ( TALER_curl_easy_post_finished (&roh->post_ctx); GNUNET_free (roh->coins); GNUNET_free (roh->url); + TALER_EXCHANGE_keys_decref (roh->keys); GNUNET_free (roh); } diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_status.c index 57fb0427..9f98b7f8 100644 --- a/src/lib/exchange_api_reserves_status.c +++ b/src/lib/exchange_api_reserves_status.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2022 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,9 +39,9 @@ struct TALER_EXCHANGE_ReservesStatusHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -119,7 +119,7 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh, rhistory = GNUNET_new_array (len, struct TALER_EXCHANGE_ReserveHistoryEntry); if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rsh->exchange, + TALER_EXCHANGE_parse_reserve_history (rsh->keys, history, &rsh->reserve_pub, rs.details.ok.balance.currency, @@ -233,27 +233,21 @@ handle_reserves_status_finished (void *cls, struct TALER_EXCHANGE_ReservesStatusHandle * TALER_EXCHANGE_reserves_status ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, TALER_EXCHANGE_ReservesStatusCallback cb, void *cb_cls) { struct TALER_EXCHANGE_ReservesStatusHandle *rsh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32]; struct TALER_ReserveSignatureP reserve_sig; struct GNUNET_TIME_Timestamp ts = GNUNET_TIME_timestamp_get (); - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesStatusHandle); - rsh->exchange = exchange; rsh->cb = cb; rsh->cb_cls = cb_cls; GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, @@ -270,11 +264,12 @@ TALER_EXCHANGE_reserves_status ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/reserves/%s/status", + "reserves/%s/status", pub_str); } - rsh->url = TEAH_path_to_url (exchange, - arg_str); + rsh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == rsh->url) { GNUNET_free (rsh); @@ -312,7 +307,7 @@ TALER_EXCHANGE_reserves_status ( } json_decref (status_obj); } - ctx = TEAH_handle_to_context (exchange); + rsh->keys = TALER_EXCHANGE_keys_incref (keys); rsh->job = GNUNET_CURL_job_add2 (ctx, eh, rsh->post_ctx.headers, @@ -333,6 +328,7 @@ TALER_EXCHANGE_reserves_status_cancel ( } TALER_curl_easy_post_finished (&rsh->post_ctx); GNUNET_free (rsh->url); + TALER_EXCHANGE_keys_decref (rsh->keys); GNUNET_free (rsh); } diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c index 3a5a64fd..14cf51ff 100644 --- a/src/lib/exchange_api_transfers_get.c +++ b/src/lib/exchange_api_transfers_get.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2021 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -38,9 +38,9 @@ struct TALER_EXCHANGE_TransfersGetHandle { /** - * The connection to exchange this request handle will use + * The keys of the exchange this request handle will use */ - struct TALER_EXCHANGE_Handle *exchange; + struct TALER_EXCHANGE_Keys *keys; /** * The url for this request. @@ -130,7 +130,7 @@ check_transfers_get_response_ok ( } if (GNUNET_OK != TALER_EXCHANGE_test_signing_key ( - TALER_EXCHANGE_get_keys (wdh->exchange), + wdh->keys, &td->exchange_pub)) { GNUNET_break_op (0); @@ -320,25 +320,18 @@ handle_transfers_get_finished (void *cls, struct TALER_EXCHANGE_TransfersGetHandle * TALER_EXCHANGE_transfers_get ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *ctx, + const char *url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_EXCHANGE_TransfersGetCallback cb, void *cb_cls) { struct TALER_EXCHANGE_TransfersGetHandle *wdh; - struct GNUNET_CURL_Context *ctx; CURL *eh; char arg_str[sizeof (struct TALER_WireTransferIdentifierRawP) * 2 + 32]; - if (GNUNET_YES != - TEAH_handle_is_ready (exchange)) - { - GNUNET_break (0); - return NULL; - } - wdh = GNUNET_new (struct TALER_EXCHANGE_TransfersGetHandle); - wdh->exchange = exchange; wdh->cb = cb; wdh->cb_cls = cb_cls; @@ -354,11 +347,12 @@ TALER_EXCHANGE_transfers_get ( *end = '\0'; GNUNET_snprintf (arg_str, sizeof (arg_str), - "/transfers/%s", + "transfers/%s", wtid_str); } - wdh->url = TEAH_path_to_url (wdh->exchange, - arg_str); + wdh->url = TALER_url_join (url, + arg_str, + NULL); if (NULL == wdh->url) { GNUNET_free (wdh); @@ -372,7 +366,7 @@ TALER_EXCHANGE_transfers_get ( GNUNET_free (wdh); return NULL; } - ctx = TEAH_handle_to_context (exchange); + wdh->keys = TALER_EXCHANGE_keys_incref (keys); wdh->job = GNUNET_CURL_job_add_with_ct_json (ctx, eh, &handle_transfers_get_finished, @@ -397,6 +391,7 @@ TALER_EXCHANGE_transfers_get_cancel ( wdh->job = NULL; } GNUNET_free (wdh->url); + TALER_EXCHANGE_keys_decref (wdh->keys); GNUNET_free (wdh); } diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c index bf2bd023..daac429c 100644 --- a/src/lib/exchange_api_withdraw2.c +++ b/src/lib/exchange_api_withdraw2.c @@ -192,7 +192,8 @@ reserve_withdraw_payment_required ( } if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (wh->exchange, + TALER_EXCHANGE_parse_reserve_history (TALER_EXCHANGE_get_keys ( + wh->exchange), history, &wh->reserve_pub, balance.currency, diff --git a/src/testing/testing_api_cmd_deposits_get.c b/src/testing/testing_api_cmd_deposits_get.c index 972a85b7..165af9b1 100644 --- a/src/testing/testing_api_cmd_deposits_get.c +++ b/src/testing/testing_api_cmd_deposits_get.c @@ -198,12 +198,8 @@ track_transaction_run (void *cls, struct TALER_MerchantWireHashP h_wire_details; struct TALER_PrivateContractHashP h_contract_terms; const struct TALER_MerchantPrivateKeyP *merchant_priv; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); tts->cmd = cmd; - if (NULL == exchange) - return; tts->is = is; transaction_cmd = TALER_TESTING_interpreter_lookup_command (tts->is, @@ -275,14 +271,17 @@ track_transaction_run (void *cls, return; } - tts->tth = TALER_EXCHANGE_deposits_get (exchange, - merchant_priv, - &h_wire_details, - &h_contract_terms, - &coin_pub, - GNUNET_TIME_UNIT_ZERO, - &deposit_wtid_cb, - tts); + tts->tth = TALER_EXCHANGE_deposits_get ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + merchant_priv, + &h_wire_details, + &h_contract_terms, + &coin_pub, + GNUNET_TIME_UNIT_ZERO, + &deposit_wtid_cb, + tts); GNUNET_assert (NULL != tts->tth); } diff --git a/src/testing/testing_api_cmd_purse_create_deposit.c b/src/testing/testing_api_cmd_purse_create_deposit.c index 2f13849d..36dbfbff 100644 --- a/src/testing/testing_api_cmd_purse_create_deposit.c +++ b/src/testing/testing_api_cmd_purse_create_deposit.c @@ -189,12 +189,8 @@ deposit_run (void *cls, { struct PurseCreateDepositState *ds = cls; struct TALER_EXCHANGE_PurseDeposit deposits[ds->num_coin_references]; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); (void) cmd; - if (NULL == exchange) - return; ds->is = is; for (unsigned int i = 0; inum_coin_references; i++) { @@ -259,7 +255,9 @@ deposit_run (void *cls, "pay_deadline", GNUNET_JSON_from_timestamp (ds->purse_expiration))); ds->dh = TALER_EXCHANGE_purse_create_with_deposit ( - exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), &ds->purse_priv, &ds->merge_priv, &ds->contract_priv, diff --git a/src/testing/testing_api_cmd_purse_deposit.c b/src/testing/testing_api_cmd_purse_deposit.c index fb1d5155..8bddc53a 100644 --- a/src/testing/testing_api_cmd_purse_deposit.c +++ b/src/testing/testing_api_cmd_purse_deposit.c @@ -259,11 +259,7 @@ deposit_run (void *cls, struct TALER_EXCHANGE_PurseDeposit deposits[ds->num_coin_references]; const struct TALER_PurseContractPublicKeyP *purse_pub; const struct TALER_TESTING_Command *purse_cmd; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); - if (NULL == exchange) - return; (void) cmd; ds->is = is; purse_cmd = TALER_TESTING_interpreter_lookup_command (is, @@ -321,7 +317,9 @@ deposit_run (void *cls, } ds->dh = TALER_EXCHANGE_purse_deposit ( - exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), NULL, /* FIXME #7271: WADs support: purse exchange URL */ &ds->purse_pub, ds->min_age, diff --git a/src/testing/testing_api_cmd_purse_get.c b/src/testing/testing_api_cmd_purse_get.c index 235ae63c..d5246660 100644 --- a/src/testing/testing_api_cmd_purse_get.c +++ b/src/testing/testing_api_cmd_purse_get.c @@ -183,11 +183,7 @@ status_run (void *cls, { struct StatusState *ss = cls; const struct TALER_TESTING_Command *create_purse; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); - if (NULL == exchange) - return; ss->is = is; create_purse = TALER_TESTING_interpreter_lookup_command (is, @@ -202,12 +198,15 @@ status_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } - ss->pgh = TALER_EXCHANGE_purse_get (exchange, - ss->purse_pub, - ss->timeout, - ss->wait_for_merge, - &purse_status_cb, - ss); + ss->pgh = TALER_EXCHANGE_purse_get ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + ss->purse_pub, + ss->timeout, + ss->wait_for_merge, + &purse_status_cb, + ss); if (! GNUNET_TIME_relative_is_zero (ss->timeout)) { TALER_TESTING_interpreter_next (is); diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c index 8f4f6b3c..503ef162 100644 --- a/src/testing/testing_api_cmd_purse_merge.c +++ b/src/testing/testing_api_cmd_purse_merge.c @@ -201,12 +201,8 @@ merge_run (void *cls, const struct TALER_PurseMergePrivateKeyP *merge_priv; const json_t *ct; const struct TALER_TESTING_Command *ref; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); (void) cmd; - if (NULL == exchange) - return; ds->is = is; ref = TALER_TESTING_interpreter_lookup_command (ds->is, ds->merge_ref); @@ -322,7 +318,9 @@ merge_run (void *cls, &ds->merge_pub.eddsa_pub); ds->merge_timestamp = GNUNET_TIME_timestamp_get (); ds->dh = TALER_EXCHANGE_account_merge ( - exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), NULL, /* no wad */ &ds->reserve_priv, &ds->purse_pub, diff --git a/src/testing/testing_api_cmd_recoup.c b/src/testing/testing_api_cmd_recoup.c index 9483b158..263a3303 100644 --- a/src/testing/testing_api_cmd_recoup.c +++ b/src/testing/testing_api_cmd_recoup.c @@ -182,11 +182,7 @@ recoup_run (void *cls, char *cref; unsigned int idx; const struct TALER_ExchangeWithdrawValues *ewv; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); - if (NULL == exchange) - return; ps->is = is; if (GNUNET_OK != TALER_TESTING_parse_coin_reference ( @@ -259,13 +255,16 @@ recoup_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Trying to recoup denomination '%s'\n", TALER_B2S (&denom_pub->h_key)); - ps->ph = TALER_EXCHANGE_recoup (exchange, - denom_pub, - coin_sig, - ewv, - planchet, - &recoup_cb, - ps); + ps->ph = TALER_EXCHANGE_recoup ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + denom_pub, + coin_sig, + ewv, + planchet, + &recoup_cb, + ps); GNUNET_assert (NULL != ps->ph); } diff --git a/src/testing/testing_api_cmd_recoup_refresh.c b/src/testing/testing_api_cmd_recoup_refresh.c index 1c7456c7..7de5b96d 100644 --- a/src/testing/testing_api_cmd_recoup_refresh.c +++ b/src/testing/testing_api_cmd_recoup_refresh.c @@ -184,11 +184,7 @@ recoup_refresh_run (void *cls, const struct TALER_ExchangeWithdrawValues *ewv; char *cref; unsigned int idx; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); - if (NULL == exchange) - return; rrs->is = is; if (GNUNET_OK != TALER_TESTING_parse_coin_reference ( @@ -273,15 +269,18 @@ recoup_refresh_run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Trying to recoup_refresh denomination '%s'\n", TALER_B2S (&denom_pub->h_key)); - rrs->ph = TALER_EXCHANGE_recoup_refresh (exchange, - denom_pub, - coin_sig, - ewv, - rplanchet, - planchet, - idx, - &recoup_refresh_cb, - rrs); + rrs->ph = TALER_EXCHANGE_recoup_refresh ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + denom_pub, + coin_sig, + ewv, + rplanchet, + planchet, + idx, + &recoup_refresh_cb, + rrs); GNUNET_assert (NULL != rrs->ph); } diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c index 3b420ac6..dfaf31fd 100644 --- a/src/testing/testing_api_cmd_refresh.c +++ b/src/testing/testing_api_cmd_refresh.c @@ -496,12 +496,8 @@ refresh_reveal_run (void *cls, struct RefreshRevealState *rrs = cls; struct RefreshMeltState *rms; const struct TALER_TESTING_Command *melt_cmd; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); rrs->cmd = cmd; - if (NULL == exchange) - return; rrs->is = is; melt_cmd = TALER_TESTING_interpreter_lookup_command (is, rrs->melt_reference); @@ -518,14 +514,16 @@ refresh_reveal_run (void *cls, for (unsigned int i = 0; inum_fresh_coins; i++) alg_values[i] = rms->mbds[i].alg_value; - rrs->rrh = TALER_EXCHANGE_refreshes_reveal (exchange, - &rms->rms, - &rms->refresh_data, - rms->num_fresh_coins, - alg_values, - rms->noreveal_index, - &reveal_cb, - rrs); + rrs->rrh = TALER_EXCHANGE_refreshes_reveal ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + &rms->rms, + &rms->refresh_data, + rms->num_fresh_coins, + alg_values, + rms->noreveal_index, + &reveal_cb, + rrs); } if (NULL == rrs->rrh) { @@ -913,12 +911,8 @@ melt_cb (void *cls, { struct RefreshMeltState *rms = cls; const struct TALER_EXCHANGE_HttpResponse *hr = &mr->hr; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (rms->is); rms->rmh = NULL; - if (NULL == exchange) - return; if (rms->expected_response_code != hr->http_status) { if (0 != rms->do_retry) @@ -978,11 +972,14 @@ melt_cb (void *cls, { TALER_LOG_DEBUG ("Doubling the melt (%s)\n", rms->cmd->label); - rms->rmh = TALER_EXCHANGE_melt (exchange, - &rms->rms, - &rms->refresh_data, - &melt_cb, - rms); + rms->rmh = TALER_EXCHANGE_melt ( + TALER_TESTING_interpreter_get_context (rms->is), + TALER_TESTING_get_exchange_url (rms->is), + TALER_TESTING_get_keys (rms->is), + &rms->rms, + &rms->refresh_data, + &melt_cb, + rms); rms->double_melt = false; return; } @@ -1154,11 +1151,14 @@ melt_run (void *cls, GNUNET_assert (age_restricted == (NULL != age_commitment_proof)); - rms->rmh = TALER_EXCHANGE_melt (exchange, - &rms->rms, - &rms->refresh_data, - &melt_cb, - rms); + rms->rmh = TALER_EXCHANGE_melt ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + &rms->rms, + &rms->refresh_data, + &melt_cb, + rms); if (NULL == rms->rmh) { diff --git a/src/testing/testing_api_cmd_refund.c b/src/testing/testing_api_cmd_refund.c index a3ebd2e8..b8ce85f9 100644 --- a/src/testing/testing_api_cmd_refund.c +++ b/src/testing/testing_api_cmd_refund.c @@ -53,11 +53,6 @@ struct RefundState */ uint64_t refund_transaction_id; - /** - * Connection to the exchange. - */ - struct TALER_EXCHANGE_Handle *exchange; - /** * Handle to the refund operation. */ @@ -116,9 +111,6 @@ refund_run (void *cls, const struct TALER_MerchantPrivateKeyP *merchant_priv; const struct TALER_TESTING_Command *coin_cmd; - rs->exchange = TALER_TESTING_get_exchange (is); - if (NULL == rs->exchange) - return; rs->is = is; if (GNUNET_OK != TALER_string_to_amount (rs->refund_amount, @@ -172,14 +164,17 @@ refund_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } - rs->rh = TALER_EXCHANGE_refund (rs->exchange, - &refund_amount, - &h_contract_terms, - &coin, - rs->refund_transaction_id, - merchant_priv, - &refund_cb, - rs); + rs->rh = TALER_EXCHANGE_refund ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + &refund_amount, + &h_contract_terms, + &coin, + rs->refund_transaction_id, + merchant_priv, + &refund_cb, + rs); GNUNET_assert (NULL != rs->rh); } diff --git a/src/testing/testing_api_cmd_reserve_close.c b/src/testing/testing_api_cmd_reserve_close.c index b2929f16..8e272f54 100644 --- a/src/testing/testing_api_cmd_reserve_close.c +++ b/src/testing/testing_api_cmd_reserve_close.c @@ -142,11 +142,7 @@ close_run (void *cls, { struct CloseState *ss = cls; const struct TALER_TESTING_Command *create_reserve; - struct TALER_EXCHANGE_Handle *exchange - = TALER_TESTING_get_exchange (is); - if (NULL == exchange) - return; ss->is = is; create_reserve = TALER_TESTING_interpreter_lookup_command (is, @@ -169,11 +165,13 @@ close_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_close (exchange, - ss->reserve_priv, - ss->target_account, - &reserve_close_cb, - ss); + ss->rsh = TALER_EXCHANGE_reserves_close ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + ss->reserve_priv, + ss->target_account, + &reserve_close_cb, + ss); } diff --git a/src/testing/testing_api_cmd_reserve_history.c b/src/testing/testing_api_cmd_reserve_history.c index e9cc11a6..6e68bbe2 100644 --- a/src/testing/testing_api_cmd_reserve_history.c +++ b/src/testing/testing_api_cmd_reserve_history.c @@ -369,10 +369,13 @@ history_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_history (exchange, - ss->reserve_priv, - &reserve_history_cb, - ss); + ss->rsh = TALER_EXCHANGE_reserves_history ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + ss->reserve_priv, + &reserve_history_cb, + ss); } diff --git a/src/testing/testing_api_cmd_reserve_open.c b/src/testing/testing_api_cmd_reserve_open.c index 6a6247b8..a78662c3 100644 --- a/src/testing/testing_api_cmd_reserve_open.c +++ b/src/testing/testing_api_cmd_reserve_open.c @@ -256,7 +256,9 @@ open_run (void *cls, cpi->h_denom_pub = denom_pub->h_key; } ss->rsh = TALER_EXCHANGE_reserves_open ( - exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), ss->reserve_priv, &ss->reserve_pay, ss->cpl, diff --git a/src/testing/testing_api_cmd_reserve_purse.c b/src/testing/testing_api_cmd_reserve_purse.c index 79530803..7a356c23 100644 --- a/src/testing/testing_api_cmd_reserve_purse.c +++ b/src/testing/testing_api_cmd_reserve_purse.c @@ -245,7 +245,9 @@ purse_run (void *cls, GNUNET_JSON_from_timestamp (ds->purse_expiration))); ds->merge_timestamp = GNUNET_TIME_timestamp_get (); ds->dh = TALER_EXCHANGE_purse_create_with_merge ( - exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), &ds->reserve_priv, &ds->purse_priv, &ds->merge_priv, diff --git a/src/testing/testing_api_cmd_reserve_status.c b/src/testing/testing_api_cmd_reserve_status.c index 7e7b45cd..2da1bf74 100644 --- a/src/testing/testing_api_cmd_reserve_status.c +++ b/src/testing/testing_api_cmd_reserve_status.c @@ -341,10 +341,13 @@ status_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_status (exchange, - ss->reserve_priv, - &reserve_status_cb, - ss); + ss->rsh = TALER_EXCHANGE_reserves_status ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + ss->reserve_priv, + &reserve_status_cb, + ss); } diff --git a/src/testing/testing_api_cmd_transfer_get.c b/src/testing/testing_api_cmd_transfer_get.c index 10fe48c2..37fe736b 100644 --- a/src/testing/testing_api_cmd_transfer_get.c +++ b/src/testing/testing_api_cmd_transfer_get.c @@ -345,10 +345,13 @@ track_transfer_run (void *cls, } GNUNET_assert (NULL != wtid_ptr); } - tts->tth = TALER_EXCHANGE_transfers_get (exchange, - wtid_ptr, - &track_transfer_cb, - tts); + tts->tth = TALER_EXCHANGE_transfers_get ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + wtid_ptr, + &track_transfer_cb, + tts); GNUNET_assert (NULL != tts->tth); } -- cgit v1.2.3