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
|
||||
|
||||
secrets:
|
||||
- b7161fff-05f4-4470-b4a1-57bd67dede23
|
||||
- 6c23a8c1-7a30-4a7e-b3b7-0171e898a7d3
|
||||
- 996295b0-681c-49e8-8774-1be2f3e0bfe9
|
||||
|
||||
environment:
|
||||
|
|
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -41,7 +41,7 @@ dependencies = [
|
|||
"proptest",
|
||||
"rand 0.8.3",
|
||||
"rayon",
|
||||
"reed-solomon-erasure",
|
||||
"reed-solomon",
|
||||
"rust-crypto",
|
||||
"serde",
|
||||
"serde_cbor",
|
||||
|
@ -642,15 +642,10 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "reed-solomon-erasure"
|
||||
version = "4.0.2"
|
||||
name = "reed-solomon"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"smallvec",
|
||||
]
|
||||
checksum = "13de68c877a77f35885442ac72c8beb7c2f0b09380c43b734b9d63d1db69ee54"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
|
@ -773,12 +768,6 @@ dependencies = [
|
|||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
|
|
|
@ -19,7 +19,7 @@ log = "0.4"
|
|||
nix = "0.19"
|
||||
rand = "0.8"
|
||||
rayon = "1.5"
|
||||
reed-solomon-erasure = { version = "4.0", features = ["simd-accel"] }
|
||||
reed-solomon = "0.2"
|
||||
rust-crypto = "0.2"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_cbor = "0.11"
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Index {
|
|||
|
||||
{
|
||||
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()?;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
use std::io::Read;
|
||||
|
||||
use anyhow::Result;
|
||||
use reed_solomon::Encoder;
|
||||
|
||||
pub fn encode(bytes: &[u8]) -> Result<&[u8]> {
|
||||
// find number of shards and parity blocks
|
||||
// encode checksum with each block
|
||||
// when decoding, remove blocks with invalid checksum
|
||||
const ECC_LENGTH: usize = 8;
|
||||
|
||||
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]> {
|
||||
// find number of shards and parity blocks
|
||||
// encode checksum with each block
|
||||
// when decoding, remove blocks with invalid checksum
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
|
@ -20,7 +19,6 @@ mod must {
|
|||
|
||||
use anyhow::Result;
|
||||
use rand::{thread_rng, Rng, RngCore};
|
||||
use vfs::{MemoryFS, VfsPath};
|
||||
|
||||
use super::{decode, encode};
|
||||
|
||||
|
@ -35,7 +33,7 @@ mod must {
|
|||
let corrupt_byte_index = rand::thread_rng().gen_range::<usize, _>(0..size);
|
||||
|
||||
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>();
|
||||
|
||||
let decoded = decode(&corrupted)?;
|
||||
|
|
Loading…
Reference in a new issue