diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c index be88c4ef9f..3d6941be1e 100644 --- a/src/libostree/ostree-fetcher-curl.c +++ b/src/libostree/ostree-fetcher-curl.c @@ -79,6 +79,9 @@ struct OstreeFetcher int tmpdir_dfd; bool force_anonymous; char *custom_user_agent; + guint32 opt_low_speed_limit; + guint32 opt_low_speed_time; + gboolean opt_retry_all; GMainContext *mainctx; CURLM *multi; @@ -330,7 +333,13 @@ check_multi_info (OstreeFetcher *fetcher) } else { - g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, + /* When it is not a file, we want to retry the request. + * We accomplish that by using G_IO_ERROR_TIMED_OUT. + */ + gboolean opt_retry_all = req->fetcher->opt_retry_all; + int g_io_error_code + = (is_file || !opt_retry_all) ? G_IO_ERROR_FAILED : G_IO_ERROR_TIMED_OUT; + g_task_return_new_error (task, G_IO_ERROR, g_io_error_code, "While fetching %s: [%u] %s", eff_url, curlres, curl_easy_strerror (curlres)); _ostree_fetcher_journal_failure (req->fetcher->remote_name, eff_url, @@ -664,6 +673,24 @@ _ostree_fetcher_set_proxy (OstreeFetcher *self, const char *http_proxy) self->proxy = g_strdup (http_proxy); } +void +_ostree_fetcher_set_low_speed_time (OstreeFetcher *self, guint32 opt_low_speed_time) +{ + self->opt_low_speed_time = opt_low_speed_time; +} + +void +_ostree_fetcher_set_low_speed_limit (OstreeFetcher *self, guint32 opt_low_speed_limit) +{ + self->opt_low_speed_limit = opt_low_speed_limit; +} + +void +_ostree_fetcher_set_retry_all (OstreeFetcher *self, gboolean opt_retry_all) +{ + self->opt_retry_all = opt_retry_all; +} + void _ostree_fetcher_set_cookie_jar (OstreeFetcher *self, const char *jar_path) { @@ -912,14 +939,10 @@ initiate_next_curl_request (FetcherRequest *req, GTask *task) g_assert_cmpint (rc, ==, CURLM_OK); rc = curl_easy_setopt (req->easy, CURLOPT_CONNECTTIMEOUT, 30L); g_assert_cmpint (rc, ==, CURLM_OK); - /* We used to set CURLOPT_LOW_SPEED_LIMIT and CURLOPT_LOW_SPEED_TIME - * here, but see https://github.com/ostreedev/ostree/issues/878#issuecomment-347228854 - * basically those options don't play well with HTTP2 at the moment - * where we can have lots of outstanding requests. Further, - * we could implement that functionality at a higher level - * more consistently too. - */ - + rc = curl_easy_setopt (req->easy, CURLOPT_LOW_SPEED_LIMIT, req->fetcher->opt_low_speed_limit); + g_assert_cmpint (rc, ==, CURLM_OK); + rc = curl_easy_setopt (req->easy, CURLOPT_LOW_SPEED_TIME, req->fetcher->opt_low_speed_time); + g_assert_cmpint (rc, ==, CURLM_OK); /* closure bindings -> task */ rc = curl_easy_setopt (req->easy, CURLOPT_PRIVATE, task); g_assert_cmpint (rc, ==, CURLM_OK); diff --git a/src/libostree/ostree-fetcher-soup.c b/src/libostree/ostree-fetcher-soup.c index 629065fffe..c727235c9d 100644 --- a/src/libostree/ostree-fetcher-soup.c +++ b/src/libostree/ostree-fetcher-soup.c @@ -377,6 +377,24 @@ session_thread_set_extra_user_agent_cb (ThreadClosure *thread_closure, gpointer } } +void +_ostree_fetcher_set_low_speed_time (OstreeFetcher *self, guint32 opt_low_speed_time) +{ + // TODO +} + +void +_ostree_fetcher_set_low_speed_limit (OstreeFetcher *self, guint32 opt_low_speed_limit) +{ + // TODO +} + +void +_ostree_fetcher_set_retry_all (OstreeFetcher *self, gboolean opt_retry_all) +{ + // TODO +} + static void on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data); static void diff --git a/src/libostree/ostree-fetcher-soup3.c b/src/libostree/ostree-fetcher-soup3.c index 380168023f..c503998222 100644 --- a/src/libostree/ostree-fetcher-soup3.c +++ b/src/libostree/ostree-fetcher-soup3.c @@ -380,6 +380,24 @@ _ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, const char *extra_use self->user_agent = g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent); } +void +_ostree_fetcher_set_low_speed_time (OstreeFetcher *self, guint32 opt_low_speed_time) +{ + // TODO +} + +void +_ostree_fetcher_set_low_speed_limit (OstreeFetcher *self, guint32 opt_low_speed_limit) +{ + // TODO +} + +void +_ostree_fetcher_set_retry_all (OstreeFetcher *self, gboolean opt_retry_all) +{ + // TODO +} + static gboolean finish_stream (FetcherRequest *request, GCancellable *cancellable, GError **error) { diff --git a/src/libostree/ostree-fetcher.h b/src/libostree/ostree-fetcher.h index 6a555e0962..f69871b443 100644 --- a/src/libostree/ostree-fetcher.h +++ b/src/libostree/ostree-fetcher.h @@ -99,6 +99,12 @@ void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher, const char *proxy); void _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher, const char *cert_path, const char *key_path); +void _ostree_fetcher_set_low_speed_limit (OstreeFetcher *self, guint32 opt_low_speed_limit); + +void _ostree_fetcher_set_low_speed_time (OstreeFetcher *self, guint32 opt_low_speed_time); + +void _ostree_fetcher_set_retry_all (OstreeFetcher *self, gboolean opt_retry_all); + void _ostree_fetcher_set_tls_database (OstreeFetcher *self, const char *tlsdb_path); void _ostree_fetcher_set_extra_headers (OstreeFetcher *self, GVariant *extra_headers); diff --git a/src/libostree/ostree-repo-pull-private.h b/src/libostree/ostree-repo-pull-private.h index 982cf1b57b..86183c81c8 100644 --- a/src/libostree/ostree-repo-pull-private.h +++ b/src/libostree/ostree-repo-pull-private.h @@ -54,6 +54,9 @@ typedef struct GVariant *extra_headers; char *append_user_agent; + guint32 low_speed_limit; + guint32 low_speed_time; + gboolean retry_all; gboolean dry_run; gboolean dry_run_emitted_progress; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 9ec9789183..13403d859b 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -61,6 +61,9 @@ * _ostree_fetcher_should_retry_request(). This is the default value for the * `n-network-retries` pull option. */ #define DEFAULT_N_NETWORK_RETRIES 5 +#define OPT_LOWSPEEDLIMIT_DEFAULT 1000 +#define OPT_LOWSPEEDTIME_DEFAULT 30 +#define OPT_RETRYALL_DEFAULT TRUE typedef struct { @@ -2928,7 +2931,9 @@ _ostree_repo_cache_summary (OstreeRepo *self, const char *remote, GBytes *summar static OstreeFetcher * _ostree_repo_remote_new_fetcher (OstreeRepo *self, const char *remote_name, gboolean gzip, GVariant *extra_headers, const char *append_user_agent, - OstreeFetcherSecurityState *out_state, GError **error) + guint32 low_speed_limit, guint32 low_speed_time, + gboolean retry_all, OstreeFetcherSecurityState *out_state, + GError **error) { OstreeFetcher *fetcher = NULL; OstreeFetcherConfigFlags fetcher_flags = 0; @@ -2995,6 +3000,12 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, const char *remote_name, gboo } } + _ostree_fetcher_set_low_speed_limit (fetcher, (low_speed_limit) ? low_speed_limit + : OPT_LOWSPEEDLIMIT_DEFAULT); + _ostree_fetcher_set_low_speed_time (fetcher, + (low_speed_time) ? low_speed_time : OPT_LOWSPEEDTIME_DEFAULT); + _ostree_fetcher_set_retry_all (fetcher, (retry_all) ? retry_all : OPT_RETRYALL_DEFAULT); + { g_autofree char *tls_ca_path = NULL; @@ -3221,6 +3232,7 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, GError **e g_clear_object (&pull_data->fetcher); pull_data->fetcher = _ostree_repo_remote_new_fetcher ( pull_data->repo, remote_name, FALSE, pull_data->extra_headers, pull_data->append_user_agent, + pull_data->low_speed_limit, pull_data->low_speed_time, pull_data->retry_all, &pull_data->fetcher_security_state, error); if (pull_data->fetcher == NULL) return FALSE; @@ -3450,6 +3462,12 @@ all_requested_refs_have_commit ( * * `n-network-retries` (`u`): Number of times to retry each download on receiving * a transient network error, such as a socket timeout; default is 5, 0 * means return errors without retrying. Since: 2018.6 + * * `low-speed-limit-bytes` (`u`): The average transfer speed per second of a transfer + during the time set via "low-speed-time-seconds" for libcurl to abort. + * * `low-speed-time-seconds` (`u`): The time in number seconds that the transfer + speed should be below the "low-speed-limit-bytes" setting for libcurl to abort. + * * `retry-all-network-errors` (`b`): Retry when network issues happen, instead of + * failing automatically. Currently only affects libcurl. (Default set to true) * * `ref-keyring-map` (`a(sss)`): Array of (collection ID, ref name, keyring * remote name) tuples specifying which remote's keyring should be used when * doing GPG verification of each collection-ref. This is useful to prevent a @@ -3570,6 +3588,9 @@ ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_base &pull_data->timestamp_check_from_rev); (void)g_variant_lookup (options, "max-metadata-size", "t", &pull_data->max_metadata_size); (void)g_variant_lookup (options, "append-user-agent", "s", &pull_data->append_user_agent); + (void)g_variant_lookup (options, "low-speed-limit-bytes", "u", &pull_data->low_speed_limit); + (void)g_variant_lookup (options, "low-speed-time-seconds", "u", &pull_data->low_speed_time); + (void)g_variant_lookup (options, "retry-all-network-errors", "b", &pull_data->retry_all); opt_n_network_retries_set = g_variant_lookup (options, "n-network-retries", "u", &pull_data->n_network_retries); opt_ref_keyring_map_set @@ -5693,7 +5714,7 @@ find_remotes_cb (GObject *obj, GAsyncResult *async_result, gpointer user_data) goto error; fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, TRUE, NULL, - NULL, NULL, &error); + NULL, 0, 0, TRUE, NULL, &error); if (fetcher == NULL) goto error; @@ -6307,6 +6328,9 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *nam g_autoptr (GVariant) extra_headers = NULL; g_autoptr (GPtrArray) mirrorlist = NULL; const char *append_user_agent = NULL; + guint32 low_speed_limit = OPT_LOWSPEEDLIMIT_DEFAULT; + guint32 low_speed_time = OPT_LOWSPEEDTIME_DEFAULT; + gboolean retry_all = OPT_RETRYALL_DEFAULT; guint n_network_retries = DEFAULT_N_NETWORK_RETRIES; gboolean summary_sig_not_modified = FALSE; g_autofree char *summary_sig_if_none_match = NULL; @@ -6331,6 +6355,9 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *nam (void)g_variant_lookup (options, "http-headers", "@a(ss)", &extra_headers); (void)g_variant_lookup (options, "append-user-agent", "&s", &append_user_agent); (void)g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); + (void)g_variant_lookup (options, "low-speed-limit-bytes", "u", &low_speed_limit); + (void)g_variant_lookup (options, "low-speed-time-seconds", "u", &low_speed_time); + (void)g_variant_lookup (options, "retry-all-network-errors", "b", &retry_all); } if (!ostree_repo_remote_get_gpg_verify_summary (self, name, &gpg_verify_summary, error)) @@ -6342,8 +6369,9 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *nam mainctx = _ostree_main_context_new_default (); (void)mainctx; // Used for autocleanup - fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, - NULL, error); + fetcher + = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, + low_speed_limit, low_speed_time, retry_all, NULL, error); if (fetcher == NULL) return FALSE;