Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > d9faa203c2b0b6fbb179d93daaea81b7 > files > 126

libdtn-devel-2.6.0-1mdv2009.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: BundleProtocol.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<h1>BundleProtocol.cc</h1><a href="BundleProtocol_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2004-2006 Intel Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;netinet/in.h&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;oasys/debug/DebugUtils.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;oasys/util/StringUtils.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="BlockInfo_8h.html">BlockInfo.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="BlockProcessor_8h.html">BlockProcessor.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">Bundle.h</a>"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="BundleProtocol_8h.html">BundleProtocol.h</a>"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="BundleTimestamp_8h.html">BundleTimestamp.h</a>"</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="MetadataBlockProcessor_8h.html">MetadataBlockProcessor.h</a>"</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="PayloadBlockProcessor_8h.html">PayloadBlockProcessor.h</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="PreviousHopBlockProcessor_8h.html">PreviousHopBlockProcessor.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="PrimaryBlockProcessor_8h.html">PrimaryBlockProcessor.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">SDNV.h</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="SessionBlockProcessor_8h.html">SessionBlockProcessor.h</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="SequenceIDBlockProcessor_8h.html">SequenceIDBlockProcessor.h</a>"</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="UnknownBlockProcessor_8h.html">UnknownBlockProcessor.h</a>"</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="preprocessor">#ifdef BSP_ENABLED</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#  include "<a class="code" href="SPD_8h.html">security/SPD.h</a>"</span>
<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span>
<a name="l00045"></a>00045 <span class="keyword">namespace </span>dtn {
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">00047</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>;
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* <a class="code" href="classdtn_1_1BundleProtocol.html#43a86367ca937ca31641d9c57ca38726" title="Array of registered BlockProcessor handlers -- fixed size since there can be at most...">BundleProtocol::processors_</a>[256];
<a name="l00050"></a>00050 
<a name="l00051"></a>00051 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00052"></a>00052 <span class="keywordtype">void</span>
<a name="l00053"></a><a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a">00053</a> <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* bp)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055     <span class="comment">// can't override an existing processor</span>
<a name="l00056"></a>00056     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#43a86367ca937ca31641d9c57ca38726" title="Array of registered BlockProcessor handlers -- fixed size since there can be at most...">processors_</a>[bp-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>()] == 0);
<a name="l00057"></a>00057     <a class="code" href="classdtn_1_1BundleProtocol.html#43a86367ca937ca31641d9c57ca38726" title="Array of registered BlockProcessor handlers -- fixed size since there can be at most...">processors_</a>[bp-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>()] = bp;
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00061"></a>00061 <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>*
<a name="l00062"></a><a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61">00062</a> BundleProtocol::find_processor(u_int8_t type)
<a name="l00063"></a>00063 {
<a name="l00064"></a>00064     <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* ret = <a class="code" href="classdtn_1_1BundleProtocol.html#43a86367ca937ca31641d9c57ca38726" title="Array of registered BlockProcessor handlers -- fixed size since there can be at most...">processors_</a>[type];
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (ret == 0) {
<a name="l00066"></a>00066         ret = UnknownBlockProcessor::instance();
<a name="l00067"></a>00067     }
<a name="l00068"></a>00068     <span class="keywordflow">return</span> ret;
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 
<a name="l00071"></a>00071 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00072"></a>00072 <span class="keywordtype">void</span>
<a name="l00073"></a><a class="code" href="classdtn_1_1BundleProtocol.html#6aa13dcc0ae96b1b832970c3f71678be">00073</a> <a class="code" href="classdtn_1_1BundleProtocol.html#6aa13dcc0ae96b1b832970c3f71678be" title="Initialize the default set of block processors.">BundleProtocol::init_default_processors</a>()
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     <span class="comment">// register default block processor handlers</span>
<a name="l00076"></a>00076     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html" title="Block processor implementation for the primary bundle block.">PrimaryBlockProcessor</a>());
<a name="l00077"></a>00077     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1PayloadBlockProcessor.html" title="Block processor implementation for the payload bundle block.">PayloadBlockProcessor</a>());
<a name="l00078"></a>00078     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1PreviousHopBlockProcessor.html" title="Block processor implementation for the previous hop bundle block.">PreviousHopBlockProcessor</a>());
<a name="l00079"></a>00079     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html" title="Block processor implementation for the metadata extension block.">MetadataBlockProcessor</a>());
<a name="l00080"></a>00080     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1SessionBlockProcessor.html" title="Block processor implementation for session blocks.">SessionBlockProcessor</a>());
<a name="l00081"></a>00081     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(
<a name="l00082"></a>00082         <span class="keyword">new</span> <a class="code" href="classdtn_1_1SequenceIDBlockProcessor.html" title="Block processor implementation for sequence id blocks and obsoletes blocks since...">SequenceIDBlockProcessor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca782910c2fe9ca3b672f39e125f46e87b6" title="NOT IN SPEC YET.">BundleProtocol::SEQUENCE_ID_BLOCK</a>));
<a name="l00083"></a>00083     <a class="code" href="classdtn_1_1BundleProtocol.html#a08624ba2b213ce97adfc6b5bc5a054a" title="Register a new BlockProcessor handler to handle the given block type code when received...">BundleProtocol::register_processor</a>(
<a name="l00084"></a>00084         <span class="keyword">new</span> <a class="code" href="classdtn_1_1SequenceIDBlockProcessor.html" title="Block processor implementation for sequence id blocks and obsoletes blocks since...">SequenceIDBlockProcessor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca787466c93eee1166b0fa3642ee1360905" title="NOT IN SPEC YET.">BundleProtocol::OBSOLETES_ID_BLOCK</a>));
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00088"></a>00088 <span class="keywordtype">void</span>
<a name="l00089"></a><a class="code" href="classdtn_1_1BundleProtocol.html#77c2dbd79cef726e0234e639e19a34f4">00089</a> <a class="code" href="classdtn_1_1BundleProtocol.html#77c2dbd79cef726e0234e639e19a34f4" title="Give the processors a chance to chew on the bundle after reloading from disk.">BundleProtocol::reload_post_process</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle)
<a name="l00090"></a>00090 {
<a name="l00091"></a>00091     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* recv_blocks = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5c48f51fba15c89a82d5d98c9881f0bd" title="Setters and mutable accessors.">mutable_recv_blocks</a>();
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="keywordflow">for</span> (BlockInfoVec::iterator iter = recv_blocks-&gt;begin();
<a name="l00094"></a>00094          iter != recv_blocks-&gt;end();
<a name="l00095"></a>00095          ++iter)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097         <span class="comment">// allow BlockProcessors [and Ciphersuites] a chance to re-do</span>
<a name="l00098"></a>00098         <span class="comment">// things needed after a load-from-store</span>
<a name="l00099"></a>00099         iter-&gt;owner()-&gt;reload_post_process(bundle, recv_blocks, &amp;*iter);
<a name="l00100"></a>00100     }
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102         
<a name="l00103"></a>00103 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00104"></a>00104 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*
<a name="l00105"></a><a class="code" href="classdtn_1_1BundleProtocol.html#ef1c34c75b476f408546f73b4de1f2f5">00105</a> <a class="code" href="classdtn_1_1BundleProtocol.html#ef1c34c75b476f408546f73b4de1f2f5" title="Generate a BlockInfoVec for the outgoing link and put it into xmit_blocks_.">BundleProtocol::prepare_blocks</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link)
<a name="l00106"></a>00106 {
<a name="l00107"></a>00107     <span class="comment">// create a new block list for the outgoing link by first calling</span>
<a name="l00108"></a>00108     <span class="comment">// prepare on all the BlockProcessor classes for the blocks that</span>
<a name="l00109"></a>00109     <span class="comment">// arrived on the link</span>
<a name="l00110"></a>00110     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* xmit_blocks = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#0ce0961036dd0da1fd322721cbb794aa" title="Setters and mutable accessors.">xmit_blocks</a>()-&gt;<a class="code" href="classdtn_1_1LinkBlockSet.html#7fd0f75b4caa20c373c532cc8256e86c" title="Create a new BlockInfoVec for the given link.">create_blocks</a>(link);
<a name="l00111"></a>00111     <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* recv_blocks = &amp;bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ec3c2ef7670fb2d34d46ab547bf9fb80" title="Accessors.">recv_blocks</a>();
<a name="l00112"></a>00112     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* api_blocks  = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5e06eba17ac3706daa934b6a58c16dda" title="Setters and mutable accessors.">api_blocks</a>();
<a name="l00113"></a>00113 
<a name="l00114"></a>00114     <span class="keywordflow">if</span> (recv_blocks-&gt;size() &gt; 0) {
<a name="l00115"></a>00115         <span class="comment">// if there is a received block, the first one better be the primary</span>
<a name="l00116"></a>00116         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(recv_blocks-&gt;front().type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">PRIMARY_BLOCK</a>);
<a name="l00117"></a>00117     
<a name="l00118"></a>00118         <span class="keywordflow">for</span> (BlockInfoVec::const_iterator iter = recv_blocks-&gt;begin();
<a name="l00119"></a>00119              iter != recv_blocks-&gt;end();
<a name="l00120"></a>00120              ++iter)
<a name="l00121"></a>00121         {
<a name="l00122"></a>00122             <span class="comment">// if this block follows the payload block, and the bundle was</span>
<a name="l00123"></a>00123             <span class="comment">// reactively fragmented, this block should be in the later</span>
<a name="l00124"></a>00124             <span class="comment">// fragment, so don't include it</span>
<a name="l00125"></a>00125             <span class="comment">//</span>
<a name="l00126"></a>00126             <span class="comment">// XXX/demmer it seems to me like this should just break</span>
<a name="l00127"></a>00127             <span class="comment">// out of the loop once it's processed the PAYLOAD_BLOCK</span>
<a name="l00128"></a>00128             <span class="comment">// if fragmented_incoming_ is true</span>
<a name="l00129"></a>00129             <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#786fe13c6220382bb032e740fb31da7e" title="Accessors.">fragmented_incoming</a>()
<a name="l00130"></a>00130                 &amp;&amp; xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#646316c3b0fb301712bb39fdbfd3207e" title="Find the block for the given type.">find_block</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">BundleProtocol::PAYLOAD_BLOCK</a>)) {
<a name="l00131"></a>00131                 <span class="keywordflow">continue</span>;
<a name="l00132"></a>00132             }
<a name="l00133"></a>00133             
<a name="l00134"></a>00134             iter-&gt;owner()-&gt;prepare(bundle, xmit_blocks, &amp;*iter, link,
<a name="l00135"></a>00135                                    <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c988069568eb548f51e7c4b8120b6292f">BlockInfo::LIST_RECEIVED</a>);
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     <span class="keywordflow">else</span> {
<a name="l00139"></a>00139         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"adding primary and payload block"</span>);
<a name="l00140"></a>00140         <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* bp = <a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">PRIMARY_BLOCK</a>);
<a name="l00141"></a>00141         bp-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48" title="First callback to generate blocks for the output pass.">prepare</a>(bundle, xmit_blocks, NULL, link, <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c2b3215ede385d632516efe713ee24058">BlockInfo::LIST_NONE</a>);
<a name="l00142"></a>00142         bp = <a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">PAYLOAD_BLOCK</a>);
<a name="l00143"></a>00143         bp-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48" title="First callback to generate blocks for the output pass.">prepare</a>(bundle, xmit_blocks, NULL, link, <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c2b3215ede385d632516efe713ee24058">BlockInfo::LIST_NONE</a>);
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146     <span class="comment">// locally generated bundles need to include blocks specified at the API</span>
<a name="l00147"></a>00147     <span class="keywordflow">for</span> (BlockInfoVec::iterator iter = api_blocks-&gt;begin();
<a name="l00148"></a>00148          iter != api_blocks-&gt;end();
<a name="l00149"></a>00149          ++iter)
<a name="l00150"></a>00150     {
<a name="l00151"></a>00151         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"adding api_block"</span>);
<a name="l00152"></a>00152         iter-&gt;owner()-&gt;prepare(bundle, xmit_blocks, 
<a name="l00153"></a>00153                                &amp;*iter, link, <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1cc8b73fa28c81de6bc46fdc065e7b506c">BlockInfo::LIST_API</a>);
<a name="l00154"></a>00154     }
<a name="l00155"></a>00155 
<a name="l00156"></a>00156     <span class="comment">// now we also make sure to prepare() on any registered processors</span>
<a name="l00157"></a>00157     <span class="comment">// that don't already have a block in the output list. this</span>
<a name="l00158"></a>00158     <span class="comment">// handles the case where we have a locally generated block with</span>
<a name="l00159"></a>00159     <span class="comment">// nothing in the recv_blocks vector</span>
<a name="l00160"></a>00160     <span class="comment">//</span>
<a name="l00161"></a>00161     <span class="comment">// XXX/demmer this needs some options for the router to select</span>
<a name="l00162"></a>00162     <span class="comment">// which block elements should be in the list, i.e. security, etc</span>
<a name="l00163"></a>00163     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 256; ++i) {
<a name="l00164"></a>00164         <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* bp = <a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(i);
<a name="l00165"></a>00165         <span class="keywordflow">if</span> (bp == UnknownBlockProcessor::instance()) {
<a name="l00166"></a>00166             <span class="keywordflow">continue</span>;
<a name="l00167"></a>00167         }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         <span class="keywordflow">if</span> (! xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#6ab6d60e4c8df6ec3b478880d5a33fb3" title="Check if an entry exists in the vector for the given block type.">has_block</a>(i)) {
<a name="l00170"></a>00170             bp-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48" title="First callback to generate blocks for the output pass.">prepare</a>(bundle, xmit_blocks, NULL, link, <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c2b3215ede385d632516efe713ee24058">BlockInfo::LIST_NONE</a>);
<a name="l00171"></a>00171         }
<a name="l00172"></a>00172     }
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     <span class="comment">// include any metadata locally generated by the API or DP</span>
<a name="l00175"></a>00175     <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* metadata_processor = <a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">METADATA_BLOCK</a>);
<a name="l00176"></a>00176     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata_processor != NULL);
<a name="l00177"></a>00177     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata_processor-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">METADATA_BLOCK</a>);
<a name="l00178"></a>00178     ((<a class="code" href="classdtn_1_1MetadataBlockProcessor.html" title="Block processor implementation for the metadata extension block.">MetadataBlockProcessor</a> *)metadata_processor)-&gt;
<a name="l00179"></a>00179         prepare_generated_metadata(bundle, xmit_blocks, link);
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 <span class="preprocessor">#ifdef BSP_ENABLED</span>
<a name="l00182"></a>00182 <span class="preprocessor"></span>    <span class="comment">// Finally add security blocks</span>
<a name="l00183"></a>00183     SPD::prepare_out_blocks(bundle, link, xmit_blocks);
<a name="l00184"></a>00184 <span class="preprocessor">#endif</span>
<a name="l00185"></a>00185 <span class="preprocessor"></span>
<a name="l00186"></a>00186     <span class="keywordflow">return</span> xmit_blocks;
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00190"></a>00190 <span class="keywordtype">size_t</span>
<a name="l00191"></a><a class="code" href="classdtn_1_1BundleProtocol.html#77305bae9d1251ebd42e2b602684f59b">00191</a> <a class="code" href="classdtn_1_1BundleProtocol.html#77305bae9d1251ebd42e2b602684f59b" title="Generate contents for the given BlockInfoVec on the given Link.">BundleProtocol::generate_blocks</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*        bundle,
<a name="l00192"></a>00192                                 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*  blocks,
<a name="l00193"></a>00193                                 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link)
<a name="l00194"></a>00194 {
<a name="l00195"></a>00195     <span class="comment">// now assert there's at least 2 blocks (primary + payload) and</span>
<a name="l00196"></a>00196     <span class="comment">// that the primary is first</span>
<a name="l00197"></a>00197     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(blocks-&gt;size() &gt;= 2);
<a name="l00198"></a>00198     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(blocks-&gt;front().type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">PRIMARY_BLOCK</a>);
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="comment">// now we make another pass through the list and call generate on</span>
<a name="l00201"></a>00201     <span class="comment">// each block processor</span>
<a name="l00202"></a>00202     BlockInfoVec::iterator last_block = blocks-&gt;end() - 1;
<a name="l00203"></a>00203     <span class="keywordflow">for</span> (BlockInfoVec::iterator iter = blocks-&gt;begin();
<a name="l00204"></a>00204          iter != blocks-&gt;end();
<a name="l00205"></a>00205          ++iter)
<a name="l00206"></a>00206     {
<a name="l00207"></a>00207         <span class="keywordtype">bool</span> last = (iter == last_block);
<a name="l00208"></a>00208         iter-&gt;owner()-&gt;generate(bundle, blocks, &amp;*iter, link, last);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"generated block (owner 0x%x type 0x%x) "</span>
<a name="l00211"></a>00211                     <span class="stringliteral">"data_offset %u data_length %u contents length %zu"</span>,
<a name="l00212"></a>00212                     iter-&gt;owner()-&gt;block_type(), iter-&gt;type(),
<a name="l00213"></a>00213                     iter-&gt;data_offset(), iter-&gt;data_length(),
<a name="l00214"></a>00214                     iter-&gt;contents().len());
<a name="l00215"></a>00215         
<a name="l00216"></a>00216         <span class="keywordflow">if</span> (last) {
<a name="l00217"></a>00217             <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((iter-&gt;flags() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BLOCK_FLAG_LAST_BLOCK</a>) != 0);
<a name="l00218"></a>00218         } <span class="keywordflow">else</span> {
<a name="l00219"></a>00219             <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((iter-&gt;flags() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BLOCK_FLAG_LAST_BLOCK</a>) == 0);
<a name="l00220"></a>00220         }
<a name="l00221"></a>00221     }
<a name="l00222"></a>00222     
<a name="l00223"></a>00223     <span class="comment">// Now that all the EID references are added to the dictionary,</span>
<a name="l00224"></a>00224     <span class="comment">// generate the primary block.</span>
<a name="l00225"></a>00225     <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html" title="Block processor implementation for the primary bundle block.">PrimaryBlockProcessor</a>* pbp =
<a name="l00226"></a>00226         (<a class="code" href="classdtn_1_1PrimaryBlockProcessor.html" title="Block processor implementation for the primary bundle block.">PrimaryBlockProcessor</a>*)<a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">PRIMARY_BLOCK</a>);
<a name="l00227"></a>00227     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(blocks-&gt;front().owner() == pbp);
<a name="l00228"></a>00228     pbp-&gt;<a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#541fb8e13968042f46b8d6e699e81941" title="Virtual from BlockProcessor.">generate_primary</a>(bundle, blocks, &amp;blocks-&gt;front());
<a name="l00229"></a>00229     
<a name="l00230"></a>00230     <span class="comment">// make a final pass through, calling finalize() and extracting</span>
<a name="l00231"></a>00231     <span class="comment">// the block length</span>
<a name="l00232"></a>00232     <span class="comment">//</span>
<a name="l00233"></a>00233     <span class="comment">// NOTE: this pass must be in reverse order, from end of the list</span>
<a name="l00234"></a>00234     <span class="comment">// to the begining, in order for security processing to work.</span>
<a name="l00235"></a>00235     <span class="keywordtype">size_t</span> total_len = 0;
<a name="l00236"></a>00236     <span class="keywordflow">for</span> (BlockInfoVec::reverse_iterator iter = blocks-&gt;rbegin();
<a name="l00237"></a>00237          iter != blocks-&gt;rend();
<a name="l00238"></a>00238          ++iter)
<a name="l00239"></a>00239     {
<a name="l00240"></a>00240         iter-&gt;owner()-&gt;finalize(bundle, blocks, &amp;*iter, link);
<a name="l00241"></a>00241         total_len += iter-&gt;full_length();
<a name="l00242"></a>00242     }
<a name="l00243"></a>00243     
<a name="l00244"></a>00244     <span class="keywordflow">return</span> total_len;
<a name="l00245"></a>00245 }
<a name="l00246"></a>00246 
<a name="l00247"></a>00247 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00248"></a>00248 <span class="keywordtype">void</span>
<a name="l00249"></a><a class="code" href="classdtn_1_1BundleProtocol.html#df59b9b818853e07bfb7464312ca7092">00249</a> <a class="code" href="classdtn_1_1BundleProtocol.html#df59b9b818853e07bfb7464312ca7092">BundleProtocol::delete_blocks</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; link)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL);
<a name="l00252"></a>00252 
<a name="l00253"></a>00253     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#0ce0961036dd0da1fd322721cbb794aa" title="Setters and mutable accessors.">xmit_blocks</a>()-&gt;<a class="code" href="classdtn_1_1LinkBlockSet.html#8657b919c8356da3736c8ced6a740d30" title="Remove the BlockInfoVec for the given link.">delete_blocks</a>(link);
<a name="l00254"></a>00254 
<a name="l00255"></a>00255     <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>* metadata_processor = <a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">METADATA_BLOCK</a>);
<a name="l00256"></a>00256     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata_processor != NULL);
<a name="l00257"></a>00257     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata_processor-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">METADATA_BLOCK</a>);
<a name="l00258"></a>00258     ((<a class="code" href="classdtn_1_1MetadataBlockProcessor.html" title="Block processor implementation for the metadata extension block.">MetadataBlockProcessor</a> *)metadata_processor)-&gt;
<a name="l00259"></a>00259                                    delete_generated_metadata(bundle, link);
<a name="l00260"></a>00260 }
<a name="l00261"></a>00261 
<a name="l00262"></a>00262 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00263"></a>00263 <span class="keywordtype">size_t</span>
<a name="l00264"></a><a class="code" href="classdtn_1_1BundleProtocol.html#a1dedd9ea4300339bc2a3f7a231ca5dd">00264</a> <a class="code" href="classdtn_1_1BundleProtocol.html#a1dedd9ea4300339bc2a3f7a231ca5dd" title="Return the total length of the formatted bundle block data.">BundleProtocol::total_length</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* blocks)
<a name="l00265"></a>00265 {
<a name="l00266"></a>00266     <span class="keywordtype">size_t</span> ret = 0;
<a name="l00267"></a>00267     <span class="keywordflow">for</span> (BlockInfoVec::const_iterator iter = blocks-&gt;begin();
<a name="l00268"></a>00268          iter != blocks-&gt;end();
<a name="l00269"></a>00269          ++iter)
<a name="l00270"></a>00270     {
<a name="l00271"></a>00271         ret += iter-&gt;full_length();
<a name="l00272"></a>00272     }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274     <span class="keywordflow">return</span> ret;
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276 
<a name="l00277"></a>00277 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00278"></a>00278 <span class="keywordtype">size_t</span>
<a name="l00279"></a><a class="code" href="classdtn_1_1BundleProtocol.html#1b5ecc82d428705f3ba067622faace2c">00279</a> <a class="code" href="classdtn_1_1BundleProtocol.html#1b5ecc82d428705f3ba067622faace2c" title="Temporary helper function to find the offset of the first byte of the payload in...">BundleProtocol::payload_offset</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* blocks)
<a name="l00280"></a>00280 {
<a name="l00281"></a>00281     <span class="keywordtype">size_t</span> ret = 0;
<a name="l00282"></a>00282     <span class="keywordflow">for</span> (BlockInfoVec::const_iterator iter = blocks-&gt;begin();
<a name="l00283"></a>00283          iter != blocks-&gt;end();
<a name="l00284"></a>00284          ++iter)
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286         <span class="keywordflow">if</span> (iter-&gt;type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">PAYLOAD_BLOCK</a>) {
<a name="l00287"></a>00287             ret += iter-&gt;data_offset();
<a name="l00288"></a>00288             <span class="keywordflow">return</span> ret;
<a name="l00289"></a>00289         }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291         ret += iter-&gt;full_length();
<a name="l00292"></a>00292     }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294     <span class="keywordflow">return</span> ret;
<a name="l00295"></a>00295 }
<a name="l00296"></a>00296 
<a name="l00297"></a>00297 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00298"></a>00298 <span class="keywordtype">size_t</span>
<a name="l00299"></a><a class="code" href="classdtn_1_1BundleProtocol.html#98a0ecbc789e7f84006909b884e70439">00299</a> <a class="code" href="classdtn_1_1BundleProtocol.html#98a0ecbc789e7f84006909b884e70439" title="Copies out a chunk of formatted bundle data at a specified offset from the provided...">BundleProtocol::produce</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* blocks,
<a name="l00300"></a>00300                         u_char* data, <span class="keywordtype">size_t</span> offset, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>, <span class="keywordtype">bool</span>* last)
<a name="l00301"></a>00301 {
<a name="l00302"></a>00302     <span class="keywordtype">size_t</span> origlen = len;
<a name="l00303"></a>00303     *last = <span class="keyword">false</span>;
<a name="l00304"></a>00304 
<a name="l00305"></a>00305     <span class="keywordflow">if</span> (len == 0)
<a name="l00306"></a>00306         <span class="keywordflow">return</span> 0;
<a name="l00307"></a>00307     
<a name="l00308"></a>00308     <span class="comment">// advance past any blocks that are skipped by the given offset</span>
<a name="l00309"></a>00309     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!blocks-&gt;empty());
<a name="l00310"></a>00310     BlockInfoVec::const_iterator iter = blocks-&gt;begin();
<a name="l00311"></a>00311     <span class="keywordflow">while</span> (offset &gt;= iter-&gt;full_length()) {
<a name="l00312"></a>00312         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"BundleProtocol::produce skipping block type 0x%x "</span>
<a name="l00313"></a>00313                     <span class="stringliteral">"since offset %zu &gt;= block length %u"</span>,
<a name="l00314"></a>00314                     iter-&gt;type(), offset, iter-&gt;full_length());
<a name="l00315"></a>00315         
<a name="l00316"></a>00316         offset -= iter-&gt;full_length();
<a name="l00317"></a>00317         iter++;
<a name="l00318"></a>00318         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(iter != blocks-&gt;end());
<a name="l00319"></a>00319     }
<a name="l00320"></a>00320     
<a name="l00321"></a>00321     <span class="comment">// the offset should be within the bounds of this block</span>
<a name="l00322"></a>00322     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(iter != blocks-&gt;end());
<a name="l00323"></a>00323         
<a name="l00324"></a>00324     <span class="comment">// figure out the amount to generate from this block</span>
<a name="l00325"></a>00325     <span class="keywordflow">while</span> (1) {
<a name="l00326"></a>00326         <span class="keywordtype">size_t</span> remainder = iter-&gt;full_length() - offset;
<a name="l00327"></a>00327         <span class="keywordtype">size_t</span> tocopy    = std::min(len, remainder);
<a name="l00328"></a>00328         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"BundleProtocol::produce copying %zu/%zu bytes from "</span>
<a name="l00329"></a>00329                     <span class="stringliteral">"block type 0x%x at offset %zu"</span>,
<a name="l00330"></a>00330                     tocopy, remainder, iter-&gt;type(), offset);
<a name="l00331"></a>00331         iter-&gt;owner()-&gt;produce(bundle, &amp;*iter, data, offset, tocopy);
<a name="l00332"></a>00332         
<a name="l00333"></a>00333         len    -= tocopy;
<a name="l00334"></a>00334         data   += tocopy;
<a name="l00335"></a>00335         offset = 0;
<a name="l00336"></a>00336 
<a name="l00337"></a>00337         <span class="comment">// if we've copied out the full amount the user asked for,</span>
<a name="l00338"></a>00338         <span class="comment">// we're done. note that we need to check the corner case</span>
<a name="l00339"></a>00339         <span class="comment">// where we completed the block exactly to properly set the</span>
<a name="l00340"></a>00340         <span class="comment">// *last bit</span>
<a name="l00341"></a>00341         <span class="keywordflow">if</span> (len == 0) {
<a name="l00342"></a>00342             <span class="keywordflow">if</span> ((tocopy == remainder) &amp;&amp;
<a name="l00343"></a>00343                 (iter-&gt;flags() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BLOCK_FLAG_LAST_BLOCK</a>))
<a name="l00344"></a>00344             {
<a name="l00345"></a>00345                 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(iter + 1 == blocks-&gt;end());
<a name="l00346"></a>00346                 *last = <span class="keyword">true</span>;
<a name="l00347"></a>00347             }
<a name="l00348"></a>00348             
<a name="l00349"></a>00349             <span class="keywordflow">break</span>;
<a name="l00350"></a>00350         }
<a name="l00351"></a>00351 
<a name="l00352"></a>00352         <span class="comment">// we completed the current block, so we're done if this</span>
<a name="l00353"></a>00353         <span class="comment">// is the lat block, even if there's space in the user buffer</span>
<a name="l00354"></a>00354         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == remainder);
<a name="l00355"></a>00355         <span class="keywordflow">if</span> (iter-&gt;flags() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BLOCK_FLAG_LAST_BLOCK</a>) {
<a name="l00356"></a>00356             <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(iter + 1 == blocks-&gt;end());
<a name="l00357"></a>00357             *last = <span class="keyword">true</span>;
<a name="l00358"></a>00358             <span class="keywordflow">break</span>;
<a name="l00359"></a>00359         }
<a name="l00360"></a>00360         
<a name="l00361"></a>00361         ++iter;
<a name="l00362"></a>00362         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(iter != blocks-&gt;end());
<a name="l00363"></a>00363     }
<a name="l00364"></a>00364     
<a name="l00365"></a>00365     log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"BundleProtocol::produce complete: "</span>
<a name="l00366"></a>00366                 <span class="stringliteral">"produced %zu bytes, bundle %s"</span>,
<a name="l00367"></a>00367                 origlen - len, *last ? <span class="stringliteral">"complete"</span> : <span class="stringliteral">"not complete"</span>);
<a name="l00368"></a>00368     
<a name="l00369"></a>00369     <span class="keywordflow">return</span> origlen - len;
<a name="l00370"></a>00370 }
<a name="l00371"></a>00371     
<a name="l00372"></a>00372 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00373"></a>00373 <span class="keywordtype">int</span>
<a name="l00374"></a><a class="code" href="classdtn_1_1BundleProtocol.html#b1641c2fd8771fbda02c9ee59a1474df">00374</a> <a class="code" href="classdtn_1_1BundleProtocol.html#b1641c2fd8771fbda02c9ee59a1474df" title="Parse the supplied chunk of arriving data and append it to the rcvd_blocks_ list...">BundleProtocol::consume</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle,
<a name="l00375"></a>00375                         u_char* data,
<a name="l00376"></a>00376                         <span class="keywordtype">size_t</span>  <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>,
<a name="l00377"></a>00377                         <span class="keywordtype">bool</span>*   last)
<a name="l00378"></a>00378 {
<a name="l00379"></a>00379     <span class="keywordtype">size_t</span> origlen = len;
<a name="l00380"></a>00380     *last = <span class="keyword">false</span>;
<a name="l00381"></a>00381 
<a name="l00382"></a>00382     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* recv_blocks = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5c48f51fba15c89a82d5d98c9881f0bd" title="Setters and mutable accessors.">mutable_recv_blocks</a>();
<a name="l00383"></a>00383     
<a name="l00384"></a>00384     <span class="comment">// special case for first time we get called, since we need to</span>
<a name="l00385"></a>00385     <span class="comment">// create a BlockInfo struct for the primary block without knowing</span>
<a name="l00386"></a>00386     <span class="comment">// the typecode or the length</span>
<a name="l00387"></a>00387     <span class="keywordflow">if</span> (recv_blocks-&gt;empty()) {
<a name="l00388"></a>00388         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: got first block... "</span>
<a name="l00389"></a>00389                     <span class="stringliteral">"creating primary block info"</span>);
<a name="l00390"></a>00390         recv_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#3dd17df5cfc9f0ddac71580724739866" title="Append a block using the given processor and optional source block.">append_block</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">PRIMARY_BLOCK</a>));
<a name="l00391"></a>00391     }
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     <span class="comment">// loop as long as there is data left to process</span>
<a name="l00394"></a>00394     <span class="keywordflow">while</span> (len != 0) {
<a name="l00395"></a>00395         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: %zu bytes left to process"</span>, len);
<a name="l00396"></a>00396         <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* <a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a> = &amp;recv_blocks-&gt;back();
<a name="l00397"></a>00397 
<a name="l00398"></a>00398         <span class="comment">// if the last received block is complete, create a new one</span>
<a name="l00399"></a>00399         <span class="comment">// and push it onto the vector. at this stage we consume all</span>
<a name="l00400"></a>00400         <span class="comment">// blocks, even if there's no BlockProcessor that understands</span>
<a name="l00401"></a>00401         <span class="comment">// how to parse it</span>
<a name="l00402"></a>00402         <span class="keywordflow">if</span> (info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>()) {
<a name="l00403"></a>00403             info = recv_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#3dd17df5cfc9f0ddac71580724739866" title="Append a block using the given processor and optional source block.">append_block</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#9baff2ff7f808753a44b05f90a366c61" title="Find the appropriate BlockProcessor for the given block type code.">find_processor</a>(*data));
<a name="l00404"></a>00404             log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: previous block complete, "</span>
<a name="l00405"></a>00405                         <span class="stringliteral">"created new BlockInfo type 0x%x"</span>,
<a name="l00406"></a>00406                         info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>()-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>());
<a name="l00407"></a>00407         }
<a name="l00408"></a>00408         
<a name="l00409"></a>00409         <span class="comment">// now we know that the block isn't complete, so we tell it to</span>
<a name="l00410"></a>00410         <span class="comment">// consume a chunk of data</span>
<a name="l00411"></a>00411         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: block processor 0x%x type 0x%x incomplete, "</span>
<a name="l00412"></a>00412                     <span class="stringliteral">"calling consume (%zu bytes already buffered)"</span>,
<a name="l00413"></a>00413                     info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>()-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>(), info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>(),
<a name="l00414"></a>00414                     info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len());
<a name="l00415"></a>00415         
<a name="l00416"></a>00416         <span class="keywordtype">int</span> cc = info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>()-&gt;<a class="code" href="classdtn_1_1BlockProcessor.html#1f73d119593ef13da9c5ee845fd5ec00" title="First callback for parsing blocks that is expected to append a chunk of the given...">consume</a>(bundle, info, data, len);
<a name="l00417"></a>00417         <span class="keywordflow">if</span> (cc &lt; 0) {
<a name="l00418"></a>00418             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: protocol error handling block 0x%x"</span>,
<a name="l00419"></a>00419                       info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>());
<a name="l00420"></a>00420             <span class="keywordflow">return</span> -1;
<a name="l00421"></a>00421         }
<a name="l00422"></a>00422         
<a name="l00423"></a>00423         <span class="comment">// decrement the amount that was just handled from the overall</span>
<a name="l00424"></a>00424         <span class="comment">// total. verify that the block was either completed or</span>
<a name="l00425"></a>00425         <span class="comment">// consumed all the data that was passed in.</span>
<a name="l00426"></a>00426         len  -= cc;
<a name="l00427"></a>00427         data += cc;
<a name="l00428"></a>00428 
<a name="l00429"></a>00429         log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume: consumed %u bytes of block type 0x%x (%s)"</span>,
<a name="l00430"></a>00430                     cc, info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>(),
<a name="l00431"></a>00431                     info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>() ? <span class="stringliteral">"complete"</span> : <span class="stringliteral">"not complete"</span>);
<a name="l00432"></a>00432 
<a name="l00433"></a>00433         <span class="keywordflow">if</span> (info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>()) {
<a name="l00434"></a>00434             <span class="comment">// check if we're done with the bundle</span>
<a name="l00435"></a>00435             <span class="keywordflow">if</span> (info-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BLOCK_FLAG_LAST_BLOCK</a>) {
<a name="l00436"></a>00436                 *last = <span class="keyword">true</span>;
<a name="l00437"></a>00437                 <span class="keywordflow">break</span>;
<a name="l00438"></a>00438             }
<a name="l00439"></a>00439                 
<a name="l00440"></a>00440         } <span class="keywordflow">else</span> {
<a name="l00441"></a>00441             <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(len == 0);
<a name="l00442"></a>00442         }
<a name="l00443"></a>00443     }
<a name="l00444"></a>00444     
<a name="l00445"></a>00445     log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"consume completed, %zu/%zu bytes consumed %s"</span>,
<a name="l00446"></a>00446                 origlen - len, origlen, *last ? <span class="stringliteral">"(completed bundle)"</span> : <span class="stringliteral">""</span>);
<a name="l00447"></a>00447     <span class="keywordflow">return</span> origlen - len;
<a name="l00448"></a>00448 }
<a name="l00449"></a>00449 
<a name="l00450"></a>00450 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00451"></a>00451 <span class="keywordtype">bool</span>
<a name="l00452"></a><a class="code" href="classdtn_1_1BundleProtocol.html#403d237e6ea6655a5e19b6c8f45dae3b">00452</a> <a class="code" href="classdtn_1_1BundleProtocol.html#403d237e6ea6655a5e19b6c8f45dae3b" title="Loop through the bundle&amp;#39;s received block list to validate each entry.">BundleProtocol::validate</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle,
<a name="l00453"></a>00453                          <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &amp;quot;Reason Code&amp;quot; flags.">status_report_reason_t</a>* reception_reason,
<a name="l00454"></a>00454                          <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &amp;quot;Reason Code&amp;quot; flags.">status_report_reason_t</a>* deletion_reason)
<a name="l00455"></a>00455 {
<a name="l00456"></a>00456     <span class="keywordtype">int</span> primary_blocks = 0, payload_blocks = 0;
<a name="l00457"></a>00457     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* recv_blocks = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5c48f51fba15c89a82d5d98c9881f0bd" title="Setters and mutable accessors.">mutable_recv_blocks</a>();
<a name="l00458"></a>00458  
<a name="l00459"></a>00459     <span class="comment">// a bundle must include at least two blocks (primary and payload)</span>
<a name="l00460"></a>00460     <span class="keywordflow">if</span> (recv_blocks-&gt;size() &lt; 2) {
<a name="l00461"></a>00461         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle fails to contain at least two blocks"</span>);
<a name="l00462"></a>00462         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00463"></a>00463         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00464"></a>00464     }
<a name="l00465"></a>00465 
<a name="l00466"></a>00466     <span class="comment">// the first block of a bundle must be a primary block</span>
<a name="l00467"></a>00467     <span class="keywordflow">if</span> (recv_blocks-&gt;front().type() != <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>) {
<a name="l00468"></a>00468         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle fails to contain a primary block"</span>);
<a name="l00469"></a>00469         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00470"></a>00470         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00471"></a>00471     }
<a name="l00472"></a>00472 
<a name="l00473"></a>00473     <span class="comment">// validate each individual block</span>
<a name="l00474"></a>00474     BlockInfoVec::iterator last_block = recv_blocks-&gt;end() - 1;
<a name="l00475"></a>00475     <span class="keywordflow">for</span> (BlockInfoVec::iterator iter = recv_blocks-&gt;begin();
<a name="l00476"></a>00476          iter != recv_blocks-&gt;end();
<a name="l00477"></a>00477          ++iter)
<a name="l00478"></a>00478     {
<a name="l00479"></a>00479         <span class="comment">// a block may not have enough data for the preamble</span>
<a name="l00480"></a>00480         <span class="keywordflow">if</span> (iter-&gt;data_offset() == 0) {
<a name="l00481"></a>00481             <span class="comment">// either the block is not the last one and something went</span>
<a name="l00482"></a>00482             <span class="comment">// badly wrong, or it is the last block present</span>
<a name="l00483"></a>00483             <span class="keywordflow">if</span> (iter != last_block) {
<a name="l00484"></a>00484                 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle block too short for the preamble"</span>);
<a name="l00485"></a>00485                 *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00486"></a>00486                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00487"></a>00487             }
<a name="l00488"></a>00488             <span class="comment">// this is the last block, so drop it</span>
<a name="l00489"></a>00489             log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"forgetting preamble-starved last block"</span>);
<a name="l00490"></a>00490             recv_blocks-&gt;erase(iter);
<a name="l00491"></a>00491             <span class="keywordflow">if</span> (recv_blocks-&gt;size() &lt; 2) {
<a name="l00492"></a>00492                 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle fails to contain at least two blocks"</span>);
<a name="l00493"></a>00493                 *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00494"></a>00494                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00495"></a>00495             }
<a name="l00496"></a>00496             <span class="comment">// continue with the tests; results may have changed now that</span>
<a name="l00497"></a>00497             <span class="comment">// a different block is last</span>
<a name="l00498"></a>00498             iter = last_block = recv_blocks-&gt;end() - 1;
<a name="l00499"></a>00499         }
<a name="l00500"></a>00500         <span class="keywordflow">else</span> {
<a name="l00501"></a>00501             <span class="keywordflow">if</span> (iter-&gt;type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>) {
<a name="l00502"></a>00502                 primary_blocks++;
<a name="l00503"></a>00503             }
<a name="l00504"></a>00504 
<a name="l00505"></a>00505             <span class="keywordflow">if</span> (iter-&gt;type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca711ba3c0a764c41add8e738d757393d60">BundleProtocol::PAYLOAD_BLOCK</a>) {
<a name="l00506"></a>00506                 payload_blocks++;
<a name="l00507"></a>00507             }
<a name="l00508"></a>00508         }
<a name="l00509"></a>00509 
<a name="l00510"></a>00510         <span class="keywordflow">if</span> (!iter-&gt;owner()-&gt;validate(bundle, recv_blocks, &amp;*iter, 
<a name="l00511"></a>00511                                 reception_reason, deletion_reason)) {
<a name="l00512"></a>00512             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00513"></a>00513         }
<a name="l00514"></a>00514 
<a name="l00515"></a>00515         <span class="comment">// a bundle's last block must be flagged as such,</span>
<a name="l00516"></a>00516         <span class="comment">// and all other blocks should not be flagged</span>
<a name="l00517"></a>00517         <span class="keywordflow">if</span> (iter == last_block) {
<a name="l00518"></a>00518             <span class="keywordflow">if</span> (!iter-&gt;last_block()) {
<a name="l00519"></a>00519                 <span class="comment">// this may be okay, if it is a reactive fragment</span>
<a name="l00520"></a>00520                 <span class="keywordflow">if</span> (!bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#786fe13c6220382bb032e740fb31da7e" title="Accessors.">fragmented_incoming</a>()) {
<a name="l00521"></a>00521                     <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle's last block not flagged"</span>);
<a name="l00522"></a>00522                     *deletion_reason
<a name="l00523"></a>00523                         = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00524"></a>00524                     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00525"></a>00525                 }
<a name="l00526"></a>00526                 <span class="keywordflow">else</span> {
<a name="l00527"></a>00527                     log_debug_p(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle's last block not flagged, but "</span>
<a name="l00528"></a>00528                                      <span class="stringliteral">"it is a reactive fragment"</span>);
<a name="l00529"></a>00529                 }
<a name="l00530"></a>00530             }
<a name="l00531"></a>00531         } <span class="keywordflow">else</span> {
<a name="l00532"></a>00532             <span class="keywordflow">if</span> (iter-&gt;last_block()) {
<a name="l00533"></a>00533                 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle block incorrectly flagged as last"</span>);
<a name="l00534"></a>00534                 *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00535"></a>00535                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00536"></a>00536             }
<a name="l00537"></a>00537         }
<a name="l00538"></a>00538     }
<a name="l00539"></a>00539 
<a name="l00540"></a>00540     <span class="comment">// a bundle must contain one, and only one, primary block</span>
<a name="l00541"></a>00541     <span class="keywordflow">if</span> (primary_blocks != 1) {
<a name="l00542"></a>00542         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle contains %d primary blocks"</span>, primary_blocks);
<a name="l00543"></a>00543         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00544"></a>00544         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00545"></a>00545     }
<a name="l00546"></a>00546            
<a name="l00547"></a>00547     <span class="comment">// a bundle must not contain more than one payload block</span>
<a name="l00548"></a>00548     <span class="keywordflow">if</span> (payload_blocks &gt; 1) {
<a name="l00549"></a>00549         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle contains %d payload blocks"</span>, payload_blocks);
<a name="l00550"></a>00550         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00551"></a>00551         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00552"></a>00552     }
<a name="l00553"></a>00553 
<a name="l00554"></a>00554 <span class="preprocessor">#ifdef BSP_ENABLED</span>
<a name="l00555"></a>00555 <span class="preprocessor"></span>    <span class="comment">// verify that bundle matches inbound security policy</span>
<a name="l00556"></a>00556     <span class="comment">// XXX also need to verify that block order is sane!</span>
<a name="l00557"></a>00557     <span class="keywordflow">if</span> (! SPD::verify_in_policy(bundle)) {
<a name="l00558"></a>00558         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(<a class="code" href="namespacedtn.html#a316af661cbfed69c13e77d524d1012e">LOG</a>, <span class="stringliteral">"bundle failed security policy verification"</span>);
<a name="l00559"></a>00559         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f9177d3cf6e00cf9ebd5eb174355289acaea">BundleProtocol::REASON_SECURITY_FAILED</a>;
<a name="l00560"></a>00560         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00561"></a>00561     }
<a name="l00562"></a>00562 <span class="preprocessor">#endif</span>
<a name="l00563"></a>00563 <span class="preprocessor"></span>
<a name="l00564"></a>00564     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00565"></a>00565 }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00568"></a>00568 <span class="keywordtype">int</span>
<a name="l00569"></a><a class="code" href="classdtn_1_1BundleProtocol.html#c590d33b1e828121f9d096860d4cad9a">00569</a> <a class="code" href="classdtn_1_1BundleProtocol.html#c590d33b1e828121f9d096860d4cad9a" title="Store a DTN timestamp into a 64-bit value suitable for transmission over the network...">BundleProtocol::set_timestamp</a>(u_char* ts, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>, <span class="keyword">const</span> <a class="code" href="structdtn_1_1BundleTimestamp.html" title="Simple struct definition for bundle creation timestamps.">BundleTimestamp</a>&amp; tv)
<a name="l00570"></a>00570 {
<a name="l00571"></a>00571     <span class="keywordtype">int</span> sec_size = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(tv.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>, ts, len);
<a name="l00572"></a>00572     <span class="keywordflow">if</span> (sec_size &lt; 0)
<a name="l00573"></a>00573         <span class="keywordflow">return</span> -1;
<a name="l00574"></a>00574     
<a name="l00575"></a>00575     <span class="keywordtype">int</span> seqno_size = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(tv.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>, ts + sec_size, len - sec_size);
<a name="l00576"></a>00576     <span class="keywordflow">if</span> (seqno_size &lt; 0)
<a name="l00577"></a>00577         <span class="keywordflow">return</span> -1;
<a name="l00578"></a>00578     
<a name="l00579"></a>00579     <span class="keywordflow">return</span> sec_size + seqno_size;
<a name="l00580"></a>00580 }
<a name="l00581"></a>00581 
<a name="l00582"></a>00582 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00583"></a>00583 <span class="keywordtype">int</span>
<a name="l00584"></a><a class="code" href="classdtn_1_1BundleProtocol.html#09d040740695f886e1e09bd9065767ab">00584</a> <a class="code" href="classdtn_1_1BundleProtocol.html#09d040740695f886e1e09bd9065767ab" title="Retrieve a DTN timestamp from a 64-bit value that was transmitted over the network...">BundleProtocol::get_timestamp</a>(<a class="code" href="structdtn_1_1BundleTimestamp.html" title="Simple struct definition for bundle creation timestamps.">BundleTimestamp</a>* tv, <span class="keyword">const</span> u_char* ts, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00585"></a>00585 {
<a name="l00586"></a>00586     u_int64_t tmp;
<a name="l00587"></a>00587     
<a name="l00588"></a>00588     <span class="keywordtype">int</span> sec_size = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(ts, len, &amp;tmp);
<a name="l00589"></a>00589     <span class="keywordflow">if</span> (sec_size &lt; 0)
<a name="l00590"></a>00590         <span class="keywordflow">return</span> -1;
<a name="l00591"></a>00591     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tmp &lt; 0xffffffff);
<a name="l00592"></a>00592     tv-&gt;<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a> = (u_int32_t)tmp;
<a name="l00593"></a>00593     
<a name="l00594"></a>00594     <span class="keywordtype">int</span> seqno_size = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(ts + sec_size, len - sec_size, &amp;tmp);
<a name="l00595"></a>00595     <span class="keywordflow">if</span> (seqno_size &lt; 0)
<a name="l00596"></a>00596         <span class="keywordflow">return</span> -1;
<a name="l00597"></a>00597     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tmp &lt; 0xffffffff);
<a name="l00598"></a>00598     tv-&gt;<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a> = (u_int32_t)tmp;
<a name="l00599"></a>00599     
<a name="l00600"></a>00600     <span class="keywordflow">return</span> sec_size + seqno_size;
<a name="l00601"></a>00601 }
<a name="l00602"></a>00602 
<a name="l00603"></a>00603 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00604"></a>00604 <span class="keywordtype">size_t</span>
<a name="l00605"></a><a class="code" href="classdtn_1_1BundleProtocol.html#efd5468219b7a40e33d4d6eaa7fa610e">00605</a> <a class="code" href="classdtn_1_1BundleProtocol.html#efd5468219b7a40e33d4d6eaa7fa610e" title="Return the length required to encode the timestamp as two SDNVs.">BundleProtocol::ts_encoding_len</a>(<span class="keyword">const</span> <a class="code" href="structdtn_1_1BundleTimestamp.html" title="Simple struct definition for bundle creation timestamps.">BundleTimestamp</a>&amp; tv)
<a name="l00606"></a>00606 {
<a name="l00607"></a>00607     <span class="keywordflow">return</span> <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(tv.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>) + <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(tv.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>);
<a name="l00608"></a>00608 }
<a name="l00609"></a>00609 
<a name="l00610"></a>00610 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00611"></a>00611 <span class="keywordtype">bool</span>
<a name="l00612"></a><a class="code" href="classdtn_1_1BundleProtocol.html#0100870ed71be16830543b822cfffd2c">00612</a> <a class="code" href="classdtn_1_1BundleProtocol.html#0100870ed71be16830543b822cfffd2c" title="Assuming the given bundle is an administrative bundle, extract the admin bundle type...">BundleProtocol::get_admin_type</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece20" title="Administrative Record Type Codes.">admin_record_type_t</a>* type)
<a name="l00613"></a>00613 {
<a name="l00614"></a>00614     <span class="keywordflow">if</span> (! bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#839db0b56b61020d9f2b3878e6c2d34a" title="Accessors.">is_admin</a>()) {
<a name="l00615"></a>00615         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00616"></a>00616     }
<a name="l00617"></a>00617 
<a name="l00618"></a>00618     u_char <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>[16];
<a name="l00619"></a>00619     <span class="keyword">const</span> u_char* bp = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#c4ce25f2d2d7ad54a9306ea2599731b4" title="Copy out a chunk of payload data into the supplied buffer.">read_data</a>(0, <span class="keyword">sizeof</span>(buf), buf);
<a name="l00620"></a>00620 
<a name="l00621"></a>00621     <span class="keywordflow">switch</span> (bp[0] &gt;&gt; 4)
<a name="l00622"></a>00622     {
<a name="l00623"></a>00623 <span class="preprocessor">#define CASE(_what) case _what: *type = _what; return true;</span>
<a name="l00624"></a>00624 <span class="preprocessor"></span>
<a name="l00625"></a>00625         <a class="code" href="dtn__ipc_8c.html#6d24efd83036c2dde8d9100adb9abffd">CASE</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece20e4dc69cfbb7fd68487cffea427db7f7f">ADMIN_STATUS_REPORT</a>);
<a name="l00626"></a>00626         <a class="code" href="dtn__ipc_8c.html#6d24efd83036c2dde8d9100adb9abffd">CASE</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece207e6e1a30d0fed8a953bc65802798f7dd">ADMIN_CUSTODY_SIGNAL</a>);
<a name="l00627"></a>00627         <a class="code" href="dtn__ipc_8c.html#6d24efd83036c2dde8d9100adb9abffd">CASE</a>(<a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece20f8fdc109b1a0407b5a3107a3585f6dc3">ADMIN_ANNOUNCE</a>);
<a name="l00628"></a>00628 
<a name="l00629"></a>00629 <span class="preprocessor">#undef  CASE</span>
<a name="l00630"></a>00630 <span class="preprocessor"></span>    <span class="keywordflow">default</span>:
<a name="l00631"></a>00631         <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// unknown type</span>
<a name="l00632"></a>00632     }
<a name="l00633"></a>00633 
<a name="l00634"></a>00634     NOTREACHED;
<a name="l00635"></a>00635 }
<a name="l00636"></a>00636 
<a name="l00637"></a>00637 } <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:38 2008 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>