Skip to content

Commit 7bc2d34

Browse files
committed
WIP
1 parent 4645452 commit 7bc2d34

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

examples/transfer-collection.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use anyhow::Result;
2+
use iroh::{protocol::Router, Endpoint};
3+
use iroh_blobs::{
4+
api::{blobs::Blobs, Store},
5+
format::collection::Collection,
6+
hashseq::HashSeq,
7+
store::mem::MemStore,
8+
BlobsProtocol, Hash,
9+
};
10+
11+
struct Node {
12+
store: Store,
13+
blobs: Blobs,
14+
router: Router,
15+
}
16+
17+
impl Node {
18+
async fn new() -> Result<Self> {
19+
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
20+
21+
// We initialize an in-memory backing store for iroh-blobs
22+
let store = MemStore::new();
23+
// Then we initialize a struct that can accept blobs requests over iroh connections
24+
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
25+
26+
let router = Router::builder(endpoint)
27+
.accept(iroh_blobs::ALPN, blobs.clone())
28+
.spawn();
29+
30+
Ok(Self {
31+
store,
32+
blobs: blobs.blobs().clone(),
33+
router,
34+
})
35+
}
36+
37+
async fn list_hashes(&self) -> Result<Vec<Hash>> {
38+
todo!();
39+
}
40+
41+
async fn create_collection(&self) -> Result<Hash> {
42+
let tx = self.store.batch().await?;
43+
let a = tx.add_slice(b"a").await?;
44+
let b = tx.add_slice(b"b").await?;
45+
let c = tx.add_slice(b"c").await?;
46+
47+
let collection = Collection::from_iter([
48+
("a", a.hash().clone()),
49+
("b", b.hash().clone()),
50+
("c", c.hash().clone()),
51+
]);
52+
53+
let collection = collection.store(&self.store).await?;
54+
let tag = self.store.tags().create(collection).await?;
55+
Ok(tag.hash())
56+
}
57+
58+
async fn get_collection(&self, hash: Hash) -> Result<()> {
59+
todo!();
60+
}
61+
}
62+
63+
#[tokio::main]
64+
async fn main() -> anyhow::Result<()> {
65+
let send_node = Node::new().await?;
66+
let hash = send_node.create_collection().await?;
67+
68+
let recv_node = Node::new().await?;
69+
recv_node.get_collection(hash).await?;
70+
71+
let send_hashes = send_node.list_hashes().await?;
72+
let recv_hashes = recv_node.list_hashes().await?;
73+
assert_eq!(send_hashes, recv_hashes);
74+
75+
Ok(())
76+
}

src/api/blobs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub struct AddPathOptions {
620620
/// stream directly can be inconvenient, so this struct provides some convenience
621621
/// methods to work with the result.
622622
///
623-
/// It also implements [`IntoFuture`], so you can await it to get the [`TempTag`] that
623+
/// It also implements [`IntoFuture`], so you can await it to get the [`TagInfo`] that
624624
/// contains the hash of the added content and also protects the content.
625625
///
626626
/// If you want access to the stream, you can use the [`AddProgress::stream`] method.

0 commit comments

Comments
 (0)