Class: Selenium::WebDriver::Tor::TorProcess
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Tor::TorProcess
- 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\] .*/- SOCKS_PORT_REGEX =
/Opened Socks listener connection \(ready\) on 127\.0\.0\.1:(\d+)$/- 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
-
.cached_certs ⇒ Object
set when tor first started.
-
.cached_microdesc_consensus ⇒ Object
set when tor first started.
-
.cached_microdescs ⇒ Object
set when tor first started.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#socks_port ⇒ Object
readonly
Returns the value of attribute socks_port.
Instance Method Summary collapse
- #control_port ⇒ Object
-
#initialize(data_dir, opts = {}) ⇒ TorProcess
constructor
A new instance of TorProcess.
- #start_tor(timeout: 120) ⇒ Object
- #stop_tor ⇒ Object
Constructor Details
#initialize(data_dir, opts = {}) ⇒ TorProcess
Returns a new instance of TorProcess.
25 26 27 28 29 30 31 32 33 |
# File 'lib/tor/tor_process.rb', line 25 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 @socks_port = 0 end |
Class Attribute Details
.cached_certs ⇒ Object
set when tor first started
20 21 22 |
# File 'lib/tor/tor_process.rb', line 20 def cached_certs @cached_certs end |
.cached_microdesc_consensus ⇒ Object
set when tor first started
20 21 22 |
# File 'lib/tor/tor_process.rb', line 20 def cached_microdesc_consensus @cached_microdesc_consensus end |
.cached_microdescs ⇒ Object
set when tor first started
20 21 22 |
# File 'lib/tor/tor_process.rb', line 20 def cached_microdescs @cached_microdescs end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/tor/tor_process.rb', line 23 def config @config end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
23 24 25 |
# File 'lib/tor/tor_process.rb', line 23 def pid @pid end |
#socks_port ⇒ Object (readonly)
Returns the value of attribute socks_port.
23 24 25 |
# File 'lib/tor/tor_process.rb', line 23 def socks_port @socks_port end |
Instance Method Details
#control_port ⇒ Object
55 56 57 |
# File 'lib/tor/tor_process.rb', line 55 def control_port File.read(@torrc.control_port_file_path).split(':').last.to_i # "PORT=127.0.0.1:<port>" end |
#start_tor(timeout: 120) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tor/tor_process.rb', line 35 def start_tor(timeout: 120) r, io = IO.pipe pid = Process.spawn tor_command, out: io, err: :out io.close parse_tor_bootstrap_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_tor ⇒ Object
49 50 51 52 53 |
# File 'lib/tor/tor_process.rb', line 49 def stop_tor Process.kill 'KILL', pid if pid FileUtils.rm_rf @data_dir if @data_dir @pid = nil end |