Fix windowsize parsing
This commit is contained in:
parent
0a5e7af5ac
commit
6cad01fafd
5 changed files with 20 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -4,4 +4,4 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "tftpd"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tftpd"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["Altuğ Bakan <mail@alt.ug>"]
|
||||
edition = "2021"
|
||||
description = "Multithreaded TFTP server daemon"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ impl Config {
|
|||
let mut config = Config {
|
||||
ip_address: Ipv4Addr::new(127, 0, 0, 1),
|
||||
port: 69,
|
||||
directory: env::current_dir().unwrap_or(env::temp_dir()),
|
||||
directory: env::current_dir().unwrap_or_else(|_| env::temp_dir()),
|
||||
};
|
||||
|
||||
args.next();
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ impl FromStr for OptionType {
|
|||
"blksize" => Ok(OptionType::BlockSize),
|
||||
"tsize" => Ok(OptionType::TransferSize),
|
||||
"timeout" => Ok(OptionType::Timeout),
|
||||
"windowsize" => Ok(OptionType::Windowsize),
|
||||
_ => Err("Invalid option type"),
|
||||
}
|
||||
}
|
||||
|
|
@ -304,7 +305,7 @@ fn parse_rq(buf: &[u8], opcode: Opcode) -> Result<Packet, Box<dyn Error>> {
|
|||
(option, zero_index) = Convert::to_string(buf, zero_index + 1)?;
|
||||
(value, zero_index) = Convert::to_string(buf, zero_index + 1)?;
|
||||
|
||||
if let Ok(option) = OptionType::from_str(option.as_str()) {
|
||||
if let Ok(option) = OptionType::from_str(option.to_lowercase().as_str()) {
|
||||
options.push(TransferOption {
|
||||
option,
|
||||
value: value.parse()?,
|
||||
|
|
@ -428,6 +429,10 @@ mod tests {
|
|||
&[0x00],
|
||||
("5".as_bytes()),
|
||||
&[0x00],
|
||||
(OptionType::Windowsize.as_str().as_bytes()),
|
||||
&[0x00],
|
||||
("4".as_bytes()),
|
||||
&[0x00],
|
||||
]
|
||||
.concat();
|
||||
|
||||
|
|
@ -439,7 +444,7 @@ mod tests {
|
|||
{
|
||||
assert_eq!(filename, "test.png");
|
||||
assert_eq!(mode, "octet");
|
||||
assert_eq!(options.len(), 2);
|
||||
assert_eq!(options.len(), 3);
|
||||
assert_eq!(
|
||||
options[0],
|
||||
TransferOption {
|
||||
|
|
@ -454,6 +459,13 @@ mod tests {
|
|||
value: 5
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
options[2],
|
||||
TransferOption {
|
||||
option: OptionType::Windowsize,
|
||||
value: 4
|
||||
}
|
||||
);
|
||||
} else {
|
||||
panic!("cannot parse read request with options")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ enum WorkType {
|
|||
|
||||
const MAX_RETRIES: u32 = 6;
|
||||
const DEFAULT_TIMEOUT_SECS: u64 = 5;
|
||||
const TIMEOUT_BUFFER_SECS: u64 = 1;
|
||||
const DEFAULT_BLOCK_SIZE: usize = 512;
|
||||
|
||||
impl Worker {
|
||||
|
|
@ -139,7 +140,8 @@ fn send_file(
|
|||
let filled = window.fill()?;
|
||||
|
||||
let mut retry_cnt = 0;
|
||||
let mut time = SystemTime::now() - Duration::from_secs(DEFAULT_TIMEOUT_SECS);
|
||||
let mut time =
|
||||
SystemTime::now() - Duration::from_secs(DEFAULT_TIMEOUT_SECS + TIMEOUT_BUFFER_SECS);
|
||||
loop {
|
||||
if time.elapsed()? >= Duration::from_secs(DEFAULT_TIMEOUT_SECS) {
|
||||
send_window(socket, &window, block_number)?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue