Skip to content

Commit

Permalink
handle socks connection
Browse files Browse the repository at this point in the history
  • Loading branch information
lizzypy committed Aug 8, 2024
1 parent 49aa7d0 commit c1179c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/socksify/tcpsocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(host = nil, port = nil, local_host = nil, local_port = nil, **kwa
socks_ignores = set_socks_ignores(socks_peer)
host = socks_peer.peer_host if socks_peer
if socks_server && socks_port && !socks_ignores.include?(host)
make_socks_connection(host, port, socks_server, socks_port)
make_socks_connection(host, port, socks_server, socks_port, **kwargs)
else
make_direct_connection(host, port, local_host, local_port, **kwargs)
end
Expand Down Expand Up @@ -57,9 +57,9 @@ def set_socks_ignores(socks_peer = nil)
socks_peer ? [] : self.class.socks_ignores
end

def make_socks_connection(host, port, socks_server, socks_port)
def make_socks_connection(host, port, socks_server, socks_port, **kwargs)
Socksify.debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}"
initialize_tcp socks_server, socks_port
initialize_tcp socks_server, socks_port, **kwargs
socks_authenticate unless @socks_version =~ /^4/
socks_connect(host, port) if host
end
Expand Down
15 changes: 14 additions & 1 deletion test/test_tcpsocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ class TCPSocketTest < Minitest::Test

if RUBY_VERSION.to_f >= 3.0
def test_tcp_socket_direct_connection_with_connection_timeout
disable_socks

socket = TCPSocket.new('127.0.0.1', 9050, connect_timeout: 0.1)

assert !socket.closed?
end

def test_tcp_socket_socks_connection_with_connection_timeout
enable_socks

# leave off the host because we don't need to worry about connecting to socks
socket = TCPSocket.new(connect_timeout: 0.1)

assert !socket.closed?
end
end

def test_tcp_socket_direct_connection_with_connection_timeout
def test_tcp_socket_direct_connection_with_connection_timeout_no_kwargs
disable_socks

socket = TCPSocket.new('127.0.0.1', 9050)

assert !socket.closed?
Expand Down

0 comments on commit c1179c8

Please sign in to comment.