-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A PATCH endpoint for the content-addressable store (#67)
`utils::diffs::make_patch()` and `utils::diffs::make_patch()` now exist to make compressed binary patches. The intended use case is to send executable deltas around instead of full payloads. These use the new dependency [qbsdiff](https://lib.rs/crates/qbsdiff) to generate and apply compressed binary patches. Implemented `PATCH /v1/storage/data/*address` using the `apply_patch()` function. It's up to you to generate the patch that gets applied somehow. (qbsdiff has command-line tools for this.) Renamed some storage functions to make it clear that they return streams, to distinguish them from ones that return vecs of u8.
- Loading branch information
Showing
12 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::io::Cursor; | ||
|
||
use qbsdiff::{Bsdiff, Bspatch}; | ||
|
||
use crate::errors::ServalResult; | ||
|
||
pub fn make_patch(source: &[u8], target: &[u8]) -> ServalResult<Vec<u8>> { | ||
let mut patch = Vec::new(); | ||
Bsdiff::new(source, target).compare(Cursor::new(&mut patch))?; | ||
Ok(patch) | ||
} | ||
|
||
pub fn apply_patch(source: &[u8], patch: &[u8]) -> ServalResult<Vec<u8>> { | ||
let patcher = Bspatch::new(patch)?; | ||
let mut target = Vec::with_capacity(patcher.hint_target_size() as usize); | ||
patcher.apply(source, Cursor::new(&mut target))?; | ||
Ok(target) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs::File; | ||
use std::io::{BufReader, Read}; | ||
|
||
use ssri::Integrity; | ||
|
||
use super::{apply_patch, make_patch}; | ||
|
||
#[test] | ||
fn patch_integrity() { | ||
// verify that our patcher does what it promises. | ||
let mut version1: Vec<u8> = Vec::new(); | ||
let file = File::open("./tests/fixtures/serval-facts-1.wasm").expect("fixture 1 missing!"); | ||
let mut reader = BufReader::new(file); | ||
reader | ||
.read_to_end(&mut version1) | ||
.expect("fixture should be readable"); | ||
|
||
let mut version2: Vec<u8> = Vec::new(); | ||
let file = File::open("./tests/fixtures/serval-facts-2.wasm").expect("fixture 2 missing!"); | ||
let mut reader = BufReader::new(file); | ||
reader | ||
.read_to_end(&mut version2) | ||
.expect("fixture should be readable"); | ||
|
||
let patch = make_patch(&version1, &version2).expect("creating the patch failed!"); | ||
let patched = apply_patch(&version1, &patch).expect("applying the patch failed!"); | ||
|
||
let source_sri = Integrity::from(version2); | ||
let patched_sri = Integrity::from(patched); | ||
assert_eq!(source_sri, patched_sri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod diffs; | ||
pub mod errors; | ||
pub mod futures; | ||
pub mod mesh; | ||
|
Binary file not shown.
Binary file not shown.