Class: TorManager::TorProcess

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TorProcess

Returns a new instance of TorProcess.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tormanager/tor_process.rb', line 10

def initialize params={}
  @settings = {}
  @settings[:tor_port] = params.fetch(:tor_port, 9050)
  @settings[:control_port] = params.fetch(:control_port, 50500)
  @settings[:pid_dir] = params.fetch(:pid_dir, '/tmp'.freeze)
  @settings[:log_dir] = params.fetch(:log_dir, '/tmp'.freeze)
  @settings[:tor_data_dir] = params.fetch(:tor_data_dir, nil)
  @settings[:tor_new_circuit_period] = params.fetch(:tor_new_circuit_period, 60)
  @settings[:max_tor_memory_usage_mb] = params.fetch(:max_tor_memory_usage, 200)
  @settings[:max_tor_cpu_percentage] = params.fetch(:max_tor_cpu_percentage, 10)
  @settings[:eye_tor_config_template] =
      params.fetch(:eye_tor_config_template,
        File.join(File.dirname(__dir__),'tormanager/eye/tor.template.eye.rb'))
  @settings[:parent_pid] = Process.pid
  @settings[:control_password] = params.fetch(:control_password, random_password)
  @settings[:hashed_control_password] =
      tor_hash_password_from(@settings[:control_password])
  @settings[:tor_log_switch] = params.fetch(:tor_log_switch, nil)
  @settings[:eye_logging] = params.fetch(:eye_logging, nil)
  @settings[:tor_logging] = params.fetch(:tor_logging, nil)
  @settings[:dont_remove_tor_config] = params.fetch(:dont_remove_tor_config, nil)
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



8
9
10
# File 'lib/tormanager/tor_process.rb', line 8

def settings
  @settings
end

Class Method Details

.stop_obsolete_processesObject



44
45
46
47
48
49
# File 'lib/tormanager/tor_process.rb', line 44

def stop_obsolete_processes
  (EyeManager.list_apps || []).each do |app|
    EyeManager.stop(application: app, process: 'tor') unless
        ProcessHelper.process_pid_running? pid_of_tor_eye_process(app)
  end
end

.tor_running_on?(params = {}) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tormanager/tor_process.rb', line 51

def tor_running_on? params={}
  is_running = false
  (EyeManager.list_apps || []).each do |app|
    if port_and_or_pid_matches_eye_tor_name?(app, params) &&
       EyeManager.status(application: app,
                         process: 'tor') == 'up'
      is_running = true
      break
    end
  end
  is_running
end

Instance Method Details

#startObject



33
34
35
# File 'lib/tormanager/tor_process.rb', line 33

def start
  prepare_tor_start_and_monitor if tor_ports_are_open?
end

#stopObject



37
38
39
40
41
# File 'lib/tormanager/tor_process.rb', line 37

def stop
  EyeManager.stop application: eye_app_name, process: 'tor'
  remove_eye_tor_config unless @settings[:dont_remove_tor_config]
  ensure_tor_is_down
end