Wp/ updated delete file to use pk as filename#33
Conversation
|
At this stage, most of the features are working and tested, |
cryptoquick
left a comment
There was a problem hiding this comment.
Please clean up the "GOT HERE", "AM I HERE??", extra spaces, etc. Less git noise to review, and it makes the code less readable.
src/backend/fs.rs
Outdated
| let mut file = fs::File::create(&path)?; | ||
|
|
||
| // let mut file = OpenOptions::new() | ||
| // .create_new(true) | ||
| // .write(true) | ||
| // .open(&path)?; |
There was a problem hiding this comment.
I'm not sure why you'd go with this approach. This overwrites the catalog. We should be checking if the catalog already exists in this code, but it seems this code also got commented out. Please put the other code back in, and let's use the old OpenOptions code here.
There was a problem hiding this comment.
This solved an Internal Error 500 while using multi-part.
Good to point out it was over-writing the catalog.
This change has no value since we are not even using multi-part.
src/backend/fs.rs
Outdated
| assert_eq!(std::io::ErrorKind::InvalidData, err.kind()); | ||
|
|
||
| Ok(decoded) | ||
| } |
There was a problem hiding this comment.
Why is this code here? Can't we just use extract_slice from carbonado core?
There was a problem hiding this comment.
Removing this section, as I was using it for A/B testing on the results.
There was a problem hiding this comment.
You have not yet removed it. Only request my review once everything has been addressed.
…efactor file_stream to use explicit FileStream type alias
|
This branch has been merged and lifted to accommodate |
* Stream `post_file` (#34) * Implement HTTP body streaming version of post_file. * Refactor streaming interface format. Fix tests. * Reduce number of files created in test by increasing chunk size to 1MB. * Fix check catalog_exists test. Cleanup unused libraries. * Log node public key in config. Correct Error Message in fs backend. Refactor file_stream to use explicit FileStream type alias (#35) * Update carbonado to 0.3.0-rc.7 and secp256k1 to 0.27.0. Fix misnamed variable in tests. * Add drive_redundancy option to config. * Update directories crate. Default volume directory is now the Carbonado folder in the home directory. Configurable drive redundancy. * Fixes in response to review items. --------- Co-authored-by: Wesley Parr <rustchain64@gmail.com> * Merge main. * Streaming improvements (#37) * Update unfold in write method to produce stream chunks of uniform segment size. * Parallelize write_file. Add config node_shared_secret method and /key endpoint. Improve tests. * Debugging... * Fixes. * Stream read file using axum response StreamBody. Parallelized decoding using par_then. * Cleanup. * Cleanup. --------- Co-authored-by: Wesley Parr <rustchain64@gmail.com>
cryptoquick
left a comment
There was a problem hiding this comment.
Still a number of things to address. Also, be sure there are no unused variables present.
.DS_Store
Outdated
file/body_test.png
Outdated
There was a problem hiding this comment.
Do not add this file, please remove
src/backend/fs.rs
Outdated
| assert_eq!(std::io::ErrorKind::InvalidData, err.kind()); | ||
|
|
||
| Ok(decoded) | ||
| } |
There was a problem hiding this comment.
You have not yet removed it. Only request my review once everything has been addressed.
src/backend/fs.rs
Outdated
| } | ||
|
|
||
| #[allow(unused_variables)] | ||
| // TODO: These aren't worth breaking out into their own functions |
There was a problem hiding this comment.
Read this TODO item. Once addressed, remove it.
src/frontend/http.rs
Outdated
| Ok((StatusCode::OK, hash.to_hex().to_string())) | ||
| } | ||
|
|
||
| /* TODO: This seems unnecessary, and could introduce concurrency and security issues |
There was a problem hiding this comment.
Please see this TODO. Once addressed, remove it.
|
Test write_read() while file streaming doesn't finish before |
cryptoquick
left a comment
There was a problem hiding this comment.
Good work so far on delete_file. Not so good work on read_slices.
Please update the description to annotate the issues this closes. The RwLock comment seems outdated.
.DS_Store
Outdated
There was a problem hiding this comment.
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.
added the (global) .gitignore for Mac
There was a problem hiding this comment.
ran
sudo find / -name ".DS_Store" -depth -exec rm {} ;
ran cargo test, no .DS_Store present
file/body_test.png
Outdated
There was a problem hiding this comment.
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.
removed, not used for testing at this anymore
src/backend/fs.rs
Outdated
| 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.
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:
#18
There was a problem hiding this comment.
those values where for initial testing only.
actual slice data comes from the params.
src/backend/fs.rs
Outdated
| 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.
None of this makes any sense. Do not submit this code again.
There was a problem hiding this comment.
Reworking slices by reading catalog, not files as you stated.
src/backend/fs.rs
Outdated
| 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.
This should pass &str, not &String, this is not a pattern we use.
| 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.
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.
Yes, your changes address that.
|
While Testing Locally, test write_read ... FAILED test write_read ... FAILED failures: ---- write_read stdout ---- |
Implements, getting the hash just after upload to then use a fetch get from the client to fetch that under RwLock