Merge remote-tracking branch 'origin/topic/jsiwek/reassembly-improvements-map'

* origin/topic/jsiwek/reassembly-improvements-map:
  Rename a reassembly DataBlockList function
  Add comments to reassembly classes
  Use DataBlock value instead of pointer in reassembly map
  Remove linked list from reassembly data structures
  Use an std::map for reassembly DataBlock searches
  Refactor Reassembler/DataBlock bookkeeping
  Reorganize reassembly data structures
  Remove a superfluous reassembler DataBlock member
This commit is contained in:
Robin Sommer 2019-09-24 09:03:56 +00:00
commit c23764483d
11 changed files with 675 additions and 399 deletions

View file

@ -26,16 +26,16 @@ uint64_t FileReassembler::Flush()
if ( flushing )
return 0;
if ( last_block )
{
// This is expected to call back into FileReassembler::Undelivered().
flushing = true;
uint64_t rval = TrimToSeq(last_block->upper);
flushing = false;
return rval;
}
if ( block_list.Empty() )
return 0;
return 0;
const auto& last_block = std::prev(block_list.End())->second;
// This is expected to call back into FileReassembler::Undelivered().
flushing = true;
uint64_t rval = TrimToSeq(last_block.upper);
flushing = false;
return rval;
}
uint64_t FileReassembler::FlushTo(uint64_t sequence)
@ -50,21 +50,29 @@ uint64_t FileReassembler::FlushTo(uint64_t sequence)
return rval;
}
void FileReassembler::BlockInserted(DataBlock* start_block)
void FileReassembler::BlockInserted(DataBlockMap::const_iterator it)
{
if ( start_block->seq > last_reassem_seq ||
start_block->upper <= last_reassem_seq )
const auto& start_block = it->second;
if ( start_block.seq > last_reassem_seq ||
start_block.upper <= last_reassem_seq )
return;
for ( DataBlock* b = start_block;
b && b->seq <= last_reassem_seq; b = b->next )
while ( it != block_list.End() )
{
if ( b->seq == last_reassem_seq )
const auto& b = it->second;
if ( b.seq > last_reassem_seq )
break;
if ( b.seq == last_reassem_seq )
{ // New stuff.
uint64_t len = b->Size();
uint64_t len = b.Size();
last_reassem_seq += len;
the_file->DeliverStream(b->block, len);
the_file->DeliverStream(b.block, len);
}
++it;
}
// Throw out forwarded data
@ -74,29 +82,31 @@ void FileReassembler::BlockInserted(DataBlock* start_block)
void FileReassembler::Undelivered(uint64_t up_to_seq)
{
// If we have blocks that begin below up_to_seq, deliver them.
DataBlock* b = blocks;
auto it = block_list.Begin();
while ( b )
while ( it != block_list.End() )
{
if ( b->seq < last_reassem_seq )
const auto& b = it->second;
if ( b.seq < last_reassem_seq )
{
// Already delivered this block.
b = b->next;
++it;
continue;
}
if ( b->seq >= up_to_seq )
if ( b.seq >= up_to_seq )
// Block is beyond what we need to process at this point.
break;
uint64_t gap_at_seq = last_reassem_seq;
uint64_t gap_len = b->seq - last_reassem_seq;
uint64_t gap_len = b.seq - last_reassem_seq;
the_file->Gap(gap_at_seq, gap_len);
last_reassem_seq += gap_len;
BlockInserted(b);
BlockInserted(it);
// Inserting a block may cause trimming of what's buffered,
// so have to assume 'b' is invalid, hence re-assign to start.
b = blocks;
it = block_list.Begin();
}
if ( up_to_seq > last_reassem_seq )

View file

@ -50,7 +50,7 @@ protected:
FileReassembler();
void Undelivered(uint64_t up_to_seq) override;
void BlockInserted(DataBlock* b) override;
void BlockInserted(DataBlockMap::const_iterator it) override;
void Overlap(const u_char* b1, const u_char* b2, uint64_t n) override;
File* the_file;