Class: Tor::HiddenService

Inherits:
Object
  • Object
show all
Defined in:
lib/tor/hidden-service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HiddenService

Returns a new instance of HiddenService.



10
11
12
13
# File 'lib/tor/hidden-service.rb', line 10

def initialize(options={})
  @options = parse_options(options)
  @base_dir = "#{@options[:temp_dir]}/tor_#{@options[:tor_control_port]}"
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/tor/hidden-service.rb', line 8

def options
  @options
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tor/hidden-service.rb', line 15

def start
  generate_tor_config

  @pid = fork do
    spawn @options[:tor_executable], '-f',  "#{@base_dir}/torrc"
  end
  Process.wait(@pid)

  begin
    @tor_pid = File.read(open("#{@base_dir}/pid")).strip.to_i
  rescue Errno::ENOENT
    log_message "Waiting for Tor PID to appear..."
    sleep 1
    retry
  end

  log_message "Started Tor with PID #{@tor_pid} on control port #{@options[:tor_control_port]}"

  at_exit do
    log_message "Killing Tor PID #{@tor_pid}..."
    Process.kill :SIGTERM, @tor_pid
    Process.wait
  end
end