diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd_helper.c | 5 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves.c | 143 |
2 files changed, 70 insertions, 78 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c index 48a42f40..407323e2 100644 --- a/src/backend/taler-merchant-httpd_helper.c +++ b/src/backend/taler-merchant-httpd_helper.c @@ -803,6 +803,11 @@ add_matching_account (void *cls, * Return JSON array with all of the exchange accounts * that support the given @a wire_method. * + * FIXME: bad API, doesn't inherently ensure that we + * actually did request /wire before! + * => move into t-m-h_exchanges.c and integrate with /wire + * logic there! + * * @param master_pub master public key to match exchange by * @param wire_method NULL for any * @return JSON array with information about all matching accounts diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c index 2fef1302..00e4a4ee 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves.c @@ -84,14 +84,14 @@ struct PostReserveContext json_t *accounts; /** - * Handle for contacting the exchange. + * Handle for contacting the exchange for /keys. */ struct TMH_EXCHANGES_Find2Operation *fo; /** - * Task run on timeout. + * Handle for contacting the exchange for /wire. */ - struct GNUNET_SCHEDULER_Task *timeout_task; + struct TMH_EXCHANGES_WireOperation *wo; /** * Master public key of the exchange matching @@ -155,11 +155,6 @@ TMH_force_rc_resume () rc = rcn) { rcn = rc->next; - if (NULL != rc->timeout_task) - { - GNUNET_SCHEDULER_cancel (rc->timeout_task); - rc->timeout_task = NULL; - } if (GNUNET_YES == rc->suspended) { rc->suspended = GNUNET_SYSERR; @@ -173,6 +168,11 @@ TMH_force_rc_resume () TMH_EXCHANGES_keys4exchange_cancel (rc->fo); rc->fo = NULL; } + if (NULL != rc->wo) + { + TMH_EXCHANGES_wire4exchange_cancel (rc->wo); + rc->wo = NULL; + } } } @@ -192,11 +192,6 @@ reserve_context_cleanup (void *cls) TMH_EXCHANGES_keys4exchange_cancel (rc->fo); rc->fo = NULL; } - if (NULL != rc->timeout_task) - { - GNUNET_SCHEDULER_cancel (rc->timeout_task); - rc->timeout_task = NULL; - } GNUNET_assert (GNUNET_YES != rc->suspended); json_decref (rc->accounts); GNUNET_free (rc); @@ -204,95 +199,91 @@ reserve_context_cleanup (void *cls) /** - * Function called with the result of a #TMH_EXCHANGES_keys4exchange() - * operation. + * Resume request handling. * - * @param cls closure with our `struct PostReserveContext *` - * @param keys exchange keys + * @param[in,out] rc request to resume */ static void -handle_exchange (void *cls, - struct TALER_EXCHANGE_Keys *keys) +resume_request (struct PostReserveContext *rc) { - struct PostReserveContext *rc = cls; - - rc->fo = NULL; - if (NULL != rc->timeout_task) - { - GNUNET_SCHEDULER_cancel (rc->timeout_task); - rc->timeout_task = NULL; - } rc->suspended = GNUNET_NO; MHD_resume_connection (rc->connection); GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); - if (NULL == keys) + TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ +} + + +/** + * Function called once we go the /wire response from the exchange. + * + * @param cls a `struct PostReserveContext *` + * @param wire exchange wire details + */ +static void +wire_cb (void *cls, + struct TMH_Exchange *wire) +{ + struct PostReserveContext *rc = cls; + + rc->wo = NULL; + rc->accounts = TMH_exchange_accounts_by_method ( + &rc->master_pub, + rc->wire_method); + if (NULL == rc->accounts) { - rc->ec = TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE; - rc->http_status = MHD_HTTP_GATEWAY_TIMEOUT; - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ + rc->ec = TALER_EC_GENERIC_DB_FETCH_FAILED; + rc->http_status = MHD_HTTP_CONFLICT; + resume_request (rc); return; } - if (! keys->tipping_allowed) + if (0 == json_array_size (rc->accounts)) { - rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_TIPPING_NOT_ALLOWED; + rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_UNSUPPORTED_WIRE_METHOD; rc->http_status = MHD_HTTP_CONFLICT; - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ + resume_request (rc); return; } - rc->master_pub = keys->master_pub; - { - rc->accounts = TMH_exchange_accounts_by_method ( - &keys->master_pub, - rc->wire_method); - if (NULL == rc->accounts) - { - rc->ec = TALER_EC_GENERIC_DB_FETCH_FAILED; - rc->http_status = MHD_HTTP_CONFLICT; - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ - return; - } - if (0 == json_array_size (rc->accounts)) - { - rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_UNSUPPORTED_WIRE_METHOD; - rc->http_status = MHD_HTTP_CONFLICT; - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ - return; - } - } - rc->reserve_expiration - = GNUNET_TIME_relative_to_timestamp (keys->reserve_closing_delay); - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ + resume_request (rc); } /** - * Handle a timeout for the processing of the wire request. + * Function called with the result of a #TMH_EXCHANGES_keys4exchange() + * operation. * - * @param cls closure + * @param cls closure with our `struct PostReserveContext *` + * @param keys exchange keys */ static void -handle_exchange_timeout (void *cls) +handle_exchange (void *cls, + struct TALER_EXCHANGE_Keys *keys) { struct PostReserveContext *rc = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resuming POST /private/reserves with error after timeout\n"); - rc->timeout_task = NULL; - if (NULL != rc->fo) + rc->fo = NULL; + if (NULL == keys) { - TMH_EXCHANGES_keys4exchange_cancel (rc->fo); - rc->fo = NULL; + GNUNET_break_op (0); + rc->ec = TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE; + rc->http_status = MHD_HTTP_GATEWAY_TIMEOUT; + resume_request (rc); + return; } - rc->suspended = GNUNET_NO; - MHD_resume_connection (rc->connection); - GNUNET_CONTAINER_DLL_remove (rc_head, - rc_tail, - rc); - rc->ec = TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT; - rc->http_status = MHD_HTTP_GATEWAY_TIMEOUT; - TALER_MHD_daemon_trigger (); /* we resumed, kick MHD */ + if (! keys->tipping_allowed) + { + rc->ec = TALER_EC_MERCHANT_PRIVATE_POST_RESERVES_TIPPING_NOT_ALLOWED; + rc->http_status = MHD_HTTP_CONFLICT; + resume_request (rc); + return; + } + rc->master_pub = keys->master_pub; + rc->reserve_expiration + = GNUNET_TIME_relative_to_timestamp (keys->reserve_closing_delay); + rc->wo = TMH_EXCHANGES_wire4exchange (rc->exchange_url, + &wire_cb, + rc); } @@ -337,10 +328,6 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, rc->fo = TMH_EXCHANGES_keys4exchange (rc->exchange_url, &handle_exchange, rc); - rc->timeout_task - = GNUNET_SCHEDULER_add_delayed (EXCHANGE_GENERIC_TIMEOUT, - &handle_exchange_timeout, - rc); rc->suspended = GNUNET_YES; GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, |