Skip to content

Commit

Permalink
mmm instance_eval fun on 1.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Nov 7, 2011
1 parent 936da05 commit 6c9754e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/hydra/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(options)
@hosts = @hosts.inject({}) {|h,k| h[@hosts.index(k)] = k; h}

@log.info "Establishing #{@hosts.size} SOCKS5 tunnels"
@live = {}
@@live = {}
@pids = []
end

Expand All @@ -41,15 +41,15 @@ def start!

@pids << EM.system(tunnel) do |cmd, out|
@log.error ["Connection closed", out, @hosts[index]]
@live.delete(index)
@@live.delete(index)

if @live.empty?
if @@live.empty?
@log.info "No live tunnels left, exiting"
exit
end
end

@live[index] = host
@@live[index] = host
end

at_exit do
Expand All @@ -60,10 +60,11 @@ def start!
end

@log.info "Starting proxy on port #{@listen}"
::Proxy.start(:host => "0.0.0.0", :port => @listen) do |conn|
tunnel = @live.keys.shuffle.first

@log.info ["Routing request to", tunnel, @hosts[tunnel]]
::Proxy.start(:host => "0.0.0.0", :port => @listen, :debug => @verbose) do |conn|
tunnel = @@live.keys.shuffle.first

puts "routing connection to #{@@live[tunnel]}"
conn.server :srv, :host => "127.0.0.1", :port => 7000 + tunnel, :relay_client => true, :relay_server => true
end
end
Expand Down

0 comments on commit 6c9754e

Please sign in to comment.