minor rename, accurate variable names
This commit is contained in:
parent
aa8402b28c
commit
5ecb1676ea
@ -30,7 +30,7 @@ USAGE:
|
|||||||
fragilebyte [OPTIONS]
|
fragilebyte [OPTIONS]
|
||||||
|
|
||||||
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
|
-f, --fileroot <FILEROOT> Path to the folder where the files are outputted as a client or
|
||||||
served from as a server [default: './output' / './data']
|
served from as a server [default: './output' / './data']
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
|
@ -45,13 +45,13 @@ pub async fn connect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive buffersize
|
// Receive chunksize
|
||||||
let buffersize = recv_msg_string(&mut reader, &mut buf)
|
let chunksize = recv_msg_string(&mut reader, &mut buf)
|
||||||
.await?
|
.await?
|
||||||
.parse::<usize>()?;
|
.parse::<usize>()?;
|
||||||
println!("[+] Selected buffersize: {}", buffersize);
|
println!("[+] Selected chunksize: {}", chunksize);
|
||||||
|
|
||||||
// ACK buffersize
|
// ACK chunksize
|
||||||
send_msg(&mut writer, "ACK\n").await?;
|
send_msg(&mut writer, "ACK\n").await?;
|
||||||
|
|
||||||
// Receive metadata
|
// Receive metadata
|
||||||
@ -69,7 +69,7 @@ pub async fn connect(
|
|||||||
&mut reader,
|
&mut reader,
|
||||||
&mut writer,
|
&mut writer,
|
||||||
rx,
|
rx,
|
||||||
&buffersize,
|
&chunksize,
|
||||||
&metadata,
|
&metadata,
|
||||||
&fileroot,
|
&fileroot,
|
||||||
&download_all,
|
&download_all,
|
||||||
@ -224,7 +224,7 @@ async fn handle_file_reqs(
|
|||||||
reader: &mut BufReader<ReadHalf<'_>>,
|
reader: &mut BufReader<ReadHalf<'_>>,
|
||||||
writer: &mut BufWriter<WriteHalf<'_>>,
|
writer: &mut BufWriter<WriteHalf<'_>>,
|
||||||
rx: Receiver<String>,
|
rx: Receiver<String>,
|
||||||
buffersize: &usize,
|
chunksize: &usize,
|
||||||
metadata: &HashMap<String, u64>,
|
metadata: &HashMap<String, u64>,
|
||||||
fileroot: &PathBuf,
|
fileroot: &PathBuf,
|
||||||
download_all: &bool,
|
download_all: &bool,
|
||||||
@ -268,7 +268,7 @@ async fn handle_file_reqs(
|
|||||||
|
|
||||||
// Receive the file itself
|
// Receive the file itself
|
||||||
let filesize = metadata.get(input_string.as_str()).unwrap().clone();
|
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
|
// ACK file
|
||||||
send_msg(writer, "ACK\n").await?;
|
send_msg(writer, "ACK\n").await?;
|
||||||
@ -285,13 +285,13 @@ async fn receive_file(
|
|||||||
reader: &mut BufReader<ReadHalf<'_>>,
|
reader: &mut BufReader<ReadHalf<'_>>,
|
||||||
file_buf: &mut BufWriter<File>,
|
file_buf: &mut BufWriter<File>,
|
||||||
filesize: &u64,
|
filesize: &u64,
|
||||||
buffersize: &usize,
|
chunksize: &usize,
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
let mut remaining_data = *filesize;
|
let mut remaining_data = *filesize;
|
||||||
let mut buf = vec![0u8; *buffersize];
|
let mut buf = vec![0u8; *chunksize];
|
||||||
|
|
||||||
while remaining_data != 0 {
|
while remaining_data != 0 {
|
||||||
if remaining_data >= *buffersize as u64 {
|
if remaining_data >= *chunksize as u64 {
|
||||||
let read_result = reader.read(&mut buf);
|
let read_result = reader.read(&mut buf);
|
||||||
|
|
||||||
match read_result.await {
|
match read_result.await {
|
||||||
|
@ -16,8 +16,8 @@ struct Args {
|
|||||||
/// Port where the service is hosted
|
/// Port where the service is hosted
|
||||||
port: u16,
|
port: u16,
|
||||||
#[clap(default_value_t = 8192usize, short = 'b', long, value_parser = validate_arg::<usize>)]
|
#[clap(default_value_t = 8192usize, short = 'b', long, value_parser = validate_arg::<usize>)]
|
||||||
/// Buffersize used in the file transfer (bytes)
|
/// Chunksize used in the file transfer (bytes)
|
||||||
buffersize: usize,
|
chunksize: usize,
|
||||||
#[clap(default_value_t = false, long, action)]
|
#[clap(default_value_t = false, long, action)]
|
||||||
/// Run only in the local network
|
/// Run only in the local network
|
||||||
localhost: bool,
|
localhost: bool,
|
||||||
@ -66,7 +66,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
server::listen(
|
server::listen(
|
||||||
args.port,
|
args.port,
|
||||||
fileroot,
|
fileroot,
|
||||||
args.buffersize,
|
args.chunksize,
|
||||||
args.localhost,
|
args.localhost,
|
||||||
args.timeout,
|
args.timeout,
|
||||||
false,
|
false,
|
||||||
|
@ -23,7 +23,7 @@ use tokio::{
|
|||||||
pub async fn listen(
|
pub async fn listen(
|
||||||
port: u16,
|
port: u16,
|
||||||
fileroot: PathBuf,
|
fileroot: PathBuf,
|
||||||
buffersize: usize,
|
chunksize: usize,
|
||||||
localhost: bool,
|
localhost: bool,
|
||||||
timeout_duration: u64,
|
timeout_duration: u64,
|
||||||
use_testing_key: bool,
|
use_testing_key: bool,
|
||||||
@ -79,10 +79,10 @@ pub async fn listen(
|
|||||||
return Ok::<(), Box<dyn Error + Send + Sync>>(());
|
return Ok::<(), Box<dyn Error + Send + Sync>>(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send buffersize
|
// Send chunksize
|
||||||
send_msg(&mut writer, (buffersize.to_string() + "\n").as_str()).await?;
|
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" {
|
if recv_msg_string(&mut reader, &mut vec_buf).await? != "ACK" {
|
||||||
return Ok::<(), Box<dyn Error + Send + Sync>>(());
|
return Ok::<(), Box<dyn Error + Send + Sync>>(());
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ pub async fn listen(
|
|||||||
&mut writer,
|
&mut writer,
|
||||||
&mut vec_buf,
|
&mut vec_buf,
|
||||||
&alt_fileroot,
|
&alt_fileroot,
|
||||||
&buffersize,
|
&chunksize,
|
||||||
&addr,
|
&addr,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -239,7 +239,7 @@ async fn handle_file_reqs(
|
|||||||
writer: &mut BufWriter<WriteHalf<'_>>,
|
writer: &mut BufWriter<WriteHalf<'_>>,
|
||||||
buf: &mut Vec<u8>,
|
buf: &mut Vec<u8>,
|
||||||
fileroot: &PathBuf,
|
fileroot: &PathBuf,
|
||||||
buffersize: &usize,
|
chunksize: &usize,
|
||||||
addr: &SocketAddr,
|
addr: &SocketAddr,
|
||||||
) -> Result<Option<String>, Box<dyn Error + Send + Sync>> {
|
) -> Result<Option<String>, Box<dyn Error + Send + Sync>> {
|
||||||
loop {
|
loop {
|
||||||
@ -256,7 +256,7 @@ async fn handle_file_reqs(
|
|||||||
println!("\n[REQ] {}: {:#?}", addr, input_path);
|
println!("\n[REQ] {}: {:#?}", addr, input_path);
|
||||||
let mut file = File::open(input_path.clone()).await?;
|
let mut file = File::open(input_path.clone()).await?;
|
||||||
let mut remaining_data = file.metadata().await?.len();
|
let mut remaining_data = file.metadata().await?.len();
|
||||||
let mut filebuf = vec![0u8; *buffersize];
|
let mut filebuf = vec![0u8; *chunksize];
|
||||||
|
|
||||||
// Serve the file itself
|
// Serve the file itself
|
||||||
while remaining_data != 0 {
|
while remaining_data != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user