rusty-cat 0.1.3

Async HTTP client for resumable file upload and download.
Documentation
use std::time::Duration;

use crate::http_breakpoint::BreakpointDownloadHttpConfig;

#[derive(Debug, Clone)]
pub struct MeowConfig {
    max_upload_concurrency: usize,
    max_download_concurrency: usize,
    breakpoint_download_http: BreakpointDownloadHttpConfig,
    http_client: Option<reqwest::Client>,
    http_timeout: Duration,
    tcp_keepalive: Duration,
    command_queue_capacity: usize,
    worker_event_queue_capacity: usize,
}

impl Default for MeowConfig {
    fn default() -> Self {
        Self {
            max_upload_concurrency: 2,
            max_download_concurrency: 2,
            breakpoint_download_http: BreakpointDownloadHttpConfig::default(),
            http_client: None,
            http_timeout: Duration::from_secs(5),
            tcp_keepalive: Duration::from_secs(30),
            command_queue_capacity: 128,
            worker_event_queue_capacity: 256,
        }
    }
}

impl MeowConfig {
    pub fn new(max_upload_concurrency: usize, max_download_concurrency: usize) -> Self {
        Self {
            max_upload_concurrency,
            max_download_concurrency,
            breakpoint_download_http: BreakpointDownloadHttpConfig::default(),
            http_client: None,
            http_timeout: Duration::from_secs(5),
            tcp_keepalive: Duration::from_secs(30),
            command_queue_capacity: 128,
            worker_event_queue_capacity: 256,
        }
    }

    pub fn with_http_client(mut self, client: reqwest::Client) -> Self {
        self.http_client = Some(client);
        self
    }

    pub fn with_http_timeout(mut self, timeout: Duration) -> Self {
        self.http_timeout = timeout;
        self
    }

    pub fn with_tcp_keepalive(mut self, keepalive: Duration) -> Self {
        self.tcp_keepalive = keepalive;
        self
    }

    /// 这是“控制平面”的命令队列——你往里塞控制命令,worker 收到后改变调度状态。
    /// 控制/管理命令 TransferCmd 的通道数量。包括 Enqueue/Pause/Resume/Cancel/Snapshot/Close(而且 Pause/Resume/Cancel/Close/Snapshot 还带 oneshot 回执,保证调用方拿到最终结果)。
    pub fn with_command_queue_capacity(mut self, command_queue_capacity: usize) -> Self {
        self.command_queue_capacity = command_queue_capacity;
        self
    }

    /// 传输执行过程事件的通道数量
    /// 任务跑着跑着不断上报进度/完成/失败等事件WorkerEvent::{Progress, Completed, Failed, Canceled}
    pub fn with_worker_event_queue_capacity(mut self, worker_event_queue_capacity: usize) -> Self {
        self.worker_event_queue_capacity = worker_event_queue_capacity;
        self
    }

    pub fn max_upload_concurrency(&self) -> usize {
        self.max_upload_concurrency
    }

    pub fn max_download_concurrency(&self) -> usize {
        self.max_download_concurrency
    }

    pub fn breakpoint_download_http(&self) -> &BreakpointDownloadHttpConfig {
        &self.breakpoint_download_http
    }

    pub fn with_breakpoint_download_http(mut self, config: BreakpointDownloadHttpConfig) -> Self {
        self.breakpoint_download_http = config;
        self
    }

    pub fn http_timeout(&self) -> Duration {
        self.http_timeout
    }

    pub fn tcp_keepalive(&self) -> Duration {
        self.tcp_keepalive
    }

    pub(crate) fn http_client_ref(&self) -> Option<&reqwest::Client> {
        self.http_client.as_ref()
    }

    pub fn command_queue_capacity(&self) -> usize {
        self.command_queue_capacity
    }

    pub fn worker_event_queue_capacity(&self) -> usize {
        self.worker_event_queue_capacity
    }


}