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.

Author:

  • Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

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

Instance Method Details

#connect_to_instance(instance) ⇒ Object

Connects to a remote Instance.

Parameters:

  • instance (Hash)

    The hash must hold the `'url'` and the `'token'`. In subsequent calls the `'token'` can be omitted.



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( options, instance[:url], @tokens[instance[:url]] )
end

#each_slave(foreach = nil, after = nil, &block) ⇒ Object

Parameters:

  • foreach (Proc) (defaults to: nil)

    Invoked once for each slave instance.

  • after (Proc) (defaults to: nil)

    Invoked after the iteration has completed.

  • block (Proc)

    Invoked once for each slave instance.



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.

Parameters:

Returns:

  • (Arachni::Reactor::Iterator)

    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

Parameters:

  • foreach (Proc)

    Invoked once for each slave instance and an array from the returned values.

  • after (Proc)

    To handle the resulting array.



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_iteratorArachni::Reactor::Iterator

Returns Iterator for all slave instances.

Returns:

  • (Arachni::Reactor::Iterator)

    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