Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions iroh-s3-bao-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust-version = "1.75"

[dependencies]
anyhow = "1.0.75"
bao-tree = "0.11"
bao-tree = "0.13"
base32 = "0.4.0"
bytes = "1.5.0"
clap = { version = "4.4.10", features = ["derive"] }
Expand All @@ -21,8 +21,8 @@ flume = "0.11.0"
futures = "0.3.29"
hex = "0.4.3"
indicatif = "0.17.7"
iroh = "0.13"
iroh-io = { version = "0.4.0", features = ["x-http"] }
iroh = "0.14"
iroh-io = { version = "0.6.0", features = ["x-http"] }
num_cpus = "1.16.0"
rand = "0.8.5"
redb = "1.5.0"
Expand Down
42 changes: 27 additions & 15 deletions iroh-s3-bao-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::io;
use std::sync::{Arc, Mutex};

use bao_tree::io::fsm::Outboard;
use bao_tree::io::outboard::PreOrderMemOutboard;
use bao_tree::{BaoTree, ByteNum};
use bao_tree::io::outboard::{PostOrderMemOutboard, PreOrderMemOutboard};
use bao_tree::BaoTree;
use bytes::Bytes;
use iroh::bytes::store::bao_tree::blake3;
use iroh::bytes::store::{BaoBlobSize, MapEntry};
Expand All @@ -24,11 +24,17 @@ struct Inner {
impl S3Store {
pub async fn import_mem(&self, data: Bytes) -> anyhow::Result<Hash> {
let size = data.as_ref().len() as u64;
let (mut outboard, hash) = bao_tree::io::outboard(&data, IROH_BLOCK_SIZE);
outboard.splice(0..8, []);
let tree = BaoTree::new(ByteNum(size), IROH_BLOCK_SIZE);
let outboard = PreOrderMemOutboard::new(hash, tree, outboard.into())
.map_err(|e| anyhow::anyhow!("outboard creation fail {}", e))?;
let (outboard, hash) = {
let outboard = PostOrderMemOutboard::create(&data, IROH_BLOCK_SIZE).flip();
let hash = outboard.root;
(outboard.data, hash)
};
let tree = BaoTree::new(size, IROH_BLOCK_SIZE);
let outboard = PreOrderMemOutboard {
root: hash,
tree,
data: outboard.into(),
};
let mut state = self.0.entries.lock().unwrap();
state.insert(
hash,
Expand All @@ -41,11 +47,17 @@ impl S3Store {
let mut http_adapter = HttpAdapter::new(url.clone());
let data = http_adapter.read_to_end().await?;
let size = data.len() as u64;
let (mut outboard, hash) = bao_tree::io::outboard(data, IROH_BLOCK_SIZE);
outboard.splice(0..8, []);
let tree = BaoTree::new(ByteNum(size), IROH_BLOCK_SIZE);
let outboard = PreOrderMemOutboard::new(hash, tree, outboard.into())
.map_err(|e| anyhow::anyhow!("outboard creation fail {}", e))?;
let (outboard, hash) = {
let outboard = PostOrderMemOutboard::create(data, IROH_BLOCK_SIZE).flip();
let hash = outboard.root;
(outboard.data, hash)
};
let tree = BaoTree::new(size, IROH_BLOCK_SIZE);
let outboard = PreOrderMemOutboard {
root: hash,
tree,
data: outboard.into(),
};
let mut state = self.0.entries.lock().unwrap();
state.insert(
hash,
Expand Down Expand Up @@ -133,10 +145,10 @@ impl AsyncSliceReader for File {
}
}

async fn len(&mut self) -> io::Result<u64> {
async fn size(&mut self) -> io::Result<u64> {
match self {
Self::S3(s3) => s3.len().await,
Self::Inline(bytes) => bytes.len().await,
Self::S3(s3) => s3.size().await,
Self::Inline(bytes) => bytes.size().await,
}
}
}
Expand Down