00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #include "SessionBlockProcessor.h"
00022 #include "Bundle.h"
00023 #include "BundleDaemon.h"
00024 #include "BundleProtocol.h"
00025 #include "contacts/Link.h"
00026
00027 namespace dtn {
00028
00029
00030 SessionBlockProcessor::SessionBlockProcessor()
00031 : BlockProcessor(BundleProtocol::SESSION_BLOCK)
00032 {
00033 }
00034
00035
00036 int
00037 SessionBlockProcessor::prepare(const Bundle* bundle,
00038 BlockInfoVec* xmit_blocks,
00039 const BlockInfo* source,
00040 const LinkRef& link,
00041 BlockInfo::list_owner_t list)
00042 {
00043 if (bundle->session_eid().length() == 0) {
00044 return BP_SUCCESS;
00045 }
00046
00047 ASSERT(bundle->session_eid() != EndpointID::NULL_EID());
00048 BlockProcessor::prepare(bundle, xmit_blocks, source, link, list);
00049 return BP_SUCCESS;
00050 }
00051
00052
00053 int
00054 SessionBlockProcessor::generate(const Bundle* bundle,
00055 BlockInfoVec* xmit_blocks,
00056 BlockInfo* block,
00057 const LinkRef& link,
00058 bool last)
00059 {
00060 (void)link;
00061
00062 ASSERT(bundle->session_eid().length() != 0);
00063
00064
00065 block->add_eid(bundle->session_eid());
00066
00067 size_t length = 1;
00068 generate_preamble(xmit_blocks,
00069 block,
00070 BundleProtocol::SESSION_BLOCK,
00071 BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR |
00072 BundleProtocol::BLOCK_FLAG_REPORT_ONERROR |
00073 (last ? BundleProtocol::BLOCK_FLAG_LAST_BLOCK : 0),
00074 length);
00075
00076 BlockInfo::DataBuffer* contents = block->writable_contents();
00077 contents->reserve(block->data_offset() + length);
00078 contents->set_len(block->data_offset() + length);
00079 u_int8_t* bp = contents->buf() + block->data_offset();
00080 *bp = bundle->session_flags();
00081
00082 return BP_SUCCESS;
00083 }
00084
00085
00086 int
00087 SessionBlockProcessor::consume(Bundle* bundle, BlockInfo* block,
00088 u_char* buf, size_t len)
00089 {
00090 int cc = BlockProcessor::consume(bundle, block, buf, len);
00091
00092 if (cc == -1) {
00093 return -1;
00094 }
00095
00096 if (! block->complete()) {
00097 ASSERT(cc == (int)len);
00098 return cc;
00099 }
00100
00101 if (block->eid_list().size() != 1) {
00102 log_err_p("/dtn/bundle/protocol",
00103 "error parsing session block -- %zu eids in list",
00104 block->eid_list().size());
00105 return -1;
00106 }
00107
00108 bundle->mutable_session_eid()->assign(block->eid_list()[0]);
00109 bundle->set_session_flags(*block->data());
00110
00111 return cc;
00112 }
00113
00114
00115 }