Class: ForwardMachine::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/forwardmachine/controller.rb

Overview

Server which listens for forward requests. It should be run on internal address, like localhost because it doesn’t have any authentication. Each connection is handled by ControllerConnection

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Controller

Returns a new instance of Controller.



7
8
9
10
11
12
# File 'lib/forwardmachine/controller.rb', line 7

def initialize(options = {})
  @host = options[:host] || "localhost"
  @port = options[:port] || 8899
  @forwarder_host = options[:forwarder_host] || @host
  @ports = PortsPool.new(options[:ports_range] || (23200..23500))
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/forwardmachine/controller.rb', line 14

def run
  EM.run {
    EM.error_handler { |error|
      logger.error(error.message)
      logger.error(error.backtrace.join("\n"))
    }
    EM.start_server(@host, @port, ControllerConnection,
      @forwarder_host, @ports)
    logger.info("Started controller at #{@host}:#{@port}")
  }
end