class RFlow::Components::IRC::Client

Component that subscribes to an IRC channel and issues +RFlow::Message+s of type {RFlow::Message::Data::IRC::Message} when it receives messages.

Assumes a single connection, meaning that it can choose to be 'promiscuous' and not limit its sending to only those messages derived from one of its own

Accepts config parameters:

Constants

DEFAULT_CONFIG

Default configuration.

Attributes

client_connection[RW]

@!visibility private

config[RW]

@!visibility private

port[RW]

@!visibility private

server[RW]

@!visibility private

Public Instance Methods

configure!(config) click to toggle source

RFlow-called method at startup. @return [void]

# File lib/rflow/components/irc/client.rb, line 99
def configure!(config)
  @config = DEFAULT_CONFIG.merge config

  @config['port'] = @config['port'].to_i
  @config['reconnect_interval'] = @config['reconnect_interval'].to_i
  # TODO: More config sanitization

  @server = @config['server']
  @port = @config['port'].to_i
end
process_message(input_port, input_port_key, connection, message) click to toggle source

RFlow-called method at message arrival. @return [void]

# File lib/rflow/components/irc/client.rb, line 121
def process_message(input_port, input_port_key, connection, message)
  RFlow.logger.debug { "#{name}: Received a message" }
  return unless message.data_type_name == 'RFlow::Message::Data::IRC::Message'

  if config['promiscuous']
    RFlow.logger.debug { "#{name}: Received an IRC::Message message, sending to client connection" }
    client_connection.send_irc_message message
  else
    RFlow.logger.debug { "#{name}: Received an IRC::Message message, determining if it's mine" }
    my_events = message.provenance.find_all {|event| event.component_instance_uuid == uuid}
    RFlow.logger.debug { "#{name}: Found #{my_events.size} processing events from me" }
    # Attempt to send the data to each context match.
    # TODO: check for correctness
    my_events.each do |event|
      RFlow.logger.debug { "#{name}: Inspecting context #{client_connection.signature.to_s} == #{event.context.to_s}" }
      if client_connection.signature.to_s == event.context.to_s
        RFlow.logger.debug { "#{name}: Found connection for #{event.context}, sending message to associated client connection" }
        client_connection.send_irc_message message
      end
    end
  end
end
run!() click to toggle source

RFlow-called method at startup. @return [void]

# File lib/rflow/components/irc/client.rb, line 112
def run!
  @client_connection = EM.connect(@server, @port, Connection) do |conn|
    conn.client = self
    RFlow.logger.debug { "#{name}: Connection from #{@client_ip}:#{@client_port} to #{@server_ip}:#{@server_port}" }
  end
end