class QReplay::TcpProcessor

Public Class Methods

new() click to toggle source
# File lib/qreplay/tcpprocessor.rb, line 9
def initialize
  @streams = {}
  @stream_processors = []
end

Public Instance Methods

add_stream_processor(processor) click to toggle source
# File lib/qreplay/tcpprocessor.rb, line 14
def add_stream_processor processor
  @stream_processors << processor
end
finalize() click to toggle source
# File lib/qreplay/tcpprocessor.rb, line 50
def finalize
  @streams.each do |k, stream|
    current = {:index => k, :data => stream[:data]}
    @stream_processors.each do |p|
      current = p.process_stream current
      break unless current
    end
  end

  @stream_processors.each do |p|
    p.finalize
  end
end
inject(index, packet) click to toggle source
# File lib/qreplay/tcpprocessor.rb, line 18
def inject index, packet
  stream_index = packet[:stream]
  if stream_index
    if packet[:tcp_flags][:syn] && packet[:tcp_flags][:ack] === false
      @streams[stream_index] = {
        :first => packet,
        :data => [],
      }
    elsif packet[:tcp_flags][:fin] || packet[:tcp_flags][:rst]
      if @streams[stream_index]
        current = {:index => stream_index, :data => @streams[stream_index][:data]}
        @stream_processors.each do |p|
          current = p.process_stream current
          break unless current
        end
        @streams.delete stream_index
      end
    else
      unless @streams[stream_index]
        @streams[stream_index] = {
          :first => packet,
          :data => [],
        }
      end

      packet[:type] = (packet[:from] == @streams[stream_index][:first][:from] && packet[:from_port] == @streams[stream_index][:first][:from_port]) ? :out : :in
      packet.delete :tcp_flags
      @streams[stream_index][:data] << packet if packet[:size] > 0
    end
  end
end