Skip to content

Commit 1c1369e

Browse files
upgrade s3-bao-store to irohv0.14.0 (#45)
* update example as done in bao-tree#5ee6d9169109bb9003f7c9e32201c916602532c8 * Do not add and then remove size prefix... --------- Co-authored-by: Ruediger Klaehn <rklaehn@protonmail.com>
1 parent 67871e3 commit 1c1369e

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

iroh-s3-bao-store/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version = "1.75"
1212

1313
[dependencies]
1414
anyhow = "1.0.75"
15-
bao-tree = "0.11"
15+
bao-tree = "0.13"
1616
base32 = "0.4.0"
1717
bytes = "1.5.0"
1818
clap = { version = "4.4.10", features = ["derive"] }
@@ -21,8 +21,8 @@ flume = "0.11.0"
2121
futures = "0.3.29"
2222
hex = "0.4.3"
2323
indicatif = "0.17.7"
24-
iroh = "0.13"
25-
iroh-io = { version = "0.4.0", features = ["x-http"] }
24+
iroh = "0.14"
25+
iroh-io = { version = "0.6.0", features = ["x-http"] }
2626
num_cpus = "1.16.0"
2727
rand = "0.8.5"
2828
redb = "1.5.0"

iroh-s3-bao-store/src/lib.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::io;
33
use std::sync::{Arc, Mutex};
44

55
use bao_tree::io::fsm::Outboard;
6-
use bao_tree::io::outboard::PreOrderMemOutboard;
7-
use bao_tree::{BaoTree, ByteNum};
6+
use bao_tree::io::outboard::{PostOrderMemOutboard, PreOrderMemOutboard};
7+
use bao_tree::BaoTree;
88
use bytes::Bytes;
99
use iroh::bytes::store::bao_tree::blake3;
1010
use iroh::bytes::store::{BaoBlobSize, MapEntry};
@@ -24,11 +24,17 @@ struct Inner {
2424
impl S3Store {
2525
pub async fn import_mem(&self, data: Bytes) -> anyhow::Result<Hash> {
2626
let size = data.as_ref().len() as u64;
27-
let (mut outboard, hash) = bao_tree::io::outboard(&data, IROH_BLOCK_SIZE);
28-
outboard.splice(0..8, []);
29-
let tree = BaoTree::new(ByteNum(size), IROH_BLOCK_SIZE);
30-
let outboard = PreOrderMemOutboard::new(hash, tree, outboard.into())
31-
.map_err(|e| anyhow::anyhow!("outboard creation fail {}", e))?;
27+
let (outboard, hash) = {
28+
let outboard = PostOrderMemOutboard::create(&data, IROH_BLOCK_SIZE).flip();
29+
let hash = outboard.root;
30+
(outboard.data, hash)
31+
};
32+
let tree = BaoTree::new(size, IROH_BLOCK_SIZE);
33+
let outboard = PreOrderMemOutboard {
34+
root: hash,
35+
tree,
36+
data: outboard.into(),
37+
};
3238
let mut state = self.0.entries.lock().unwrap();
3339
state.insert(
3440
hash,
@@ -41,11 +47,17 @@ impl S3Store {
4147
let mut http_adapter = HttpAdapter::new(url.clone());
4248
let data = http_adapter.read_to_end().await?;
4349
let size = data.len() as u64;
44-
let (mut outboard, hash) = bao_tree::io::outboard(data, IROH_BLOCK_SIZE);
45-
outboard.splice(0..8, []);
46-
let tree = BaoTree::new(ByteNum(size), IROH_BLOCK_SIZE);
47-
let outboard = PreOrderMemOutboard::new(hash, tree, outboard.into())
48-
.map_err(|e| anyhow::anyhow!("outboard creation fail {}", e))?;
50+
let (outboard, hash) = {
51+
let outboard = PostOrderMemOutboard::create(data, IROH_BLOCK_SIZE).flip();
52+
let hash = outboard.root;
53+
(outboard.data, hash)
54+
};
55+
let tree = BaoTree::new(size, IROH_BLOCK_SIZE);
56+
let outboard = PreOrderMemOutboard {
57+
root: hash,
58+
tree,
59+
data: outboard.into(),
60+
};
4961
let mut state = self.0.entries.lock().unwrap();
5062
state.insert(
5163
hash,
@@ -133,10 +145,10 @@ impl AsyncSliceReader for File {
133145
}
134146
}
135147

136-
async fn len(&mut self) -> io::Result<u64> {
148+
async fn size(&mut self) -> io::Result<u64> {
137149
match self {
138-
Self::S3(s3) => s3.len().await,
139-
Self::Inline(bytes) => bytes.len().await,
150+
Self::S3(s3) => s3.size().await,
151+
Self::Inline(bytes) => bytes.size().await,
140152
}
141153
}
142154
}

0 commit comments

Comments
 (0)