Module: Arachni::RPC::Server::Framework::Distributor
- Included in:
- MultiInstance
- Defined in:
- lib/arachni/rpc/server/framework/distributor.rb
Overview
Contains utility methods used to connect to instances and dispatchers and split and distribute the workload.
Constant Summary collapse
- MAX_CONCURRENCY =
Maximum concurrency when communicating with instances.
Means that you should connect to MAX_CONCURRENCY instances at a time while iterating through them.
20
Instance Method Summary collapse
-
#connect_to_instance(instance) ⇒ Object
Connects to a remote Instance.
- #each_slave(foreach = nil, after = nil, &block) ⇒ Object
-
#iterator_for(arr) ⇒ Arachni::Reactor::Iterator
Iterator for the provided array.
- #map_slaves(foreach, after) ⇒ Object
-
#slave_iterator ⇒ Arachni::Reactor::Iterator
Iterator for all slave instances.
Instance Method Details
#connect_to_instance(instance) ⇒ Object
Connects to a remote Instance.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/arachni/rpc/server/framework/distributor.rb', line 29 def connect_to_instance( instance ) instance = instance.my_symbolize_keys @instance_connections ||= {} if @instance_connections[instance[:url]] return @instance_connections[instance[:url]] end @tokens ||= {} @tokens[instance[:url]] = instance[:token] if instance[:token] @instance_connections[instance[:url]] = RPC::Client::Instance.new( , instance[:url], @tokens[instance[:url]] ) end |
#each_slave(foreach = nil, after = nil, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/arachni/rpc/server/framework/distributor.rb', line 60 def each_slave( foreach = nil, after = nil, &block ) foreach ||= block wrapped_foreach = proc do |instance, iterator| foreach.call( connect_to_instance( instance ), iterator ) end slave_iterator.each( *[wrapped_foreach, after] ) end |
#iterator_for(arr) ⇒ Arachni::Reactor::Iterator
Returns Iterator for the provided array.
78 79 80 |
# File 'lib/arachni/rpc/server/framework/distributor.rb', line 78 def iterator_for( arr ) Reactor.global.create_iterator( arr, MAX_CONCURRENCY ) end |
#map_slaves(foreach, after) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/arachni/rpc/server/framework/distributor.rb', line 47 def map_slaves( foreach, after ) wrap = proc do |instance, iterator| foreach.call( connect_to_instance( instance ), iterator ) end slave_iterator.map( wrap, after ) end |
#slave_iterator ⇒ Arachni::Reactor::Iterator
Returns Iterator for all slave instances.
70 71 72 |
# File 'lib/arachni/rpc/server/framework/distributor.rb', line 70 def slave_iterator iterator_for( @slaves ) end |