Skip to content

Commit 419f8d8

Browse files
committed
Move entire multiprovider downloader into an example.
This is a bit unfortunate, but there are major refactorings coming for the store, and the current code has to fake a part of the functionality that is needed from the store. This way people can take a look at the code structure and also try it out. Once the main store changes are merged, the multiprovider downloader will move into the main crate.
1 parent 54ec3e3 commit 419f8d8

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

src/downloader2.rs renamed to examples/multiprovider/downloader2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{
2121
u64,
2222
};
2323

24-
use crate::{
24+
use iroh_blobs::{
2525
get::{
2626
fsm::{BlobContentNext, ConnectedNext, EndBlobNext},
2727
Stats,
@@ -433,7 +433,7 @@ impl<S> SimpleBitfieldSubscription<S> {
433433

434434
async fn get_valid_ranges_local<S: Store>(hash: &Hash, store: S) -> anyhow::Result<BitfieldEvent> {
435435
if let Some(entry) = store.get_mut(hash).await? {
436-
let ranges = crate::get::db::valid_ranges::<S>(&entry).await?;
436+
let ranges = iroh_blobs::get::db::valid_ranges::<S>(&entry).await?;
437437
let size = entry.size();
438438
let size = match size {
439439
size @ BaoBlobSize::Unverified(value) => {
@@ -462,8 +462,8 @@ async fn get_valid_ranges_remote(
462462
id: NodeId,
463463
hash: &Hash,
464464
) -> anyhow::Result<BitfieldEvent> {
465-
let conn = endpoint.connect(id, crate::ALPN).await?;
466-
let (size, _) = crate::get::request::get_verified_size(&conn, hash).await?;
465+
let conn = endpoint.connect(id, iroh_blobs::ALPN).await?;
466+
let (size, _) = iroh_blobs::get::request::get_verified_size(&conn, hash).await?;
467467
let chunks = (size + 1023) / 1024;
468468
let ranges = ChunkRanges::from(ChunkNum(0)..ChunkNum(chunks));
469469
Ok(BitfieldState {

src/downloader2/actor.rs renamed to examples/multiprovider/downloader2/actor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ async fn peer_download<S: Store>(
238238
start: Instant,
239239
) -> anyhow::Result<Stats> {
240240
info!("Connecting to peer {peer}");
241-
let conn = endpoint.connect(peer, crate::ALPN).await?;
241+
let conn = endpoint.connect(peer, iroh_blobs::ALPN).await?;
242242
info!("Got connection to peer {peer}");
243243
let spec = RangeSpec::new(ranges);
244244
let ranges = RangeSpecSeq::new([spec, RangeSpec::EMPTY]);
245245
info!("starting download from {peer} for {hash} {ranges:?}");
246246
let request = GetRequest::new(hash, ranges);
247-
let initial = crate::get::fsm::start(conn, request);
247+
let initial = iroh_blobs::get::fsm::start(conn, request);
248248
// connect
249249
let connected = initial.next().await?;
250250
// read the first bytes

examples/multiprovider.rs renamed to examples/multiprovider/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use bao_tree::{ChunkNum, ChunkRanges};
44
use clap::Parser;
55
use console::Term;
66
use iroh::{NodeId, SecretKey};
7+
mod downloader2;
8+
use downloader2::{
9+
print_bitmap, BitfieldEvent, BitfieldState, BitfieldUpdate, DownloadRequest, Downloader,
10+
ObserveRequest, StaticContentDiscovery,
11+
};
712
use iroh_blobs::{
8-
downloader2::{
9-
print_bitmap, BitfieldEvent, BitfieldState, BitfieldUpdate, DownloadRequest, Downloader,
10-
ObserveRequest, StaticContentDiscovery,
11-
},
1213
store::Store,
1314
Hash,
1415
};

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
pub mod cli;
3333
#[cfg(feature = "downloader")]
3434
pub mod downloader;
35-
#[cfg(feature = "downloader")]
36-
pub mod downloader2;
3735
pub mod export;
3836
pub mod format;
3937
pub mod get;

0 commit comments

Comments
 (0)