summary refs log tree commit diff
path: root/ripple/fossil/src
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r--ripple/fossil/src/lib.rs53
-rw-r--r--ripple/fossil/src/store.proto1
2 files changed, 26 insertions, 28 deletions
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs
index 8c182eb..4c747e8 100644
--- a/ripple/fossil/src/lib.rs
+++ b/ripple/fossil/src/lib.rs
@@ -108,10 +108,11 @@ impl Store {
 	}
 
 	fn write_blob(&self, data: &[u8]) -> Digest {
-		let ident = {
-			let mut h = blake3::Hasher::new();
-			h.update_rayon(data);
-			h.finalize()
+		let mut outboard = Vec::new();
+		let ident: blake3::Hash = {
+			let mut encoder = bao::encode::Encoder::new_outboard(io::Cursor::new(&mut outboard));
+			encoder.write_all(&data).unwrap();
+			encoder.finalize().unwrap()
 		};
 
 		if self.db.contains_key(&*ident.as_bytes()).unwrap() {
@@ -132,6 +133,7 @@ impl Store {
 		let blob_buf = store::Blob {
 			offset,
 			length: data.len() as u64,
+			bao_inline: outboard,
 		}
 		.encode_to_vec();
 
@@ -155,37 +157,32 @@ impl Store {
 	}
 
 	pub fn read_blob(&self, ident: Digest) -> Vec<u8> {
-		let mut buffer = Vec::new();
-		self.raw_blob(ident).read_to_end(&mut buffer).unwrap();
-
-		let mut outboard = Vec::new();
-		let computed_ident: blake3::Hash = {
-			let mut encoder = bao::encode::Encoder::new_outboard(io::Cursor::new(&mut outboard));
-			encoder.write_all(&buffer).unwrap();
-			encoder.finalize().unwrap()
-		};
-
-		if computed_ident != ident {
-			panic!("hash mismatch");
-		}
-
-		buffer
-	}
-
-	fn raw_blob(&self, ident: Digest) -> RawBlob<'_> {
 		let buf = self
 			.db
 			.get(&*ident.as_bytes())
 			.unwrap()
 			.expect("blob not found");
 
-		let store::Blob { offset, length } = store::Blob::decode(&*buf).unwrap();
+		let store::Blob {
+			offset,
+			length,
+			bao_inline,
+		} = store::Blob::decode(&*buf).unwrap();
+
+		let mut blob = bao::decode::Decoder::new_outboard(
+			RawBlob {
+				store: self,
+				slice: Slice { offset, length },
+				position: 0,
+			},
+			io::Cursor::new(bao_inline),
+			&ident,
+		);
+
+		let mut buffer = Vec::new();
+		blob.read_to_end(&mut buffer).unwrap();
 
-		RawBlob {
-			store: self,
-			slice: Slice { offset, length },
-			position: 0,
-		}
+		buffer
 	}
 }
 
diff --git a/ripple/fossil/src/store.proto b/ripple/fossil/src/store.proto
index cbbbbf1..cbeb16d 100644
--- a/ripple/fossil/src/store.proto
+++ b/ripple/fossil/src/store.proto
@@ -32,4 +32,5 @@ message LinkNode {
 message Blob {
     uint64 offset = 1;
     uint64 length = 2;
+    bytes bao_inline = 3;
 }