Class: Metasploit::Aggregator::Router
- Inherits:
-
Object
- Object
- Metasploit::Aggregator::Router
- Includes:
- Singleton
- Defined in:
- lib/metasploit/aggregator/router.rb
Instance Method Summary collapse
- #add_route(uuid, payload) ⇒ Object
- #get_forward(payload) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #remove_route(payload) ⇒ Object
- #reverse_route(uuid) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
8 9 10 11 12 |
# File 'lib/metasploit/aggregator/router.rb', line 8 def initialize @mutex = Mutex.new @forward_routes = {} @queue_by_uuid = {} end |
Instance Method Details
#add_route(uuid, payload) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/metasploit/aggregator/router.rb', line 14 def add_route(uuid, payload) # for now always replace in future may check if same route to avoid request loss forward = uuid.nil? ? [] : [Queue.new, Queue.new, uuid] @mutex.synchronize do if payload.nil? @forward_routes['default'] = forward return end @forward_routes[payload] = forward end end |
#get_forward(payload) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/metasploit/aggregator/router.rb', line 34 def get_forward(payload) unless @forward_routes[payload].nil? @forward_routes[payload] else @forward_routes['default'] end end |
#remove_route(payload) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/metasploit/aggregator/router.rb', line 26 def remove_route(payload) unless payload.nil? @mutex.synchronize do @forward_routes.delete(payload) end end end |
#reverse_route(uuid) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/metasploit/aggregator/router.rb', line 42 def reverse_route(uuid) # this method is not ready for prime time yet as will not # support multiple sessions properly, either need unique Queue # for each session which can be identified on reverse or need # pipeline request order to ensure all results are posted in order only # this could create deadlocks while one session waits for a response # if another fails to respond. # try returning a uuid queue filled an aggregate of queues for all requests # for a reverse uuid, and refill that on each reverse, this puts logic # here that I do not like but accomplishes the requirement for now unless @queue_by_uuid[uuid] @queue_by_uuid[uuid] = Queue.new end @forward_routes.each_pair do |key, val| request, response, remote_uuid = val next unless remote_uuid == uuid while !request.empty? @queue_by_uuid[uuid] << request.pop end end [@queue_by_uuid[uuid], nil, uuid] end |