Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.5 #12

Merged
merged 8 commits into from
May 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions socks5-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum Socks5 {
Awaiting,
Reading(u8, u8),
Active(NetAddr<HostName>),
Rejected(ServerError),
Rejected(ServerError, u8, u8),
Failed(Error),
}

Expand Down Expand Up @@ -116,10 +116,10 @@ impl Socks5 {
}
if input[1] != 0x00 {
let err = ServerError::from(input[1]);
*self = Socks5::Rejected(err);
return Err(Error::Closed);
*self = Socks5::Rejected(err, input[3], input[4]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously if Socks5 proxy failed, we were leaving some unread data in a buffer. Not important, since the connection is useless anyway, but better to clean up!

} else {
*self = Socks5::Reading(input[3], input[4]);
}
*self = Socks5::Reading(input[3], input[4]);
Ok(vec![])
}
Socks5::Reading(code1, code2) => {
Expand All @@ -132,7 +132,7 @@ impl Socks5 {
Ok(vec![])
}
Socks5::Active(_) => Err(Error::Completed),
Socks5::Rejected(_) | Socks5::Failed(_) => Err(Error::Closed),
Socks5::Rejected(_, _, _) | Socks5::Failed(_) => Err(Error::Closed),
}
}

Expand All @@ -141,11 +141,13 @@ impl Socks5 {
Socks5::Initial(_, _) => 0,
Socks5::Connected(_) => 2,
Socks5::Awaiting => 5,
Socks5::Reading(ty, _) if *ty == IPV4 => 5,
Socks5::Reading(ty, _) if *ty == IPV6 => 17,
Socks5::Reading(ty, len) if *ty == DOMAIN => *len as usize + 1,
Socks5::Reading(_, _) => 1,
Socks5::Active(_) | Socks5::Rejected(_) | Socks5::Failed(_) => 0,
Socks5::Reading(ty, _) | Socks5::Rejected(_, ty, _) if *ty == IPV4 => 5,
Socks5::Reading(ty, _) | Socks5::Rejected(_, ty, _) if *ty == IPV6 => 17,
Socks5::Reading(ty, len) | Socks5::Rejected(_, ty, len) if *ty == DOMAIN => {
*len as usize + 1
}
Socks5::Reading(_, _) | Socks5::Rejected(_, _, _) => 1,
Socks5::Active(_) | Socks5::Failed(_) => 0,
}
}
}
Loading