Class: Arachni::Processes::Instances
- Includes:
- Utilities, Singleton
- Defined in:
- lib/arachni/processes/instances.rb
Overview
Helper for managing RPC::Server::Instance processes.
Instance Attribute Summary collapse
-
#list ⇒ Array<String>
readonly
URLs and tokens of all running Instances.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect(url, token = nil) ⇒ RPC::Client::Instance
Connects to a Instance by URL.
-
#dispatcher_spawn ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher and returns an Instance.
- #each(&block) ⇒ Object
-
#grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
-
#initialize ⇒ Instances
constructor
A new instance of Instances.
- #kill(url) ⇒ Object
-
#killall ⇒ Object
Kills all #list.
-
#light_grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
-
#spawn(options = {}) ⇒ RPC::Client::Instance
Spawns an RPC::Server::Instance process.
-
#token_for(client_or_url) ⇒ String
Cached authentication token for the given Instance.
Methods included from Utilities
#available_port, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite
Constructor Details
#initialize ⇒ Instances
Returns a new instance of Instances.
24 25 26 27 |
# File 'lib/arachni/processes/instances.rb', line 24 def initialize @list = {} @instance_connections = {} end |
Instance Attribute Details
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
205 206 207 208 209 210 211 |
# File 'lib/arachni/processes/instances.rb', line 205 def self.method_missing( sym, *args, &block ) if instance.respond_to?( sym ) instance.send( sym, *args, &block ) else super( sym, *args, &block ) end end |
.respond_to?(m) ⇒ Boolean
213 214 215 |
# File 'lib/arachni/processes/instances.rb', line 213 def self.respond_to?( m ) super( m ) || instance.respond_to?( m ) end |
Instance Method Details
#connect(url, token = nil) ⇒ RPC::Client::Instance
Connects to a Instance by URL.
38 39 40 41 42 43 44 45 46 |
# File 'lib/arachni/processes/instances.rb', line 38 def connect( url, token = nil ) Reactor.global.run_in_thread if !Reactor.global.running? token ||= @list[url] @list[url] ||= token @instance_connections[url] ||= RPC::Client::Instance.new( Options, url, token ) end |
#dispatcher_spawn ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher and returns an Instance.
165 166 167 168 |
# File 'lib/arachni/processes/instances.rb', line 165 def dispatcher_spawn info = Dispatchers.light_spawn.dispatch connect( info['url'], info['token'] ) end |
#each(&block) ⇒ Object
49 50 51 52 53 |
# File 'lib/arachni/processes/instances.rb', line 49 def each( &block ) @list.keys.each do |url| block.call connect( url ) end end |
#grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/arachni/processes/instances.rb', line 115 def grid_spawn( = {} ) [:grid_size] ||= 3 last_member = nil [:grid_size].times do |i| last_member = Dispatchers.spawn( neighbour: last_member ? last_member.url : last_member, pipe_id: available_port.to_s + available_port.to_s ) end info = last_member.dispatch instance = connect( info['url'], info['token'] ) instance.framework.set_as_master instance..set( dispatcher: { grid_mode: :aggregate } ) instance end |
#kill(url) ⇒ Object
170 171 172 173 |
# File 'lib/arachni/processes/instances.rb', line 170 def kill( url ) Manager.kill_many connect( url ).service.consumed_pids @list.delete url end |
#killall ⇒ Object
Kills all #list.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/arachni/processes/instances.rb', line 176 def killall pids = [] each do |instance| begin Timeout.timeout 5 do pids |= instance.service.consumed_pids end rescue => e #ap e #ap e.backtrace end end each do |instance| begin Timeout.timeout 5 do instance.service.shutdown end rescue => e #ap e #ap e.backtrace end end @list.clear @instance_connections.clear Manager.kill_many pids end |
#light_grid_spawn(options = {}) ⇒ RPC::Client::Instance
Starts RPC::Server::Dispatcher grid and returns a high-performance Instance.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/arachni/processes/instances.rb', line 140 def light_grid_spawn( = {} ) [:grid_size] ||= 3 last_member = nil [:grid_size].times do |i| last_member = Dispatchers.light_spawn( neighbour: last_member ? last_member.url : last_member, pipe_id: available_port.to_s + available_port.to_s ) end info = nil info = last_member.dispatch while !info && sleep( 0.1 ) instance = connect( info['url'], info['token'] ) instance.framework.set_as_master instance..set( dispatcher: { grid_mode: :aggregate } ) instance end |
#spawn(options = {}) ⇒ RPC::Client::Instance
Spawns an RPC::Server::Instance process.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/arachni/processes/instances.rb', line 71 def spawn( = {} ) token = .delete(:token) || generate_token fork = .delete(:fork) = { spawns: [:spawns], rpc: { server_socket: [:socket], server_port: [:port] || available_port, server_address: [:address] || '127.0.0.1' } } url = nil if [:rpc][:server_socket] url = [:rpc][:server_socket] [:rpc].delete :server_address [:rpc].delete :server_port else url = "#{[:rpc][:server_address]}:#{[:rpc][:server_port]}" end Manager.spawn( :instance, options: , token: token, fork: fork ) while sleep( 0.1 ) begin connect( url, token ).service.alive? break rescue => e # ap e end end @list[url] = token connect( url ) end |