Class: ProxyManager
- Inherits:
-
Object
- Object
- ProxyManager
- Defined in:
- lib/proxy/proxy_manager.rb
Constant Summary collapse
- START_PORT =
5000
Instance Attribute Summary collapse
-
#assigned_proxy_ports ⇒ Object
readonly
Returns the value of attribute assigned_proxy_ports.
-
#running_proxy_servers ⇒ Object
readonly
Returns the value of attribute running_proxy_servers.
Instance Method Summary collapse
- #delete_proxies ⇒ Object
- #find_proxy_port ⇒ Object
- #get_proxy(port) ⇒ Object
-
#initialize ⇒ ProxyManager
constructor
A new instance of ProxyManager.
- #new_proxy ⇒ Object
- #proxies ⇒ Object
- #proxy_host_address ⇒ Object
- #start_proxy(options) ⇒ Object
- #stop_proxy(port) ⇒ Object
Constructor Details
#initialize ⇒ ProxyManager
Returns a new instance of ProxyManager.
9 10 11 12 |
# File 'lib/proxy/proxy_manager.rb', line 9 def initialize @running_proxy_servers = {} @assigned_proxy_ports = [] end |
Instance Attribute Details
#assigned_proxy_ports ⇒ Object (readonly)
Returns the value of attribute assigned_proxy_ports.
7 8 9 |
# File 'lib/proxy/proxy_manager.rb', line 7 def assigned_proxy_ports @assigned_proxy_ports end |
#running_proxy_servers ⇒ Object (readonly)
Returns the value of attribute running_proxy_servers.
7 8 9 |
# File 'lib/proxy/proxy_manager.rb', line 7 def running_proxy_servers @running_proxy_servers end |
Instance Method Details
#delete_proxies ⇒ Object
24 25 26 |
# File 'lib/proxy/proxy_manager.rb', line 24 def delete_proxies assigned_proxy_ports.clear end |
#find_proxy_port ⇒ Object
55 56 57 58 |
# File 'lib/proxy/proxy_manager.rb', line 55 def find_proxy_port new_proxy_port = (assigned_proxy_ports.max || ProxyManager::START_PORT) + 1 PortProber.above(new_proxy_port) end |
#get_proxy(port) ⇒ Object
14 15 16 |
# File 'lib/proxy/proxy_manager.rb', line 14 def get_proxy(port) running_proxy_servers[port] end |
#new_proxy ⇒ Object
38 39 40 41 42 |
# File 'lib/proxy/proxy_manager.rb', line 38 def new_proxy port = find_proxy_port assigned_proxy_ports << port URI.parse("http://#{proxy_host_address}:#{port}") end |
#proxies ⇒ Object
28 29 30 |
# File 'lib/proxy/proxy_manager.rb', line 28 def proxies assigned_proxy_ports end |
#proxy_host_address ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/proxy/proxy_manager.rb', line 44 def proxy_host_address orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily UDPSocket.open do |s| s.connect '64.233.187.99', 1 s.addr.last end ensure Socket.do_not_reverse_lookup = orig end |
#start_proxy(options) ⇒ Object
32 33 34 35 36 |
# File 'lib/proxy/proxy_manager.rb', line 32 def start_proxy() proxy_server = ProxyServer.new() proxy_server.start running_proxy_servers[[:port]] = proxy_server end |
#stop_proxy(port) ⇒ Object
18 19 20 21 22 |
# File 'lib/proxy/proxy_manager.rb', line 18 def stop_proxy(port) proxy_server = running_proxy_servers[port] proxy_server.stop running_proxy_servers.delete proxy_server end |