servlib/security/BA_BlockProcessor.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2006 SPARTA Inc
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _BA_BLOCK_PROCESSOR_H_
       
    18 #define _BA_BLOCK_PROCESSOR_H_
       
    19 
       
    20 #ifdef BSP_ENABLED
       
    21 
       
    22 #include "bundling/BlockProcessor.h"
       
    23 #include "Ciphersuite.h"
       
    24 
       
    25 namespace dtn {
       
    26 
       
    27 /**
       
    28  * Block processor implementation for the bundle authentication block.
       
    29  */
       
    30 class BA_BlockProcessor : public BlockProcessor {
       
    31 public:
       
    32     /// Constructor
       
    33     BA_BlockProcessor();
       
    34     
       
    35     /// @{ Virtual from BlockProcessor
       
    36     /**
       
    37      * First callback for parsing blocks that is expected to append a
       
    38      * chunk of the given data to the given block. When the block is
       
    39      * completely received, this should also parse the block into any
       
    40      * fields in the bundle class.
       
    41      *
       
    42      * The base class implementation parses the block preamble fields
       
    43      * to find the length of the block and copies the preamble and the
       
    44      * data in the block's contents buffer.
       
    45      *
       
    46      * This and all derived implementations must be able to handle a
       
    47      * block that is received in chunks, including cases where the
       
    48      * preamble is split into multiple chunks.
       
    49      *
       
    50      * @return the amount of data consumed or -1 on error
       
    51      */
       
    52     virtual int consume(Bundle*    bundle,
       
    53                         BlockInfo* block,
       
    54                         u_char*    buf,
       
    55                         size_t     len);
       
    56 
       
    57     /**
       
    58      * Perform any needed action in the case where a block/bundle
       
    59      * has been reloaded from store
       
    60      */
       
    61     virtual int reload_post_process(Bundle*       bundle,
       
    62                                     BlockInfoVec* block_list,
       
    63                                     BlockInfo*    block);
       
    64 
       
    65     /**
       
    66      * Validate the block. This is called after all blocks in the
       
    67      * bundle have been fully received.
       
    68      *
       
    69      * @return true if the block passes validation
       
    70      */
       
    71     virtual bool validate(const Bundle*           bundle,
       
    72                           BlockInfoVec*           block_list,
       
    73                           BlockInfo*              block,
       
    74                           status_report_reason_t* reception_reason,
       
    75                           status_report_reason_t* deletion_reason);
       
    76 
       
    77     /**
       
    78      * First callback to generate blocks for the output pass. The
       
    79      * function is expected to initialize an appropriate BlockInfo
       
    80      * structure in the given BlockInfoVec.
       
    81      *
       
    82      * The base class simply initializes an empty BlockInfo with the
       
    83      * appropriate owner_ pointer.
       
    84      */
       
    85     virtual int prepare(const Bundle*    bundle,
       
    86                         BlockInfoVec*    xmit_blocks,
       
    87                         const BlockInfo* source,
       
    88                         const LinkRef&   link,
       
    89                         list_owner_t     list);
       
    90     
       
    91     /**
       
    92      * Second callback for transmitting a bundle. This pass should
       
    93      * generate any data for the block that does not depend on other
       
    94      * blocks' contents.  It MUST add any EID references it needs by
       
    95      * calling block->add_eid(), then call generate_preamble(), which
       
    96      * will add the EIDs to the primary block's dictionary and write
       
    97      * their offsets to this block's preamble.
       
    98      */
       
    99     virtual int generate(const Bundle*  bundle,
       
   100                          BlockInfoVec*  xmit_blocks,
       
   101                          BlockInfo*     block,
       
   102                          const LinkRef& link,
       
   103                          bool           last);
       
   104     
       
   105     /**
       
   106      * Third callback for transmitting a bundle. This pass should
       
   107      * generate any data (such as security signatures) for the block
       
   108      * that may depend on other blocks' contents.
       
   109      *
       
   110      * The base class implementation does nothing. 
       
   111      */
       
   112     virtual int finalize(const Bundle*  bundle, 
       
   113                          BlockInfoVec*  xmit_blocks, 
       
   114                          BlockInfo*     block, 
       
   115                          const LinkRef& link);
       
   116 
       
   117     /// @}
       
   118 };
       
   119 
       
   120 } // namespace dtn
       
   121 
       
   122 #endif /* BSP_ENABLED */
       
   123 
       
   124 #endif /* _BA_BLOCK_PROCESSOR_H_ */