Skip to content

Commit

Permalink
Use the new Config and Workers in Engine#initialize (closes #124).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed May 10, 2024
1 parent 2a6a5d1 commit 9f1e5fa
Showing 1 changed file with 62 additions and 16 deletions.
78 changes: 62 additions & 16 deletions lib/ronin/recon/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
#

require 'ronin/recon/workers'
require 'ronin/recon/config'
require 'ronin/recon/worker_tasks'
require 'ronin/recon/value_status'
require 'ronin/recon/graph'
Expand All @@ -29,7 +31,6 @@
require 'ronin/recon/message/job_failed'
require 'ronin/recon/message/value'
require 'ronin/recon/message/shutdown'
require 'ronin/recon/worker_set'

require 'set'
require 'console/logger'
Expand All @@ -42,6 +43,16 @@ module Recon
#
class Engine

# The configuration for the engine.
#
# @return [Config]
attr_reader :config

# The workers to use.
#
# @return [Workers]
attr_reader :workers

# The scope to constrain recon to.
#
# @return [Scope]
Expand All @@ -59,6 +70,13 @@ class Engine
# @api public
attr_reader :graph

# The intensity to filter workers by.
#
# @return [:passive, :active, :intensive, nil]
#
# @api public
attr_reader :intensity

# The maximum depth to recon.
#
# @return [Integer, nil]
Expand All @@ -69,6 +87,23 @@ class Engine
#
# Initializes the recon engine.
#
# @param [Array<Value>] values
# The initial values to start the recon engine with.
#
# @param [String, nil] config_file
# The path to the configuration file.
#
# @param [Config, nil] config
# The configuration for the engine. If specified, it will override
# `config_file:`.
#
# @param [Workers, nil] workers
# The worker classes to use. If specified, it will override the workers
# specified in `config.worker_set`.
#
# @param [:passive, :active, :intensive, nil] intensity
# The intensity level to filter worker classes by.
#
# @yield [self]
# If a block is given it will be passed the newly created engine.
#
Expand All @@ -80,34 +115,45 @@ class Engine
#
# @api public
#
def initialize(values, workers: WorkerSet.default,
max_depth: nil,
logger: Console.logger,
ignore: [])
def initialize(values, ignore: [],
max_depth: nil,
intensity: nil,
config: nil,
config_file: nil,
workers: nil,
logger: Console.logger)
@scope = Scope.new(values, ignore: ignore)

@worker_classes = {}
@worker_tasks = {}
@worker_task_count = 0
@max_depth = max_depth
@intensity = intensity

@value_status = ValueStatus.new
@graph = Graph.new
@max_depth = max_depth
@output_queue = Async::Queue.new
@config = if config then config
elsif config_file then Config.load_file(config_file)
else Config.default
end

@value_callbacks = []
@connection_callbacks = []
@job_started_callbacks = []
@job_completed_callbacks = []
@job_failed_callbacks = []

@logger = logger
@value_status = ValueStatus.new
@graph = Graph.new
@output_queue = Async::Queue.new
@logger = logger

yield self if block_given?

@workers = workers || @config.worker_set.load_workers

@worker_classes = {}
@worker_tasks = {}
@worker_task_count = 0

workers.each do |worker_class|
@workers.each do |worker_class|
add_worker(worker_class)
end

yield self if block_given?
end

#
Expand Down

0 comments on commit 9f1e5fa

Please sign in to comment.