Skip to content

Commit

Permalink
wip feat: provide only root, and only at the end of add
Browse files Browse the repository at this point in the history
We are still waiting for the add to complete
  • Loading branch information
rklaehn committed Oct 24, 2022
1 parent 7b0a631 commit e0f2598
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions iroh-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::p2p::MockP2p;
use crate::p2p::{ClientP2p, P2p};
use crate::{AddEvent, IpfsPath};
use anyhow::Result;
use cid::Cid;
use futures::future::{BoxFuture, LocalBoxFuture};
use futures::stream::LocalBoxStream;
use futures::FutureExt;
Expand Down Expand Up @@ -40,6 +41,8 @@ pub trait Api {

fn p2p(&self) -> Result<Self::P>;

fn provide(&self, cid: Cid) -> LocalBoxFuture<'_, Result<()>>;

/// Produces a asynchronous stream of file descriptions
/// Each description is a tuple of a relative path, and either a `Directory` or a `Reader`
/// with the file contents.
Expand Down Expand Up @@ -100,6 +103,10 @@ impl Iroh {
impl Api for Iroh {
type P = ClientP2p;

fn provide(&self, cid: Cid) -> LocalBoxFuture<'_, Result<()>> {
async move { self.client.try_p2p()?.start_providing(&cid).await }.boxed_local()
}

fn p2p(&self) -> Result<ClientP2p> {
let p2p_client = self.client.try_p2p()?;
Ok(ClientP2p::new(p2p_client))
Expand Down
5 changes: 3 additions & 2 deletions iroh-resolver/src/unixfs_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,9 @@ impl Store for StoreAndProvideClient {
}

async fn put(&self, cid: Cid, blob: Bytes, links: Vec<Cid>) -> Result<()> {
self.client.try_store()?.put(cid, blob, links).await?;
self.client.try_p2p()?.start_providing(&cid).await
self.client.try_store()?.put(cid, blob, links).await
// we provide after insertion is finished
// self.client.try_p2p()?.start_providing(&cid).await
}
}

Expand Down
7 changes: 4 additions & 3 deletions iroh/src/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use anyhow::{ensure, Result};
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use console::style;
use futures::StreamExt;
Expand Down Expand Up @@ -209,8 +209,9 @@ async fn add(api: &impl Api, path: &Path, no_wrap: bool, recursive: bool) -> Res
}
}
pb.finish_and_clear();
ensure!(root.is_some(), "File processing failed");
println!("/ipfs/{}", root.unwrap());
let root = root.context("File processing failed")?;
println!("/ipfs/{}", root);
api.provide(root).await?;

Ok(())
}

0 comments on commit e0f2598

Please sign in to comment.