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

refactoring Socks::Reply#server_message #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
24 changes: 11 additions & 13 deletions src/reply.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,32 @@ class Socks::Reply
end

def server_message
message = "Unknown State"

return "Server doesn't reply" if buffer.empty?
return "SOCKS version #{version} is not supported" if ![V4, V5].includes?(version)
return "ADDR type not supported" if !ADDR_TYPE.values.includes?(addr_type)

case buffer[2]
when 0_u8
message = "succeeded"
"succeeded"
when 1_u8
message = "general SOCKS server failure"
"general SOCKS server failure"
when 2_u8
message = "connection not allowed by ruleset"
"connection not allowed by ruleset"
when 3_u8
message = "Network unreachable"
"Network unreachable"
when 4_u8
message = "Host unreachable"
"Host unreachable"
when 5_u8
message = "Connection refused"
"Connection refused"
when 6_u8
message = "TTL expired"
"TTL expired"
when 7_u8
message = "Command not supported"
"Command not supported"
when 8_u8
message = "Address type not supported"
"Address type not supported"
else
"Unknown State"
end

message
end

def size
Expand Down