Class: OnesnooperServer::UDPHandler

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/onesnooper_server/udp_handler.rb

Overview

Handler for incoming UDP datagrams. Implements required methods for direct use with EventMachine listeners. This handler will not respond to incoming datagrams as its primary purpose is to record mirrored monitoring traffic.

Constant Summary collapse

DATAGRAM_PREFIX =
'MONITOR'

Instance Method Summary collapse

Instance Method Details

#receive_data(monitoring_datagram) ⇒ Object

Receives data and triggers processing of the given datagram. Main internal processing triggered from this method should always happen asynchronously (i.e., using EventMachine.defer or Deferrable classes).

Parameters:

  • monitoring_datagram (String)

    incoming data payload


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/onesnooper_server/udp_handler.rb', line 15

def receive_data(monitoring_datagram)
  monitoring_datagram.chomp!
  source_port, source_ip = Socket.unpack_sockaddr_in(get_peername)
  unless monitoring_datagram.start_with?(DATAGRAM_PREFIX)
    ::OnesnooperServer::Log.warn "[#{self.class.name}] Discarding datagram from " \
                                 "#{source_ip}:#{source_port} (not #{DATAGRAM_PREFIX})"
    return
  end

  ::OnesnooperServer::Log.debug "[#{self.class.name}] Received #{monitoring_datagram.inspect} " \
                                "from #{source_ip}:#{source_port}"
  ::OnesnooperServer::RequestHandler.parse(
    monitoring_datagram,
    source_ip,
    source_port
  ).run(callback)
end