refactor app config

This commit is contained in:
Scott E. Graves 2024-12-20 17:51:30 -06:00
parent d2a8aef843
commit ca6f919664
7 changed files with 221 additions and 236 deletions

View File

@ -31,26 +31,26 @@
namespace repertory { namespace repertory {
class app_config final { class app_config final {
public: public:
[[nodiscard]] static auto default_agent_name(const provider_type &prov) [[nodiscard]] static auto
-> std::string; default_agent_name(const provider_type &prov) -> std::string;
[[nodiscard]] static auto default_api_port(const provider_type &prov) [[nodiscard]] static auto
-> std::uint16_t; default_api_port(const provider_type &prov) -> std::uint16_t;
[[nodiscard]] static auto default_data_directory(const provider_type &prov) [[nodiscard]] static auto
-> std::string; default_data_directory(const provider_type &prov) -> std::string;
[[nodiscard]] static auto default_remote_api_port(const provider_type &prov) [[nodiscard]] static auto
-> std::uint16_t; default_remote_api_port(const provider_type &prov) -> std::uint16_t;
[[nodiscard]] static auto default_rpc_port(const provider_type &prov) [[nodiscard]] static auto
-> std::uint16_t; default_rpc_port(const provider_type &prov) -> std::uint16_t;
[[nodiscard]] static auto get_provider_display_name(const provider_type &prov) [[nodiscard]] static auto
-> std::string; get_provider_display_name(const provider_type &prov) -> std::string;
[[nodiscard]] static auto get_provider_name(const provider_type &prov) [[nodiscard]] static auto
-> std::string; get_provider_name(const provider_type &prov) -> std::string;
public: public:
app_config(const provider_type &prov, std::string_view data_directory = ""); app_config(const provider_type &prov, std::string_view data_directory = "");
@ -65,7 +65,7 @@ private:
std::atomic<bool> config_changed_; std::atomic<bool> config_changed_;
std::atomic<database_type> db_type_{database_type::rocksdb}; std::atomic<database_type> db_type_{database_type::rocksdb};
std::atomic<std::uint8_t> download_timeout_secs_; std::atomic<std::uint8_t> download_timeout_secs_;
std::atomic<bool> enable_chunk_downloader_timeout_; std::atomic<bool> enable_download_timeout_;
std::atomic<bool> enable_comm_duration_events_; std::atomic<bool> enable_comm_duration_events_;
std::atomic<bool> enable_drive_events_; std::atomic<bool> enable_drive_events_;
#if defined(_WIN32) #if defined(_WIN32)
@ -79,7 +79,6 @@ private:
std::atomic<std::uint64_t> max_cache_size_bytes_; std::atomic<std::uint64_t> max_cache_size_bytes_;
std::atomic<std::uint8_t> max_upload_count_; std::atomic<std::uint8_t> max_upload_count_;
std::atomic<std::uint16_t> med_freq_interval_secs_; std::atomic<std::uint16_t> med_freq_interval_secs_;
std::atomic<std::uint8_t> min_download_timeout_secs_;
std::atomic<std::uint16_t> online_check_retry_secs_; std::atomic<std::uint16_t> online_check_retry_secs_;
std::atomic<std::uint16_t> orphaned_file_retention_days_; std::atomic<std::uint16_t> orphaned_file_retention_days_;
atomic<download_type> preferred_download_type_; atomic<download_type> preferred_download_type_;
@ -129,18 +128,18 @@ public:
[[nodiscard]] auto get_cache_directory() const -> std::string; [[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_config_file_path() const -> std::string;
[[nodiscard]] auto get_database_type() const -> database_type; [[nodiscard]] auto get_database_type() const -> database_type;
[[nodiscard]] auto get_data_directory() const -> std::string; [[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_comm_duration_events() const -> bool;
[[nodiscard]] auto get_enable_download_timeout() const -> bool;
[[nodiscard]] auto get_enable_drive_events() const -> bool; [[nodiscard]] auto get_enable_drive_events() const -> bool;
[[nodiscard]] auto get_encrypt_config() const -> encrypt_config; [[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_task_wait_ms() const -> std::uint16_t;
[[nodiscard]] auto get_value_by_name(const std::string &name) const [[nodiscard]] auto
-> std::string; get_value_by_name(const std::string &name) const -> std::string;
[[nodiscard]] auto get_version() const -> std::uint64_t; [[nodiscard]] auto get_version() const -> std::uint64_t;
void save(); 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 void set_download_timeout_secs(std::uint8_t value);
set_chunk_downloader_timeout_secs(std::uint8_t chunk_downloader_timeout_secs);
void set_database_type(const database_type &type); void set_database_type(const database_type &value);
void void set_enable_download_timeout(bool value);
set_enable_chunk_downloader_timeout(bool enable_chunk_downloader_timeout);
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) #if defined(_WIN32)
void set_enable_mount_manager(bool enable_mount_manager); void set_enable_mount_manager(bool value);
#endif // defined(_WIN32) #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 void set_high_frequency_interval_secs(std::uint16_t value);
set_high_frequency_interval_secs(std::uint16_t high_frequency_interval_secs);
void set_host_config(host_config cfg); void set_host_config(host_config value);
void void set_low_frequency_interval_secs(std::uint16_t value);
set_low_frequency_interval_secs(std::uint16_t low_frequency_interval_secs);
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 void set_med_frequency_interval_secs(std::uint16_t value);
set_med_frequency_interval_secs(std::uint16_t med_frequency_interval_secs);
void set_online_check_retry_secs(std::uint16_t online_check_retry_secs); void set_online_check_retry_secs(std::uint16_t value);
void void set_orphaned_file_retention_days(std::uint16_t value);
set_orphaned_file_retention_days(std::uint16_t orphaned_file_retention_days);
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, [[nodiscard]] auto set_value_by_name(const std::string &name,
const std::string &value) -> std::string; const std::string &value) -> std::string;

View File

@ -33,14 +33,19 @@ inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP};
inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE}; inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE};
#endif // defined(_WIN32) #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 { namespace repertory::remote {
struct remote_config final { struct remote_config final {
std::uint16_t api_port{}; std::uint16_t api_port{};
std::string encryption_token; std::string encryption_token;
std::string host_name_or_ip; std::string host_name_or_ip;
std::uint8_t max_connections{20U}; std::uint8_t max_connections{default_remote_max_connections};
std::uint32_t recv_timeout_ms{120U * 1000U}; std::uint32_t recv_timeout_ms{default_remote_receive_timeout_ms};
std::uint32_t send_timeout_ms{30U * 1000U}; std::uint32_t send_timeout_ms{default_remote_send_timeout_ms};
auto operator==(const remote_config &cfg) const noexcept -> bool { auto operator==(const remote_config &cfg) const noexcept -> bool {
if (&cfg != this) { if (&cfg != this) {
@ -66,7 +71,7 @@ struct remote_config final {
struct remote_mount final { struct remote_mount final {
std::uint16_t api_port{}; 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}; bool enable{false};
std::string encryption_token; std::string encryption_token;
@ -212,8 +217,8 @@ struct statfs_x final : public statfs {
#if !defined(_WIN32) #if !defined(_WIN32)
[[nodiscard]] auto create_open_flags(std::uint32_t flags) -> open_flags; [[nodiscard]] auto create_open_flags(std::uint32_t flags) -> open_flags;
[[nodiscard]] auto create_os_open_flags(const open_flags &flags) [[nodiscard]] auto
-> std::uint32_t; create_os_open_flags(const open_flags &flags) -> std::uint32_t;
#endif // !defined(_WIN32) #endif // !defined(_WIN32)
} // namespace repertory::remote } // namespace repertory::remote

View File

@ -187,33 +187,31 @@ enum class api_error {
[[nodiscard]] auto api_error_from_string(std::string_view str) -> api_error; [[nodiscard]] auto api_error_from_string(std::string_view str) -> api_error;
[[nodiscard]] auto api_error_to_string(const api_error &error) [[nodiscard]] auto
-> const std::string &; api_error_to_string(const api_error &error) -> const std::string &;
enum class database_type { enum class database_type {
rocksdb, rocksdb,
sqlite, sqlite,
}; };
[[nodiscard]] auto [[nodiscard]] auto database_type_from_string(
database_type_from_string(std::string type, std::string type,
database_type default_type = database_type::rocksdb) database_type default_type = database_type::rocksdb) -> database_type;
-> database_type;
[[nodiscard]] auto database_type_to_string(const database_type &type) [[nodiscard]] auto
-> std::string; database_type_to_string(const database_type &type) -> std::string;
enum class download_type { enum class download_type {
direct, direct,
fallback, fallback,
ring_buffer, ring_buffer,
}; };
[[nodiscard]] auto [[nodiscard]] auto download_type_from_string(
download_type_from_string(std::string type, std::string type,
download_type default_type = download_type::fallback) download_type default_type = download_type::fallback) -> download_type;
-> download_type;
[[nodiscard]] auto download_type_to_string(const download_type &type) [[nodiscard]] auto
-> std::string; download_type_to_string(const download_type &type) -> std::string;
enum class exit_code : std::int32_t { enum class exit_code : std::int32_t {
success = 0, 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_PATH{"ApiPath"};
inline constexpr const auto JSON_API_PORT{"ApiPort"}; inline constexpr const auto JSON_API_PORT{"ApiPort"};
inline constexpr const auto JSON_API_USER{"ApiUser"}; 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_BUCKET{"Bucket"};
inline constexpr const auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"}; inline constexpr const auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"};
inline constexpr const auto JSON_DATABASE_TYPE{"DatabaseType"}; inline constexpr const auto JSON_DATABASE_TYPE{"DatabaseType"};
inline constexpr const auto JSON_DIRECTORY{"Directory"}; inline constexpr const auto JSON_DIRECTORY{"Directory"};
inline constexpr const auto JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT{ inline constexpr const auto JSON_DOWNLOAD_TIMEOUT_SECS{
"EnableChunkDownloaderTimeout"}; "DownloadTimeoutSeconds"};
inline constexpr const auto JSON_ENABLE_COMM_DURATION_EVENTS{ inline constexpr const auto JSON_ENABLE_COMM_DURATION_EVENTS{
"EnableCommDurationEvents"}; "EnableCommDurationEvents"};
inline constexpr const auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"}; 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_MOUNT_MANAGER{"EnableMountManager"};
inline constexpr const auto JSON_ENABLE_REMOTE_MOUNT{"Enable"}; inline constexpr const auto JSON_ENABLE_REMOTE_MOUNT{"Enable"};
inline constexpr const auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"}; inline constexpr const auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"};

View File

@ -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_high_freq_interval_secs{30U};
constexpr const auto default_low_freq_interval_secs{0U * 60U}; constexpr const auto default_low_freq_interval_secs{0U * 60U};
constexpr const auto default_max_cache_size_bytes{ 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_max_upload_count{5U};
constexpr const auto default_med_freq_interval_secs{2U * 60U}; 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_online_check_retry_secs{60U};
constexpr const auto default_orphaned_file_retention_days{15U}; 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_retry_read_count{6U};
constexpr const auto default_ring_buffer_file_size{512U}; constexpr const auto default_ring_buffer_file_size{512U};
constexpr const auto default_task_wait_ms{100U}; 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 <typename dest> template <typename dest>
auto get_value(const json &data, const std::string &name, dest &dst, 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}), api_user_(std::string{REPERTORY}),
config_changed_(false), config_changed_(false),
download_timeout_secs_(default_download_timeout_ces), download_timeout_secs_(default_download_timeout_ces),
enable_chunk_downloader_timeout_(true), enable_download_timeout_(true),
enable_comm_duration_events_(false), enable_comm_duration_events_(false),
enable_drive_events_(false), enable_drive_events_(false),
#if defined(_WIN32) #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_cache_size_bytes_(default_max_cache_size_bytes),
max_upload_count_(default_max_upload_count), max_upload_count_(default_max_upload_count),
med_freq_interval_secs_(default_med_freq_interval_secs), 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), online_check_retry_secs_(default_online_check_retry_secs),
orphaned_file_retention_days_(default_orphaned_file_retention_days), orphaned_file_retention_days_(default_orphaned_file_retention_days),
preferred_download_type_(download_type::fallback), 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_AUTH, [this]() { return get_api_auth(); }},
{JSON_API_PORT, [this]() { return std::to_string(get_api_port()); }}, {JSON_API_PORT, [this]() { return std::to_string(get_api_port()); }},
{JSON_API_USER, [this]() { return get_api_user(); }}, {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, {JSON_DATABASE_TYPE,
[this]() { return database_type_to_string(get_database_type()); }}, [this]() { return database_type_to_string(get_database_type()); }},
{JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, {JSON_DOWNLOAD_TIMEOUT_SECS,
[this]() { [this]() { return std::to_string(get_download_timeout_secs()); }},
return utils::string::from_bool(get_enable_chunk_download_timeout());
}},
{JSON_ENABLE_COMM_DURATION_EVENTS, {JSON_ENABLE_COMM_DURATION_EVENTS,
[this]() { [this]() {
return utils::string::from_bool(get_enable_comm_duration_events()); 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, {JSON_ENABLE_DRIVE_EVENTS,
[this]() { [this]() {
return utils::string::from_bool(get_enable_drive_events()); 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(); 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, JSON_DATABASE_TYPE,
[this](const std::string &value) { [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) { [this](const std::string &value) {
set_enable_chunk_downloader_timeout(utils::string::to_bool(value)); set_download_timeout_secs(utils::string::to_uint8(value));
return utils::string::from_bool( return std::to_string(get_download_timeout_secs());
get_enable_chunk_download_timeout());
}, },
}, },
{ {
@ -318,6 +308,13 @@ app_config::app_config(const provider_type &prov,
return utils::string::from_bool(get_enable_comm_duration_events()); 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, JSON_ENABLE_DRIVE_EVENTS,
[this](const std::string &value) { [this](const std::string &value) {
@ -767,11 +764,6 @@ auto app_config::get_cache_directory() const -> std::string {
return cache_directory_; return cache_directory_;
} }
auto app_config::get_chunk_downloader_timeout_secs() const -> std::uint8_t {
return std::max(static_cast<std::uint8_t>(5U),
min_download_timeout_secs_.load());
}
auto app_config::get_config_file_path() const -> std::string { auto app_config::get_config_file_path() const -> std::string {
return utils::path::combine(data_directory_, {"config.json"}); return utils::path::combine(data_directory_, {"config.json"});
} }
@ -782,14 +774,18 @@ auto app_config::get_data_directory() const -> std::string {
return data_directory_; return data_directory_;
} }
auto app_config::get_enable_chunk_download_timeout() const -> bool { auto app_config::get_download_timeout_secs() const -> std::uint8_t {
return enable_chunk_downloader_timeout_; return std::max(min_download_timeout_secs, download_timeout_secs_.load());
} }
auto app_config::get_enable_comm_duration_events() const -> bool { auto app_config::get_enable_comm_duration_events() const -> bool {
return enable_comm_duration_events_; 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 { auto app_config::get_enable_drive_events() const -> bool {
return enable_drive_events_; return enable_drive_events_;
} }
@ -826,9 +822,9 @@ auto app_config::get_json() const -> json {
{JSON_API_AUTH, api_auth_}, {JSON_API_AUTH, api_auth_},
{JSON_API_PORT, api_port_}, {JSON_API_PORT, api_port_},
{JSON_API_USER, api_user_}, {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_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_COMM_DURATION_EVENTS, enable_comm_duration_events_},
{JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_}, {JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_},
#if defined(_WIN32) #if defined(_WIN32)
@ -859,8 +855,8 @@ auto app_config::get_json() const -> json {
switch (prov_) { switch (prov_) {
case provider_type::encrypt: { case provider_type::encrypt: {
ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS); ret.erase(JSON_DOWNLOAD_TIMEOUT_SECS);
ret.erase(JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT); ret.erase(JSON_ENABLE_DOWNLOAD_TIMEOUT);
ret.erase(JSON_EVICTION_DELAY_MINS); ret.erase(JSON_EVICTION_DELAY_MINS);
ret.erase(JSON_EVICTION_USE_ACCESS_TIME); ret.erase(JSON_EVICTION_USE_ACCESS_TIME);
ret.erase(JSON_HOST_CONFIG); ret.erase(JSON_HOST_CONFIG);
@ -876,9 +872,9 @@ auto app_config::get_json() const -> json {
ret.erase(JSON_SIA_CONFIG); ret.erase(JSON_SIA_CONFIG);
} break; } break;
case provider_type::remote: { case provider_type::remote: {
ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS);
ret.erase(JSON_DATABASE_TYPE); 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_ENCRYPT_CONFIG);
ret.erase(JSON_EVICTION_DELAY_MINS); ret.erase(JSON_EVICTION_DELAY_MINS);
ret.erase(JSON_EVICTION_USE_ACCESS_TIME); 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 { 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 { auto app_config::get_orphaned_file_retention_days() const -> std::uint16_t {
return std::min(static_cast<std::uint16_t>(31U), return std::min(max_orphaned_file_retention_days,
std::max(static_cast<std::uint16_t>(1U), std::max(min_orphaned_file_retention_days,
orphaned_file_retention_days_.load())); 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 { 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 { auto app_config::get_ring_buffer_file_size() const -> std::uint16_t {
return std::max(static_cast<std::uint16_t>(64U), return std::max(
std::min(static_cast<std::uint16_t>(1024U), min_ring_buffer_file_size,
ring_buffer_file_size_.load())); std::min(max_ring_buffer_file_size, ring_buffer_file_size_.load()));
} }
auto app_config::get_s3_config() const -> s3_config { return s3_config_; } 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_sia_config() const -> sia_config { return sia_config_; }
auto app_config::get_task_wait_ms() const -> std::uint16_t { auto app_config::get_task_wait_ms() const -> std::uint16_t {
return std::max(static_cast<std::uint16_t>(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 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_AUTH, api_auth_, found);
get_value(json_document, JSON_API_PORT, api_port_, 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_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_DATABASE_TYPE, db_type_, found);
get_value(json_document, JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, get_value(json_document, JSON_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_,
enable_chunk_downloader_timeout_, found); found);
get_value(json_document, JSON_ENABLE_DOWNLOAD_TIMEOUT,
enable_download_timeout_, found);
get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS, get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS,
enable_comm_duration_events_, found); enable_comm_duration_events_, found);
get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_, 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) { void app_config::set_api_auth(const std::string &value) {
set_value(api_auth_, api_auth); set_value(api_auth_, value);
} }
void app_config::set_api_port(std::uint16_t api_port) { void app_config::set_api_port(std::uint16_t value) {
set_value(api_port_, api_port); set_value(api_port_, value);
} }
void app_config::set_api_user(const std::string &api_user) { void app_config::set_api_user(const std::string &value) {
set_value(api_user_, api_user); set_value(api_user_, value);
} }
void app_config::set_chunk_downloader_timeout_secs( void app_config::set_download_timeout_secs(std::uint8_t value) {
std::uint8_t chunk_downloader_timeout_secs) { set_value(download_timeout_secs_, value);
set_value(download_timeout_secs_, chunk_downloader_timeout_secs);
} }
void app_config::set_database_type(const database_type &type) { void app_config::set_database_type(const database_type &value) {
set_value(db_type_, type); set_value(db_type_, value);
} }
void app_config::set_enable_chunk_downloader_timeout( void app_config::set_enable_download_timeout(bool value) {
bool enable_chunk_downloader_timeout) { set_value(enable_download_timeout_, value);
set_value(enable_chunk_downloader_timeout_, enable_chunk_downloader_timeout);
} }
void app_config::set_enable_comm_duration_events( void app_config::set_enable_comm_duration_events(bool value) {
bool enable_comm_duration_events) { set_value(enable_comm_duration_events_, value);
set_value(enable_comm_duration_events_, enable_comm_duration_events);
} }
void app_config::set_enable_drive_events(bool enable_drive_events) { void app_config::set_enable_drive_events(bool value) {
set_value(enable_drive_events_, enable_drive_events); set_value(enable_drive_events_, value);
} }
#if defined(_WIN32) #if defined(_WIN32)
void app_config::set_enable_mount_manager(bool enable_mount_manager) { void app_config::set_enable_mount_manager(bool value) {
set_value(enable_mount_manager_, enable_mount_manager); set_value(enable_mount_manager_, value);
} }
#endif // defined(_WIN32) #endif // defined(_WIN32)
void app_config::set_event_level(const event_level &level) { void app_config::set_event_level(const event_level &value) {
if (set_value(event_level_, level)) { if (set_value(event_level_, value)) {
event_system::instance().raise<event_level_changed>( event_system::instance().raise<event_level_changed>(
event_level_to_string(level)); event_level_to_string(value));
} }
} }
void app_config::set_encrypt_config(encrypt_config cfg) { void app_config::set_encrypt_config(encrypt_config value) {
set_value(encrypt_config_, cfg); set_value(encrypt_config_, value);
} }
void app_config::set_eviction_delay_mins(std::uint32_t eviction_delay_mins) { void app_config::set_eviction_delay_mins(std::uint32_t value) {
set_value(eviction_delay_mins_, eviction_delay_mins); set_value(eviction_delay_mins_, value);
} }
void app_config::set_eviction_uses_accessed_time( void app_config::set_eviction_uses_accessed_time(bool value) {
bool eviction_uses_accessed_time) { set_value(eviction_uses_accessed_time_, value);
set_value(eviction_uses_accessed_time_, eviction_uses_accessed_time);
} }
void app_config::set_high_frequency_interval_secs( void app_config::set_high_frequency_interval_secs(std::uint16_t value) {
std::uint16_t high_frequency_interval_secs) { set_value(high_freq_interval_secs_, value);
set_value(high_freq_interval_secs_, high_frequency_interval_secs);
} }
void app_config::set_host_config(host_config cfg) { void app_config::set_host_config(host_config value) {
set_value(host_config_, cfg); set_value(host_config_, value);
} }
void app_config::set_low_frequency_interval_secs( void app_config::set_low_frequency_interval_secs(std::uint16_t value) {
std::uint16_t low_frequency_interval_secs) { set_value(low_freq_interval_secs_, value);
set_value(low_freq_interval_secs_, low_frequency_interval_secs);
} }
void app_config::set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes) { void app_config::set_max_cache_size_bytes(std::uint64_t value) {
set_value(max_cache_size_bytes_, max_cache_size_bytes); set_value(max_cache_size_bytes_, value);
} }
void app_config::set_max_upload_count(std::uint8_t max_upload_count) { void app_config::set_max_upload_count(std::uint8_t value) {
set_value(max_upload_count_, max_upload_count); set_value(max_upload_count_, value);
} }
void app_config::set_med_frequency_interval_secs( void app_config::set_med_frequency_interval_secs(std::uint16_t value) {
std::uint16_t med_frequency_interval_secs) { set_value(med_freq_interval_secs_, value);
set_value(med_freq_interval_secs_, med_frequency_interval_secs);
} }
void app_config::set_online_check_retry_secs( void app_config::set_online_check_retry_secs(std::uint16_t value) {
std::uint16_t online_check_retry_secs) { set_value(online_check_retry_secs_, value);
set_value(online_check_retry_secs_, online_check_retry_secs);
} }
void app_config::set_orphaned_file_retention_days( void app_config::set_orphaned_file_retention_days(std::uint16_t value) {
std::uint16_t orphaned_file_retention_days) { set_value(orphaned_file_retention_days_, value);
set_value(orphaned_file_retention_days_, orphaned_file_retention_days);
} }
void app_config::set_preferred_download_type(const download_type &type) { void app_config::set_preferred_download_type(const download_type &value) {
set_value(preferred_download_type_, type); set_value(preferred_download_type_, value);
} }
void app_config::set_remote_config(remote::remote_config cfg) { void app_config::set_remote_config(remote::remote_config value) {
set_value(remote_config_, cfg); set_value(remote_config_, value);
} }
void app_config::set_remote_mount(remote::remote_mount cfg) { void app_config::set_remote_mount(remote::remote_mount value) {
set_value(remote_mount_, cfg); set_value(remote_mount_, value);
} }
void app_config::set_retry_read_count(std::uint16_t retry_read_count) { void app_config::set_retry_read_count(std::uint16_t value) {
set_value(retry_read_count_, retry_read_count); set_value(retry_read_count_, value);
} }
void app_config::set_ring_buffer_file_size( void app_config::set_ring_buffer_file_size(std::uint16_t value) {
std::uint16_t ring_buffer_file_size) { set_value(ring_buffer_file_size_, value);
set_value(ring_buffer_file_size_, ring_buffer_file_size);
} }
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) { void app_config::set_task_wait_ms(std::uint16_t value) {
set_value(task_wait_ms_, task_wait_ms); set_value(task_wait_ms_, value);
} }
auto app_config::set_value_by_name(const std::string &name, auto app_config::set_value_by_name(const std::string &name,

View File

@ -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()) { if (write_supported && not file_ptr->is_write_supported()) {
auto writeable_file = std::make_shared<open_file>( auto writeable_file = std::make_shared<open_file>(
utils::encryption::encrypting_reader::get_data_chunk_size(), utils::encryption::encrypting_reader::get_data_chunk_size(),
config_.get_enable_chunk_download_timeout() config_.get_enable_download_timeout()
? config_.get_chunk_downloader_timeout_secs() ? config_.get_download_timeout_secs()
: 0U, : 0U,
file_ptr->get_filesystem_item(), file_ptr->get_open_data(), provider_, file_ptr->get_filesystem_item(), file_ptr->get_open_data(), provider_,
*this); *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); return open(api_path, directory, ofd, handle, file, nullptr);
} }
auto file_manager::open(const std::string &api_path, bool directory, auto file_manager::open(
const open_file_data &ofd, std::uint64_t &handle, const std::string &api_path, bool directory, const open_file_data &ofd,
std::shared_ptr<i_open_file> &file, std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
std::shared_ptr<i_closeable_open_file> closeable_file) std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
-> api_error {
const auto create_and_add_handle = const auto create_and_add_handle =
[&](std::shared_ptr<i_closeable_open_file> cur_file) { [&](std::shared_ptr<i_closeable_open_file> cur_file) {
handle = get_next_handle(); handle = get_next_handle();
@ -406,8 +405,8 @@ auto file_manager::open(const std::string &api_path, bool directory,
if (not closeable_file) { if (not closeable_file) {
closeable_file = std::make_shared<open_file>( closeable_file = std::make_shared<open_file>(
utils::encryption::encrypting_reader::get_data_chunk_size(), utils::encryption::encrypting_reader::get_data_chunk_size(),
config_.get_enable_chunk_download_timeout() config_.get_enable_download_timeout()
? config_.get_chunk_downloader_timeout_secs() ? config_.get_download_timeout_secs()
: 0U, : 0U,
fsi, provider_, *this); 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, auto file_manager::rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite) const std::string &to_api_path,
-> api_error { bool overwrite) -> api_error {
if (not provider_.is_rename_supported()) { if (not provider_.is_rename_supported()) {
return api_error::not_implemented; return api_error::not_implemented;
} }
@ -769,10 +768,10 @@ void file_manager::start() {
continue; continue;
} }
auto closeable_file = std::make_shared<open_file>( auto closeable_file =
entry.chunk_size, std::make_shared<open_file>(entry.chunk_size,
config_.get_enable_chunk_download_timeout() config_.get_enable_download_timeout()
? config_.get_chunk_downloader_timeout_secs() ? config_.get_download_timeout_secs()
: 0U, : 0U,
fsi, provider_, entry.read_state, *this); fsi, provider_, entry.read_state, *this);
open_file_lookup_[entry.api_path] = closeable_file; open_file_lookup_[entry.api_path] = closeable_file;

View File

@ -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{}; std::uint8_t original_value{};
{ {
app_config config(provider_type::sia, sia_directory); app_config config(provider_type::sia, sia_directory);
original_value = config.get_chunk_downloader_timeout_secs(); original_value = config.get_download_timeout_secs();
config.set_chunk_downloader_timeout_secs(original_value + 5); config.set_download_timeout_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_chunk_downloader_timeout_secs()); EXPECT_EQ(original_value + 5, config.get_download_timeout_secs());
} }
{ {
app_config config(provider_type::sia, sia_directory); 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{}; bool original_value{};
{ {
app_config config(provider_type::sia, sia_directory); app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_chunk_download_timeout(); original_value = config.get_enable_download_timeout();
config.set_enable_chunk_downloader_timeout(not original_value); config.set_enable_download_timeout(not original_value);
EXPECT_EQ(not original_value, config.get_enable_chunk_download_timeout()); EXPECT_EQ(not original_value, config.get_enable_download_timeout());
} }
{ {
app_config config(provider_type::sia, sia_directory); 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());
} }
} }

View File

@ -66,7 +66,7 @@ protected:
{"file_manager_test" + std::to_string(++inst)}); {"file_manager_test" + std::to_string(++inst)});
cfg = std::make_unique<app_config>(provider_type::sia, file_manager_dir); cfg = std::make_unique<app_config>(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(); } 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) { 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)); 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) { 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)); 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) { 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)); 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) { TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
cfg->set_enable_chunk_downloader_timeout(true); cfg->set_enable_download_timeout(true);
cfg->set_chunk_downloader_timeout_secs(3U); cfg->set_download_timeout_secs(3U);
polling::instance().start(cfg.get()); 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, TEST_F(file_manager_test,
resize_greater_than_chunk_size_sets_new_chunks_to_read) { 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)); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));