-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wp/ updated delete file to use pk as filename #33
base: main
Are you sure you want to change the base?
Changes from 48 commits
25eef4c
61b2edc
eddf0d5
07e5283
227ed37
7d85f6b
e148dd9
8f30773
767156c
f02bc40
ab317e4
908e39d
5f6c4c2
ba92b5d
684bb7c
fc8634e
29a31b4
e50a2d5
6b77b22
657c120
50dc264
dedb85d
13134f7
2f2e403
cbf7e9b
990420d
eff5232
d32eeca
5b9a950
91ae1b9
30f7878
a7fc00a
01ba0f7
8e88ead
9e3a446
8849101
ea0c994
4629aa2
3e9949d
d1f9216
961f663
730f208
7188500
7db7d4d
4e21025
642acb4
8637f02
04d53bf
04ef77f
dd5fa8c
c675bd0
18fc5df
f651742
c4329ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file still needs to be removed. You need to add that to your global gitignore (no need to add it to the project gitignore.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added the (global) .gitignore for Mac There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ran |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not add this file, please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file does not appear to be used, and besides, it's in the wrong place. Please remove this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed, not used for testing at this anymore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod fs; | ||
// pub mod task; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
use std::{ | ||
fs::{self, OpenOptions}, | ||
io::{self, Read, Seek, Write}, | ||
path::{Path, PathBuf}, | ||
io::{Read, Seek, Write}, | ||
pin::Pin, | ||
str::FromStr, | ||
sync::Arc, | ||
}; | ||
|
||
|
@@ -134,6 +134,7 @@ pub fn write_segment(sk: &[u8], pk: &[u8], encoded: &Encoded) -> Result<BaoHash> | |
|
||
pub fn write_catalog(file_hash: &Blake3Hash, segment_hashes: &[BaoHash]) -> Result<()> { | ||
debug!("Write catalog"); | ||
|
||
let contents: Vec<u8> = segment_hashes | ||
.iter() | ||
.flat_map(|bao_hash| bao_hash.to_bytes()) | ||
|
@@ -255,73 +256,65 @@ pub fn read_catalog(file_hash: &Blake3Hash) -> Result<Vec<BaoHash>> { | |
Ok(bao_hashes) | ||
} | ||
|
||
#[allow(unused_variables)] | ||
pub fn delete_file(pk: Secp256k1PubKey, file_bytes: &[u8]) -> Result<()> { | ||
let pk_bytes = pk.to_bytes(); | ||
let (x_only_pk, _) = pk.into_inner().x_only_public_key(); | ||
|
||
let file_hash = Blake3Hash(blake3::keyed_hash(&x_only_pk.serialize(), file_bytes)); | ||
trace!(">>>>>file_hash:: {}", file_hash); | ||
|
||
for vol in &SYS_CFG.volumes { | ||
let seg_file = &vol.path.join(SEGMENT_DIR).join(file_hash.to_string()); | ||
let seg_dir = &vol.path.join(SEGMENT_DIR); | ||
remove_dir_contents(seg_dir, seg_file.to_path_buf()).unwrap(); | ||
} | ||
|
||
for vol in &SYS_CFG.volumes { | ||
let cat_path = &vol.path.join(CATALOG_DIR).join(file_hash.to_string()); | ||
let cat = &vol.path.join(CATALOG_DIR); | ||
remove_dir_catalogs(cat.to_path_buf(), cat_path.to_path_buf()).unwrap(); | ||
} | ||
Ok(()) | ||
pub async fn read_slices( | ||
//hash: bao::Hash, // from Blake3 | ||
file_bytes: &[u8], | ||
//slice_start: u64, //let slice_start = 65536; | ||
//slice_len: u16, // let slice_len = 8192; | ||
) -> Result<Vec<u8>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes no sense to provide the entire file to this method. This is supposed to be for retrieving just a slice of the file. It needs to return the range of the raw bytes on disk. It can make the disk IO calls by reading the catalog and then the appropriate segment. I've updated the issue so hopefully the task is more clear: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those values where for initial testing only. |
||
use std::io::prelude::*; | ||
|
||
// Start by encoding some input. | ||
let (encoded_input, hash) = bao::encode::encode(file_bytes); | ||
debug!(">>> encoded INPUT LENGTH:: {:?}", &encoded_input.len()); | ||
debug!(">>> fs hash hash:: {:?}", &hash); | ||
|
||
// Slice the encoding. These parameters are multiples of the chunk size, which avoids | ||
// unnecessary overhead. | ||
let slice_start = 65536; | ||
let slice_len = 8192; | ||
let encoded_cursor = std::io::Cursor::new(&encoded_input); | ||
let mut extractor = bao::encode::SliceExtractor::new(encoded_cursor, slice_start, slice_len); | ||
let mut slice = Vec::new(); | ||
extractor.read_to_end(&mut slice)?; | ||
|
||
// Decode the slice. The result should be the same as the part of the input that the slice | ||
// represents. Note that we're using the same hash that encoding produced, which is | ||
// independent of the slice parameters. That's the whole point; if we just wanted to re-encode | ||
// a portion of the input and wind up with a different hash, we wouldn't need slicing. | ||
let mut decoded = Vec::new(); | ||
let mut decoder = bao::decode::SliceDecoder::new(&*slice, &hash, slice_start, slice_len); | ||
decoder.read_to_end(&mut decoded)?; | ||
|
||
debug!( | ||
"usize vs length: {:?}", | ||
&encoded_input[slice_start as usize..][..slice_len as usize].len() | ||
); | ||
|
||
// Like regular decoding, slice decoding will fail if the hash doesn't match. | ||
// let mut bad_slice = slice.clone(); | ||
// debug!("BAD SLICE"); | ||
// let last_index = bad_slice.len() - 1; | ||
// bad_slice[last_index] ^= 1; | ||
// let mut decoder = bao::decode::SliceDecoder::new(&*bad_slice, &hash, slice_start, slice_len); | ||
// let err = decoder.read_to_end(&mut Vec::new()).unwrap_err(); | ||
// assert_eq!(std::io::ErrorKind::InvalidData, err.kind()); | ||
|
||
Ok(decoded) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of this makes any sense. Do not submit this code again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reworking slices by reading catalog, not files as you stated. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this code here? Can't we just use extract_slice from carbonado core? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this section, as I was using it for A/B testing on the results. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have not yet removed it. Only request my review once everything has been addressed. |
||
|
||
#[allow(unused_variables)] | ||
fn remove_dir_contents<P: AsRef<Path>>(path: P, seg_file: PathBuf) -> io::Result<()> { | ||
trace!(">>> remove_Segment_contents"); | ||
for entry in fs::read_dir(path)? { | ||
trace!("Delete Segment File at {:?}", entry); | ||
fs::remove_file(entry?.path())?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[allow(unused_variables)] | ||
fn remove_dir_catalogs(path: PathBuf, file: PathBuf) -> io::Result<()> { | ||
for entry in fs::read_dir(path)? { | ||
trace!("Delete CATALOG File at {:?}", entry); | ||
fs::remove_file(entry?.path())?; | ||
pub async fn delete_file(hash: &String) -> Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should pass &str, not &String, this is not a pattern we use. |
||
let blake3_hash = &Blake3Hash(blake3::Hash::from_str(hash)?); | ||
let catalog = read_catalog(blake3_hash)?; | ||
for vol in &SYS_CFG.volumes { | ||
for cat in &catalog { | ||
let seg_file = &vol.path.join(SEGMENT_DIR).join(cat.to_string() + ".c15"); | ||
let is_removed = fs::remove_file(seg_file).is_ok(); | ||
trace!("SEG: {:?} REMOVED: {:?}", &seg_file, is_removed); | ||
} | ||
let cat_path = &vol.path.join(CATALOG_DIR).join(hash); | ||
let is_removed = fs::remove_file(cat_path).is_ok(); | ||
trace!("CAT: {:?}: REMOVED: {:?}", &cat_path, is_removed); | ||
} | ||
Ok(()) | ||
} | ||
|
||
// fn remove_dir_segements<P: AsRef<Path>>(path: P, seg_file: PathBuf) -> io::Result<()> { | ||
// trace!(">>> remove_Segment_contents"); | ||
// for entry in fs::read_dir(path)? { | ||
// let entry = entry?; | ||
// trace!("ENTRY Delete SEGMENT File at {:?}", entry); | ||
|
||
// match &entry { | ||
// seg_file => { | ||
// fs::remove_file(seg_file.path())?; | ||
// trace!("Delete Segment File at {:?}", seg_file); | ||
// } | ||
// } | ||
// } | ||
// Ok(()) | ||
// } | ||
|
||
// fn remove_dir_catalogs(path: PathBuf, file: PathBuf) -> io::Result<()> { | ||
// for entry in fs::read_dir(path)? { | ||
// let entry = entry?; | ||
// trace!("ENTRY Delete CATALOG File at {:?}", entry); | ||
// match &entry { | ||
// file => { | ||
// fs::remove_file(file.path())?; | ||
// trace!("FILE MATCH Delete CATALOG File at {:?}", file); | ||
// } | ||
// } | ||
// } | ||
// Ok(()) | ||
// } | ||
cryptoquick marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,11 +70,8 @@ async fn get_file( | |
} | ||
|
||
#[axum_macros::debug_handler] | ||
async fn remove_file( | ||
Path((pk, blake3_hash)): Path<(String, String)>, | ||
) -> Result<impl IntoResponse, AppError> { | ||
let pk = Secp256k1PubKey::try_from(pk.as_str())?; | ||
delete_file(pk, blake3_hash.as_bytes())?; | ||
async fn remove_file(Path(blake3_hash): Path<String>) -> Result<impl IntoResponse, AppError> { | ||
delete_file(&blake3_hash).await?; | ||
Ok((StatusCode::OK, blake3_hash)) | ||
} | ||
|
||
|
@@ -89,9 +86,10 @@ async fn key(Path(pk): Path<String>) -> Result<impl IntoResponse, AppError> { | |
|
||
pub async fn start() -> Result<()> { | ||
let app = Router::new() | ||
.route("/remove/:pk/:blake3_hash", delete(remove_file)) | ||
.route("/remove/:blake3_hash", delete(remove_file)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the pk... We'll need this to be passed for the changes I'm making in #39. I've trimmed that PR down so we can get that merged and you can use that to make sure file deletion is namespaced by pk. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, your changes address that. |
||
.route("/store/:pk", post(post_file)) | ||
.route("/retrieve/:pk/:blake3_hash", get(get_file)) | ||
// .route("/slice/", get(get_slice)) | ||
.route("/key/:pk", get(key)) | ||
// .route("/catalog/:blake3_hash", get(get_catalog)) | ||
// .route("/raw/:bao_hash", get(get_raw)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not add this file