Skip to content

Commit 9b0497a

Browse files
veluca93Virv12
authored andcommitted
Use hashes of uncompressed chunks.
1 parent fd26492 commit 9b0497a

5 files changed

Lines changed: 27 additions & 5 deletions

File tree

pixie-server/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixie-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ futures = "0.3.30"
2929
tokio-stream = { version = "0.1.17", features = ["sync"] }
3030
chrono = "0.4.41"
3131
tokio-util = "0.7.15"
32+
lz4_flex = "0.11.5"
3233

3334
[dependencies.pixie-shared]
3435
path = "../pixie-shared"

pixie-server/src/state/images.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::state::{atomic_write, State, CHUNKS_DIR, IMAGES_DIR};
22
use anyhow::{ensure, Context, Result};
3-
use pixie_shared::{ChunkHash, ChunkStats, ChunksStats, Image, ImagesStats};
3+
use pixie_shared::{ChunkHash, ChunkStats, ChunksStats, Image, ImagesStats, MAX_CHUNK_SIZE};
44
use tokio::sync::watch;
55

66
impl State {
@@ -29,7 +29,13 @@ impl State {
2929
/// Store the given chunk to the database.
3030
pub fn add_chunk(&self, data: &[u8]) -> Result<()> {
3131
let mut res = Ok(());
32-
let hash = *blake3::hash(data).as_bytes();
32+
let dec = lz4_flex::decompress(data, MAX_CHUNK_SIZE)?;
33+
ensure!(
34+
dec.len() <= MAX_CHUNK_SIZE,
35+
"Decompressed chunk size is too big: {}",
36+
dec.len()
37+
);
38+
let hash = *blake3::hash(&dec).as_bytes();
3339
let path = self.storage_dir.join(CHUNKS_DIR).join(hex::encode(hash));
3440
self.images_stats.send_if_modified(|images_stats| {
3541
res = (|| {

pixie-uefi/src/flash.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> {
198198
let mut buf = vec![0; size];
199199
for &offset in &pos {
200200
disk.read(offset as u64, &mut buf).await.unwrap();
201-
let cdata = lz4_flex::compress(&buf);
202-
if blake3::hash(&cdata).as_bytes() == &hash {
201+
if blake3::hash(&buf).as_bytes() == &hash {
203202
found = Some(offset);
204203
break;
205204
}

pixie-uefi/src/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub async fn store(os: UefiOS, server_address: SocketAddrV4) -> Result<()> {
113113
let mut data = vec![0; chunk_info.size];
114114
disk.read(chunk_info.start as u64, &mut data).await?;
115115
let cdata = compress(&data);
116-
let hash = blake3::hash(&cdata).into();
116+
let hash = blake3::hash(&data).into();
117117
let chunk = Chunk {
118118
hash,
119119
start: chunk_info.start,

0 commit comments

Comments
 (0)