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

Add optional hash options. #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/em-socksify/socks5.rb
Expand Up @@ -100,6 +100,8 @@ def socks_parse_response

socks_unhook(ip)
end
rescue SOCKSError => e
socks_error(e) or raise
end

def socks_methods
Expand Down
26 changes: 25 additions & 1 deletion lib/em-socksify/socksify.rb
@@ -1,15 +1,23 @@
module EventMachine

module Socksify
def socksify(host, port, username = nil, password = nil, version = 5, &blk)
def socksify(host, port, username = nil, password = nil, version = 5, always_raise = false, &blk)
@socks_target_host = host
@socks_target_port = port
@socks_username = username
@socks_password = password
@socks_version = version
@socks_always_raise = always_raise
@socks_callback = blk
@socks_data = ''

if username.is_a? Hash
@socks_username = username[:username]
@socks_password = username[:password]
@socks_version = username[:version] || version
@socks_always_raise = username[:always_raise] || always_raise
end

socks_hook
socks_send_handshake
end
Expand All @@ -34,6 +42,22 @@ class << self
@socks_callback.call(ip)
end

def socks_error?
@socks_error
end

def socks_error (exc)
@socks_error = true

if @socks_callback && !@socks_always_raise
@socks_callback.call(exc)

true
else
false
end
end

def socks_receive_data(data)
@socks_data << data
socks_parse_response
Expand Down