Class: Arachni::Processes::Dispatchers
- Includes:
- Utilities, Singleton
- Defined in:
- lib/arachni/processes/dispatchers.rb
Overview
Helper for managing RPC::Server::Dispatcher processes.
Instance Attribute Summary collapse
-
#list ⇒ Array<String>
readonly
URLs of all running Dispatchers.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect(url, options = { }) ⇒ RPC::Client::Dispatcher
Connects to a Dispatcher by URL.
- #each(&block) ⇒ Object
-
#initialize ⇒ Dispatchers
constructor
A new instance of Dispatchers.
- #kill(url) ⇒ Object
-
#killall ⇒ Object
Kills all #list.
-
#light_spawn(options = {}, &block) ⇒ Object
Same as #spawn but sets the pool size to ‘1`.
-
#spawn(options = {}, &block) ⇒ RPC::Client::Dispatcher
Spawns a RPC::Server::Dispatcher process.
Methods included from Utilities
#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize
Constructor Details
#initialize ⇒ Dispatchers
Returns a new instance of Dispatchers.
32 33 34 35 |
# File 'lib/arachni/processes/dispatchers.rb', line 32 def initialize @list = [] @dispatcher_connections = {} end |
Instance Attribute Details
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/arachni/processes/dispatchers.rb', line 134 def self.method_missing( sym, *args, &block ) if instance.respond_to?( sym ) instance.send( sym, *args, &block ) elsif super( sym, *args, &block ) end end |
.respond_to?(m) ⇒ Boolean
142 143 144 |
# File 'lib/arachni/processes/dispatchers.rb', line 142 def self.respond_to?( m ) super( m ) || instance.respond_to?( m ) end |
Instance Method Details
#connect(url, options = { }) ⇒ RPC::Client::Dispatcher
Connects to a Dispatcher by URL.
45 46 47 48 |
# File 'lib/arachni/processes/dispatchers.rb', line 45 def connect( url, = { } ) opts = OpenStruct.new( ) @dispatcher_connections[url] ||= RPC::Client::Dispatcher.new( opts, url ) end |
#each(&block) ⇒ Object
51 52 53 54 55 |
# File 'lib/arachni/processes/dispatchers.rb', line 51 def each( &block ) @list.each do |url| block.call connect( url ) end end |
#kill(url) ⇒ Object
Will also kill all Instances started by the Dispatcher.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/arachni/processes/dispatchers.rb', line 114 def kill( url ) dispatcher = connect( url ) Manager.kill_many dispatcher.stats['consumed_pids'] Manager.kill dispatcher.proc_info['pid'].to_i rescue => e #ap e #ap e.backtrace nil ensure @list.delete( url ) @dispatcher_connections.delete( url ) end |
#killall ⇒ Object
Kills all #list.
128 129 130 131 132 |
# File 'lib/arachni/processes/dispatchers.rb', line 128 def killall @list.dup.each do |url| kill url end end |
#light_spawn(options = {}, &block) ⇒ Object
Same as #spawn but sets the pool size to ‘1`.
107 108 109 |
# File 'lib/arachni/processes/dispatchers.rb', line 107 def light_spawn( = {}, &block ) spawn( .merge( pool_size: 1 ), &block ) end |
#spawn(options = {}, &block) ⇒ RPC::Client::Dispatcher
Spawns a RPC::Server::Dispatcher process.
69 70 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 |
# File 'lib/arachni/processes/dispatchers.rb', line 69 def spawn( = {}, &block ) = Options.to_hash.symbolize_keys( false ).merge( ) [:rpc_port] = .delete( :port ) if .include?( :port ) [:rpc_address] = .delete( :address ) if .include?( :address ) [:rpc_port] ||= available_port url = "#{[:rpc_address]}:#{[:rpc_port]}" Manager.fork_em do Options.set( ) block.call( Options.instance ) if block_given? require "#{Arachni::Options.dir['lib']}/rpc/server/dispatcher" RPC::Server::Dispatcher.new end begin Timeout.timeout( 10 ) do while sleep( 0.1 ) begin connect( url, max_retries: 1 ).alive? break rescue Exception end end end rescue Timeout::Error abort "Dispatcher '#{url}' never started!" end @list << url connect( url ) end |