dtn::BlockProcessor Class Reference

#include <BlockProcessor.h>

Inheritance diagram for dtn::BlockProcessor:

dtn::APIBlockProcessor dtn::PayloadBlockProcessor dtn::PreviousHopBlockProcessor dtn::PrimaryBlockProcessor dtn::UnknownBlockProcessor

List of all members.


Detailed Description

Base class for the protocol handling of bundle blocks, including the core primary and payload handling, security, and other extension blocks.

Definition at line 36 of file BlockProcessor.h.


Public Member Functions

 BlockProcessor (int block_type)
 Constructor that takes the block typecode.
virtual ~BlockProcessor ()
 Virtual destructor.
virtual int consume (Bundle *bundle, BlockInfo *block, u_char *buf, size_t len)
 First callback for parsing blocks that is expected to append a chunk of the given data to the given block.
virtual bool validate (const Bundle *bundle, BlockInfo *block, BundleProtocol::status_report_reason_t *reception_reason, BundleProtocol::status_report_reason_t *deletion_reason)
 Validate the block.
virtual void prepare (const Bundle *bundle, Link *link, BlockInfoVec *blocks, const BlockInfo *source)
 First callback to generate blocks for the output pass.
virtual void generate (const Bundle *bundle, Link *link, BlockInfo *block, bool last)=0
 Second callback for transmitting a bundle.
virtual void finalize (const Bundle *bundle, Link *link, BlockInfo *block)
 Third callback for transmitting a bundle.
virtual void produce (const Bundle *bundle, const BlockInfo *block, u_char *buf, size_t offset, size_t len)
 Accessor to virtualize copying contents out from the block info.
void init_block (BlockInfo *block, u_int8_t type, u_int8_t flags, u_char *bp, size_t len)
 General hook to set up a block with the given contents.
int block_type ()
 Accessors.

Protected Member Functions

int consume_preamble (BlockInfo *block, u_char *buf, size_t len, size_t preamble_size=0)
 Consume a fixed-length preamble (defaulting to the standard BlockPreamble) followed by an SDNV containing the length of the rest of the block.
void generate_preamble (BlockInfo *block, u_int8_t type, u_int8_t flags, size_t data_length)
 Generate the standard preamble for the given block type, flags and content length.

Private Attributes

int block_type_
 The block typecode for this handler.

Friends

class BundleProtocol
class BlockInfo

Constructor & Destructor Documentation

dtn::BlockProcessor::BlockProcessor ( int  block_type  ) 

Constructor that takes the block typecode.

Generally, typecodes should be defined in BundleProtocol::bundle_block_type_t, but the field is defined as an int so that handlers for non-specified blocks can be defined.

Definition at line 27 of file BlockProcessor.cc.

dtn::BlockProcessor::~BlockProcessor (  )  [virtual]

Virtual destructor.

Definition at line 33 of file BlockProcessor.cc.


Member Function Documentation

int dtn::BlockProcessor::block_type (  )  [inline]

Accessors.

Definition at line 52 of file BlockProcessor.h.

References block_type_.

Referenced by dtn::BundleProtocol::consume(), consume(), consume_preamble(), generate_preamble(), dtn::BundleProtocol::register_processor(), dtn::BlockInfo::serialize(), and dtn::BlockInfo::type().

int dtn::BlockProcessor::consume ( Bundle bundle,
BlockInfo block,
u_char *  buf,
size_t  len 
) [virtual]

First callback for parsing blocks that is expected to append a chunk of the given data to the given block.

When the block is completely received, this should also parse the block into any fields in the bundle class.

The base class implementation parses the block preamble fields to find the length of the block and copies the preamble and the data in the block's contents buffer.

This and all derived implementations must be able to handle a block that is received in chunks, including cases where the preamble is split into multiple chunks.

Returns:
the amount of data consumed or -1 on error

Reimplemented in dtn::APIBlockProcessor, dtn::PayloadBlockProcessor, dtn::PreviousHopBlockProcessor, and dtn::PrimaryBlockProcessor.

Definition at line 152 of file BlockProcessor.cc.

References ASSERT, block_type(), dtn::BlockInfo::complete(), consume_preamble(), dtn::BlockInfo::contents(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), dtn::BlockInfo::full_length(), log_debug_p, dtn::BlockInfo::set_complete(), dtn::BlockInfo::type(), and dtn::BlockInfo::writable_contents().

Referenced by dtn::PrimaryBlockProcessor::consume(), dtn::PreviousHopBlockProcessor::consume(), and dtn::BundleProtocol::consume().

bool dtn::BlockProcessor::validate ( const Bundle bundle,
BlockInfo block,
BundleProtocol::status_report_reason_t reception_reason,
BundleProtocol::status_report_reason_t deletion_reason 
) [virtual]

Validate the block.

This is called after all blocks in the bundle have been fully received.

Returns:
true if the block passes validation

Reimplemented in dtn::UnknownBlockProcessor.

Definition at line 230 of file BlockProcessor.cc.

References dtn::BundleProtocol::BLOCK_FLAG_REPORT_ONERROR, dtn::BlockInfo::flags(), dtn::Bundle::is_admin_, log_err_p, dtn::BlockInfo::primary_block(), and dtn::BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE.

Referenced by dtn::UnknownBlockProcessor::validate().

void dtn::BlockProcessor::prepare ( const Bundle bundle,
Link link,
BlockInfoVec blocks,
const BlockInfo source 
) [virtual]

First callback to generate blocks for the output pass.

The function is expected to initialize an appropriate BlockInfo structure in the given BlockInfoVec.

The base class simply initializes an empty BlockInfo with the appropriate owner_ pointer.

Reimplemented in dtn::PreviousHopBlockProcessor, and dtn::UnknownBlockProcessor.

Definition at line 254 of file BlockProcessor.cc.

References BlockInfo.

Referenced by dtn::UnknownBlockProcessor::prepare(), dtn::PreviousHopBlockProcessor::prepare(), and dtn::BundleProtocol::prepare_blocks().

virtual void dtn::BlockProcessor::generate ( const Bundle bundle,
Link link,
BlockInfo block,
bool  last 
) [pure virtual]

Second callback for transmitting a bundle.

This pass should generate any data for the block that does not depend on other blocks' contents.

Implemented in dtn::APIBlockProcessor, dtn::PayloadBlockProcessor, dtn::PreviousHopBlockProcessor, dtn::PrimaryBlockProcessor, and dtn::UnknownBlockProcessor.

void dtn::BlockProcessor::finalize ( const Bundle bundle,
Link link,
BlockInfo block 
) [virtual]

Third callback for transmitting a bundle.

This pass should generate any data (such as security signatures) for the block that may depend on other blocks' contents.

The base class implementation does nothing.

Definition at line 266 of file BlockProcessor.cc.

References ASSERT, dtn::BundleProtocol::BLOCK_FLAG_REPORT_ONERROR, dtn::BlockInfo::flags(), dtn::Bundle::is_admin_, and dtn::BlockInfo::primary_block().

void dtn::BlockProcessor::produce ( const Bundle bundle,
const BlockInfo block,
u_char *  buf,
size_t  offset,
size_t  len 
) [virtual]

Accessor to virtualize copying contents out from the block info.

This is overloaded by the payload since the contents are not actually stored in the BlockInfo contents_ buffer but rather are on-disk.

The base class implementation simply does a memcpy from the contents into the supplied buffer.

Note that the supplied offset + length must be less than or equal to the total length of the block.

Reimplemented in dtn::PayloadBlockProcessor.

Definition at line 278 of file BlockProcessor.cc.

References ASSERT, and dtn::BlockInfo::contents().

void dtn::BlockProcessor::init_block ( BlockInfo block,
u_int8_t  type,
u_int8_t  flags,
u_char *  bp,
size_t  len 
)

General hook to set up a block with the given contents.

Used for testing generic extension blocks.

Definition at line 289 of file BlockProcessor.cc.

References ASSERT, dtn::BlockInfo::data_offset(), dtn::BlockInfo::full_length(), generate_preamble(), dtn::BlockInfo::owner(), and dtn::BlockInfo::writable_contents().

int dtn::BlockProcessor::consume_preamble ( BlockInfo block,
u_char *  buf,
size_t  len,
size_t  preamble_size = 0 
) [protected]

Consume a fixed-length preamble (defaulting to the standard BlockPreamble) followed by an SDNV containing the length of the rest of the block.

The preamble_size is optionally overridden to allow this to be used by the primary block which has a differently-sized preamble.

Definition at line 39 of file BlockProcessor.cc.

References ASSERT, block_type(), oasys::ScratchBuffer< _memory_t, _static_size >::buf(), dtn::BlockInfo::complete(), dtn::BlockInfo::contents(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), decode(), oasys::ExpandableBuffer::end(), dtn::BlockInfo::full_length(), oasys::ExpandableBuffer::len(), log_debug_p, log_err_p, MAX_LENGTH, oasys::ExpandableBuffer::nfree(), dtn::BlockInfo::set_data_length(), dtn::BlockInfo::set_data_offset(), oasys::ExpandableBuffer::set_len(), dtn::BlockInfo::type(), and dtn::BlockInfo::writable_contents().

Referenced by dtn::PrimaryBlockProcessor::consume(), dtn::PayloadBlockProcessor::consume(), and consume().

void dtn::BlockProcessor::generate_preamble ( BlockInfo block,
u_int8_t  type,
u_int8_t  flags,
size_t  data_length 
) [protected]

Generate the standard preamble for the given block type, flags and content length.

Definition at line 119 of file BlockProcessor.cc.

References ASSERT, block_type(), dtn::BlockInfo::contents(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), encode(), encoding_len(), dtn::BlockInfo::flags(), dtn::BundleProtocol::BlockPreamble::flags, dtn::BundleProtocol::BlockPreamble::length, log_debug_p, dtn::BlockInfo::set_data_length(), dtn::BlockInfo::set_data_offset(), dtn::BlockInfo::type(), dtn::BundleProtocol::BlockPreamble::type, and dtn::BlockInfo::writable_contents().

Referenced by dtn::UnknownBlockProcessor::generate(), dtn::PreviousHopBlockProcessor::generate(), dtn::PayloadBlockProcessor::generate(), dtn::APIBlockProcessor::generate(), and init_block().


Friends And Related Function Documentation

friend class BundleProtocol [friend]

Reimplemented in dtn::PrimaryBlockProcessor.

Definition at line 140 of file BlockProcessor.h.

friend class BlockInfo [friend]

Definition at line 141 of file BlockProcessor.h.

Referenced by prepare().


Member Data Documentation

int dtn::BlockProcessor::block_type_ [private]

The block typecode for this handler.

Definition at line 166 of file BlockProcessor.h.

Referenced by block_type().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:43 2007 for DTN Reference Implementation by  doxygen 1.5.3