Class: Equity::Manager
- Inherits:
-
Object
- Object
- Equity::Manager
- Defined in:
- lib/equity/manager.rb
Constant Summary collapse
- CMD_NODE_STATUS =
"S"- CMD_SHUTDOWN =
"K"- CMD_WAITDOWN =
"W"- CMD_NAMES =
{ CMD_NODE_STATUS => "status", CMD_SHUTDOWN => "shutdown", CMD_WAITDOWN => "waitdown" }
Instance Method Summary collapse
-
#initialize(nodes, port, debugging = false) ⇒ Manager
constructor
A new instance of Manager.
- #process_commands ⇒ Object
Constructor Details
#initialize(nodes, port, debugging = false) ⇒ Manager
Returns a new instance of Manager.
16 17 18 19 20 21 |
# File 'lib/equity/manager.rb', line 16 def initialize(nodes, port, debugging = false) @nodes = nodes @socket = UDPSocket.new @socket.bind(nil, port) @debugging = debugging end |
Instance Method Details
#process_commands ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/equity/manager.rb', line 23 def process_commands # Read commands from the network. begin data, address = @socket.recvfrom_nonblock(4096) rescue Errno::EAGAIN end return unless data command = data.split(/#{Controller::Key::SIGNATURE_SEPARATOR}/).first debug("received manager command: #{command_name(command)}", address) # Verify the signature and ensure that the key used to sign the command # is authorized. unless verified_data = Controller::Key.verify(data) debug("signature verification failed - ignoring command", address) return end unless Controller::Key.signature_key(data). debug("command signed by unauthorized key - ignoring command", address) return end data = verified_data # Process the command. debug("signature verified - processing command", address) case data when CMD_NODE_STATUS reply = when CMD_SHUTDOWN UDPSocket.new.send(, 0, address[2], address[1]) exit when CMD_WAITDOWN reply = waitdown else debug("command not understood (#{data.unpack('H*')})", address) return end UDPSocket.new.send(reply, 0, address[2], address[1]) end |