Module: Tor
- Defined in:
- lib/tor.rb,
lib/tor/dnsel.rb,
lib/tor/config.rb,
lib/tor/control.rb,
lib/tor/version.rb
Overview
Defined Under Namespace
Modules: DNSEL, VERSION Classes: Config, Controller
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns ‘true` if Tor is available, `false` otherwise.
-
.program_path(program_name = :tor) ⇒ String
Returns the path to the ‘tor` executable, or `nil` if the program could not be found in the user’s current ‘PATH` environment.
-
.running? ⇒ Boolean
Returns ‘true` if the Tor process is running locally, `false` otherwise.
-
.version ⇒ String
Returns the Tor version number, or ‘nil` if Tor is not available.
Class Method Details
.available? ⇒ Boolean
Returns ‘true` if Tor is available, `false` otherwise.
54 55 56 |
# File 'lib/tor.rb', line 54 def self.available? !!program_path end |
.program_path(program_name = :tor) ⇒ String
Returns the path to the ‘tor` executable, or `nil` if the program could not be found in the user’s current ‘PATH` environment.
82 83 84 85 86 87 88 |
# File 'lib/tor.rb', line 82 def self.program_path(program_name = :tor) ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| program_path = File.join(path, program_name.to_s) return program_path if File.executable?(program_path) end return nil end |
.running? ⇒ Boolean
Returns ‘true` if the Tor process is running locally, `false` otherwise.
This works by attempting to establish a Tor Control Protocol (TC) connection to the standard control port 9051 on ‘localhost`. If Tor hasn’t been configured with the ‘ControlPort 9051` option, this will return `false`.
38 39 40 41 42 43 44 45 |
# File 'lib/tor.rb', line 38 def self.running? begin Tor::Controller.new.quit true rescue Errno::ECONNREFUSED false end end |
.version ⇒ String
Returns the Tor version number, or ‘nil` if Tor is not available.
65 66 67 68 69 70 71 |
# File 'lib/tor.rb', line 65 def self.version if available? && `#{program_path} --version` =~ /Tor v(\d+)\.(\d+)\.(\d+)\.(\d+)/ [$1, $2, $3, $4].join('.') elsif available? && `#{program_path} --version` =~ /Tor version (\d+)\.(\d+)\.(\d+)\.(\d+)/ [$1, $2, $3, $4].join('.') end end |