Class: Clients::TorClient
- Inherits:
-
Object
- Object
- Clients::TorClient
- Extended by:
- Forwardable
- Defined in:
- lib/clients/tor_client.rb
Constant Summary collapse
- DEFAULT_PORT =
9050
- DEFAULT_CONTROL_PORT =
9051
- DEFAULT_HTTP_PORT =
8080
- OK_STATUS =
"250 OK\n".freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#pool_num ⇒ Object
readonly
Returns the value of attribute pool_num.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(options = {}) ⇒ TorClient
constructor
rubocop:disable Metrics/MethodLength.
- #password ⇒ Object
- #port ⇒ Object
- #switch_identity ⇒ Object (also: #reset!)
- #to_s ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TorClient
rubocop:disable Metrics/MethodLength
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/clients/tor_client.rb', line 22 def initialize( = {}) = { tor_host: "localhost", tor_port: (ENV["TOR_PORT"] || DEFAULT_PORT).to_i, control_port: (ENV["TOR_CONTROL_PORT"] || DEFAULT_CONTROL_PORT).to_i, host: "localhost", port: (ENV["HTTP_TOR_PORT"] || DEFAULT_HTTP_PORT).to_i, circuit_timeout: 10, throttle_by: 10, # .seconds implied pool_num: nil }.merge() @pool_num = .delete(:pool_num) @config = OpenStruct.new setup_pool end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/clients/tor_client.rb', line 16 def config @config end |
#pool_num ⇒ Object (readonly)
Returns the value of attribute pool_num.
16 17 18 |
# File 'lib/clients/tor_client.rb', line 16 def pool_num @pool_num end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
16 17 18 |
# File 'lib/clients/tor_client.rb', line 16 def threshold @threshold end |
Instance Method Details
#host ⇒ Object
40 41 42 |
# File 'lib/clients/tor_client.rb', line 40 def host @config[:host] end |
#password ⇒ Object
52 53 54 |
# File 'lib/clients/tor_client.rb', line 52 def password nil end |
#port ⇒ Object
44 45 46 |
# File 'lib/clients/tor_client.rb', line 44 def port @config[:port] end |
#switch_identity ⇒ Object Also known as: reset!
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/clients/tor_client.rb', line 60 def switch_identity throttle do client = Net::Telnet.new( "Host" => config.tor_host, "Port" => config.control_port, "Timeout" => config.circuit_timeout, "Prompt" => Regexp.new(OK_STATUS) ) authenticate client new_route client client.close end end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/clients/tor_client.rb', line 56 def to_s "#{host}:#{port}" end |
#user ⇒ Object
48 49 50 |
# File 'lib/clients/tor_client.rb', line 48 def user nil end |