#NEWLINE# def add( self , pkt ) : #NEWLINE# #INDENT# '\n        called for every packet coming in, instead of iterating through\n        a list\n        ' #NEWLINE# for i in xrange ( len ( self . packets ) , ( - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# if ( ( i == 0 ) or ( self . packets [ ( i - 1 ) ] . ts <= pkt . ts ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# self . packets . insert ( i , pkt ) #NEWLINE# if ( self . handshake is not None ) : #NEWLINE# #INDENT# if ( i . flags == TH_SYN ) : #NEWLINE# #INDENT# raise NewFlowError #NEWLINE# #UNINDENT# self . merge_pkt ( pkt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( self . packets ) > 13 ) : #NEWLINE# #INDENT# self . handshake = False #NEWLINE# self . socket = self . packets [ 0 ] . socket #NEWLINE# self . flush_packets ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tcp . detect_handshake ( self . packets [ ( - 3 ) : ] ) : #NEWLINE# #INDENT# self . handshake = tuple ( self . packets [ ( - 3 ) : ] ) #NEWLINE# self . socket = self . handshake [ 0 ] . socket #NEWLINE# self . flush_packets ( )