Base class for the protocol handling of bundle blocks, including the core primary and payload handling, security, and other extension blocks. More...
#include <BlockProcessor.h>
Public Types | |
typedef void( | process_func )(const Bundle *bundle, const BlockInfo *caller_block, const BlockInfo *target_block, const void *buf, size_t len, OpaqueContext *r) |
Typedef for a process function pointer. | |
typedef bool( | mutate_func )(const Bundle *bundle, const BlockInfo *caller_block, BlockInfo *target_block, void *buf, size_t len, OpaqueContext *context) |
Typedef for a mutate function pointer. | |
typedef BlockInfo::list_owner_t | list_owner_t |
Import some typedefs from other classes. | |
typedef BundleProtocol::status_report_reason_t | status_report_reason_t |
Import some typedefs from other classes. | |
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 int | reload_post_process (Bundle *bundle, BlockInfoVec *block_list, BlockInfo *block) |
Perform any needed action in the case where a block/bundle has been reloaded from store. | |
virtual bool | validate (const Bundle *bundle, BlockInfoVec *block_list, BlockInfo *block, status_report_reason_t *reception_reason, status_report_reason_t *deletion_reason) |
Validate the block. | |
virtual int | prepare (const Bundle *bundle, BlockInfoVec *xmit_blocks, const BlockInfo *source, const LinkRef &link, list_owner_t list) |
First callback to generate blocks for the output pass. | |
virtual int | generate (const Bundle *bundle, BlockInfoVec *xmit_blocks, BlockInfo *block, const LinkRef &link, bool last)=0 |
Second callback for transmitting a bundle. | |
virtual int | finalize (const Bundle *bundle, BlockInfoVec *xmit_blocks, BlockInfo *block, const LinkRef &link) |
Third callback for transmitting a bundle. | |
virtual void | process (process_func *func, const Bundle *bundle, const BlockInfo *caller_block, const BlockInfo *target_block, size_t offset, size_t len, OpaqueContext *context) |
Accessor to virtualize read-only processing contents of the block in various ways. | |
virtual bool | mutate (mutate_func *func, Bundle *bundle, const BlockInfo *caller_block, BlockInfo *target_block, size_t offset, size_t len, OpaqueContext *context) |
Similar to process() but for potentially mutating processing functions. | |
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, BlockInfoVec *block_list, u_int8_t type, u_int8_t flags, const 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 (BlockInfoVec *recv_blocks, BlockInfo *block, u_char *buf, size_t len, u_int64_t *flagp=NULL) |
Consume a block preamble consisting of type, flags(SDNV), EID-list (composite field of SDNVs) and length(SDNV). | |
void | generate_preamble (BlockInfoVec *xmit_blocks, BlockInfo *block, u_int8_t type, u_int64_t flags, u_int64_t data_length) |
Generate the standard preamble for the given block type, flags, EID-list and content length. | |
Private Attributes | |
int | block_type_ |
The block typecode for this handler. | |
Friends | |
class | BundleProtocol |
class | BlockInfo |
class | Ciphersuite |
Base class for the protocol handling of bundle blocks, including the core primary and payload handling, security, and other extension blocks.
Definition at line 42 of file BlockProcessor.h.
Import some typedefs from other classes.
Definition at line 64 of file BlockProcessor.h.
typedef bool( dtn::BlockProcessor::mutate_func)(const Bundle *bundle, const BlockInfo *caller_block, BlockInfo *target_block, void *buf, size_t len, OpaqueContext *context) |
Typedef for a mutate function pointer.
Definition at line 56 of file BlockProcessor.h.
typedef void( dtn::BlockProcessor::process_func)(const Bundle *bundle, const BlockInfo *caller_block, const BlockInfo *target_block, const void *buf, size_t len, OpaqueContext *r) |
Typedef for a process function pointer.
Definition at line 47 of file BlockProcessor.h.
Import some typedefs from other classes.
Definition at line 65 of file BlockProcessor.h.
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 31 of file BlockProcessor.cc.
References dtn::log.
dtn::BlockProcessor::~BlockProcessor | ( | ) | [virtual] |
Virtual destructor.
Definition at line 39 of file BlockProcessor.cc.
int dtn::BlockProcessor::block_type | ( | ) | [inline] |
Accessors.
Definition at line 82 of file BlockProcessor.h.
References block_type_.
Referenced by dtn::SequenceIDBlockProcessor::consume(), consume(), consume_preamble(), dtn::SequenceIDBlockProcessor::generate(), dtn::MetadataBlockProcessor::generate(), generate_preamble(), dtn::SequenceIDBlockProcessor::prepare(), dtn::BundleProtocol::register_processor(), 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.
Reimplemented in dtn::APIBlockProcessor, dtn::MetadataBlockProcessor, dtn::PayloadBlockProcessor, dtn::PreviousHopBlockProcessor, dtn::PrimaryBlockProcessor, dtn::SequenceIDBlockProcessor, and dtn::SessionBlockProcessor.
Definition at line 282 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(), dtn::log, dtn::Bundle::mutable_recv_blocks(), dtn::BlockInfo::set_complete(), dtn::BlockInfo::type(), and dtn::BlockInfo::writable_contents().
int dtn::BlockProcessor::consume_preamble | ( | BlockInfoVec * | recv_blocks, | |
BlockInfo * | block, | |||
u_char * | buf, | |||
size_t | len, | |||
u_int64_t * | flagp = NULL | |||
) | [protected] |
Consume a block preamble consisting of type, flags(SDNV), EID-list (composite field of SDNVs) and length(SDNV).
This method does not apply to the primary block, but is suitable for payload and all extensions.
Definition at line 45 of file BlockProcessor.cc.
References ASSERT, dtn::BundleProtocol::BLOCK_FLAG_EID_REFS, block_type(), dtn::BlockInfo::complete(), dtn::BlockInfo::contents(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), decode(), dtn::BlockInfoVec::dict(), dtn::BlockInfo::eid_list(), dtn::Dictionary::extract_eid(), dtn::BlockInfo::full_length(), dtn::log, log_err_p, dtn::BundleProtocol::PREAMBLE_FIXED_LENGTH, dtn::BlockInfo::set_data_length(), dtn::BlockInfo::set_data_offset(), dtn::BlockInfo::set_eid_list(), and dtn::BlockInfo::writable_contents().
Referenced by dtn::PayloadBlockProcessor::consume(), and consume().
int dtn::BlockProcessor::finalize | ( | const Bundle * | bundle, | |
BlockInfoVec * | xmit_blocks, | |||
BlockInfo * | block, | |||
const LinkRef & | link | |||
) | [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.
We pass xmit_blocks explicitly to indicate that ALL blocks might be changed by finalize, typically by being encrypted. Parameters such as length might also change due to padding and encapsulation.
Definition at line 431 of file BlockProcessor.cc.
References ASSERT, dtn::BundleProtocol::BLOCK_FLAG_REPORT_ONERROR, BP_SUCCESS, dtn::BlockInfo::flags(), dtn::Bundle::is_admin(), dtn::BundleProtocol::PRIMARY_BLOCK, and dtn::BlockInfo::type().
virtual int dtn::BlockProcessor::generate | ( | const Bundle * | bundle, | |
BlockInfoVec * | xmit_blocks, | |||
BlockInfo * | block, | |||
const LinkRef & | link, | |||
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. It MUST add any EID references it needs by calling block->add_eid(), then call generate_preamble(), which will add the EIDs to the primary block's dictionary and write their offsets to this block's preamble.
Implemented in dtn::APIBlockProcessor, dtn::MetadataBlockProcessor, dtn::PayloadBlockProcessor, dtn::PreviousHopBlockProcessor, dtn::PrimaryBlockProcessor, dtn::SequenceIDBlockProcessor, dtn::SessionBlockProcessor, and dtn::UnknownBlockProcessor.
void dtn::BlockProcessor::generate_preamble | ( | BlockInfoVec * | xmit_blocks, | |
BlockInfo * | block, | |||
u_int8_t | type, | |||
u_int64_t | flags, | |||
u_int64_t | data_length | |||
) | [protected] |
Generate the standard preamble for the given block type, flags, EID-list and content length.
Definition at line 204 of file BlockProcessor.cc.
References dtn::Dictionary::add_eid(), ASSERT, dtn::BundleProtocol::BLOCK_FLAG_EID_REFS, block_type(), dtn::BlockInfo::contents(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), dtn::BlockInfoVec::dict(), dtn::BlockInfo::eid_list(), encode(), encoding_len(), dtn::BlockInfo::flags(), dtn::Dictionary::get_offsets(), len, dtn::log, dtn::BundleProtocol::PREAMBLE_FIXED_LENGTH, dtn::BlockInfo::set_data_length(), dtn::BlockInfo::set_data_offset(), dtn::BlockInfo::type(), and dtn::BlockInfo::writable_contents().
Referenced by dtn::UnknownBlockProcessor::generate(), dtn::SessionBlockProcessor::generate(), dtn::SequenceIDBlockProcessor::generate(), dtn::PreviousHopBlockProcessor::generate(), dtn::PayloadBlockProcessor::generate(), dtn::MetadataBlockProcessor::generate(), and init_block().
void dtn::BlockProcessor::init_block | ( | BlockInfo * | block, | |
BlockInfoVec * | block_list, | |||
u_int8_t | type, | |||
u_int8_t | flags, | |||
const 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 508 of file BlockProcessor.cc.
References ASSERT, dtn::BlockInfo::data_offset(), dtn::BlockInfo::full_length(), generate_preamble(), dtn::BlockInfo::owner(), and dtn::BlockInfo::writable_contents().
bool dtn::BlockProcessor::mutate | ( | mutate_func * | func, | |
Bundle * | bundle, | |||
const BlockInfo * | caller_block, | |||
BlockInfo * | target_block, | |||
size_t | offset, | |||
size_t | len, | |||
OpaqueContext * | context | |||
) | [virtual] |
Similar to process() but for potentially mutating processing functions.
The function returns true iff it modified the target_block.
Reimplemented in dtn::PayloadBlockProcessor.
Definition at line 470 of file BlockProcessor.cc.
References ASSERT, buf, dtn::BlockInfo::contents(), and len.
int dtn::BlockProcessor::prepare | ( | const Bundle * | bundle, | |
BlockInfoVec * | xmit_blocks, | |||
const BlockInfo * | source, | |||
const LinkRef & | link, | |||
list_owner_t | list | |||
) | [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::MetadataBlockProcessor, dtn::PreviousHopBlockProcessor, dtn::PrimaryBlockProcessor, dtn::SequenceIDBlockProcessor, dtn::SessionBlockProcessor, and dtn::UnknownBlockProcessor.
Definition at line 404 of file BlockProcessor.cc.
References dtn::BlockInfoVec::append_block(), ASSERT, BlockInfo, BP_SUCCESS, dtn::BlockInfo::LIST_RECEIVED, and dtn::BundleProtocol::PRIMARY_BLOCK.
void dtn::BlockProcessor::process | ( | process_func * | func, | |
const Bundle * | bundle, | |||
const BlockInfo * | caller_block, | |||
const BlockInfo * | target_block, | |||
size_t | offset, | |||
size_t | len, | |||
OpaqueContext * | context | |||
) | [virtual] |
Accessor to virtualize read-only processing contents of the block in various ways.
This is overloaded by the payload since the contents are not actually stored in the BlockInfo contents_ buffer but rather are on-disk.
Processing can be anything the calling routine wishes, such as digest of the block, encryption, decryption etc. This routine is permitted to process the data in several calls to the target "func" routine as long as the data is processed in order and exactly once.
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 448 of file BlockProcessor.cc.
References ASSERT, buf, dtn::BlockInfo::contents(), and len.
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 494 of file BlockProcessor.cc.
References ASSERT, dtn::BlockInfo::contents(), and len.
int dtn::BlockProcessor::reload_post_process | ( | Bundle * | bundle, | |
BlockInfoVec * | block_list, | |||
BlockInfo * | block | |||
) | [virtual] |
Perform any needed action in the case where a block/bundle has been reloaded from store.
Definition at line 390 of file BlockProcessor.cc.
References dtn::BlockInfo::set_reloaded().
bool dtn::BlockProcessor::validate | ( | const Bundle * | bundle, | |
BlockInfoVec * | block_list, | |||
BlockInfo * | block, | |||
status_report_reason_t * | reception_reason, | |||
status_report_reason_t * | deletion_reason | |||
) | [virtual] |
Validate the block.
This is called after all blocks in the bundle have been fully received.
Reimplemented in dtn::MetadataBlockProcessor, dtn::PayloadBlockProcessor, dtn::PrimaryBlockProcessor, and dtn::UnknownBlockProcessor.
Definition at line 363 of file BlockProcessor.cc.
References dtn::BundleProtocol::BLOCK_FLAG_REPORT_ONERROR, dtn::BlockInfo::flags(), dtn::Bundle::is_admin(), dtn::log, log_err_p, dtn::BundleProtocol::PRIMARY_BLOCK, dtn::BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE, and dtn::BlockInfo::type().
Referenced by dtn::UnknownBlockProcessor::validate(), dtn::PayloadBlockProcessor::validate(), and dtn::MetadataBlockProcessor::validate().
friend class BlockInfo [friend] |
Definition at line 241 of file BlockProcessor.h.
Referenced by dtn::PrimaryBlockProcessor::prepare(), prepare(), and dtn::MetadataBlockProcessor::prepare_generated_metadata().
friend class BundleProtocol [friend] |
Reimplemented in dtn::PrimaryBlockProcessor.
Definition at line 240 of file BlockProcessor.h.
friend class Ciphersuite [friend] |
Definition at line 242 of file BlockProcessor.h.
int dtn::BlockProcessor::block_type_ [private] |
The block typecode for this handler.
Definition at line 268 of file BlockProcessor.h.
Referenced by block_type().