Class: Selenium::WebDriver::Tor::TorProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/tor/tor_process.rb

Overview

Respresentation of a tor process

Constant Summary collapse

BOOTSTRAP_SUCCESS_REGEX =
/Bootstrapped 100% \(done\): Done$/
BOOTSTRAP_FAIL_REGEX =
/^[A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2}\.\d{3} \[err\] .*/
DIR_MSG =
'data_dir must exist and be a dir'
DATA_FILES =
%w[cached-certs cached-microdesc-consensus cached-microdescs.new].freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir, opts = {}) ⇒ TorProcess

Returns a new instance of TorProcess.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
# File 'lib/tor/tor_process.rb', line 24

def initialize(data_dir, opts = {})
  setup_data_dir data_dir
  raise ArgumentError, 'TorProcess.new takes an options hash' unless opts.is_a? Hash

  @opts = map_opts_to_torrc_keys opts
  @torrc = Torrc.new(@data_dir)
  @config ||= setup_config # Hash to store torrc config
end

Class Attribute Details

.cached_certsObject

set when tor first started



19
20
21
# File 'lib/tor/tor_process.rb', line 19

def cached_certs
  @cached_certs
end

.cached_microdesc_consensusObject

set when tor first started



19
20
21
# File 'lib/tor/tor_process.rb', line 19

def cached_microdesc_consensus
  @cached_microdesc_consensus
end

.cached_microdescsObject

set when tor first started



19
20
21
# File 'lib/tor/tor_process.rb', line 19

def cached_microdescs
  @cached_microdescs
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/tor/tor_process.rb', line 22

def config
  @config
end

#pidObject (readonly)

Returns the value of attribute pid.



22
23
24
# File 'lib/tor/tor_process.rb', line 22

def pid
  @pid
end

Instance Method Details

#start_tor(timeout: 10) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tor/tor_process.rb', line 33

def start_tor(timeout: 10)
  r, io = IO.pipe
  pid = Process.spawn tor_command, out: io, err: :out
  io.close
  parse_tor_bootstrap_errors_with_timeout(r, timeout: timeout)
  # tor process now bootstrapped
  read_from_data_files
  @pid = pid
rescue Timeout::Error
  timeout_with pid, timeout
ensure
  r.close
end

#stop_torObject



47
48
49
50
51
# File 'lib/tor/tor_process.rb', line 47

def stop_tor
  Process.kill 'KILL', pid if pid
  FileUtils.rm_rf @data_dir if @data_dir
  @pid = nil
end