Skip to content

Commit 6e9f06b

Browse files
authored
feat: modify Downloader config through Blobs builder (#75)
## Description A fix for #74 , allowing users of the Blobs protocol to once again provide configuration for the internally-used Downloader struct - both concurrency and retry options. This PR exposes them through the Blobs Builder struct. ## Notes & open questions I haven't added tests, but this seems to work fine. I probably need tests for these methods to be a good OSS citizen ;) ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [x] All breaking changes documented.
1 parent 387c68c commit 6e9f06b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/net_protocol.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
1818
use tracing::debug;
1919

2020
use crate::{
21-
downloader::Downloader,
21+
downloader::{ConcurrencyLimits, Downloader, RetryConfig},
2222
provider::EventSender,
2323
store::GcConfig,
2424
util::{
@@ -148,6 +148,8 @@ pub struct Builder<S> {
148148
store: S,
149149
events: Option<EventSender>,
150150
rt: Option<LocalPoolHandle>,
151+
concurrency_limits: Option<ConcurrencyLimits>,
152+
retry_config: Option<RetryConfig>,
151153
}
152154

153155
impl<S: crate::store::Store> Builder<S> {
@@ -157,20 +159,38 @@ impl<S: crate::store::Store> Builder<S> {
157159
self
158160
}
159161

160-
/// Set a custom `LocalPoolHandle` to use.
162+
/// Set a custom [`LocalPoolHandle`] to use.
161163
pub fn local_pool(mut self, rt: LocalPoolHandle) -> Self {
162164
self.rt = Some(rt);
163165
self
164166
}
165167

168+
/// Set custom [`ConcurrencyLimits`] to use.
169+
pub fn concurrency_limits(mut self, concurrency_limits: ConcurrencyLimits) -> Self {
170+
self.concurrency_limits = Some(concurrency_limits);
171+
self
172+
}
173+
174+
/// Set a custom [`RetryConfig`] to use.
175+
pub fn retry_config(mut self, retry_config: RetryConfig) -> Self {
176+
self.retry_config = Some(retry_config);
177+
self
178+
}
179+
166180
/// Build the Blobs protocol handler.
167181
/// You need to provide a the endpoint.
168182
pub fn build(self, endpoint: &Endpoint) -> Blobs<S> {
169183
let rt = self
170184
.rt
171185
.map(Rt::Handle)
172186
.unwrap_or_else(|| Rt::Owned(LocalPool::default()));
173-
let downloader = Downloader::new(self.store.clone(), endpoint.clone(), rt.clone());
187+
let downloader = Downloader::with_config(
188+
self.store.clone(),
189+
endpoint.clone(),
190+
rt.clone(),
191+
self.concurrency_limits.unwrap_or_default(),
192+
self.retry_config.unwrap_or_default(),
193+
);
174194
Blobs::new(
175195
self.store,
176196
rt,
@@ -188,6 +208,8 @@ impl<S> Blobs<S> {
188208
store,
189209
events: None,
190210
rt: None,
211+
concurrency_limits: None,
212+
retry_config: None,
191213
}
192214
}
193215
}

0 commit comments

Comments
 (0)