Skip to content

Commit

Permalink
feat: Add RepoGetBlock and RepoGetBlocks (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Sep 29, 2024
1 parent 3b77f91 commit e2e5038
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 144 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- refactor: bump msrv to 1.80
- refactor: Add custom error for ipns, added `Borrow<Cid>`, `Borrow<IpfsPath>` and `Into<IpfsPath>` to different function signatures. [PR 309](https://github.com/dariusc93/rust-ipfs/pull/309)
- refactor: deprecate `{BlockStore, DataStore}::open`
- feat: Add RepoGetBlock and RepoGetBlocks.

# 0.11.21
- chore: Put libp2p-webrtc-websys behind feature.
Expand Down
12 changes: 10 additions & 2 deletions src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ impl IpldDag {
loop {
let block = match self
.repo
._get_block(&current, providers, local_only, timeout)
.get_block(current)
.providers(providers)
.set_local(local_only)
.timeout(timeout)
.await
{
Ok(block) => block,
Expand Down Expand Up @@ -414,7 +417,12 @@ impl IpldDag {
loop {
let (next, _) = lookup.pending_links();

let block = self.repo.get_block(next, providers, local_only).await?;
let block = self
.repo
.get_block(next)
.providers(providers)
.set_local(local_only)
.await?;

match lookup.continue_walk(block.data(), cache)? {
NeedToLoadMore(next) => lookup = next,
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,11 +1111,8 @@ impl Ipfs {

/// Retrieves a block from the local blockstore, or starts fetching from the network or join an
/// already started fetch.
pub async fn get_block<C: Borrow<Cid>>(&self, cid: C) -> Result<Block, Error> {
self.repo
.get_block(cid, &[], false)
.instrument(self.span.clone())
.await
pub fn get_block<C: Borrow<Cid>>(&self, cid: C) -> RepoGetBlock {
self.repo.get_block(cid).span(self.span.clone())
}

/// Remove block from the ipfs repo. A pinned block cannot be removed.
Expand Down Expand Up @@ -2588,6 +2585,7 @@ pub(crate) fn to_dht_key<B: AsRef<str>, F: Fn(&str) -> anyhow::Result<Key>>(
}

use crate::p2p::AddressBookConfig;
use crate::repo::RepoGetBlock;
#[doc(hidden)]
pub use node::Node;

Expand Down
2 changes: 1 addition & 1 deletion src/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
let borrowed = repo.borrow();

let block = if download_blocks {
match borrowed._get_block(&cid, &providers, !download_blocks, timeout).await {
match borrowed.get_block(&cid).providers(&providers).set_local(!download_blocks).timeout(timeout).await {
Ok(block) => block,
Err(e) => {
warn!("failed to load {}, linked from {}: {}", cid, source, e);
Expand Down
Loading

0 comments on commit e2e5038

Please sign in to comment.