diff options
author | Florian Dold <florian@dold.me> | 2021-01-12 15:08:15 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-01-12 15:12:26 +0100 |
commit | 8f887a215e115d7e5f10a558b465521a6da0133c (patch) | |
tree | 48a3fb46bea18f83f82499b25d9fdc29e011d83b /src/lib/exchange_api_wire.c | |
parent | 2518da8f4581d868dd8eafabc54e6b2ddcc998d4 (diff) |
dynamic curl timeouts for /keys and /wire requests
Diffstat (limited to 'src/lib/exchange_api_wire.c')
-rw-r--r-- | src/lib/exchange_api_wire.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c index 8653d5a94..eb0894c80 100644 --- a/src/lib/exchange_api_wire.c +++ b/src/lib/exchange_api_wire.c @@ -219,6 +219,8 @@ handle_wire_finished (void *cls, { case 0: hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + /* FIXME: Maybe we should only increment when we know it's a timeout? */ + wh->exchange->wire_error_count++; break; case MHD_HTTP_OK: { @@ -233,6 +235,8 @@ handle_wire_finished (void *cls, GNUNET_JSON_spec_end () }; + wh->exchange->wire_error_count = 0; + if (GNUNET_OK != GNUNET_JSON_parse (j, spec, @@ -356,6 +360,8 @@ handle_wire_finished (void *cls, break; default: /* unexpected response code */ + if (MHD_HTTP_GATEWAY_TIMEOUT == response_code) + wh->exchange->wire_error_count++; GNUNET_break_op (0); hr.ec = TALER_JSON_get_error_code (j); hr.hint = TALER_JSON_get_error_hint (j); @@ -375,6 +381,20 @@ handle_wire_finished (void *cls, /** + * Compute the network timeout for the next request to /wire. + * + * @param exchange the exchange handle + * @returns the timeout in seconds (for use by CURL) + */ +static long +get_wire_timeout_seconds (struct TALER_EXCHANGE_Handle *exchange) +{ + return GNUNET_MIN (60, + 5 + (1L << exchange->wire_error_count)); +} + + +/** * Obtain information about a exchange's wire instructions. * A exchange may provide wire instructions for creating * a reserve. The wire instructions also indicate @@ -416,6 +436,10 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange, wh->url = TEAH_path_to_url (exchange, "/wire"); eh = TALER_EXCHANGE_curl_easy_get_ (wh->url); + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT, + get_wire_timeout_seconds (wh->exchange))); if (NULL == eh) { GNUNET_break (0); |