Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 66

libdtn-devel-2.6.0-2mdv2009.1.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: BlockProcessor.cc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<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>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>BlockProcessor.cc</h1><a href="BlockProcessor_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 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;oasys/debug/Log.h&gt;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="BlockProcessor_8h.html">BlockProcessor.h</a>"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="BlockInfo_8h.html">BlockInfo.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">Bundle.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">SDNV.h</a>"</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">namespace </span>dtn {
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">00030</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>;
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00033"></a><a class="code" href="classdtn_1_1BlockProcessor.html#b1578b54c23dee910a62937b5c4f9484">00033</a> <a class="code" href="classdtn_1_1BlockProcessor.html#b1578b54c23dee910a62937b5c4f9484" title="Constructor that takes the block typecode.">BlockProcessor::BlockProcessor</a>(<span class="keywordtype">int</span> block_type)
<a name="l00034"></a>00034     : block_type_(block_type)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036     <span class="comment">// quiet down non-debugging build</span>
<a name="l00037"></a>00037     (void)<a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a>;
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00041"></a><a class="code" href="classdtn_1_1BlockProcessor.html#bee24525fc2b941b4849985b1397f699">00041</a> <a class="code" href="classdtn_1_1BlockProcessor.html#bee24525fc2b941b4849985b1397f699" title="Virtual destructor.">BlockProcessor::~BlockProcessor</a>()
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00046"></a>00046 <span class="keywordtype">int</span>
<a name="l00047"></a><a class="code" href="classdtn_1_1BlockProcessor.html#16d1b8a2805b0888536bd001ce5e9e5b">00047</a> <a class="code" href="classdtn_1_1BlockProcessor.html#16d1b8a2805b0888536bd001ce5e9e5b" title="Consume a block preamble consisting of type, flags(SDNV), EID-list (composite field...">BlockProcessor::consume_preamble</a>(<a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* recv_blocks,
<a name="l00048"></a>00048                                  <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*    block,
<a name="l00049"></a>00049                                  u_char*       <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>,
<a name="l00050"></a>00050                                  <span class="keywordtype">size_t</span>        <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>,
<a name="l00051"></a>00051                                  u_int64_t*    flagp)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>;
<a name="l00054"></a>00054     <span class="keywordtype">int</span> sdnv_len;
<a name="l00055"></a>00055     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(! block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>());
<a name="l00056"></a>00056     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() == 0);
<a name="l00057"></a>00057 
<a name="l00058"></a>00058     <span class="comment">// The block info buffer usually will already contain enough space</span>
<a name="l00059"></a>00059     <span class="comment">// for the preamble in the static part of the scratch buffer, but the </span>
<a name="l00060"></a>00060     <span class="comment">// presence of an EID-ref-list might cause it to be bigger.</span>
<a name="l00061"></a>00061     <span class="comment">// So we'll copy up to what will fit in the static part, or</span>
<a name="l00062"></a>00062     <span class="comment">// expand the buffer if it is already full. </span>
<a name="l00063"></a>00063     <span class="comment">// Actually, we will probably never get here, as doing do</span>
<a name="l00064"></a>00064     <span class="comment">// would mean that there were about fifteen EID refs in the preamble.</span>
<a name="l00065"></a>00065     <span class="keywordflow">if</span> ( block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().nfree() == 0 ) {
<a name="l00066"></a>00066         block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;reserve(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len() + 64);
<a name="l00067"></a>00067     }    
<a name="l00068"></a>00068     
<a name="l00069"></a>00069     <span class="keywordtype">size_t</span> max_preamble  = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf_len();
<a name="l00070"></a>00070     <span class="keywordtype">size_t</span> prev_consumed = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len();
<a name="l00071"></a>00071     <span class="keywordtype">size_t</span> tocopy        = std::min(len, max_preamble - prev_consumed);
<a name="l00072"></a>00072     
<a name="l00073"></a>00073     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(max_preamble &gt; prev_consumed);
<a name="l00074"></a>00074     <a class="code" href="classdtn_1_1BlockInfo.html#369e8412fcff682247168dbc4776ded2" title="To store the formatted block data, we use a scratch buffer with 64 bytes of static...">BlockInfo::DataBuffer</a>* contents = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>();
<a name="l00075"></a>00075     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(contents-&gt;nfree() &gt;= tocopy);
<a name="l00076"></a>00076     memcpy(contents-&gt;end(), buf, tocopy);
<a name="l00077"></a>00077     contents-&gt;set_len(contents-&gt;len() + tocopy);
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="comment">// Make sure we have at least one byte of sdnv before trying to</span>
<a name="l00080"></a>00080     <span class="comment">// parse it.</span>
<a name="l00081"></a>00081     <span class="keywordflow">if</span> (contents-&gt;len() &lt;= <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a>) {
<a name="l00082"></a>00082         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00083"></a>00083         <span class="keywordflow">return</span> len;
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085     
<a name="l00086"></a>00086     <span class="keywordtype">size_t</span> buf_offset = <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a>;
<a name="l00087"></a>00087     u_int64_t flags;
<a name="l00088"></a>00088     
<a name="l00089"></a>00089     <span class="comment">// Now we try decoding the sdnv that contains the block processing</span>
<a name="l00090"></a>00090     <span class="comment">// flags. If we can't, then we have a partial preamble, so we can</span>
<a name="l00091"></a>00091     <span class="comment">// assert that the whole incoming buffer was consumed.</span>
<a name="l00092"></a>00092     sdnv_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(contents-&gt;buf() + buf_offset,
<a name="l00093"></a>00093                             contents-&gt;len() - buf_offset,
<a name="l00094"></a>00094                             &amp;flags);
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (sdnv_len == -1) {
<a name="l00096"></a>00096         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00097"></a>00097         <span class="keywordflow">return</span> len;
<a name="l00098"></a>00098     }
<a name="l00099"></a>00099     
<a name="l00100"></a>00100     <span class="keywordflow">if</span> (flagp != NULL)
<a name="l00101"></a>00101         *flagp = flags;
<a name="l00102"></a>00102     
<a name="l00103"></a>00103     buf_offset += sdnv_len;
<a name="l00104"></a>00104     
<a name="l00105"></a>00105     <span class="comment">// point at the local dictionary</span>
<a name="l00106"></a>00106     <a class="code" href="classdtn_1_1Dictionary.html" title="Simple data structure to handle a dictionary data structure, as specified by the...">Dictionary</a>* dict = recv_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>();
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     <span class="comment">// Now we try decoding the EID-references field, if it is present.</span>
<a name="l00109"></a>00109     <span class="comment">// As with the flags, if we don't finish then we have a partial</span>
<a name="l00110"></a>00110     <span class="comment">// preamble and will try again when we get more, so we first</span>
<a name="l00111"></a>00111     <span class="comment">// construct a temporary eid list and then only assign it to the</span>
<a name="l00112"></a>00112     <span class="comment">// block if we've parsed the whole preamble.</span>
<a name="l00113"></a>00113     <span class="comment">//</span>
<a name="l00114"></a>00114     <span class="comment">// We assert that the whole incoming buffer was consumed.</span>
<a name="l00115"></a>00115     u_int64_t eid_ref_count = 0LLU;
<a name="l00116"></a>00116     u_int64_t scheme_offset;
<a name="l00117"></a>00117     u_int64_t ssp_offset;
<a name="l00118"></a>00118     
<a name="l00119"></a>00119     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#b20777efd3367156feb424643fc089e4" title="Accessors.">eid_list</a>().empty());
<a name="l00120"></a>00120     <a class="code" href="classdtn_1_1EndpointIDVector.html" title="A (serializable) vector of endpoint ids.">EndpointIDVector</a> eid_list;
<a name="l00121"></a>00121         
<a name="l00122"></a>00122     <span class="keywordflow">if</span> ( flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b6616947d5db3ac647eeb6d6f0411a593">BundleProtocol::BLOCK_FLAG_EID_REFS</a> ) {
<a name="l00123"></a>00123         sdnv_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(contents-&gt;buf() + buf_offset,
<a name="l00124"></a>00124                                 contents-&gt;len() - buf_offset,
<a name="l00125"></a>00125                                 &amp;eid_ref_count);
<a name="l00126"></a>00126         <span class="keywordflow">if</span> (sdnv_len == -1) {
<a name="l00127"></a>00127             <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00128"></a>00128             <span class="keywordflow">return</span> len;
<a name="l00129"></a>00129         }
<a name="l00130"></a>00130             
<a name="l00131"></a>00131         buf_offset += sdnv_len;
<a name="l00132"></a>00132             
<a name="l00133"></a>00133         <span class="keywordflow">for</span> ( u_int32_t i = 0; i &lt; eid_ref_count; ++i ) {
<a name="l00134"></a>00134             <span class="comment">// Now we try decoding the sdnv pair with the offsets</span>
<a name="l00135"></a>00135             sdnv_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(contents-&gt;buf() + buf_offset,
<a name="l00136"></a>00136                                     contents-&gt;len() - buf_offset,
<a name="l00137"></a>00137                                     &amp;scheme_offset);
<a name="l00138"></a>00138             <span class="keywordflow">if</span> (sdnv_len == -1) {
<a name="l00139"></a>00139                 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00140"></a>00140                 <span class="keywordflow">return</span> len;
<a name="l00141"></a>00141             }
<a name="l00142"></a>00142             buf_offset += sdnv_len;
<a name="l00143"></a>00143                     
<a name="l00144"></a>00144             sdnv_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(contents-&gt;buf() + buf_offset,
<a name="l00145"></a>00145                                     contents-&gt;len() - buf_offset,
<a name="l00146"></a>00146                                     &amp;ssp_offset);
<a name="l00147"></a>00147             <span class="keywordflow">if</span> (sdnv_len == -1) {
<a name="l00148"></a>00148                 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00149"></a>00149                 <span class="keywordflow">return</span> len;
<a name="l00150"></a>00150             }
<a name="l00151"></a>00151             buf_offset += sdnv_len;
<a name="l00152"></a>00152                 
<a name="l00153"></a>00153             <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a> eid;
<a name="l00154"></a>00154             dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#192d234238daaefda8062da1d16836ad" title="Create an eid from the dictionary, given the offsets.">extract_eid</a>(&amp;eid, scheme_offset, ssp_offset);
<a name="l00155"></a>00155             eid_list.push_back(eid);
<a name="l00156"></a>00156         }
<a name="l00157"></a>00157     }
<a name="l00158"></a>00158     
<a name="l00159"></a>00159     <span class="comment">// Now we try decoding the sdnv that contains the actual block</span>
<a name="l00160"></a>00160     <span class="comment">// length. If we can't, then we have a partial preamble, so we can</span>
<a name="l00161"></a>00161     <span class="comment">// assert that the whole incoming buffer was consumed.</span>
<a name="l00162"></a>00162     u_int64_t block_len;
<a name="l00163"></a>00163     sdnv_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(contents-&gt;buf() + buf_offset,
<a name="l00164"></a>00164                             contents-&gt;len() - buf_offset,
<a name="l00165"></a>00165                             &amp;block_len);
<a name="l00166"></a>00166     <span class="keywordflow">if</span> (sdnv_len == -1) {
<a name="l00167"></a>00167         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(tocopy == len);
<a name="l00168"></a>00168         <span class="keywordflow">return</span> len;
<a name="l00169"></a>00169     }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     <span class="keywordflow">if</span> (block_len &gt; 0xFFFFFFFFLL) {
<a name="l00172"></a>00172         <span class="comment">// XXX/demmer implement big blocks</span>
<a name="l00173"></a>00173         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"overflow in SDNV value for block type 0x%x"</span>,
<a name="l00174"></a>00174                   *contents-&gt;buf());
<a name="l00175"></a>00175         <span class="keywordflow">return</span> -1;
<a name="l00176"></a>00176     }
<a name="l00177"></a>00177     
<a name="l00178"></a>00178     buf_offset += sdnv_len;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180     <span class="comment">// We've successfully consumed the preamble so initialize the</span>
<a name="l00181"></a>00181     <span class="comment">// data_length and data_offset fields of the block and adjust the</span>
<a name="l00182"></a>00182     <span class="comment">// length field of the contents buffer to include only the</span>
<a name="l00183"></a>00183     <span class="comment">// preamble part (even though a few more bytes might be in there.</span>
<a name="l00184"></a>00184     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#38d215397b046a403f252512227c29a9" title="Mutating accessors.">set_data_length</a>(static_cast&lt;u_int32_t&gt;(block_len));
<a name="l00185"></a>00185     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#67e9f36d2da267e95270a4dd7d0aa65e" title="Mutating accessors.">set_data_offset</a>(buf_offset);
<a name="l00186"></a>00186     contents-&gt;set_len(buf_offset);
<a name="l00187"></a>00187 
<a name="l00188"></a>00188     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#371f09d4cb7cbd6c6cd60a7823f1630a" title="Mutating accessors.">set_eid_list</a>(eid_list);
<a name="l00189"></a>00189 
<a name="l00190"></a>00190     log_debug_p(log, <span class="stringliteral">"BlockProcessor type 0x%x "</span>
<a name="l00191"></a>00191                 <span class="stringliteral">"consumed preamble %zu/%u for block: "</span>
<a name="l00192"></a>00192                 <span class="stringliteral">"data_offset %u data_length %u eid_ref_count %llu"</span>,
<a name="l00193"></a>00193                 <a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>(), buf_offset + prev_consumed,
<a name="l00194"></a>00194                 block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>(),
<a name="l00195"></a>00195                 block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(), block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>(),
<a name="l00196"></a>00196                 U64FMT(eid_ref_count));
<a name="l00197"></a>00197     
<a name="l00198"></a>00198     <span class="comment">// Finally, be careful to return only the amount of the buffer</span>
<a name="l00199"></a>00199     <span class="comment">// that we needed to complete the preamble.</span>
<a name="l00200"></a>00200     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(buf_offset &gt; prev_consumed);
<a name="l00201"></a>00201     <span class="keywordflow">return</span> buf_offset - prev_consumed;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00205"></a>00205 <span class="keywordtype">void</span>
<a name="l00206"></a><a class="code" href="classdtn_1_1BlockProcessor.html#c08f7b82f6049f30710a5dcdebb61ce7">00206</a> <a class="code" href="classdtn_1_1BlockProcessor.html#c08f7b82f6049f30710a5dcdebb61ce7" title="Generate the standard preamble for the given block type, flags, EID-list and content...">BlockProcessor::generate_preamble</a>(<a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* xmit_blocks,
<a name="l00207"></a>00207                                   <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*    block,
<a name="l00208"></a>00208                                   u_int8_t      type,
<a name="l00209"></a>00209                                   u_int64_t     flags,
<a name="l00210"></a>00210                                   u_int64_t     data_length)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     <span class="keywordtype">char</span>      work[1000];
<a name="l00213"></a>00213     <span class="keywordtype">char</span>*     ptr = work;
<a name="l00214"></a>00214     <span class="keywordtype">size_t</span>    <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = <span class="keyword">sizeof</span>(work);
<a name="l00215"></a>00215     int32_t   sdnv_len;             <span class="comment">// must be signed</span>
<a name="l00216"></a>00216     u_int32_t scheme_offset;
<a name="l00217"></a>00217     u_int32_t ssp_offset;
<a name="l00218"></a>00218     
<a name="l00219"></a>00219     <span class="comment">// point at the local dictionary</span>
<a name="l00220"></a>00220     <a class="code" href="classdtn_1_1Dictionary.html" title="Simple data structure to handle a dictionary data structure, as specified by the...">Dictionary</a>* dict = xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>();
<a name="l00221"></a>00221     
<a name="l00222"></a>00222     <span class="comment">// see if we have EIDs in the list, and process them</span>
<a name="l00223"></a>00223     u_int32_t eid_count = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#b20777efd3367156feb424643fc089e4" title="Accessors.">eid_list</a>().size();
<a name="l00224"></a>00224     <span class="keywordflow">if</span> ( eid_count &gt; 0 ) {
<a name="l00225"></a>00225         flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b6616947d5db3ac647eeb6d6f0411a593">BundleProtocol::BLOCK_FLAG_EID_REFS</a>;
<a name="l00226"></a>00226         sdnv_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(eid_count, ptr, len);
<a name="l00227"></a>00227         ptr += sdnv_len;
<a name="l00228"></a>00228         len -= sdnv_len;
<a name="l00229"></a>00229         EndpointIDVector::const_iterator iter = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#b20777efd3367156feb424643fc089e4" title="Accessors.">eid_list</a>().begin();
<a name="l00230"></a>00230         <span class="keywordflow">for</span> ( ; iter &lt; block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#b20777efd3367156feb424643fc089e4" title="Accessors.">eid_list</a>().end(); ++iter ) {
<a name="l00231"></a>00231             dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#b08d7b9e5ce7bb481827a78107f50b3a" title="Add the scheme and ssp of the given endpoint id to the dictionary.">add_eid</a>(*iter);
<a name="l00232"></a>00232             dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#20b04310b304f88c32302b64b75853de" title="Look up the given eid in the dictionary, returning true and assigning the offsets...">get_offsets</a>(*iter, &amp;scheme_offset, &amp;ssp_offset);
<a name="l00233"></a>00233             sdnv_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(scheme_offset, ptr, len);
<a name="l00234"></a>00234             ptr += sdnv_len;
<a name="l00235"></a>00235             len -= sdnv_len;
<a name="l00236"></a>00236             sdnv_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(ssp_offset, ptr, len);
<a name="l00237"></a>00237             ptr += sdnv_len;
<a name="l00238"></a>00238             len -= sdnv_len;
<a name="l00239"></a>00239         }
<a name="l00240"></a>00240     }
<a name="l00241"></a>00241     
<a name="l00242"></a>00242     <span class="keywordtype">size_t</span> eid_field_len = ptr - work;    <span class="comment">// size of the data in the work buffer</span>
<a name="l00243"></a>00243     
<a name="l00244"></a>00244     <span class="keywordtype">size_t</span> flag_sdnv_len = <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(flags);
<a name="l00245"></a>00245     <span class="keywordtype">size_t</span> length_sdnv_len = <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(data_length);
<a name="l00246"></a>00246     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len() == 0);
<a name="l00247"></a>00247     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf_len() &gt;= <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a> 
<a name="l00248"></a>00248            + flag_sdnv_len + eid_field_len + length_sdnv_len);
<a name="l00249"></a>00249 
<a name="l00250"></a>00250     u_char* bp = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;buf();
<a name="l00251"></a>00251     len = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf_len();
<a name="l00252"></a>00252     
<a name="l00253"></a>00253     *bp = type;
<a name="l00254"></a>00254     bp  += <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a>;
<a name="l00255"></a>00255     len -= <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a>;
<a name="l00256"></a>00256     
<a name="l00257"></a>00257     <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(flags, bp, flag_sdnv_len);
<a name="l00258"></a>00258     bp  += flag_sdnv_len;
<a name="l00259"></a>00259     len -= flag_sdnv_len;
<a name="l00260"></a>00260     
<a name="l00261"></a>00261     memcpy(bp, work, eid_field_len);
<a name="l00262"></a>00262     bp  += eid_field_len;
<a name="l00263"></a>00263     len -= eid_field_len;
<a name="l00264"></a>00264     
<a name="l00265"></a>00265     <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(data_length, bp, length_sdnv_len);
<a name="l00266"></a>00266     bp  += length_sdnv_len;
<a name="l00267"></a>00267     len -= length_sdnv_len;
<a name="l00268"></a>00268 
<a name="l00269"></a>00269     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#38d215397b046a403f252512227c29a9" title="Mutating accessors.">set_data_length</a>(data_length);
<a name="l00270"></a>00270     u_int32_t offset = <a class="code" href="classdtn_1_1BundleProtocol.html#45c131425fd4c84700dcfe7733c11376">BundleProtocol::PREAMBLE_FIXED_LENGTH</a> + 
<a name="l00271"></a>00271                        flag_sdnv_len + eid_field_len + length_sdnv_len;
<a name="l00272"></a>00272     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#67e9f36d2da267e95270a4dd7d0aa65e" title="Mutating accessors.">set_data_offset</a>(offset);
<a name="l00273"></a>00273     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;set_len(offset);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275     log_debug_p(<a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a>, <span class="stringliteral">"BlockProcessor type 0x%x "</span>
<a name="l00276"></a>00276                 <span class="stringliteral">"generated preamble for block type 0x%x flags 0x%llx: "</span>
<a name="l00277"></a>00277                 <span class="stringliteral">"data_offset %u data_length %u eid_count %u"</span>,
<a name="l00278"></a>00278                 <a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>(), block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>(), U64FMT(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>()),
<a name="l00279"></a>00279                 block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(), block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>(), eid_count);
<a name="l00280"></a>00280 }
<a name="l00281"></a>00281 
<a name="l00282"></a>00282 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00283"></a>00283 <span class="keywordtype">int</span>
<a name="l00284"></a><a class="code" href="classdtn_1_1BlockProcessor.html#1f73d119593ef13da9c5ee845fd5ec00">00284</a> <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...">BlockProcessor::consume</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*    bundle,
<a name="l00285"></a>00285                         <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block,
<a name="l00286"></a>00286                         u_char*    <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>,
<a name="l00287"></a>00287                         <span class="keywordtype">size_t</span>     <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00288"></a>00288 {
<a name="l00289"></a>00289     (void)bundle;
<a name="l00290"></a>00290     
<a name="l00291"></a>00291     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>;
<a name="l00292"></a>00292     (void)log;
<a name="l00293"></a>00293     
<a name="l00294"></a>00294     <span class="keywordtype">size_t</span> consumed = 0;
<a name="l00295"></a>00295 
<a name="l00296"></a>00296     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(! block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>());
<a name="l00297"></a>00297     <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="l00298"></a>00298 
<a name="l00299"></a>00299     <span class="comment">// Check if we still need to consume the preamble by checking if</span>
<a name="l00300"></a>00300     <span class="comment">// the data_offset_ field is initialized in the block info</span>
<a name="l00301"></a>00301     <span class="comment">// structure.</span>
<a name="l00302"></a>00302     <span class="keywordflow">if</span> (block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() == 0) {
<a name="l00303"></a>00303         <span class="keywordtype">int</span> cc = <a class="code" href="classdtn_1_1BlockProcessor.html#16d1b8a2805b0888536bd001ce5e9e5b" title="Consume a block preamble consisting of type, flags(SDNV), EID-list (composite field...">consume_preamble</a>(recv_blocks, block, buf, len);
<a name="l00304"></a>00304         <span class="keywordflow">if</span> (cc == -1) {
<a name="l00305"></a>00305             <span class="keywordflow">return</span> -1;
<a name="l00306"></a>00306         }
<a name="l00307"></a>00307 
<a name="l00308"></a>00308         buf += cc;
<a name="l00309"></a>00309         len -= cc;
<a name="l00310"></a>00310 
<a name="l00311"></a>00311         consumed += cc;
<a name="l00312"></a>00312     }
<a name="l00313"></a>00313 
<a name="l00314"></a>00314     <span class="comment">// If we still don't know the data offset, we must have consumed</span>
<a name="l00315"></a>00315     <span class="comment">// the whole buffer</span>
<a name="l00316"></a>00316     <span class="keywordflow">if</span> (block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() == 0) {
<a name="l00317"></a>00317         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(len == 0);
<a name="l00318"></a>00318     }
<a name="l00319"></a>00319 
<a name="l00320"></a>00320     <span class="comment">// If the preamble is complete (i.e., data offset is non-zero) and</span>
<a name="l00321"></a>00321     <span class="comment">// the block's data length is zero, then mark the block as complete</span>
<a name="l00322"></a>00322     <span class="keywordflow">if</span> (block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() != 0 &amp;&amp; block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>() == 0) {
<a name="l00323"></a>00323         block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#78731d47494fb3e29e818379f627d3e0" title="Mutating accessors.">set_complete</a>(<span class="keyword">true</span>);
<a name="l00324"></a>00324     }
<a name="l00325"></a>00325     
<a name="l00326"></a>00326     <span class="comment">// If there's nothing left to do, we can bail for now.</span>
<a name="l00327"></a>00327     <span class="keywordflow">if</span> (len == 0)
<a name="l00328"></a>00328         <span class="keywordflow">return</span> consumed;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     <span class="comment">// Now make sure there's still something left to do for the block,</span>
<a name="l00331"></a>00331     <span class="comment">// otherwise it should have been marked as complete</span>
<a name="l00332"></a>00332     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>() == 0 ||
<a name="l00333"></a>00333            block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>() &gt; block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len());
<a name="l00334"></a>00334 
<a name="l00335"></a>00335     <span class="comment">// make sure the contents buffer has enough space</span>
<a name="l00336"></a>00336     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;reserve(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>());
<a name="l00337"></a>00337 
<a name="l00338"></a>00338     <span class="keywordtype">size_t</span> rcvd      = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len();
<a name="l00339"></a>00339     <span class="keywordtype">size_t</span> remainder = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>() - rcvd;
<a name="l00340"></a>00340     <span class="keywordtype">size_t</span> tocopy;
<a name="l00341"></a>00341 
<a name="l00342"></a>00342     <span class="keywordflow">if</span> (len &gt;= remainder) {
<a name="l00343"></a>00343         block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#78731d47494fb3e29e818379f627d3e0" title="Mutating accessors.">set_complete</a>(<span class="keyword">true</span>);
<a name="l00344"></a>00344         tocopy = remainder;
<a name="l00345"></a>00345     } <span class="keywordflow">else</span> {
<a name="l00346"></a>00346         tocopy = len;
<a name="l00347"></a>00347     }
<a name="l00348"></a>00348     
<a name="l00349"></a>00349     <span class="comment">// copy in the data</span>
<a name="l00350"></a>00350     memcpy(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;end(), buf, tocopy);
<a name="l00351"></a>00351     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;set_len(rcvd + tocopy);
<a name="l00352"></a>00352     len -= tocopy;
<a name="l00353"></a>00353     consumed += tocopy;
<a name="l00354"></a>00354 
<a name="l00355"></a>00355     log_debug_p(log, <span class="stringliteral">"BlockProcessor type 0x%x "</span>
<a name="l00356"></a>00356                 <span class="stringliteral">"consumed %zu/%u for block type 0x%x (%s)"</span>,
<a name="l00357"></a>00357                 <a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>(), consumed, block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>(), block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>(),
<a name="l00358"></a>00358                 block-&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="l00359"></a>00359     
<a name="l00360"></a>00360     <span class="keywordflow">return</span> consumed;
<a name="l00361"></a>00361 }
<a name="l00362"></a>00362 
<a name="l00363"></a>00363 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00364"></a>00364 <span class="keywordtype">bool</span>
<a name="l00365"></a><a class="code" href="classdtn_1_1BlockProcessor.html#14242dcdb094a179f718a5eaee23cabd">00365</a> <a class="code" href="classdtn_1_1BlockProcessor.html#14242dcdb094a179f718a5eaee23cabd" title="Validate the block.">BlockProcessor::validate</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 name="l00366"></a>00366                          <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*           block_list,
<a name="l00367"></a>00367                          <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*              block,
<a name="l00368"></a>00368                          <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="l00369"></a>00369                          <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="l00370"></a>00370 {
<a name="l00371"></a>00371     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>;
<a name="l00372"></a>00372     (void)block_list;
<a name="l00373"></a>00373     (void)reception_reason;
<a name="l00374"></a>00374 
<a name="l00375"></a>00375     <span class="comment">// An administrative bundle MUST NOT contain an extension block</span>
<a name="l00376"></a>00376     <span class="comment">// with a processing flag that requires a reception status report</span>
<a name="l00377"></a>00377     <span class="comment">// be transmitted in the case of an error</span>
<a name="l00378"></a>00378     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#839db0b56b61020d9f2b3878e6c2d34a" title="Accessors.">is_admin</a>() &amp;&amp;
<a name="l00379"></a>00379         block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>() != <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a> &amp;&amp;
<a name="l00380"></a>00380         block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b08e26de152eecfd35ff1081abf480309">BundleProtocol::BLOCK_FLAG_REPORT_ONERROR</a>) {
<a name="l00381"></a>00381         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"invalid block flag 0x%x for received admin bundle"</span>,
<a name="l00382"></a>00382                   <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b08e26de152eecfd35ff1081abf480309">BundleProtocol::BLOCK_FLAG_REPORT_ONERROR</a>);
<a name="l00383"></a>00383         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00384"></a>00384         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00385"></a>00385     }
<a name="l00386"></a>00386         
<a name="l00387"></a>00387     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00388"></a>00388 }
<a name="l00389"></a>00389 
<a name="l00390"></a>00390 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00391"></a>00391 <span class="keywordtype">int</span>
<a name="l00392"></a><a class="code" href="classdtn_1_1BlockProcessor.html#95caddbca046da1a05538359c351f644">00392</a> <a class="code" href="classdtn_1_1BlockProcessor.html#95caddbca046da1a05538359c351f644" title="Perform any needed action in the case where a block/bundle has been reloaded from...">BlockProcessor::reload_post_process</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*       bundle,
<a name="l00393"></a>00393                                     <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* block_list,
<a name="l00394"></a>00394                                     <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*    block)
<a name="l00395"></a>00395 {
<a name="l00396"></a>00396     (void)bundle;
<a name="l00397"></a>00397     (void)block_list;
<a name="l00398"></a>00398     (void)block;
<a name="l00399"></a>00399     
<a name="l00400"></a>00400     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a0d24ac3331dddcbd70fb9f4cceb086e" title="Mutating accessors.">set_reloaded</a>(<span class="keyword">false</span>);
<a name="l00401"></a>00401     <span class="keywordflow">return</span> 0;
<a name="l00402"></a>00402 }
<a name="l00403"></a>00403 
<a name="l00404"></a>00404 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00405"></a>00405 <span class="keywordtype">int</span>
<a name="l00406"></a><a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48">00406</a> <a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48" title="First callback to generate blocks for the output pass.">BlockProcessor::prepare</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 name="l00407"></a>00407                         <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*    xmit_blocks,
<a name="l00408"></a>00408                         <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* source,
<a name="l00409"></a>00409                         <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="l00410"></a>00410                         <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c" title="List owner indicator (not transmitted).">list_owner_t</a>     list)
<a name="l00411"></a>00411 {
<a name="l00412"></a>00412     (void)bundle;
<a name="l00413"></a>00413     (void)link;
<a name="l00414"></a>00414     (void)list;
<a name="l00415"></a>00415     
<a name="l00416"></a>00416     <span class="comment">// Received blocks are added to the end of the list (which</span>
<a name="l00417"></a>00417     <span class="comment">// maintains the order they arrived in) but blocks from any other</span>
<a name="l00418"></a>00418     <span class="comment">// source are added after the primary block (that is, before the</span>
<a name="l00419"></a>00419     <span class="comment">// payload and the received blocks). This places them "outside"</span>
<a name="l00420"></a>00420     <span class="comment">// the original blocks.</span>
<a name="l00421"></a>00421     <span class="keywordflow">if</span> (list == <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c988069568eb548f51e7c4b8120b6292f">BlockInfo::LIST_RECEIVED</a>) {
<a name="l00422"></a>00422         xmit_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>(<span class="keyword">this</span>, source);
<a name="l00423"></a>00423     }
<a name="l00424"></a>00424     <span class="keywordflow">else</span> {
<a name="l00425"></a>00425         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((*xmit_blocks)[0].type() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>);
<a name="l00426"></a>00426         xmit_blocks-&gt;insert(xmit_blocks-&gt;begin() + 1, <a class="code" href="classdtn_1_1BlockProcessor.html#f60b1c05e77bb387f21aaff2c8ac532b">BlockInfo</a>(<span class="keyword">this</span>, source));
<a name="l00427"></a>00427     }
<a name="l00428"></a>00428     <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>;
<a name="l00429"></a>00429 }
<a name="l00430"></a>00430 
<a name="l00431"></a>00431 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00432"></a>00432 <span class="keywordtype">int</span>
<a name="l00433"></a><a class="code" href="classdtn_1_1BlockProcessor.html#0256b44d0f9f42b1f36054c68444de6c">00433</a> <a class="code" href="classdtn_1_1BlockProcessor.html#0256b44d0f9f42b1f36054c68444de6c" title="Third callback for transmitting a bundle.">BlockProcessor::finalize</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 name="l00434"></a>00434                          <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*  xmit_blocks,
<a name="l00435"></a>00435                          <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*     block,
<a name="l00436"></a>00436                          <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="l00437"></a>00437 {
<a name="l00438"></a>00438     (void)xmit_blocks;
<a name="l00439"></a>00439     (void)link;
<a name="l00440"></a>00440         
<a name="l00441"></a>00441     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#839db0b56b61020d9f2b3878e6c2d34a" title="Accessors.">is_admin</a>() &amp;&amp; block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>() != <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca753097979cfe600d2c1dfb5cf3629b195" title="INTERNAL ONLY -- NOT IN SPEC.">BundleProtocol::PRIMARY_BLOCK</a>) {
<a name="l00442"></a>00442         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() &amp;
<a name="l00443"></a>00443                 <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b08e26de152eecfd35ff1081abf480309">BundleProtocol::BLOCK_FLAG_REPORT_ONERROR</a>) == 0);
<a name="l00444"></a>00444     }
<a name="l00445"></a>00445     <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>;
<a name="l00446"></a>00446 }
<a name="l00447"></a>00447 
<a name="l00448"></a>00448 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00449"></a>00449 <span class="keywordtype">void</span>
<a name="l00450"></a><a class="code" href="classdtn_1_1BlockProcessor.html#4e9295a532828f2cc6a20fb9f95a69c9">00450</a> <a class="code" href="classdtn_1_1BlockProcessor.html#4e9295a532828f2cc6a20fb9f95a69c9" title="Accessor to virtualize read-only processing contents of the block in various ways...">BlockProcessor::process</a>(process_func*    func,
<a name="l00451"></a>00451                         <span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*    bundle,
<a name="l00452"></a>00452                         <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* caller_block,
<a name="l00453"></a>00453                         <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* target_block,
<a name="l00454"></a>00454                         <span class="keywordtype">size_t</span>           offset,
<a name="l00455"></a>00455                         <span class="keywordtype">size_t</span>           <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>,
<a name="l00456"></a>00456                         OpaqueContext*   context)
<a name="l00457"></a>00457 {
<a name="l00458"></a>00458     u_char* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>;
<a name="l00459"></a>00459     
<a name="l00460"></a>00460     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(offset &lt; target_block-&gt;contents().<a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>());
<a name="l00461"></a>00461     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(target_block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len() &gt;= offset + len);
<a name="l00462"></a>00462     
<a name="l00463"></a>00463     <span class="comment">// convert the offset to a pointer in the target block</span>
<a name="l00464"></a>00464     buf = target_block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf() + offset;
<a name="l00465"></a>00465     
<a name="l00466"></a>00466     <span class="comment">// call the processing function to do the work</span>
<a name="l00467"></a>00467     (*func)(bundle, caller_block, target_block, buf, len, context);
<a name="l00468"></a>00468 }
<a name="l00469"></a>00469 
<a name="l00470"></a>00470 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00471"></a>00471 <span class="keywordtype">bool</span>
<a name="l00472"></a><a class="code" href="classdtn_1_1BlockProcessor.html#05bcb879796314ae4a2c0d909277c008">00472</a> <a class="code" href="classdtn_1_1BlockProcessor.html#05bcb879796314ae4a2c0d909277c008" title="Similar to process() but for potentially mutating processing functions.">BlockProcessor::mutate</a>(mutate_func*     func,
<a name="l00473"></a>00473                        <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*          bundle,
<a name="l00474"></a>00474                        <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* caller_block,
<a name="l00475"></a>00475                        <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*       target_block,
<a name="l00476"></a>00476                        <span class="keywordtype">size_t</span>           offset,   
<a name="l00477"></a>00477                        <span class="keywordtype">size_t</span>           <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>,
<a name="l00478"></a>00478                        OpaqueContext*   context)
<a name="l00479"></a>00479 {
<a name="l00480"></a>00480     u_char* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>;
<a name="l00481"></a>00481     
<a name="l00482"></a>00482     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(offset &lt; target_block-&gt;contents().<a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>());
<a name="l00483"></a>00483     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(target_block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len() &gt;= offset + len);
<a name="l00484"></a>00484     
<a name="l00485"></a>00485     <span class="comment">// convert the offset to a pointer in the target block</span>
<a name="l00486"></a>00486     buf = target_block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf() + offset;
<a name="l00487"></a>00487     
<a name="l00488"></a>00488     <span class="comment">// call the processing function to do the work</span>
<a name="l00489"></a>00489     <span class="keywordflow">return</span> (*func)(bundle, caller_block, target_block, buf, len, context);
<a name="l00490"></a>00490     
<a name="l00491"></a>00491     <span class="comment">// if we need to flush changed content back to disk, do it here</span>
<a name="l00492"></a>00492 }
<a name="l00493"></a>00493 
<a name="l00494"></a>00494 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00495"></a>00495 <span class="keywordtype">void</span>
<a name="l00496"></a><a class="code" href="classdtn_1_1BlockProcessor.html#f7307eeed9add202cbaa215e48c3d5da">00496</a> <a class="code" href="classdtn_1_1BlockProcessor.html#f7307eeed9add202cbaa215e48c3d5da" title="Accessor to virtualize copying contents out from the block info.">BlockProcessor::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,
<a name="l00497"></a>00497                         <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block,
<a name="l00498"></a>00498                         u_char*          <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>,
<a name="l00499"></a>00499                         <span class="keywordtype">size_t</span>           offset,
<a name="l00500"></a>00500                         <span class="keywordtype">size_t</span>           <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00501"></a>00501 {
<a name="l00502"></a>00502     (void)bundle;
<a name="l00503"></a>00503     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(offset &lt; block-&gt;contents().<a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>());
<a name="l00504"></a>00504     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().len() &gt;= offset + len);
<a name="l00505"></a>00505     memcpy(buf, block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf() + offset, len);
<a name="l00506"></a>00506 }
<a name="l00507"></a>00507 
<a name="l00508"></a>00508 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00509"></a>00509 <span class="keywordtype">void</span>
<a name="l00510"></a><a class="code" href="classdtn_1_1BlockProcessor.html#e0866915affada343af6b8d8b16bf354">00510</a> <a class="code" href="classdtn_1_1BlockProcessor.html#e0866915affada343af6b8d8b16bf354" title="General hook to set up a block with the given contents.">BlockProcessor::init_block</a>(<a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>*    block,
<a name="l00511"></a>00511                            <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* block_list,
<a name="l00512"></a>00512                            u_int8_t      type,
<a name="l00513"></a>00513                            u_int8_t      flags,
<a name="l00514"></a>00514                            <span class="keyword">const</span> u_char* bp,
<a name="l00515"></a>00515                            <span class="keywordtype">size_t</span>        <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00516"></a>00516 {
<a name="l00517"></a>00517     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() != NULL);
<a name="l00518"></a>00518     <a class="code" href="classdtn_1_1BlockProcessor.html#c08f7b82f6049f30710a5dcdebb61ce7" title="Generate the standard preamble for the given block type, flags, EID-list and content...">generate_preamble</a>(block_list, block, type, flags, len);
<a name="l00519"></a>00519     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() != 0);
<a name="l00520"></a>00520     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;reserve(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>());
<a name="l00521"></a>00521     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;set_len(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>());
<a name="l00522"></a>00522     memcpy(block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;buf() + block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(),
<a name="l00523"></a>00523            bp, len);
<a name="l00524"></a>00524 }
<a name="l00525"></a>00525 
<a name="l00526"></a>00526 } <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:52 2009 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.8 </small></address>
</body>
</html>