class Metasploit::Aggregator::GrpcServer

Public Class Methods

new(host, port) click to toggle source
# File lib/metasploit/aggregator.rb, line 394
def initialize(host, port)
  @host = host
  @port = port

  # TODO: investigate using Core::Channel to secure this communication
  # server = TCPServer.new(@host, @port)
  # sslContext = OpenSSL::SSL::SSLContext.new
  # sslContext.key, sslContext.cert = Metasploit::Aggregator::ConnectionManager.ssl_generate_certificate
  # sslServer = OpenSSL::SSL::SSLServer.new(server, sslContext)

  @svr = GRPC::RpcServer.new
  @svr.add_http2_port("#{@host}:#{@port}", :this_port_is_insecure)
  @svr.handle(ServerImpl)

  @exec = Thread.new do
    GrpcServer.register_for_cleanup(self)
    @svr.run_till_terminated
  end
end

Protected Class Methods

register_for_cleanup(connection) click to toggle source
# File lib/metasploit/aggregator.rb, line 421
def self.register_for_cleanup(connection)
  @exit_lock.synchronize do
    unless @cleanup_list
      @cleanup_list = ::Set.new
      at_exit { GrpcServer.run_cleanup }
    end
    @cleanup_list.add connection
  end
end
run_cleanup() click to toggle source
# File lib/metasploit/aggregator.rb, line 437
def self.run_cleanup
  @exit_lock.synchronize do
    if @cleanup_list
      @cleanup_list.each do |connection|
        connection.stop(true)
      end
    end
  end
end
unregister_for_cleanup(connection) click to toggle source
# File lib/metasploit/aggregator.rb, line 431
def self.unregister_for_cleanup(connection)
  @exit_lock.synchronize do
    @cleanup_list.delete connection if @cleanup_list
  end
end

Public Instance Methods

stop(force = false) click to toggle source
# File lib/metasploit/aggregator.rb, line 414
def stop(force = false)
  GrpcServer.unregister_for_cleanup(self) unless force
  @svr.stop if @svr.running?
end