p2panda_blobs/
config.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Alternative configuration API which can be passed into `Blobs::from_builder_with_config` constructor.
4use std::time::Duration;
5
6use iroh_blobs::downloader::{ConcurrencyLimits, RetryConfig};
7
8/// Configuration parameters for the blobs service.
9#[derive(Clone, Debug)]
10pub struct Config {
11    /// Maximum number of requests the service performs concurrently.
12    pub max_concurrent_requests: usize,
13    /// Maximum number of requests performed by a single node concurrently.
14    pub max_concurrent_requests_per_node: usize,
15    /// Maximum number of open connections the service maintains.
16    pub max_open_connections: usize,
17    /// Maximum number of nodes to dial concurrently for a single request.
18    pub max_concurrent_dials_per_hash: usize,
19    /// Maximum number of retry attempts for a node that failed to dial or failed with IO errors.
20    pub max_retries_per_node: u32,
21    /// The initial delay to wait before retrying a node. On subsequent failures, the retry delay
22    /// will be multiplied with the number of failed retries.
23    pub initial_retry_delay: Duration,
24}
25
26impl Default for Config {
27    fn default() -> Self {
28        let concurrency_limits = ConcurrencyLimits::default();
29        let retry_config = RetryConfig::default();
30
31        Self {
32            max_concurrent_requests: concurrency_limits.max_concurrent_requests,
33            max_concurrent_requests_per_node: concurrency_limits.max_concurrent_requests_per_node,
34            max_open_connections: concurrency_limits.max_open_connections,
35            max_concurrent_dials_per_hash: concurrency_limits.max_concurrent_dials_per_hash,
36            max_retries_per_node: retry_config.max_retries_per_node,
37            initial_retry_delay: retry_config.initial_retry_delay,
38        }
39    }
40}
41
42impl From<Config> for ConcurrencyLimits {
43    fn from(val: Config) -> Self {
44        ConcurrencyLimits {
45            max_concurrent_requests: val.max_concurrent_requests,
46            max_concurrent_requests_per_node: val.max_concurrent_requests_per_node,
47            max_open_connections: val.max_open_connections,
48            max_concurrent_dials_per_hash: val.max_concurrent_dials_per_hash,
49        }
50    }
51}
52
53impl From<Config> for RetryConfig {
54    fn from(val: Config) -> Self {
55        RetryConfig {
56            max_retries_per_node: val.max_retries_per_node,
57            initial_retry_delay: val.initial_retry_delay,
58        }
59    }
60}