Class: Option::Proxy::RelayManager
- Inherits:
-
Object
- Object
- Option::Proxy::RelayManager
- Defined in:
- lib/option/proxy.rb
Constant Summary collapse
- RELAY_PORTS =
[8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099, 8010]
- STATUS_FILE =
'/etc/openvpn/relays.txt'
Instance Method Summary collapse
Instance Method Details
#free(host) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/option/proxy.rb', line 51 def free(host) list = File.readlines(STATUS_FILE).map { |l| l.split(' ') } port = list.find { |e| e[0] == host }[1] updated_list = list.reject { |e| e[0] == host }.join() File.open(STATUS_FILE, 'w') { |file| file.write(updated_list) } port end |
#lock(host, port) ⇒ Object
47 48 49 |
# File 'lib/option/proxy.rb', line 47 def lock(host, port) File.open(STATUS_FILE, 'a') { |f| f.puts("#{host} #{port} ") } end |
#next_available_port ⇒ Object
59 60 61 62 63 |
# File 'lib/option/proxy.rb', line 59 def next_available_port used_ports = File.readlines(STATUS_FILE).map { |l| l.split(' ')[1] } available_ports = RELAY_PORTS - used_ports available_ports.sample end |