minor rename, accurate variable names

This commit is contained in:
17ms 2023-03-08 01:45:29 +02:00
parent aa8402b28c
commit 5ecb1676ea
4 changed files with 21 additions and 21 deletions

View File

@ -30,7 +30,7 @@ USAGE:
fragilebyte [OPTIONS]
OPTIONS:
-b, --buffersize <BUFFERSIZE> Buffersize used in the file transfer (bytes) [default: 8192]
-b, --chunksize <CHUNKSIZE> Chunksize used in the file transfer (bytes) [default: 8192]
-f, --fileroot <FILEROOT> Path to the folder where the files are outputted as a client or
served from as a server [default: './output' / './data']
-h, --help Print help information

View File

@ -45,13 +45,13 @@ pub async fn connect(
}
}
// Receive buffersize
let buffersize = recv_msg_string(&mut reader, &mut buf)
// Receive chunksize
let chunksize = recv_msg_string(&mut reader, &mut buf)
.await?
.parse::<usize>()?;
println!("[+] Selected buffersize: {}", buffersize);
println!("[+] Selected chunksize: {}", chunksize);
// ACK buffersize
// ACK chunksize
send_msg(&mut writer, "ACK\n").await?;
// Receive metadata
@ -69,7 +69,7 @@ pub async fn connect(
&mut reader,
&mut writer,
rx,
&buffersize,
&chunksize,
&metadata,
&fileroot,
&download_all,
@ -224,7 +224,7 @@ async fn handle_file_reqs(
reader: &mut BufReader<ReadHalf<'_>>,
writer: &mut BufWriter<WriteHalf<'_>>,
rx: Receiver<String>,
buffersize: &usize,
chunksize: &usize,
metadata: &HashMap<String, u64>,
fileroot: &PathBuf,
download_all: &bool,
@ -268,7 +268,7 @@ async fn handle_file_reqs(
// Receive the file itself
let filesize = metadata.get(input_string.as_str()).unwrap().clone();
receive_file(reader, &mut file_buf, &filesize, buffersize).await?;
receive_file(reader, &mut file_buf, &filesize, chunksize).await?;
// ACK file
send_msg(writer, "ACK\n").await?;
@ -285,13 +285,13 @@ async fn receive_file(
reader: &mut BufReader<ReadHalf<'_>>,
file_buf: &mut BufWriter<File>,
filesize: &u64,
buffersize: &usize,
chunksize: &usize,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let mut remaining_data = *filesize;
let mut buf = vec![0u8; *buffersize];
let mut buf = vec![0u8; *chunksize];
while remaining_data != 0 {
if remaining_data >= *buffersize as u64 {
if remaining_data >= *chunksize as u64 {
let read_result = reader.read(&mut buf);
match read_result.await {

View File

@ -16,8 +16,8 @@ struct Args {
/// Port where the service is hosted
port: u16,
#[clap(default_value_t = 8192usize, short = 'b', long, value_parser = validate_arg::<usize>)]
/// Buffersize used in the file transfer (bytes)
buffersize: usize,
/// Chunksize used in the file transfer (bytes)
chunksize: usize,
#[clap(default_value_t = false, long, action)]
/// Run only in the local network
localhost: bool,
@ -66,7 +66,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
server::listen(
args.port,
fileroot,
args.buffersize,
args.chunksize,
args.localhost,
args.timeout,
false,

View File

@ -23,7 +23,7 @@ use tokio::{
pub async fn listen(
port: u16,
fileroot: PathBuf,
buffersize: usize,
chunksize: usize,
localhost: bool,
timeout_duration: u64,
use_testing_key: bool,
@ -79,10 +79,10 @@ pub async fn listen(
return Ok::<(), Box<dyn Error + Send + Sync>>(());
}
// Send buffersize
send_msg(&mut writer, (buffersize.to_string() + "\n").as_str()).await?;
// Send chunksize
send_msg(&mut writer, (chunksize.to_string() + "\n").as_str()).await?;
// ACK buffersize
// ACK chunksize
if recv_msg_string(&mut reader, &mut vec_buf).await? != "ACK" {
return Ok::<(), Box<dyn Error + Send + Sync>>(());
}
@ -104,7 +104,7 @@ pub async fn listen(
&mut writer,
&mut vec_buf,
&alt_fileroot,
&buffersize,
&chunksize,
&addr,
)
.await?
@ -239,7 +239,7 @@ async fn handle_file_reqs(
writer: &mut BufWriter<WriteHalf<'_>>,
buf: &mut Vec<u8>,
fileroot: &PathBuf,
buffersize: &usize,
chunksize: &usize,
addr: &SocketAddr,
) -> Result<Option<String>, Box<dyn Error + Send + Sync>> {
loop {
@ -256,7 +256,7 @@ async fn handle_file_reqs(
println!("\n[REQ] {}: {:#?}", addr, input_path);
let mut file = File::open(input_path.clone()).await?;
let mut remaining_data = file.metadata().await?.len();
let mut filebuf = vec![0u8; *buffersize];
let mut filebuf = vec![0u8; *chunksize];
// Serve the file itself
while remaining_data != 0 {