Class: QReplay::TcpProcessor
- Inherits:
-
Object
- Object
- QReplay::TcpProcessor
- Defined in:
- lib/qreplay/tcpprocessor.rb
Instance Method Summary collapse
- #add_stream_processor(processor) ⇒ Object
- #finalize ⇒ Object
-
#initialize ⇒ TcpProcessor
constructor
A new instance of TcpProcessor.
- #inject(index, packet) ⇒ Object
Constructor Details
#initialize ⇒ TcpProcessor
Returns a new instance of TcpProcessor.
9 10 11 12 |
# File 'lib/qreplay/tcpprocessor.rb', line 9 def initialize @streams = {} @stream_processors = [] end |
Instance Method Details
#add_stream_processor(processor) ⇒ Object
14 15 16 |
# File 'lib/qreplay/tcpprocessor.rb', line 14 def add_stream_processor processor @stream_processors << processor end |
#finalize ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
18 19 20 21 22 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 |
# 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 |