From ca6f919664f719dfc6651fe014075b17b03d4c7e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 20 Dec 2024 17:51:30 -0600 Subject: [PATCH] refactor app config --- repertory/librepertory/include/app_config.hpp | 105 ++++---- .../librepertory/include/types/remote.hpp | 17 +- .../librepertory/include/types/repertory.hpp | 34 ++- repertory/librepertory/src/app_config.cpp | 234 +++++++++--------- .../src/file_manager/file_manager.cpp | 33 ++- repertory/repertory_test/src/config_test.cpp | 20 +- .../repertory_test/src/file_manager_test.cpp | 14 +- 7 files changed, 221 insertions(+), 236 deletions(-) diff --git a/repertory/librepertory/include/app_config.hpp b/repertory/librepertory/include/app_config.hpp index dea68fcc..19442a74 100644 --- a/repertory/librepertory/include/app_config.hpp +++ b/repertory/librepertory/include/app_config.hpp @@ -31,26 +31,26 @@ namespace repertory { class app_config final { public: - [[nodiscard]] static auto default_agent_name(const provider_type &prov) - -> std::string; + [[nodiscard]] static auto + default_agent_name(const provider_type &prov) -> std::string; - [[nodiscard]] static auto default_api_port(const provider_type &prov) - -> std::uint16_t; + [[nodiscard]] static auto + default_api_port(const provider_type &prov) -> std::uint16_t; - [[nodiscard]] static auto default_data_directory(const provider_type &prov) - -> std::string; + [[nodiscard]] static auto + default_data_directory(const provider_type &prov) -> std::string; - [[nodiscard]] static auto default_remote_api_port(const provider_type &prov) - -> std::uint16_t; + [[nodiscard]] static auto + default_remote_api_port(const provider_type &prov) -> std::uint16_t; - [[nodiscard]] static auto default_rpc_port(const provider_type &prov) - -> std::uint16_t; + [[nodiscard]] static auto + default_rpc_port(const provider_type &prov) -> std::uint16_t; - [[nodiscard]] static auto get_provider_display_name(const provider_type &prov) - -> std::string; + [[nodiscard]] static auto + get_provider_display_name(const provider_type &prov) -> std::string; - [[nodiscard]] static auto get_provider_name(const provider_type &prov) - -> std::string; + [[nodiscard]] static auto + get_provider_name(const provider_type &prov) -> std::string; public: app_config(const provider_type &prov, std::string_view data_directory = ""); @@ -65,7 +65,7 @@ private: std::atomic config_changed_; std::atomic db_type_{database_type::rocksdb}; std::atomic download_timeout_secs_; - std::atomic enable_chunk_downloader_timeout_; + std::atomic enable_download_timeout_; std::atomic enable_comm_duration_events_; std::atomic enable_drive_events_; #if defined(_WIN32) @@ -79,7 +79,6 @@ private: std::atomic max_cache_size_bytes_; std::atomic max_upload_count_; std::atomic med_freq_interval_secs_; - std::atomic min_download_timeout_secs_; std::atomic online_check_retry_secs_; std::atomic orphaned_file_retention_days_; atomic preferred_download_type_; @@ -129,18 +128,18 @@ public: [[nodiscard]] auto get_cache_directory() const -> std::string; - [[nodiscard]] auto get_chunk_downloader_timeout_secs() const -> std::uint8_t; - [[nodiscard]] auto get_config_file_path() const -> std::string; [[nodiscard]] auto get_database_type() const -> database_type; [[nodiscard]] auto get_data_directory() const -> std::string; - [[nodiscard]] auto get_enable_chunk_download_timeout() const -> bool; + [[nodiscard]] auto get_download_timeout_secs() const -> std::uint8_t; [[nodiscard]] auto get_enable_comm_duration_events() const -> bool; + [[nodiscard]] auto get_enable_download_timeout() const -> bool; + [[nodiscard]] auto get_enable_drive_events() const -> bool; [[nodiscard]] auto get_encrypt_config() const -> encrypt_config; @@ -193,78 +192,72 @@ public: [[nodiscard]] auto get_task_wait_ms() const -> std::uint16_t; - [[nodiscard]] auto get_value_by_name(const std::string &name) const - -> std::string; + [[nodiscard]] auto + get_value_by_name(const std::string &name) const -> std::string; [[nodiscard]] auto get_version() const -> std::uint64_t; void save(); - void set_api_auth(const std::string &api_auth); + void set_api_auth(const std::string &value); - void set_api_port(std::uint16_t api_port); + void set_api_port(std::uint16_t value); - void set_api_user(const std::string &api_user); + void set_api_user(const std::string &value); - void - set_chunk_downloader_timeout_secs(std::uint8_t chunk_downloader_timeout_secs); + void set_download_timeout_secs(std::uint8_t value); - void set_database_type(const database_type &type); + void set_database_type(const database_type &value); - void - set_enable_chunk_downloader_timeout(bool enable_chunk_downloader_timeout); + void set_enable_download_timeout(bool value); - void set_enable_comm_duration_events(bool enable_comm_duration_events); + void set_enable_comm_duration_events(bool value); - void set_enable_drive_events(bool enable_drive_events); + void set_enable_drive_events(bool value); #if defined(_WIN32) - void set_enable_mount_manager(bool enable_mount_manager); + void set_enable_mount_manager(bool value); #endif // defined(_WIN32) - void set_event_level(const event_level &level); + void set_event_level(const event_level &value); - void set_encrypt_config(encrypt_config cfg); + void set_encrypt_config(encrypt_config value); - void set_eviction_delay_mins(std::uint32_t eviction_delay_mins); + void set_eviction_delay_mins(std::uint32_t value); - void set_eviction_uses_accessed_time(bool eviction_uses_accessed_time); + void set_eviction_uses_accessed_time(bool value); - void - set_high_frequency_interval_secs(std::uint16_t high_frequency_interval_secs); + void set_high_frequency_interval_secs(std::uint16_t value); - void set_host_config(host_config cfg); + void set_host_config(host_config value); - void - set_low_frequency_interval_secs(std::uint16_t low_frequency_interval_secs); + void set_low_frequency_interval_secs(std::uint16_t value); - void set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes); + void set_max_cache_size_bytes(std::uint64_t value); - void set_max_upload_count(std::uint8_t max_upload_count); + void set_max_upload_count(std::uint8_t value); - void - set_med_frequency_interval_secs(std::uint16_t med_frequency_interval_secs); + void set_med_frequency_interval_secs(std::uint16_t value); - void set_online_check_retry_secs(std::uint16_t online_check_retry_secs); + void set_online_check_retry_secs(std::uint16_t value); - void - set_orphaned_file_retention_days(std::uint16_t orphaned_file_retention_days); + void set_orphaned_file_retention_days(std::uint16_t value); - void set_preferred_download_type(const download_type &type); + void set_preferred_download_type(const download_type &value); - void set_remote_config(remote::remote_config cfg); + void set_remote_config(remote::remote_config value); - void set_remote_mount(remote::remote_mount cfg); + void set_remote_mount(remote::remote_mount value); - void set_retry_read_count(std::uint16_t retry_read_count); + void set_retry_read_count(std::uint16_t value); - void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size); + void set_ring_buffer_file_size(std::uint16_t value); - void set_s3_config(s3_config cfg); + void set_s3_config(s3_config value); - void set_sia_config(sia_config cfg); + void set_sia_config(sia_config value); - void set_task_wait_ms(std::uint16_t task_wait_ms); + void set_task_wait_ms(std::uint16_t value); [[nodiscard]] auto set_value_by_name(const std::string &name, const std::string &value) -> std::string; diff --git a/repertory/librepertory/include/types/remote.hpp b/repertory/librepertory/include/types/remote.hpp index 6b6ddc52..2548dd85 100644 --- a/repertory/librepertory/include/types/remote.hpp +++ b/repertory/librepertory/include/types/remote.hpp @@ -33,14 +33,19 @@ inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP}; inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE}; #endif // defined(_WIN32) +constexpr const auto default_remote_client_pool_size{20U}; +constexpr const auto default_remote_max_connections{20U}; +constexpr const auto default_remote_receive_timeout_ms{120U * 1000U}; +constexpr const auto default_remote_send_timeout_ms{30U * 1000U}; + namespace repertory::remote { struct remote_config final { std::uint16_t api_port{}; std::string encryption_token; std::string host_name_or_ip; - std::uint8_t max_connections{20U}; - std::uint32_t recv_timeout_ms{120U * 1000U}; - std::uint32_t send_timeout_ms{30U * 1000U}; + std::uint8_t max_connections{default_remote_max_connections}; + std::uint32_t recv_timeout_ms{default_remote_receive_timeout_ms}; + std::uint32_t send_timeout_ms{default_remote_send_timeout_ms}; auto operator==(const remote_config &cfg) const noexcept -> bool { if (&cfg != this) { @@ -66,7 +71,7 @@ struct remote_config final { struct remote_mount final { std::uint16_t api_port{}; - std::uint8_t client_pool_size{20U}; + std::uint8_t client_pool_size{default_remote_client_pool_size}; bool enable{false}; std::string encryption_token; @@ -212,8 +217,8 @@ struct statfs_x final : public statfs { #if !defined(_WIN32) [[nodiscard]] auto create_open_flags(std::uint32_t flags) -> open_flags; -[[nodiscard]] auto create_os_open_flags(const open_flags &flags) - -> std::uint32_t; +[[nodiscard]] auto +create_os_open_flags(const open_flags &flags) -> std::uint32_t; #endif // !defined(_WIN32) } // namespace repertory::remote diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index 6013ea8f..0b010f35 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -187,33 +187,31 @@ enum class api_error { [[nodiscard]] auto api_error_from_string(std::string_view str) -> api_error; -[[nodiscard]] auto api_error_to_string(const api_error &error) - -> const std::string &; +[[nodiscard]] auto +api_error_to_string(const api_error &error) -> const std::string &; enum class database_type { rocksdb, sqlite, }; -[[nodiscard]] auto -database_type_from_string(std::string type, - database_type default_type = database_type::rocksdb) - -> database_type; +[[nodiscard]] auto database_type_from_string( + std::string type, + database_type default_type = database_type::rocksdb) -> database_type; -[[nodiscard]] auto database_type_to_string(const database_type &type) - -> std::string; +[[nodiscard]] auto +database_type_to_string(const database_type &type) -> std::string; enum class download_type { direct, fallback, ring_buffer, }; -[[nodiscard]] auto -download_type_from_string(std::string type, - download_type default_type = download_type::fallback) - -> download_type; +[[nodiscard]] auto download_type_from_string( + std::string type, + download_type default_type = download_type::fallback) -> download_type; -[[nodiscard]] auto download_type_to_string(const download_type &type) - -> std::string; +[[nodiscard]] auto +download_type_to_string(const download_type &type) -> std::string; enum class exit_code : std::int32_t { success = 0, @@ -412,17 +410,17 @@ inline constexpr const auto JSON_API_PASSWORD{"ApiPassword"}; inline constexpr const auto JSON_API_PATH{"ApiPath"}; inline constexpr const auto JSON_API_PORT{"ApiPort"}; inline constexpr const auto JSON_API_USER{"ApiUser"}; -inline constexpr const auto JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS{ - "ChunkDownloaderTimeoutSeconds"}; inline constexpr const auto JSON_BUCKET{"Bucket"}; inline constexpr const auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"}; inline constexpr const auto JSON_DATABASE_TYPE{"DatabaseType"}; inline constexpr const auto JSON_DIRECTORY{"Directory"}; -inline constexpr const auto JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT{ - "EnableChunkDownloaderTimeout"}; +inline constexpr const auto JSON_DOWNLOAD_TIMEOUT_SECS{ + "DownloadTimeoutSeconds"}; inline constexpr const auto JSON_ENABLE_COMM_DURATION_EVENTS{ "EnableCommDurationEvents"}; inline constexpr const auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"}; +inline constexpr const auto JSON_ENABLE_DOWNLOAD_TIMEOUT{ + "EnableDownloadTimeout"}; inline constexpr const auto JSON_ENABLE_MOUNT_MANAGER{"EnableMountManager"}; inline constexpr const auto JSON_ENABLE_REMOTE_MOUNT{"Enable"}; inline constexpr const auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"}; diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index 8a1ee353..ca354d39 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -36,23 +36,24 @@ constexpr const auto default_eviction_delay_mins{1U}; constexpr const auto default_high_freq_interval_secs{30U}; constexpr const auto default_low_freq_interval_secs{0U * 60U}; constexpr const auto default_max_cache_size_bytes{ - 20ULL * 1024ULL * 1024ULL * 1024ULL, + 20UL * 1024UL * 1024UL * 1024UL, }; constexpr const auto default_max_upload_count{5U}; constexpr const auto default_med_freq_interval_secs{2U * 60U}; -constexpr const auto default_min_download_timeout_secs{5U}; constexpr const auto default_online_check_retry_secs{60U}; constexpr const auto default_orphaned_file_retention_days{15U}; -constexpr const auto default_remote_client_pool_size{10U}; -constexpr const auto default_remote_host_name_or_ip{""}; -constexpr const auto default_remote_max_connections{20U}; -constexpr const auto default_remote_receive_timeout_secs{120U}; -constexpr const auto default_remote_send_timeout_secs{30U}; -constexpr const auto default_remote_encryption_token{""}; constexpr const auto default_retry_read_count{6U}; constexpr const auto default_ring_buffer_file_size{512U}; constexpr const auto default_task_wait_ms{100U}; -constexpr const auto min_cache_size_bytes{100ULL * 1024ULL * 1024ULL}; +constexpr const auto max_orphaned_file_retention_days{std::uint16_t(31U)}; +constexpr const auto max_ring_buffer_file_size{std::uint16_t(1024U)}; +constexpr const auto min_cache_size_bytes{100UL * 1024UL * 1024UL}; +constexpr const auto min_download_timeout_secs{std::uint8_t(5U)}; +constexpr const auto min_online_check_retry_secs{std::uint16_t(15U)}; +constexpr const auto min_orphaned_file_retention_days{std::uint16_t(1U)}; +constexpr const auto min_retry_read_count{std::uint16_t(2U)}; +constexpr const auto min_ring_buffer_file_size{std::uint16_t(64U)}; +constexpr const auto min_task_wait_ms{std::uint16_t(50U)}; template auto get_value(const json &data, const std::string &name, dest &dst, @@ -86,7 +87,7 @@ app_config::app_config(const provider_type &prov, api_user_(std::string{REPERTORY}), config_changed_(false), download_timeout_secs_(default_download_timeout_ces), - enable_chunk_downloader_timeout_(true), + enable_download_timeout_(true), enable_comm_duration_events_(false), enable_drive_events_(false), #if defined(_WIN32) @@ -100,7 +101,6 @@ app_config::app_config(const provider_type &prov, max_cache_size_bytes_(default_max_cache_size_bytes), max_upload_count_(default_max_upload_count), med_freq_interval_secs_(default_med_freq_interval_secs), - min_download_timeout_secs_(default_min_download_timeout_secs), online_check_retry_secs_(default_online_check_retry_secs), orphaned_file_retention_days_(default_orphaned_file_retention_days), preferred_download_type_(download_type::fallback), @@ -141,20 +141,18 @@ app_config::app_config(const provider_type &prov, {JSON_API_AUTH, [this]() { return get_api_auth(); }}, {JSON_API_PORT, [this]() { return std::to_string(get_api_port()); }}, {JSON_API_USER, [this]() { return get_api_user(); }}, - {JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, - [this]() { - return std::to_string(get_chunk_downloader_timeout_secs()); - }}, {JSON_DATABASE_TYPE, [this]() { return database_type_to_string(get_database_type()); }}, - {JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, - [this]() { - return utils::string::from_bool(get_enable_chunk_download_timeout()); - }}, + {JSON_DOWNLOAD_TIMEOUT_SECS, + [this]() { return std::to_string(get_download_timeout_secs()); }}, {JSON_ENABLE_COMM_DURATION_EVENTS, [this]() { return utils::string::from_bool(get_enable_comm_duration_events()); }}, + {JSON_ENABLE_DOWNLOAD_TIMEOUT, + [this]() { + return utils::string::from_bool(get_enable_download_timeout()); + }}, {JSON_ENABLE_DRIVE_EVENTS, [this]() { return utils::string::from_bool(get_enable_drive_events()); @@ -289,13 +287,6 @@ app_config::app_config(const provider_type &prov, return get_api_user(); }, }, - { - JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, - [this](const std::string &value) { - set_chunk_downloader_timeout_secs(utils::string::to_uint8(value)); - return std::to_string(get_chunk_downloader_timeout_secs()); - }, - }, { JSON_DATABASE_TYPE, [this](const std::string &value) { @@ -304,11 +295,10 @@ app_config::app_config(const provider_type &prov, }, }, { - JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, + JSON_DOWNLOAD_TIMEOUT_SECS, [this](const std::string &value) { - set_enable_chunk_downloader_timeout(utils::string::to_bool(value)); - return utils::string::from_bool( - get_enable_chunk_download_timeout()); + set_download_timeout_secs(utils::string::to_uint8(value)); + return std::to_string(get_download_timeout_secs()); }, }, { @@ -318,6 +308,13 @@ app_config::app_config(const provider_type &prov, return utils::string::from_bool(get_enable_comm_duration_events()); }, }, + { + JSON_ENABLE_DOWNLOAD_TIMEOUT, + [this](const std::string &value) { + set_enable_download_timeout(utils::string::to_bool(value)); + return utils::string::from_bool(get_enable_download_timeout()); + }, + }, { JSON_ENABLE_DRIVE_EVENTS, [this](const std::string &value) { @@ -767,11 +764,6 @@ auto app_config::get_cache_directory() const -> std::string { return cache_directory_; } -auto app_config::get_chunk_downloader_timeout_secs() const -> std::uint8_t { - return std::max(static_cast(5U), - min_download_timeout_secs_.load()); -} - auto app_config::get_config_file_path() const -> std::string { return utils::path::combine(data_directory_, {"config.json"}); } @@ -782,14 +774,18 @@ auto app_config::get_data_directory() const -> std::string { return data_directory_; } -auto app_config::get_enable_chunk_download_timeout() const -> bool { - return enable_chunk_downloader_timeout_; +auto app_config::get_download_timeout_secs() const -> std::uint8_t { + return std::max(min_download_timeout_secs, download_timeout_secs_.load()); } auto app_config::get_enable_comm_duration_events() const -> bool { return enable_comm_duration_events_; } +auto app_config::get_enable_download_timeout() const -> bool { + return enable_download_timeout_; +} + auto app_config::get_enable_drive_events() const -> bool { return enable_drive_events_; } @@ -826,9 +822,9 @@ auto app_config::get_json() const -> json { {JSON_API_AUTH, api_auth_}, {JSON_API_PORT, api_port_}, {JSON_API_USER, api_user_}, - {JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_}, + {JSON_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_}, {JSON_DATABASE_TYPE, db_type_}, - {JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, enable_chunk_downloader_timeout_}, + {JSON_ENABLE_DOWNLOAD_TIMEOUT, enable_download_timeout_}, {JSON_ENABLE_COMM_DURATION_EVENTS, enable_comm_duration_events_}, {JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_}, #if defined(_WIN32) @@ -859,8 +855,8 @@ auto app_config::get_json() const -> json { switch (prov_) { case provider_type::encrypt: { - ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS); - ret.erase(JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT); + ret.erase(JSON_DOWNLOAD_TIMEOUT_SECS); + ret.erase(JSON_ENABLE_DOWNLOAD_TIMEOUT); ret.erase(JSON_EVICTION_DELAY_MINS); ret.erase(JSON_EVICTION_USE_ACCESS_TIME); ret.erase(JSON_HOST_CONFIG); @@ -876,9 +872,9 @@ auto app_config::get_json() const -> json { ret.erase(JSON_SIA_CONFIG); } break; case provider_type::remote: { - ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS); ret.erase(JSON_DATABASE_TYPE); - ret.erase(JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT); + ret.erase(JSON_DOWNLOAD_TIMEOUT_SECS); + ret.erase(JSON_ENABLE_DOWNLOAD_TIMEOUT); ret.erase(JSON_ENCRYPT_CONFIG); ret.erase(JSON_EVICTION_DELAY_MINS); ret.erase(JSON_EVICTION_USE_ACCESS_TIME); @@ -942,12 +938,12 @@ auto app_config::get_med_frequency_interval_secs() const -> std::uint16_t { } auto app_config::get_online_check_retry_secs() const -> std::uint16_t { - return std::max(std::uint16_t(15U), online_check_retry_secs_.load()); + return std::max(min_online_check_retry_secs, online_check_retry_secs_.load()); } auto app_config::get_orphaned_file_retention_days() const -> std::uint16_t { - return std::min(static_cast(31U), - std::max(static_cast(1U), + return std::min(max_orphaned_file_retention_days, + std::max(min_orphaned_file_retention_days, orphaned_file_retention_days_.load())); } @@ -991,13 +987,13 @@ auto app_config::get_remote_mount() const -> remote::remote_mount { } auto app_config::get_retry_read_count() const -> std::uint16_t { - return std::max(std::uint16_t(2), retry_read_count_.load()); + return std::max(min_retry_read_count, retry_read_count_.load()); } auto app_config::get_ring_buffer_file_size() const -> std::uint16_t { - return std::max(static_cast(64U), - std::min(static_cast(1024U), - ring_buffer_file_size_.load())); + return std::max( + min_ring_buffer_file_size, + std::min(max_ring_buffer_file_size, ring_buffer_file_size_.load())); } auto app_config::get_s3_config() const -> s3_config { return s3_config_; } @@ -1005,7 +1001,7 @@ auto app_config::get_s3_config() const -> s3_config { return s3_config_; } auto app_config::get_sia_config() const -> sia_config { return sia_config_; } auto app_config::get_task_wait_ms() const -> std::uint16_t { - return std::max(static_cast(50U), task_wait_ms_.load()); + return std::max(min_task_wait_ms, task_wait_ms_.load()); } auto app_config::get_value_by_name(const std::string &name) const @@ -1057,11 +1053,11 @@ auto app_config::load() -> bool { get_value(json_document, JSON_API_AUTH, api_auth_, found); get_value(json_document, JSON_API_PORT, api_port_, found); get_value(json_document, JSON_API_USER, api_user_, found); - get_value(json_document, JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, - download_timeout_secs_, found); get_value(json_document, JSON_DATABASE_TYPE, db_type_, found); - get_value(json_document, JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, - enable_chunk_downloader_timeout_, found); + get_value(json_document, JSON_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_, + found); + get_value(json_document, JSON_ENABLE_DOWNLOAD_TIMEOUT, + enable_download_timeout_, found); get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS, enable_comm_duration_events_, found); get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_, @@ -1146,131 +1142,125 @@ void app_config::save() { }); } -void app_config::set_api_auth(const std::string &api_auth) { - set_value(api_auth_, api_auth); +void app_config::set_api_auth(const std::string &value) { + set_value(api_auth_, value); } -void app_config::set_api_port(std::uint16_t api_port) { - set_value(api_port_, api_port); +void app_config::set_api_port(std::uint16_t value) { + set_value(api_port_, value); } -void app_config::set_api_user(const std::string &api_user) { - set_value(api_user_, api_user); +void app_config::set_api_user(const std::string &value) { + set_value(api_user_, value); } -void app_config::set_chunk_downloader_timeout_secs( - std::uint8_t chunk_downloader_timeout_secs) { - set_value(download_timeout_secs_, chunk_downloader_timeout_secs); +void app_config::set_download_timeout_secs(std::uint8_t value) { + set_value(download_timeout_secs_, value); } -void app_config::set_database_type(const database_type &type) { - set_value(db_type_, type); +void app_config::set_database_type(const database_type &value) { + set_value(db_type_, value); } -void app_config::set_enable_chunk_downloader_timeout( - bool enable_chunk_downloader_timeout) { - set_value(enable_chunk_downloader_timeout_, enable_chunk_downloader_timeout); +void app_config::set_enable_download_timeout(bool value) { + set_value(enable_download_timeout_, value); } -void app_config::set_enable_comm_duration_events( - bool enable_comm_duration_events) { - set_value(enable_comm_duration_events_, enable_comm_duration_events); +void app_config::set_enable_comm_duration_events(bool value) { + set_value(enable_comm_duration_events_, value); } -void app_config::set_enable_drive_events(bool enable_drive_events) { - set_value(enable_drive_events_, enable_drive_events); +void app_config::set_enable_drive_events(bool value) { + set_value(enable_drive_events_, value); } #if defined(_WIN32) -void app_config::set_enable_mount_manager(bool enable_mount_manager) { - set_value(enable_mount_manager_, enable_mount_manager); +void app_config::set_enable_mount_manager(bool value) { + set_value(enable_mount_manager_, value); } #endif // defined(_WIN32) -void app_config::set_event_level(const event_level &level) { - if (set_value(event_level_, level)) { +void app_config::set_event_level(const event_level &value) { + if (set_value(event_level_, value)) { event_system::instance().raise( - event_level_to_string(level)); + event_level_to_string(value)); } } -void app_config::set_encrypt_config(encrypt_config cfg) { - set_value(encrypt_config_, cfg); +void app_config::set_encrypt_config(encrypt_config value) { + set_value(encrypt_config_, value); } -void app_config::set_eviction_delay_mins(std::uint32_t eviction_delay_mins) { - set_value(eviction_delay_mins_, eviction_delay_mins); +void app_config::set_eviction_delay_mins(std::uint32_t value) { + set_value(eviction_delay_mins_, value); } -void app_config::set_eviction_uses_accessed_time( - bool eviction_uses_accessed_time) { - set_value(eviction_uses_accessed_time_, eviction_uses_accessed_time); +void app_config::set_eviction_uses_accessed_time(bool value) { + set_value(eviction_uses_accessed_time_, value); } -void app_config::set_high_frequency_interval_secs( - std::uint16_t high_frequency_interval_secs) { - set_value(high_freq_interval_secs_, high_frequency_interval_secs); +void app_config::set_high_frequency_interval_secs(std::uint16_t value) { + set_value(high_freq_interval_secs_, value); } -void app_config::set_host_config(host_config cfg) { - set_value(host_config_, cfg); +void app_config::set_host_config(host_config value) { + set_value(host_config_, value); } -void app_config::set_low_frequency_interval_secs( - std::uint16_t low_frequency_interval_secs) { - set_value(low_freq_interval_secs_, low_frequency_interval_secs); +void app_config::set_low_frequency_interval_secs(std::uint16_t value) { + set_value(low_freq_interval_secs_, value); } -void app_config::set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes) { - set_value(max_cache_size_bytes_, max_cache_size_bytes); +void app_config::set_max_cache_size_bytes(std::uint64_t value) { + set_value(max_cache_size_bytes_, value); } -void app_config::set_max_upload_count(std::uint8_t max_upload_count) { - set_value(max_upload_count_, max_upload_count); +void app_config::set_max_upload_count(std::uint8_t value) { + set_value(max_upload_count_, value); } -void app_config::set_med_frequency_interval_secs( - std::uint16_t med_frequency_interval_secs) { - set_value(med_freq_interval_secs_, med_frequency_interval_secs); +void app_config::set_med_frequency_interval_secs(std::uint16_t value) { + set_value(med_freq_interval_secs_, value); } -void app_config::set_online_check_retry_secs( - std::uint16_t online_check_retry_secs) { - set_value(online_check_retry_secs_, online_check_retry_secs); +void app_config::set_online_check_retry_secs(std::uint16_t value) { + set_value(online_check_retry_secs_, value); } -void app_config::set_orphaned_file_retention_days( - std::uint16_t orphaned_file_retention_days) { - set_value(orphaned_file_retention_days_, orphaned_file_retention_days); +void app_config::set_orphaned_file_retention_days(std::uint16_t value) { + set_value(orphaned_file_retention_days_, value); } -void app_config::set_preferred_download_type(const download_type &type) { - set_value(preferred_download_type_, type); +void app_config::set_preferred_download_type(const download_type &value) { + set_value(preferred_download_type_, value); } -void app_config::set_remote_config(remote::remote_config cfg) { - set_value(remote_config_, cfg); +void app_config::set_remote_config(remote::remote_config value) { + set_value(remote_config_, value); } -void app_config::set_remote_mount(remote::remote_mount cfg) { - set_value(remote_mount_, cfg); +void app_config::set_remote_mount(remote::remote_mount value) { + set_value(remote_mount_, value); } -void app_config::set_retry_read_count(std::uint16_t retry_read_count) { - set_value(retry_read_count_, retry_read_count); +void app_config::set_retry_read_count(std::uint16_t value) { + set_value(retry_read_count_, value); } -void app_config::set_ring_buffer_file_size( - std::uint16_t ring_buffer_file_size) { - set_value(ring_buffer_file_size_, ring_buffer_file_size); +void app_config::set_ring_buffer_file_size(std::uint16_t value) { + set_value(ring_buffer_file_size_, value); } -void app_config::set_s3_config(s3_config cfg) { set_value(s3_config_, cfg); } +void app_config::set_s3_config(s3_config value) { + set_value(s3_config_, value); +} -void app_config::set_sia_config(sia_config cfg) { set_value(sia_config_, cfg); } +void app_config::set_sia_config(sia_config value) { + set_value(sia_config_, value); +} -void app_config::set_task_wait_ms(std::uint16_t task_wait_ms) { - set_value(task_wait_ms_, task_wait_ms); +void app_config::set_task_wait_ms(std::uint16_t value) { + set_value(task_wait_ms_, value); } auto app_config::set_value_by_name(const std::string &name, diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index f641d25b..0dbfe659 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -241,8 +241,8 @@ auto file_manager::get_open_file(std::uint64_t handle, bool write_supported, if (write_supported && not file_ptr->is_write_supported()) { auto writeable_file = std::make_shared( utils::encryption::encrypting_reader::get_data_chunk_size(), - config_.get_enable_chunk_download_timeout() - ? config_.get_chunk_downloader_timeout_secs() + config_.get_enable_download_timeout() + ? config_.get_download_timeout_secs() : 0U, file_ptr->get_filesystem_item(), file_ptr->get_open_data(), provider_, *this); @@ -370,11 +370,10 @@ auto file_manager::open(const std::string &api_path, bool directory, return open(api_path, directory, ofd, handle, file, nullptr); } -auto file_manager::open(const std::string &api_path, bool directory, - const open_file_data &ofd, std::uint64_t &handle, - std::shared_ptr &file, - std::shared_ptr closeable_file) - -> api_error { +auto file_manager::open( + const std::string &api_path, bool directory, const open_file_data &ofd, + std::uint64_t &handle, std::shared_ptr &file, + std::shared_ptr closeable_file) -> api_error { const auto create_and_add_handle = [&](std::shared_ptr cur_file) { handle = get_next_handle(); @@ -406,8 +405,8 @@ auto file_manager::open(const std::string &api_path, bool directory, if (not closeable_file) { closeable_file = std::make_shared( utils::encryption::encrypting_reader::get_data_chunk_size(), - config_.get_enable_chunk_download_timeout() - ? config_.get_chunk_downloader_timeout_secs() + config_.get_enable_download_timeout() + ? config_.get_download_timeout_secs() : 0U, fsi, provider_, *this); } @@ -636,8 +635,8 @@ auto file_manager::rename_directory(const std::string &from_api_path, } auto file_manager::rename_file(const std::string &from_api_path, - const std::string &to_api_path, bool overwrite) - -> api_error { + const std::string &to_api_path, + bool overwrite) -> api_error { if (not provider_.is_rename_supported()) { return api_error::not_implemented; } @@ -769,12 +768,12 @@ void file_manager::start() { continue; } - auto closeable_file = std::make_shared( - entry.chunk_size, - config_.get_enable_chunk_download_timeout() - ? config_.get_chunk_downloader_timeout_secs() - : 0U, - fsi, provider_, entry.read_state, *this); + auto closeable_file = + std::make_shared(entry.chunk_size, + config_.get_enable_download_timeout() + ? config_.get_download_timeout_secs() + : 0U, + fsi, provider_, entry.read_state, *this); open_file_lookup_[entry.api_path] = closeable_file; event_system::instance().raise(fsi.api_path, fsi.source_path); diff --git a/repertory/repertory_test/src/config_test.cpp b/repertory/repertory_test/src/config_test.cpp index 188728bc..c92f890d 100644 --- a/repertory/repertory_test/src/config_test.cpp +++ b/repertory/repertory_test/src/config_test.cpp @@ -110,31 +110,31 @@ TEST_F(config_test, api_user) { } } -TEST_F(config_test, chunk_downloader_timeout_secs) { +TEST_F(config_test, download_timeout_secs) { std::uint8_t original_value{}; { app_config config(provider_type::sia, sia_directory); - original_value = config.get_chunk_downloader_timeout_secs(); - config.set_chunk_downloader_timeout_secs(original_value + 5); - EXPECT_EQ(original_value + 5, config.get_chunk_downloader_timeout_secs()); + original_value = config.get_download_timeout_secs(); + config.set_download_timeout_secs(original_value + 5); + EXPECT_EQ(original_value + 5, config.get_download_timeout_secs()); } { app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(original_value + 5, config.get_chunk_downloader_timeout_secs()); + EXPECT_EQ(original_value + 5, config.get_download_timeout_secs()); } } -TEST_F(config_test, enable_chunk_download_timeout) { +TEST_F(config_test, enable_download_timeout) { bool original_value{}; { app_config config(provider_type::sia, sia_directory); - original_value = config.get_enable_chunk_download_timeout(); - config.set_enable_chunk_downloader_timeout(not original_value); - EXPECT_EQ(not original_value, config.get_enable_chunk_download_timeout()); + original_value = config.get_enable_download_timeout(); + config.set_enable_download_timeout(not original_value); + EXPECT_EQ(not original_value, config.get_enable_download_timeout()); } { app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(not original_value, config.get_enable_chunk_download_timeout()); + EXPECT_EQ(not original_value, config.get_enable_download_timeout()); } } diff --git a/repertory/repertory_test/src/file_manager_test.cpp b/repertory/repertory_test/src/file_manager_test.cpp index ed361351..cdb552a5 100644 --- a/repertory/repertory_test/src/file_manager_test.cpp +++ b/repertory/repertory_test/src/file_manager_test.cpp @@ -66,7 +66,7 @@ protected: {"file_manager_test" + std::to_string(++inst)}); cfg = std::make_unique(provider_type::sia, file_manager_dir); - cfg->set_enable_chunk_downloader_timeout(false); + cfg->set_enable_download_timeout(false); } void TearDown() override { event_system::instance().stop(); } @@ -104,7 +104,7 @@ TEST_F(file_manager_test, can_start_and_stop) { } TEST_F(file_manager_test, can_create_and_close_file) { - cfg->set_enable_chunk_downloader_timeout(true); + cfg->set_enable_download_timeout(true); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false)); @@ -213,7 +213,7 @@ TEST_F(file_manager_test, can_create_and_close_file) { } TEST_F(file_manager_test, can_open_and_close_file) { - cfg->set_enable_chunk_downloader_timeout(true); + cfg->set_enable_download_timeout(true); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false)); @@ -530,7 +530,7 @@ TEST_F(file_manager_test, } TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) { - cfg->set_enable_chunk_downloader_timeout(true); + cfg->set_enable_download_timeout(true); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false)); @@ -1416,8 +1416,8 @@ TEST_F(file_manager_test, can_queue_and_remove_upload) { } TEST_F(file_manager_test, file_is_closed_after_download_timeout) { - cfg->set_enable_chunk_downloader_timeout(true); - cfg->set_chunk_downloader_timeout_secs(3U); + cfg->set_enable_download_timeout(true); + cfg->set_download_timeout_secs(3U); polling::instance().start(cfg.get()); @@ -1544,7 +1544,7 @@ TEST_F(file_manager_test, remove_file_fails_if_provider_remove_file_fails) { TEST_F(file_manager_test, resize_greater_than_chunk_size_sets_new_chunks_to_read) { - cfg->set_enable_chunk_downloader_timeout(true); + cfg->set_enable_download_timeout(true); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));