00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BLOCKPROCESSOR_H_
00018 #define _BLOCKPROCESSOR_H_
00019
00020 #include <oasys/compat/inttypes.h>
00021
00022 #include "BundleProtocol.h"
00023 #include "BlockInfo.h"
00024 #include "BP_Local.h"
00025
00026 namespace dtn {
00027
00028 class BlockInfo;
00029 class BlockInfoVec;
00030 class Bundle;
00031 class Link;
00032 class OpaqueContext;
00033
00034 #define BP_SUCCESS (int)(0)
00035 #define BP_FAIL (int)(-1)
00036
00042 class BlockProcessor {
00043 public:
00047 typedef void (process_func)(const Bundle* bundle,
00048 const BlockInfo* caller_block,
00049 const BlockInfo* target_block,
00050 const void* buf,
00051 size_t len,
00052 OpaqueContext* r);
00056 typedef bool (mutate_func)(const Bundle* bundle,
00057 const BlockInfo* caller_block,
00058 BlockInfo* target_block,
00059 void* buf,
00060 size_t len,
00061 OpaqueContext* context);
00062
00064 typedef BlockInfo::list_owner_t list_owner_t;
00065 typedef BundleProtocol::status_report_reason_t status_report_reason_t;
00067
00074 BlockProcessor(int block_type);
00075
00079 virtual ~BlockProcessor();
00080
00082 int block_type() { return block_type_; }
00084
00101 virtual int consume(Bundle* bundle,
00102 BlockInfo* block,
00103 u_char* buf,
00104 size_t len);
00105
00110 virtual int reload_post_process(Bundle* bundle,
00111 BlockInfoVec* block_list,
00112 BlockInfo* block);
00113
00114
00121 virtual bool validate(const Bundle* bundle,
00122 BlockInfoVec* block_list,
00123 BlockInfo* block,
00124 status_report_reason_t* reception_reason,
00125 status_report_reason_t* deletion_reason);
00126
00135 virtual int prepare(const Bundle* bundle,
00136 BlockInfoVec* xmit_blocks,
00137 const BlockInfo* source,
00138 const LinkRef& link,
00139 list_owner_t list);
00140
00149 virtual int generate(const Bundle* bundle,
00150 BlockInfoVec* xmit_blocks,
00151 BlockInfo* block,
00152 const LinkRef& link,
00153 bool last) = 0;
00154
00167 virtual int finalize(const Bundle* bundle,
00168 BlockInfoVec* xmit_blocks,
00169 BlockInfo* block,
00170 const LinkRef& link);
00171
00187 virtual void process(process_func* func,
00188 const Bundle* bundle,
00189 const BlockInfo* caller_block,
00190 const BlockInfo* target_block,
00191 size_t offset,
00192 size_t len,
00193 OpaqueContext* context);
00194
00201 virtual bool mutate(mutate_func* func,
00202 Bundle* bundle,
00203 const BlockInfo* caller_block,
00204 BlockInfo* target_block,
00205 size_t offset,
00206 size_t len,
00207 OpaqueContext* context);
00208
00221 virtual void produce(const Bundle* bundle,
00222 const BlockInfo* block,
00223 u_char* buf,
00224 size_t offset,
00225 size_t len);
00226
00231 void init_block(BlockInfo* block,
00232 BlockInfoVec* block_list,
00233 u_int8_t type,
00234 u_int8_t flags,
00235 const u_char* bp,
00236 size_t len);
00237
00238
00239 protected:
00240 friend class BundleProtocol;
00241 friend class BlockInfo;
00242 friend class Ciphersuite;
00243
00250 int consume_preamble(BlockInfoVec* recv_blocks,
00251 BlockInfo* block,
00252 u_char* buf,
00253 size_t len,
00254 u_int64_t* flagp = NULL);
00255
00260 void generate_preamble(BlockInfoVec* xmit_blocks,
00261 BlockInfo* block,
00262 u_int8_t type,
00263 u_int64_t flags,
00264 u_int64_t data_length);
00265
00266 private:
00268 int block_type_;
00269 };
00270
00271 }
00272
00273 #endif