From 9ec40ce8e949a18b1b76ebb9e605f8f0adc5b91f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 26 Sep 2023 16:00:16 +0200 Subject: [PATCH] Enforce minimum for curl(_file_download)_timeout --- builtin/settingtypes.txt | 4 ++-- src/client/clientmedia.cpp | 4 ++-- src/gui/guiEngine.cpp | 3 ++- src/httpfetch.cpp | 1 + src/httpfetch.h | 7 +++++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 4085e6aee..032031b0b 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2099,7 +2099,7 @@ num_emerge_threads (Number of emerge threads) int 1 0 32767 [**cURL] # Maximum time an interactive request (e.g. server list fetch) may take, stated in milliseconds. -curl_timeout (cURL interactive timeout) int 20000 100 2147483647 +curl_timeout (cURL interactive timeout) int 20000 1000 2147483647 # Limits number of parallel HTTP requests. Affects: # - Media fetch if server uses remote_media setting. @@ -2109,7 +2109,7 @@ curl_timeout (cURL interactive timeout) int 20000 100 2147483647 curl_parallel_limit (cURL parallel limit) int 8 1 2147483647 # Maximum time a file download (e.g. a mod download) may take, stated in milliseconds. -curl_file_download_timeout (cURL file download timeout) int 300000 100 2147483647 +curl_file_download_timeout (cURL file download timeout) int 300000 5000 2147483647 [**Misc] diff --git a/src/client/clientmedia.cpp b/src/client/clientmedia.cpp index 6c5d4a8bf..f78fe9e35 100644 --- a/src/client/clientmedia.cpp +++ b/src/client/clientmedia.cpp @@ -416,8 +416,8 @@ void ClientMediaDownloader::startRemoteMediaTransfers() fetch_request.url = url; fetch_request.caller = m_httpfetch_caller; fetch_request.request_id = m_httpfetch_next_id; - fetch_request.timeout = - g_settings->getS32("curl_file_download_timeout"); + fetch_request.timeout = std::max(MIN_HTTPFETCH_TIMEOUT, + (long)g_settings->getS32("curl_file_download_timeout")); httpfetch_async(fetch_request); m_remote_file_transfers.insert(std::make_pair( diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 8e75fa77e..64b2e9fa5 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -574,7 +574,8 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target) HTTPFetchResult fetch_result; fetch_request.url = url; fetch_request.caller = HTTPFETCH_SYNC; - fetch_request.timeout = g_settings->getS32("curl_file_download_timeout"); + fetch_request.timeout = std::max(MIN_HTTPFETCH_TIMEOUT, + (long)g_settings->getS32("curl_file_download_timeout")); httpfetch_sync(fetch_request, fetch_result); if (!fetch_result.succeeded) { diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index cb599fbdd..3fb7f3d6a 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -47,6 +47,7 @@ HTTPFetchRequest::HTTPFetchRequest() : connect_timeout(10 * 1000), useragent(std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")") { + timeout = std::max(timeout, MIN_HTTPFETCH_TIMEOUT_INTERACTIVE); } diff --git a/src/httpfetch.h b/src/httpfetch.h index a4901e63b..930ce591c 100644 --- a/src/httpfetch.h +++ b/src/httpfetch.h @@ -35,6 +35,13 @@ with this program; if not, write to the Free Software Foundation, Inc., // Start of regular allocated caller IDs. #define HTTPFETCH_CID_START 3 +namespace { + // lower bound for curl_timeout (see also settingtypes.txt) + constexpr long MIN_HTTPFETCH_TIMEOUT_INTERACTIVE = 1000; + // lower bound for curl_file_download_timeout + constexpr long MIN_HTTPFETCH_TIMEOUT = 5000; +} + // Methods enum HttpMethod : u8 {