class Option::Proxy::RelayManager

Constants

RELAY_PORTS
STATUS_FILE

Public Instance Methods

free(host) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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