wip on error correction
This commit is contained in:
parent
a413879cf7
commit
c6e34c5756
5 changed files with 16 additions and 29 deletions
|
@ -3,7 +3,7 @@ sources:
|
||||||
- git@git.sr.ht:~cyplo/bakare
|
- git@git.sr.ht:~cyplo/bakare
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
- b7161fff-05f4-4470-b4a1-57bd67dede23
|
- 6c23a8c1-7a30-4a7e-b3b7-0171e898a7d3
|
||||||
- 996295b0-681c-49e8-8774-1be2f3e0bfe9
|
- 996295b0-681c-49e8-8774-1be2f3e0bfe9
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -41,7 +41,7 @@ dependencies = [
|
||||||
"proptest",
|
"proptest",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
"rayon",
|
"rayon",
|
||||||
"reed-solomon-erasure",
|
"reed-solomon",
|
||||||
"rust-crypto",
|
"rust-crypto",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_cbor",
|
"serde_cbor",
|
||||||
|
@ -642,15 +642,10 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reed-solomon-erasure"
|
name = "reed-solomon"
|
||||||
version = "4.0.2"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d"
|
checksum = "13de68c877a77f35885442ac72c8beb7c2f0b09380c43b734b9d63d1db69ee54"
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
|
@ -773,12 +768,6 @@ dependencies = [
|
||||||
"opaque-debug",
|
"opaque-debug",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smallvec"
|
|
||||||
version = "1.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.60"
|
version = "1.0.60"
|
||||||
|
|
|
@ -19,7 +19,7 @@ log = "0.4"
|
||||||
nix = "0.19"
|
nix = "0.19"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
rayon = "1.5"
|
rayon = "1.5"
|
||||||
reed-solomon-erasure = { version = "4.0", features = ["simd-accel"] }
|
reed-solomon = "0.2"
|
||||||
rust-crypto = "0.2"
|
rust-crypto = "0.2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_cbor = "0.11"
|
serde_cbor = "0.11"
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl Index {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut file = index_file_path.create_file()?;
|
let mut file = index_file_path.create_file()?;
|
||||||
file.write_all(encoded).context("writing index to disk")?;
|
file.write_all(&encoded).context("writing index to disk")?;
|
||||||
file.flush()?;
|
file.flush()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use reed_solomon::Encoder;
|
||||||
|
|
||||||
pub fn encode(bytes: &[u8]) -> Result<&[u8]> {
|
const ECC_LENGTH: usize = 8;
|
||||||
// find number of shards and parity blocks
|
|
||||||
// encode checksum with each block
|
|
||||||
// when decoding, remove blocks with invalid checksum
|
|
||||||
|
|
||||||
Ok(bytes)
|
pub fn encode(bytes: &[u8]) -> Result<Vec<u8>> {
|
||||||
|
let encoder = Encoder::new(ECC_LENGTH);
|
||||||
|
let encoded = encoder.encode(bytes);
|
||||||
|
Ok(encoded.bytes().collect::<Result<Vec<u8>, _>>()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(bytes: &[u8]) -> Result<&[u8]> {
|
pub fn decode(bytes: &[u8]) -> Result<&[u8]> {
|
||||||
// find number of shards and parity blocks
|
|
||||||
// encode checksum with each block
|
|
||||||
// when decoding, remove blocks with invalid checksum
|
|
||||||
|
|
||||||
Ok(bytes)
|
Ok(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +19,6 @@ mod must {
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use rand::{thread_rng, Rng, RngCore};
|
use rand::{thread_rng, Rng, RngCore};
|
||||||
use vfs::{MemoryFS, VfsPath};
|
|
||||||
|
|
||||||
use super::{decode, encode};
|
use super::{decode, encode};
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ mod must {
|
||||||
let corrupt_byte_index = rand::thread_rng().gen_range::<usize, _>(0..size);
|
let corrupt_byte_index = rand::thread_rng().gen_range::<usize, _>(0..size);
|
||||||
|
|
||||||
let mut corrupted: [u8; 32] = [0; 32];
|
let mut corrupted: [u8; 32] = [0; 32];
|
||||||
corrupted.copy_from_slice(encoded);
|
corrupted.copy_from_slice(&encoded);
|
||||||
corrupted[corrupt_byte_index] = rand::thread_rng().gen::<u8>();
|
corrupted[corrupt_byte_index] = rand::thread_rng().gen::<u8>();
|
||||||
|
|
||||||
let decoded = decode(&corrupted)?;
|
let decoded = decode(&corrupted)?;
|
||||||
|
|
Loading…
Reference in a new issue