diff --git a/Cargo.toml b/Cargo.toml index e5b7f1c..faa1847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ libipld = "0.16" libipld-core = "0.16" serde_ipld_dagcbor = "0.4" wnfs-common = { version = "0.2.0" } +wnfs-unixfs-file = { version = "0.2.0" } # See https://doc.rust-lang.org/cargo/reference/profiles.html for more info. [profile.release.package.car-mirror-wasm] diff --git a/car-mirror-reqwest/integration/axum.rs b/car-mirror-reqwest/integration/axum.rs index 148fa1f..b43b18d 100644 --- a/car-mirror-reqwest/integration/axum.rs +++ b/car-mirror-reqwest/integration/axum.rs @@ -28,7 +28,8 @@ async fn main() -> Result<()> { .route("/dag/push/:cid", post(car_mirror_push)) .with_state(ServerState::new()); - let listener = tokio::net::TcpListener::bind("0.0.0.0:3344").await?; + let listener = tokio::net::TcpListener::bind("0.0.0.0:0").await?; + let port = listener.local_addr()?.port(); tokio::spawn(axum::serve(listener, app).into_future()); // You can issue requests from your client like so: @@ -40,13 +41,13 @@ async fn main() -> Result<()> { let client = Client::new(); client - .post(format!("http://localhost:3344/dag/push/{root}")) + .post(format!("http://localhost:{port}/dag/push/{root}")) .run_car_mirror_push(root, &store, &NoCache) // rounds of push protocol .await?; let store = MemoryBlockStore::new(); // clear out data client - .get(format!("http://localhost:3344/dag/pull/{root}")) + .get(format!("http://localhost:{port}/dag/pull/{root}")) .run_car_mirror_pull(root, config, &store, &NoCache) // rounds of pull protocol .await?; diff --git a/car-mirror/src/lib.rs b/car-mirror/src/lib.rs index f70c14d..377d517 100644 --- a/car-mirror/src/lib.rs +++ b/car-mirror/src/lib.rs @@ -64,22 +64,19 @@ pub mod messages; /// let client_cache = InMemoryCache::new(100_000); /// let server_cache = InMemoryCache::new(100_000); /// -/// let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// // At time of writing, Cargo.lock is 86KB, so this ends u ~8MB +/// let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// /// // Load some data onto the client /// let root = FileBuilder::new() /// .content_bytes(file_bytes.clone()) -/// .fixed_chunker(1024) // Generate lots of small blocks -/// .degree(4) /// .build()? /// .store(&client_store) /// .await?; /// /// // The server may already have a subset of the data /// FileBuilder::new() -/// .content_bytes(file_bytes[0..10_000].to_vec()) -/// .fixed_chunker(1024) // Generate lots of small blocks -/// .degree(4) +/// .content_bytes(file_bytes[0..1_000_000].to_vec()) /// .build()? /// .store(&server_store) /// .await?; @@ -107,20 +104,16 @@ pub mod messages; /// # let client_cache = InMemoryCache::new(100_000); /// # let server_cache = InMemoryCache::new(100_000); /// # -/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// # /// # let root = FileBuilder::new() /// # .content_bytes(file_bytes.clone()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) /// # .build()? /// # .store(&client_store) /// # .await?; /// # /// # FileBuilder::new() -/// # .content_bytes(file_bytes[0..10_000].to_vec()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) +/// # .content_bytes(file_bytes[0..1_000_000].to_vec()) /// # .build()? /// # .store(&server_store) /// # .await?; @@ -182,20 +175,16 @@ pub mod messages; /// # let client_cache = InMemoryCache::new(100_000); /// # let server_cache = InMemoryCache::new(100_000); /// # -/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// # /// # let root = FileBuilder::new() /// # .content_bytes(file_bytes.clone()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) /// # .build()? /// # .store(&client_store) /// # .await?; /// # /// # FileBuilder::new() -/// # .content_bytes(file_bytes[0..10_000].to_vec()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) +/// # .content_bytes(file_bytes[0..1_000_000].to_vec()) /// # .build()? /// # .store(&server_store) /// # .await?; @@ -260,22 +249,18 @@ pub mod pull; /// let client_cache = InMemoryCache::new(100_000); /// let server_cache = InMemoryCache::new(100_000); /// -/// let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// /// // Load some data onto the client /// let root = FileBuilder::new() /// .content_bytes(file_bytes.clone()) -/// .fixed_chunker(1024) // Generate lots of small blocks -/// .degree(4) /// .build()? /// .store(&client_store) /// .await?; /// /// // The server may already have a subset of the data /// FileBuilder::new() -/// .content_bytes(file_bytes[0..10_000].to_vec()) -/// .fixed_chunker(1024) // Generate lots of small blocks -/// .degree(4) +/// .content_bytes(file_bytes[0..1_000_000].to_vec()) /// .build()? /// .store(&server_store) /// .await?; @@ -303,20 +288,16 @@ pub mod pull; /// # let client_cache = InMemoryCache::new(100_000); /// # let server_cache = InMemoryCache::new(100_000); /// # -/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// # /// # let root = FileBuilder::new() /// # .content_bytes(file_bytes.clone()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) /// # .build()? /// # .store(&client_store) /// # .await?; /// # /// # FileBuilder::new() -/// # .content_bytes(file_bytes[0..10_000].to_vec()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) +/// # .content_bytes(file_bytes[0..1_000_000].to_vec()) /// # .build()? /// # .store(&server_store) /// # .await?; @@ -378,20 +359,16 @@ pub mod pull; /// # let client_cache = InMemoryCache::new(100_000); /// # let server_cache = InMemoryCache::new(100_000); /// # -/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?; +/// # let file_bytes = async_std::fs::read("../Cargo.lock").await?.repeat(100); /// # /// # let root = FileBuilder::new() /// # .content_bytes(file_bytes.clone()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) /// # .build()? /// # .store(&client_store) /// # .await?; /// # /// # FileBuilder::new() -/// # .content_bytes(file_bytes[0..10_000].to_vec()) -/// # .fixed_chunker(1024) // Generate lots of small blocks -/// # .degree(4) +/// # .content_bytes(file_bytes[0..1_000_000].to_vec()) /// # .build()? /// # .store(&server_store) /// # .await?;