Skip to content

Commit

Permalink
Upload improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MakisChristou committed Oct 1, 2023
1 parent 2585cb9 commit 7f9d205
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod filename_handler;
mod storage;
mod utils;

const MAX_RETRIES: usize = 3;
const CHUNK_SIZE: usize = 1024 * 1024; // 1 MiB chunks

async fn encrypt_and_upload_data_chunk(
Expand All @@ -43,12 +44,22 @@ async fn encrypt_and_upload_data_chunk(

let hashed_filename = hex::encode(Sha256::digest(plaintext_filename)).to_string();

storage
.upload(&hashed_filename, &data_to_store)
.await
.unwrap();
let mut retries = 0;

Ok(())
while retries < MAX_RETRIES {
match storage.upload(&hashed_filename, &data_to_store).await {
Ok(_) => {
return Ok(());
}
Err(e) => {
println!("{}, retrying...", e);
retries += 1;
continue;
}
}
}

return Err(Unspecified);
}

async fn download_and_decrypt_chunk(
Expand Down Expand Up @@ -93,7 +104,18 @@ async fn handle_upload(
let associated_filenames =
filename_handler.get_all_filenames_of(plaintext_filename, config.key_bytes.clone());

let remote_chunks = associated_filenames.len();
let mut remote_chunks = associated_filenames.len();

if remote_chunks > num_chunks {
handle_delete(
plaintext_filename,
storage,
filename_handler,
config.clone(),
)
.await?;
remote_chunks = 0;
}

if remote_chunks == num_chunks {
println!("File {} already uploaded!", plaintext_filename);
Expand Down

0 comments on commit 7f9d205

Please sign in to comment.