mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Remove linked list from reassembly data structures
Everything, including iteration is now done via an std::map
This commit is contained in:
parent
9b13825e16
commit
e1e779e90b
8 changed files with 248 additions and 254 deletions
|
@ -26,18 +26,16 @@ uint64_t FileReassembler::Flush()
|
|||
if ( flushing )
|
||||
return 0;
|
||||
|
||||
auto last_block = block_list.Tail();
|
||||
if ( block_list.Empty() )
|
||||
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;
|
||||
}
|
||||
auto last_block = std::prev(block_list.End())->second;
|
||||
|
||||
return 0;
|
||||
// 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)
|
||||
|
@ -52,22 +50,29 @@ uint64_t FileReassembler::FlushTo(uint64_t sequence)
|
|||
return rval;
|
||||
}
|
||||
|
||||
void FileReassembler::BlockInserted(const DataBlock* start_block)
|
||||
void FileReassembler::BlockInserted(DataBlockMap::const_iterator it)
|
||||
{
|
||||
auto start_block = it->second;
|
||||
|
||||
if ( start_block->seq > last_reassem_seq ||
|
||||
start_block->upper <= last_reassem_seq )
|
||||
return;
|
||||
|
||||
// TODO: better way to iterate ?
|
||||
for ( auto b = start_block;
|
||||
b && b->seq <= last_reassem_seq; b = b->next )
|
||||
while ( it != block_list.End() )
|
||||
{
|
||||
auto b = it->second;
|
||||
|
||||
if ( b->seq > last_reassem_seq )
|
||||
break;
|
||||
|
||||
if ( b->seq == last_reassem_seq )
|
||||
{ // New stuff.
|
||||
uint64_t len = b->Size();
|
||||
last_reassem_seq += len;
|
||||
the_file->DeliverStream(b->block, len);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// Throw out forwarded data
|
||||
|
@ -77,15 +82,16 @@ void FileReassembler::BlockInserted(const DataBlock* start_block)
|
|||
void FileReassembler::Undelivered(uint64_t up_to_seq)
|
||||
{
|
||||
// If we have blocks that begin below up_to_seq, deliver them.
|
||||
const DataBlock* b = block_list.Head();
|
||||
auto it = block_list.Begin();
|
||||
|
||||
// TODO: better way to iterate ?
|
||||
while ( b )
|
||||
while ( it != block_list.End() )
|
||||
{
|
||||
auto b = it->second;
|
||||
|
||||
if ( b->seq < last_reassem_seq )
|
||||
{
|
||||
// Already delivered this block.
|
||||
b = b->next;
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -97,10 +103,10 @@ void FileReassembler::Undelivered(uint64_t up_to_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 = block_list.Head();
|
||||
it = block_list.Begin();
|
||||
}
|
||||
|
||||
if ( up_to_seq > last_reassem_seq )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue