#NEWLINE# def add( self , pkt ) : #NEWLINE# #INDENT# '\n        Merge the packet into the first chunk it overlaps with. If data was\n        added to the end of a chunk, attempts to merge the next chunk (if there\n        is one). This way, it is ensured that everything is as fully merged as\n        it can be with the current data.\n\n        Args:\n        pkt = tcp.Packet\n        ' #NEWLINE# if self . finished : #NEWLINE# #INDENT# raise RuntimeError ( 'tried to add packets to a finished tcp.Direction' ) #NEWLINE# #UNINDENT# if ( self . chunks is None ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Tried to add packet to a tcp.Directionthat has been cleared' ) #NEWLINE# #UNINDENT# if ( pkt . data == '' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# merged = False #NEWLINE# for ( i , chunk ) in enumerate ( self . chunks ) : #NEWLINE# #INDENT# ( overlapped , ( front , back ) ) = chunk . merge ( pkt , self . create_merge_callback ( pkt ) ) #NEWLINE# if overlapped : #NEWLINE# #INDENT# if ( back and ( i < ( len ( self . chunks ) - 1 ) ) ) : #NEWLINE# #INDENT# ( overlapped2 , result2 ) = chunk . merge ( self . chunks [ ( i + 1 ) ] ) #NEWLINE# if overlapped2 : #NEWLINE# #INDENT# self . chunks . remove ( ( i + 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . seq_start and ( chunk . seq_start == self . seq_start ) ) : #NEWLINE# #INDENT# if front : #NEWLINE# #INDENT# self . final_arrival_data . insert ( ( self . seq_start , pkt . ts ) ) #NEWLINE# #UNINDENT# if back : #NEWLINE# #INDENT# self . final_arrival_data . insert ( ( self . final_arrival_pointer , pkt . ts ) ) #NEWLINE# #UNINDENT# if ( not self . final_data_chunk ) : #NEWLINE# #INDENT# self . final_data_chunk = chunk #NEWLINE# #UNINDENT# self . final_arrival_pointer = self . final_data_chunk . seq_end #NEWLINE# #UNINDENT# merged = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not merged ) : #NEWLINE# #INDENT# self . new_chunk ( pkt )