From 10c56bcea05df9ac5a7036850039900fbe435e00 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 20 Mar 2020 02:36:50 +0100 Subject: improving benchmarking logic, including more timings --- src/lib/auditor_api_exchanges.c | 18 ++++++++++++++---- src/lib/exchange_api_deposit.c | 4 ++-- src/lib/exchange_api_link.c | 6 +++++- src/lib/exchange_api_melt.c | 8 ++++---- src/lib/exchange_api_recoup.c | 15 +++++++++++++-- src/lib/exchange_api_refreshes_reveal.c | 14 +++++++++++--- src/lib/exchange_api_reserves_get.c | 12 +++++++++++- src/lib/exchange_api_transfers_get.c | 10 +++++++++- src/lib/exchange_api_wire.c | 16 +++++++++++----- src/lib/exchange_api_withdraw.c | 25 +++++++++++++++++++++---- 10 files changed, 101 insertions(+), 27 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auditor_api_exchanges.c b/src/lib/auditor_api_exchanges.c index 329b01063..4e23267fd 100644 --- a/src/lib/auditor_api_exchanges.c +++ b/src/lib/auditor_api_exchanges.c @@ -89,11 +89,13 @@ handle_exchanges_finished (void *cls, const json_t *ja; unsigned int ja_len; struct TALER_AUDITOR_ListExchangesHandle *leh = cls; + enum TALER_ErrorCode ec; leh->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: ja = json_object_get (json, @@ -102,6 +104,7 @@ handle_exchanges_finished (void *cls, (! json_is_array (ja)) ) { GNUNET_break (0); + ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED; response_code = 0; break; } @@ -110,6 +113,7 @@ handle_exchanges_finished (void *cls, if (ja_len > MAX_EXCHANGES) { GNUNET_break (0); + ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED; response_code = 0; break; } @@ -134,6 +138,7 @@ handle_exchanges_finished (void *cls, { GNUNET_break_op (0); ok = GNUNET_NO; + ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED; break; } } @@ -145,26 +150,31 @@ handle_exchanges_finished (void *cls, ja_len, ei, json); - leh->cb = NULL; + TALER_AUDITOR_list_exchanges_cancel (leh); + return; } - break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the auditor is buggy (or API version conflict); just pass JSON reply to the application */ + ec = TALER_JSON_get_error_code (json); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (json); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (json); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u\n", - (unsigned int) response_code); + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) ec); GNUNET_break (0); response_code = 0; break; diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 3fb36d240..8c00effcf 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -38,10 +38,10 @@ * 1:#AUDITOR_CHANCE is the probability that we report deposits * to the auditor. * - * 2==50% of going to auditor. This is way too high, but set + * 20==5% of going to auditor. This is possibly still too high, but set * deliberately this high for testing */ -#define AUDITOR_CHANCE 2 +#define AUDITOR_CHANCE 20 /** * @brief A Deposit Handle diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c index 756340494..5a2fc2a13 100644 --- a/src/lib/exchange_api_link.c +++ b/src/lib/exchange_api_link.c @@ -365,8 +365,12 @@ handle_link_finished (void *cls, { GNUNET_break_op (0); response_code = 0; + ec = TALER_EC_REFRESH_LINK_REPLY_MALFORMED; + break; } - break; + GNUNET_assert (NULL == lh->link_cb); + TALER_EXCHANGE_link_cancel (lh); + return; case MHD_HTTP_BAD_REQUEST: ec = TALER_JSON_get_error_code (j); /* This should never happen, either us or the exchange is buggy diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c index 621e9e1df..d6acf92c7 100644 --- a/src/lib/exchange_api_melt.c +++ b/src/lib/exchange_api_melt.c @@ -304,9 +304,9 @@ handle_melt_finished (void *cls, } break; case MHD_HTTP_BAD_REQUEST: - ec = TALER_JSON_get_error_code (j); /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: /* Double spending; check signatures on transaction history */ @@ -322,20 +322,20 @@ handle_melt_finished (void *cls, ec = TALER_EC_NONE; break; case MHD_HTTP_FORBIDDEN: - ec = TALER_JSON_get_error_code (j); /* Nothing really to verify, exchange says one of the signatures is invalid; assuming we checked them, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: - ec = TALER_JSON_get_error_code (j); /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - ec = TALER_JSON_get_error_code (j); /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c index 5a2759356..54bcab095 100644 --- a/src/lib/exchange_api_recoup.c +++ b/src/lib/exchange_api_recoup.c @@ -206,18 +206,22 @@ handle_recoup_finished (void *cls, { struct TALER_EXCHANGE_RecoupHandle *ph = cls; const json_t *j = response; + enum TALER_ErrorCode ec; ph->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: + ec = TALER_EC_NONE; if (GNUNET_OK != verify_recoup_signature_ok (ph, j)) { GNUNET_break_op (0); + ec = TALER_EC_RECOUP_REPLY_MALFORMED; response_code = 0; break; } @@ -226,6 +230,7 @@ handle_recoup_finished (void *cls, 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: { @@ -247,9 +252,10 @@ handle_recoup_finished (void *cls, GNUNET_break_op (0); response_code = 0; } + ec = TALER_JSON_get_error_code (j); ph->cb (ph->cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, &total, GNUNET_TIME_UNIT_FOREVER_ABS, NULL, @@ -262,21 +268,26 @@ handle_recoup_finished (void *cls, /* 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_GONE: /* Kind of normal: the money was already sent to the merchant (it was too late for the refund). */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", (unsigned int) response_code); @@ -286,7 +297,7 @@ handle_recoup_finished (void *cls, } ph->cb (ph->cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, NULL, GNUNET_TIME_UNIT_FOREVER_ABS, NULL, diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 8ac7d4a9d..0fdbf7c69 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -202,11 +202,13 @@ handle_refresh_reveal_finished (void *cls, { struct TALER_EXCHANGE_RefreshesRevealHandle *rrh = cls; const json_t *j = response; + enum TALER_ErrorCode ec; rrh->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { @@ -220,12 +222,14 @@ handle_refresh_reveal_finished (void *cls, if (GNUNET_OK != ret) { response_code = 0; + ec = TALER_EC_REFRESH_REVEAL_REPLY_MALFORMED; } else { + ec = TALER_EC_NONE; rrh->reveal_cb (rrh->reveal_cb_cls, MHD_HTTP_OK, - TALER_EC_NONE, + ec, rrh->md->num_fresh_coins, rrh->md->fresh_coins[rrh->noreveal_index], sigs, @@ -235,20 +239,23 @@ handle_refresh_reveal_finished (void *cls, for (unsigned int i = 0; imd->num_fresh_coins; i++) if (NULL != sigs[i].rsa_signature) GNUNET_CRYPTO_rsa_signature_free (sigs[i].rsa_signature); + return; } - 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: /* Nothing really to verify, exchange says our reveal is inconsitent with our commitment, so either side is buggy; we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ @@ -257,12 +264,13 @@ handle_refresh_reveal_finished (void *cls, (unsigned int) response_code); GNUNET_break (0); response_code = 0; + ec = TALER_JSON_get_error_code (j); break; } if (NULL != rrh->reveal_cb) rrh->reveal_cb (rrh->reveal_cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, 0, NULL, NULL, diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c index 39932d650..e44eefad6 100644 --- a/src/lib/exchange_api_reserves_get.c +++ b/src/lib/exchange_api_reserves_get.c @@ -171,32 +171,42 @@ handle_reserves_get_finished (void *cls, { struct TALER_EXCHANGE_ReservesGetHandle *rgh = cls; const json_t *j = response; + enum TALER_ErrorCode ec; rgh->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: + ec = TALER_EC_NONE; if (GNUNET_OK != handle_reserves_get_ok (rgh, j)) + { response_code = 0; + ec = TALER_EC_RESERVE_STATUS_REPLY_MALFORMED; + } 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", (unsigned int) response_code); @@ -208,7 +218,7 @@ handle_reserves_get_finished (void *cls, { rgh->cb (rgh->cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, j, NULL, 0, NULL); diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c index 6d61e1d04..617c897d3 100644 --- a/src/lib/exchange_api_transfers_get.c +++ b/src/lib/exchange_api_transfers_get.c @@ -261,11 +261,13 @@ handle_transfers_get_finished (void *cls, { struct TALER_EXCHANGE_TransfersGetHandle *wdh = cls; const json_t *j = response; + enum TALER_ErrorCode ec; wdh->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK == @@ -273,27 +275,33 @@ handle_transfers_get_finished (void *cls, j)) return; GNUNET_break_op (0); + ec = TALER_EC_TRACK_TRANSFER_REPLY_MALFORMED; response_code = 0; 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_FORBIDDEN: /* 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Exchange does not know about transaction; we should pass the reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u\n", (unsigned int) response_code); @@ -303,7 +311,7 @@ handle_transfers_get_finished (void *cls, } wdh->cb (wdh->cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, NULL, j, NULL, diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c index 1ac44c70e..ccab4562d 100644 --- a/src/lib/exchange_api_wire.c +++ b/src/lib/exchange_api_wire.c @@ -213,10 +213,10 @@ handle_wire_finished (void *cls, TALER_LOG_DEBUG ("Checking raw /wire response\n"); wh->job = NULL; - ec = TALER_EC_NONE; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { @@ -261,6 +261,7 @@ handle_wire_finished (void *cls, break; } + ec = TALER_EC_NONE; key_state = TALER_EXCHANGE_get_keys (wh->exchange); /* parse accounts */ { @@ -325,7 +326,7 @@ handle_wire_finished (void *cls, { wh->cb (wh->cb_cls, response_code, - TALER_EC_NONE, + ec, num_accounts, was); wh->cb = NULL; @@ -338,20 +339,25 @@ handle_wire_finished (void *cls, 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u\n", - (unsigned int) response_code); + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) ec); GNUNET_break (0); response_code = 0; break; @@ -359,7 +365,7 @@ handle_wire_finished (void *cls, if (NULL != wh->cb) wh->cb (wh->cb_cls, response_code, - (0 == response_code) ? ec : TALER_JSON_get_error_code (j), + ec, 0, NULL); TALER_EXCHANGE_wire_cancel (wh); diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c index d909693c1..a9fe477eb 100644 --- a/src/lib/exchange_api_withdraw.c +++ b/src/lib/exchange_api_withdraw.c @@ -277,11 +277,13 @@ handle_reserve_withdraw_finished (void *cls, { struct TALER_EXCHANGE_WithdrawHandle *wh = cls; const json_t *j = response; + enum TALER_ErrorCode ec; wh->job = NULL; switch (response_code) { case 0: + ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != @@ -290,11 +292,16 @@ handle_reserve_withdraw_finished (void *cls, { GNUNET_break_op (0); response_code = 0; + ec = TALER_EC_WITHDRAW_REPLY_MALFORMED; + break; } - break; + GNUNET_assert (NULL == wh->cb); + TALER_EXCHANGE_withdraw_cancel (wh); + return; 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: /* The exchange says that the reserve has insufficient funds; @@ -305,6 +312,11 @@ handle_reserve_withdraw_finished (void *cls, { GNUNET_break_op (0); response_code = 0; + ec = TALER_EC_WITHDRAW_REPLY_MALFORMED; + } + else + { + ec = TALER_JSON_get_error_code (j); } break; case MHD_HTTP_FORBIDDEN: @@ -312,22 +324,27 @@ handle_reserve_withdraw_finished (void *cls, /* 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 */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, the exchange basically just says that it doesn't know this reserve. Can happen if we query before the wire transfer went through. We should simply pass the JSON reply to the application. */ + ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ + ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ + ec = TALER_JSON_get_error_code (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u\n", - (unsigned int) response_code); + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) ec); GNUNET_break (0); response_code = 0; break; @@ -336,7 +353,7 @@ handle_reserve_withdraw_finished (void *cls, { wh->cb (wh->cb_cls, response_code, - TALER_JSON_get_error_code (j), + ec, NULL, j); wh->cb = NULL; -- cgit v1.2.3