Sophie

Sophie

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

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: PrimaryBlockProcessor.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>PrimaryBlockProcessor.cc</h1><a href="PrimaryBlockProcessor_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;string&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;netinet/in.h&gt;</span>
<a name="l00024"></a>00024 
<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="BundleProtocol_8h.html">BundleProtocol.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="PrimaryBlockProcessor_8h.html">PrimaryBlockProcessor.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="EndpointID_8h.html">naming/EndpointID.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">SDNV.h</a>"</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">namespace </span>dtn {
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00034"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#937b663bfe5ae27f15217c5c80abae01">00034</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#937b663bfe5ae27f15217c5c80abae01" title="Constructor.">PrimaryBlockProcessor::PrimaryBlockProcessor</a>()
<a name="l00035"></a>00035     : <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" title="Centralized class used to convert a Bundle to / from the bundle protocol specification...">BundleProtocol</a>::PRIMARY_BLOCK)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00040"></a>00040 u_int64_t
<a name="l00041"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6af9dae8b00ea10b837529c711dce499">00041</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6af9dae8b00ea10b837529c711dce499">PrimaryBlockProcessor::format_bundle_flags</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="l00042"></a>00042 {
<a name="l00043"></a>00043     u_int64_t flags = 0;
<a name="l00044"></a>00044 
<a name="l00045"></a>00045     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) {
<a name="l00046"></a>00046         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf1590239be97dedd4104bc85d8e423b5ac33f">BUNDLE_IS_FRAGMENT</a>;
<a name="l00047"></a>00047     }
<a name="l00048"></a>00048 
<a name="l00049"></a>00049     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#839db0b56b61020d9f2b3878e6c2d34a" title="Accessors.">is_admin</a>()) {
<a name="l00050"></a>00050         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf15901e598df2393cb90b3cd47c7bb842e142">BUNDLE_IS_ADMIN</a>;
<a name="l00051"></a>00051     }
<a name="l00052"></a>00052 
<a name="l00053"></a>00053     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#1931c2eeed81432743735dd245c8b95d" title="Accessors.">do_not_fragment</a>()) {
<a name="l00054"></a>00054         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf159069b81b44a73c2e669e8af7beff6cf8fb">BUNDLE_DO_NOT_FRAGMENT</a>;
<a name="l00055"></a>00055     }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2261b28c9315c50a85bc35c1bcb6ace4" title="Accessors.">custody_requested</a>()) {
<a name="l00058"></a>00058         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf159059c3ae36ce59ffb3688546c97898fcb4">BUNDLE_CUSTODY_XFER_REQUESTED</a>;
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#d6ce915f55f1dcf670575642e10f6419" title="Accessors.">singleton_dest</a>()) {
<a name="l00062"></a>00062         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf1590933b3d5cd0c8407e97a5717cdfe2845f">BUNDLE_SINGLETON_DESTINATION</a>;
<a name="l00063"></a>00063     }
<a name="l00064"></a>00064     
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7af80fedd28d8a8f7b8b947ec134a310" title="Accessors.">app_acked_rcpt</a>()) {
<a name="l00066"></a>00066         flags |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf15901af11a25f1a3143e0fafb8c322ab5ade">BUNDLE_ACK_BY_APP</a>;
<a name="l00067"></a>00067     }
<a name="l00068"></a>00068     
<a name="l00069"></a>00069     <span class="keywordflow">return</span> flags;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00073"></a>00073 <span class="keywordtype">void</span>
<a name="l00074"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#50097e7812b01ee86d75fa3bf537c4ec">00074</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#50097e7812b01ee86d75fa3bf537c4ec">PrimaryBlockProcessor::parse_bundle_flags</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, u_int64_t flags)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf1590239be97dedd4104bc85d8e423b5ac33f">BUNDLE_IS_FRAGMENT</a>) {
<a name="l00077"></a>00077         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#fc3bc80899d4f0c92b163b2d662cd637" title="Setters and mutable accessors.">set_is_fragment</a>(<span class="keyword">true</span>);
<a name="l00078"></a>00078     } <span class="keywordflow">else</span> {
<a name="l00079"></a>00079         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#fc3bc80899d4f0c92b163b2d662cd637" title="Setters and mutable accessors.">set_is_fragment</a>(<span class="keyword">false</span>);
<a name="l00080"></a>00080     }
<a name="l00081"></a>00081 
<a name="l00082"></a>00082     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf15901e598df2393cb90b3cd47c7bb842e142">BUNDLE_IS_ADMIN</a>) {
<a name="l00083"></a>00083         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#1cb30932516cd93a9d1127fb3f3352d1" title="Setters and mutable accessors.">set_is_admin</a>(<span class="keyword">true</span>);
<a name="l00084"></a>00084     } <span class="keywordflow">else</span> {
<a name="l00085"></a>00085         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#1cb30932516cd93a9d1127fb3f3352d1" title="Setters and mutable accessors.">set_is_admin</a>(<span class="keyword">false</span>);
<a name="l00086"></a>00086     }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf159069b81b44a73c2e669e8af7beff6cf8fb">BUNDLE_DO_NOT_FRAGMENT</a>) {
<a name="l00089"></a>00089         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ce75b35784c110dc09986632e9d9eba1" title="Setters and mutable accessors.">set_do_not_fragment</a>(<span class="keyword">true</span>);
<a name="l00090"></a>00090     } <span class="keywordflow">else</span> {
<a name="l00091"></a>00091         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ce75b35784c110dc09986632e9d9eba1" title="Setters and mutable accessors.">set_do_not_fragment</a>(<span class="keyword">false</span>);
<a name="l00092"></a>00092     }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf159059c3ae36ce59ffb3688546c97898fcb4">BUNDLE_CUSTODY_XFER_REQUESTED</a>) {
<a name="l00095"></a>00095         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ac195072e859df4e1e8ae28dd299d03e" title="Setters and mutable accessors.">set_custody_requested</a>(<span class="keyword">true</span>);
<a name="l00096"></a>00096     } <span class="keywordflow">else</span> {
<a name="l00097"></a>00097         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ac195072e859df4e1e8ae28dd299d03e" title="Setters and mutable accessors.">set_custody_requested</a>(<span class="keyword">false</span>);
<a name="l00098"></a>00098     }
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf1590933b3d5cd0c8407e97a5717cdfe2845f">BUNDLE_SINGLETON_DESTINATION</a>) {
<a name="l00101"></a>00101         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#3b35e450cfd2504a5980d379f71f222c" title="Setters and mutable accessors.">set_singleton_dest</a>(<span class="keyword">true</span>);
<a name="l00102"></a>00102     } <span class="keywordflow">else</span> {
<a name="l00103"></a>00103         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#3b35e450cfd2504a5980d379f71f222c" title="Setters and mutable accessors.">set_singleton_dest</a>(<span class="keyword">false</span>);
<a name="l00104"></a>00104     }
<a name="l00105"></a>00105     
<a name="l00106"></a>00106     <span class="keywordflow">if</span> (flags &amp; <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#8eaf1adb137e84715d8d1c2588bf15901af11a25f1a3143e0fafb8c322ab5ade">BUNDLE_ACK_BY_APP</a>) {
<a name="l00107"></a>00107         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#6a1c62659602921671e0d0d1e0b2f126" title="Setters and mutable accessors.">set_app_acked_rcpt</a>(<span class="keyword">true</span>);
<a name="l00108"></a>00108     } <span class="keywordflow">else</span> {
<a name="l00109"></a>00109         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#6a1c62659602921671e0d0d1e0b2f126" title="Setters and mutable accessors.">set_app_acked_rcpt</a>(<span class="keyword">false</span>);
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00114"></a>00114 u_int64_t
<a name="l00115"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#801e0dbe517b21953154a8f6df95457d">00115</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#801e0dbe517b21953154a8f6df95457d">PrimaryBlockProcessor::format_cos_flags</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117     u_int64_t cos_flags = 0;
<a name="l00118"></a>00118 
<a name="l00119"></a>00119     cos_flags = ((b-&gt;<a class="code" href="classdtn_1_1Bundle.html#06faa53f6a1ac201869c25c4c4af34f4" title="Accessors.">priority</a>() &amp; 0x3) &lt;&lt; 7);
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="keywordflow">return</span> cos_flags;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00125"></a>00125 <span class="keywordtype">void</span>
<a name="l00126"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#77f98160013cfeaeddce5bfab92033ad">00126</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#77f98160013cfeaeddce5bfab92033ad">PrimaryBlockProcessor::parse_cos_flags</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b, u_int64_t cos_flags)
<a name="l00127"></a>00127 {
<a name="l00128"></a>00128     b-&gt;<a class="code" href="classdtn_1_1Bundle.html#6025475ff9104e2720ddb5ecbc9ec923" title="Setters and mutable accessors.">set_priority</a>((cos_flags &gt;&gt; 7) &amp; 0x3);
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00132"></a>00132 u_int64_t
<a name="l00133"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#a987548dc642eca97ee24a867185987c">00133</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#a987548dc642eca97ee24a867185987c">PrimaryBlockProcessor::format_srr_flags</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135     u_int64_t srr_flags = 0;
<a name="l00136"></a>00136     
<a name="l00137"></a>00137     <span class="keywordflow">if</span> (b-&gt;<a class="code" href="classdtn_1_1Bundle.html#62e71f87a0f72127045bf18a0284843b" title="Accessors.">receive_rcpt</a>())
<a name="l00138"></a>00138         srr_flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb45084c0d1b646f1671fa15d90ab25c5c9">BundleProtocol::STATUS_RECEIVED</a>;
<a name="l00139"></a>00139 
<a name="l00140"></a>00140     <span class="keywordflow">if</span> (b-&gt;<a class="code" href="classdtn_1_1Bundle.html#108fb7cb162dcc1fdcfdad3ca477692d" title="Accessors.">custody_rcpt</a>())
<a name="l00141"></a>00141         srr_flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb4db3d621578bcd84682245b61d2830afe">BundleProtocol::STATUS_CUSTODY_ACCEPTED</a>;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143     <span class="keywordflow">if</span> (b-&gt;<a class="code" href="classdtn_1_1Bundle.html#93c641bdb9a4beda553d8f28e60c99fd" title="Accessors.">forward_rcpt</a>())
<a name="l00144"></a>00144         srr_flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb40daebdf298b9f59bfb5f56c2191003a7">BundleProtocol::STATUS_FORWARDED</a>;
<a name="l00145"></a>00145 
<a name="l00146"></a>00146     <span class="keywordflow">if</span> (b-&gt;<a class="code" href="classdtn_1_1Bundle.html#a48fd652ab931a694f79cc1c6e47985d" title="Accessors.">delivery_rcpt</a>())
<a name="l00147"></a>00147         srr_flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb42f6dc9b01285b3f7db901319b99de065">BundleProtocol::STATUS_DELIVERED</a>;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149     <span class="keywordflow">if</span> (b-&gt;<a class="code" href="classdtn_1_1Bundle.html#fa1f7ffd4437c3a9213c60e7bbef39d3" title="Accessors.">deletion_rcpt</a>())
<a name="l00150"></a>00150         srr_flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb4dddc9465fbf0a1bc602642b99fe03e28">BundleProtocol::STATUS_DELETED</a>;
<a name="l00151"></a>00151 
<a name="l00152"></a>00152     <span class="keywordflow">return</span> srr_flags;
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154     
<a name="l00155"></a>00155 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00156"></a>00156 <span class="keywordtype">void</span>
<a name="l00157"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#894369d093911b3b00adaf38c1953e44">00157</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#894369d093911b3b00adaf38c1953e44">PrimaryBlockProcessor::parse_srr_flags</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* b, u_int64_t srr_flags)
<a name="l00158"></a>00158 {
<a name="l00159"></a>00159     <span class="keywordflow">if</span> (srr_flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb45084c0d1b646f1671fa15d90ab25c5c9">BundleProtocol::STATUS_RECEIVED</a>)
<a name="l00160"></a>00160         b-&gt;<a class="code" href="classdtn_1_1Bundle.html#ddbc653176fbf0ba1bf7702a72a55321" title="Setters and mutable accessors.">set_receive_rcpt</a>(<span class="keyword">true</span>);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <span class="keywordflow">if</span> (srr_flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb4db3d621578bcd84682245b61d2830afe">BundleProtocol::STATUS_CUSTODY_ACCEPTED</a>)
<a name="l00163"></a>00163         b-&gt;<a class="code" href="classdtn_1_1Bundle.html#8ed9f01350133711a4cd23aef1f4e941" title="Setters and mutable accessors.">set_custody_rcpt</a>(<span class="keyword">true</span>);
<a name="l00164"></a>00164 
<a name="l00165"></a>00165     <span class="keywordflow">if</span> (srr_flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb40daebdf298b9f59bfb5f56c2191003a7">BundleProtocol::STATUS_FORWARDED</a>)
<a name="l00166"></a>00166         b-&gt;<a class="code" href="classdtn_1_1Bundle.html#398c69ef798e99ea2f82e03f460d4aff" title="Setters and mutable accessors.">set_forward_rcpt</a>(<span class="keyword">true</span>);
<a name="l00167"></a>00167 
<a name="l00168"></a>00168     <span class="keywordflow">if</span> (srr_flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb42f6dc9b01285b3f7db901319b99de065">BundleProtocol::STATUS_DELIVERED</a>)
<a name="l00169"></a>00169         b-&gt;<a class="code" href="classdtn_1_1Bundle.html#fc9cb55b202687f98d31f4bba7859f73" title="Setters and mutable accessors.">set_delivery_rcpt</a>(<span class="keyword">true</span>);
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     <span class="keywordflow">if</span> (srr_flags &amp; <a class="code" href="classdtn_1_1BundleProtocol.html#4e25b9c1d9577e30425bc93a8bc5ddb4dddc9465fbf0a1bc602642b99fe03e28">BundleProtocol::STATUS_DELETED</a>)
<a name="l00172"></a>00172         b-&gt;<a class="code" href="classdtn_1_1Bundle.html#c59da17a98c6ac9f32da043dc967f151" title="Setters and mutable accessors.">set_deletion_rcpt</a>(<span class="keyword">true</span>);
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00176"></a>00176 <span class="keywordtype">size_t</span>
<a name="l00177"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#49e5f6762a4b65450995e15e3d377864">00177</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#49e5f6762a4b65450995e15e3d377864">PrimaryBlockProcessor::get_primary_len</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="l00178"></a>00178                                        <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,
<a name="l00179"></a>00179                                        <a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html" title="The remainder of the fixed-length part of the primary bundle block that immediately...">PrimaryBlock</a>*  primary)
<a name="l00180"></a>00180 {
<a name="l00181"></a>00181     <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="l00182"></a>00182     <span class="keywordtype">size_t</span> primary_len = 0;
<a name="l00183"></a>00183     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a> = 0;
<a name="l00184"></a>00184     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> = 0;
<a name="l00185"></a>00185     
<a name="l00186"></a>00186     <span class="comment">/*</span>
<a name="l00187"></a>00187 <span class="comment">     * We need to figure out the total length of the primary block,</span>
<a name="l00188"></a>00188 <span class="comment">     * except for the SDNVs used to encode flags and the length itself and</span>
<a name="l00189"></a>00189 <span class="comment">     * the one byte version field.</span>
<a name="l00190"></a>00190 <span class="comment">     *</span>
<a name="l00191"></a>00191 <span class="comment">     * First, we determine the size of the dictionary by first</span>
<a name="l00192"></a>00192 <span class="comment">     * figuring out all the unique strings, and in the process,</span>
<a name="l00193"></a>00193 <span class="comment">     * remembering their offsets and summing up their lengths</span>
<a name="l00194"></a>00194 <span class="comment">     * (including the null terminator for each).</span>
<a name="l00195"></a>00195 <span class="comment">     */</span>
<a name="l00196"></a>00196     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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#507241e8ac766e1900009ed6243e2aa3" title="Accessors.">dest</a>(), 
<a name="l00197"></a>00197                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e000a7721dc9ec46e1c46ec338ac142b">dest_scheme_offset</a>,
<a name="l00198"></a>00198                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#56b10b8316036e4666876b204c395f3d">dest_ssp_offset</a>);
<a name="l00199"></a>00199     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e000a7721dc9ec46e1c46ec338ac142b">dest_scheme_offset</a>);
<a name="l00200"></a>00200     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#56b10b8316036e4666876b204c395f3d">dest_ssp_offset</a>);
<a name="l00201"></a>00201     
<a name="l00202"></a>00202     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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>(), 
<a name="l00203"></a>00203                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#9c3102b6d048f856d76e9756d47529e0">source_scheme_offset</a>,
<a name="l00204"></a>00204                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#999e6bd31377676bc73705fd507b7dc9">source_ssp_offset</a>);
<a name="l00205"></a>00205     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#9c3102b6d048f856d76e9756d47529e0">source_scheme_offset</a>);
<a name="l00206"></a>00206     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#999e6bd31377676bc73705fd507b7dc9">source_ssp_offset</a>);
<a name="l00207"></a>00207 
<a name="l00208"></a>00208     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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#a2ffacc40d2afe751142e9fd64ab5fdf" title="Accessors.">replyto</a>(),
<a name="l00209"></a>00209                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e717b3248b2fef4ec3b36289374504cd">replyto_scheme_offset</a>,
<a name="l00210"></a>00210                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3baf17b33d2833a32b49e99274129c7a">replyto_ssp_offset</a>);
<a name="l00211"></a>00211     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e717b3248b2fef4ec3b36289374504cd">replyto_scheme_offset</a>);
<a name="l00212"></a>00212     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3baf17b33d2833a32b49e99274129c7a">replyto_ssp_offset</a>);
<a name="l00213"></a>00213 
<a name="l00214"></a>00214     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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#eb68ec729851c7e7221fe7cb61f19875" title="Accessors.">custodian</a>(), 
<a name="l00215"></a>00215                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8b5daa5014dc86c729904d1f64dcb7b9">custodian_scheme_offset</a>,
<a name="l00216"></a>00216                       &amp;primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3620e1a0301accfd0f67f1e7058c043f">custodian_ssp_offset</a>);
<a name="l00217"></a>00217     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8b5daa5014dc86c729904d1f64dcb7b9">custodian_scheme_offset</a>);
<a name="l00218"></a>00218     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3620e1a0301accfd0f67f1e7058c043f">custodian_ssp_offset</a>);
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a> = dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#40ec3ad601fa0cec1a5c5749c70c3c66" title="Accessors.">length</a>();
<a name="l00221"></a>00221 
<a name="l00222"></a>00222     (void)log; <span class="comment">// in case NDEBUG is defined</span>
<a name="l00223"></a>00223     log_debug_p(log, <span class="stringliteral">"generated dictionary length %llu"</span>,
<a name="l00224"></a>00224                 U64FMT(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>));
<a name="l00225"></a>00225     
<a name="l00226"></a>00226     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>);
<a name="l00227"></a>00227     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>);
<a name="l00228"></a>00228     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#21879e67b7f065975cbd942807500746" title="Accessors.">expiration</a>());
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>);
<a name="l00231"></a>00231     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>;
<a name="l00232"></a>00232     
<a name="l00233"></a>00233     <span class="comment">/*</span>
<a name="l00234"></a>00234 <span class="comment">     * If the bundle is a fragment, we need to include space for the</span>
<a name="l00235"></a>00235 <span class="comment">     * fragment offset and the original payload length.</span>
<a name="l00236"></a>00236 <span class="comment">     *</span>
<a name="l00237"></a>00237 <span class="comment">     * Note: Any changes to this protocol must be reflected into the</span>
<a name="l00238"></a>00238 <span class="comment">     * FragmentManager since it depends on this length when</span>
<a name="l00239"></a>00239 <span class="comment">     * calculating fragment sizes.</span>
<a name="l00240"></a>00240 <span class="comment">     */</span>
<a name="l00241"></a>00241     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) {
<a name="l00242"></a>00242         primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#76cf6a44f566aa22e2a98007bf233ee2" title="Accessors.">frag_offset</a>());
<a name="l00243"></a>00243         primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a> += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#e32f3c57057214a1763dfe7709160cf8" title="Accessors.">orig_length</a>());
<a name="l00244"></a>00244     }
<a name="l00245"></a>00245     
<a name="l00246"></a>00246     <span class="comment">// Format the processing flags.</span>
<a name="l00247"></a>00247     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a> = <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6af9dae8b00ea10b837529c711dce499">format_bundle_flags</a>(bundle);
<a name="l00248"></a>00248     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a> |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#801e0dbe517b21953154a8f6df95457d">format_cos_flags</a>(bundle);
<a name="l00249"></a>00249     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a> |= <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#a987548dc642eca97ee24a867185987c">format_srr_flags</a>(bundle);
<a name="l00250"></a>00250 
<a name="l00251"></a>00251     <span class="comment">/*</span>
<a name="l00252"></a>00252 <span class="comment">     * Finally, add up the initial preamble and the variable</span>
<a name="l00253"></a>00253 <span class="comment">     * length part.</span>
<a name="l00254"></a>00254 <span class="comment">     */</span>
<a name="l00255"></a>00255     primary_len = 1 + <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>) +
<a name="l00256"></a>00256                   <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a>) +
<a name="l00257"></a>00257                   primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a>;
<a name="l00258"></a>00258     
<a name="l00259"></a>00259     log_debug_p(log, <span class="stringliteral">"get_primary_len(bundle %d): %zu"</span>,
<a name="l00260"></a>00260                 bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7031e2e5e4078445bf4ad39cdcdea3b2" title="Accessors.">bundleid</a>(), primary_len);
<a name="l00261"></a>00261     
<a name="l00262"></a>00262     <span class="comment">// Fill in the remaining values of 'primary' just for the sake of returning</span>
<a name="l00263"></a>00263     <span class="comment">// a complete data structure.</span>
<a name="l00264"></a>00264     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#61f3cedfb63a80ac5a714f793dadf001">version</a> = <a class="code" href="classdtn_1_1BundleProtocol.html#65e637cab3ab85a59f8e326a79a83856" title="The current version of the bundling protocol.">BundleProtocol::CURRENT_VERSION</a>;
<a name="l00265"></a>00265     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8334d024718d794eff9ac9fc8ccaa10f">creation_time</a> = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>;
<a name="l00266"></a>00266     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#04939e86c10b9c03fd5827655dd5200c">creation_sequence</a> = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>;
<a name="l00267"></a>00267     primary-&gt;<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#94a6e34e16c95daeadbebbce04e8d1ea">lifetime</a> = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#21879e67b7f065975cbd942807500746" title="Accessors.">expiration</a>();
<a name="l00268"></a>00268     
<a name="l00269"></a>00269     <span class="keywordflow">return</span> primary_len;
<a name="l00270"></a>00270 }
<a name="l00271"></a>00271 
<a name="l00272"></a>00272 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00273"></a>00273 <span class="keywordtype">int</span>
<a name="l00274"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#a3a1005ed5dedac560fa0e694504fa24">00274</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#a3a1005ed5dedac560fa0e694504fa24" title="Virtual from BlockProcessor.">PrimaryBlockProcessor::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="l00275"></a>00275                                <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*    xmit_blocks,
<a name="l00276"></a>00276                                <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="l00277"></a>00277                                <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="l00278"></a>00278                                <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c" title="List owner indicator (not transmitted).">list_owner_t</a>     list)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280     (void)bundle;
<a name="l00281"></a>00281     (void)link;
<a name="l00282"></a>00282     (void)list;
<a name="l00283"></a>00283 
<a name="l00284"></a>00284     <span class="comment">// There shouldn't already be anything in the xmit_blocks</span>
<a name="l00285"></a>00285     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(xmit_blocks-&gt;size() == 0);
<a name="l00286"></a>00286         
<a name="l00287"></a>00287     <span class="comment">// Add EIDs to start off the dictionary</span>
<a name="l00288"></a>00288     xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>()-&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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#507241e8ac766e1900009ed6243e2aa3" title="Accessors.">dest</a>());
<a name="l00289"></a>00289     xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>()-&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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>());
<a name="l00290"></a>00290     xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>()-&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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#a2ffacc40d2afe751142e9fd64ab5fdf" title="Accessors.">replyto</a>());
<a name="l00291"></a>00291     xmit_blocks-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>()-&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>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#eb68ec729851c7e7221fe7cb61f19875" title="Accessors.">custodian</a>());
<a name="l00292"></a>00292 
<a name="l00293"></a>00293     <span class="comment">// make sure to add the primary to the front</span>
<a name="l00294"></a>00294     xmit_blocks-&gt;insert(xmit_blocks-&gt;begin(), <a class="code" href="classdtn_1_1BlockProcessor.html#f60b1c05e77bb387f21aaff2c8ac532b">BlockInfo</a>(<span class="keyword">this</span>, source));
<a name="l00295"></a>00295 
<a name="l00296"></a>00296     <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>;
<a name="l00297"></a>00297 }
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00300"></a>00300 <span class="keywordtype">int</span>
<a name="l00301"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6e5c41fd30e22ae3d0e1f9f4ce3dec22">00301</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6e5c41fd30e22ae3d0e1f9f4ce3dec22" title="Virtual from BlockProcessor.">PrimaryBlockProcessor::consume</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>*    bundle,
<a name="l00302"></a>00302                                <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="l00303"></a>00303                                u_char*    <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>,
<a name="l00304"></a>00304                                <span class="keywordtype">size_t</span>     <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00305"></a>00305 {
<a name="l00306"></a>00306     <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="l00307"></a>00307     <span class="keywordtype">size_t</span> consumed = 0;
<a name="l00308"></a>00308     <a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html" title="The remainder of the fixed-length part of the primary bundle block that immediately...">PrimaryBlock</a> primary;
<a name="l00309"></a>00309     
<a name="l00310"></a>00310     <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="l00311"></a>00311     
<a name="l00312"></a>00312     <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 = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5c48f51fba15c89a82d5d98c9881f0bd" title="Setters and mutable accessors.">mutable_recv_blocks</a>()-&gt;<a class="code" href="classdtn_1_1BlockInfoVec.html#dfd7265c46dba7a323f99a304332506e" title="Return the dictionary.">dict</a>();
<a name="l00313"></a>00313     memset(&amp;primary, 0, <span class="keyword">sizeof</span>(primary));
<a name="l00314"></a>00314     
<a name="l00315"></a>00315     <span class="comment">/*</span>
<a name="l00316"></a>00316 <span class="comment">     * Now see if this completes the primary by calling into</span>
<a name="l00317"></a>00317 <span class="comment">     * BlockProcessor::consume() to get the default behavior (now that</span>
<a name="l00318"></a>00318 <span class="comment">     * we've found the data length above).</span>
<a name="l00319"></a>00319 <span class="comment">     */</span>
<a name="l00320"></a>00320     <span class="keywordtype">int</span> cc = <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#6e5c41fd30e22ae3d0e1f9f4ce3dec22" title="Virtual from BlockProcessor.">BlockProcessor::consume</a>(bundle, block, buf, len);
<a name="l00321"></a>00321 
<a name="l00322"></a>00322     <span class="keywordflow">if</span> (cc == -1) {
<a name="l00323"></a>00323         <span class="keywordflow">return</span> -1; <span class="comment">// protocol error</span>
<a name="l00324"></a>00324     }
<a name="l00325"></a>00325     
<a name="l00326"></a>00326     <span class="keywordflow">if</span> (! block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>()) {
<a name="l00327"></a>00327         <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(cc == (<span class="keywordtype">int</span>)len);
<a name="l00328"></a>00328         <span class="keywordflow">return</span> consumed + cc;
<a name="l00329"></a>00329     }
<a name="l00330"></a>00330 
<a name="l00331"></a>00331     <span class="comment">/*</span>
<a name="l00332"></a>00332 <span class="comment">     * Ok, now the block is complete so we can parse it. We'll return</span>
<a name="l00333"></a>00333 <span class="comment">     * the total amount consumed (or -1 for protocol error) when</span>
<a name="l00334"></a>00334 <span class="comment">     * finished.</span>
<a name="l00335"></a>00335 <span class="comment">     */</span>
<a name="l00336"></a>00336     consumed += cc;
<a name="l00337"></a>00337 
<a name="l00338"></a>00338     <span class="keywordtype">size_t</span> primary_len = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2045184fe07026a47e1226bf7142f89a" title="Accessors.">full_length</a>();
<a name="l00339"></a>00339 
<a name="l00340"></a>00340     buf = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;buf();
<a name="l00341"></a>00341     len = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;len();
<a name="l00342"></a>00342 
<a name="l00343"></a>00343     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(primary_len == len);
<a name="l00344"></a>00344 
<a name="l00345"></a>00345     primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#61f3cedfb63a80ac5a714f793dadf001">version</a> = *(u_int8_t*)buf;
<a name="l00346"></a>00346     buf += 1;
<a name="l00347"></a>00347     len -= 1;
<a name="l00348"></a>00348     
<a name="l00349"></a>00349     <span class="keywordflow">if</span> (primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#61f3cedfb63a80ac5a714f793dadf001">version</a> != <a class="code" href="classdtn_1_1BundleProtocol.html#65e637cab3ab85a59f8e326a79a83856" title="The current version of the bundling protocol.">BundleProtocol::CURRENT_VERSION</a>) {
<a name="l00350"></a>00350         log_warn_p(log, <span class="stringliteral">"protocol version mismatch %d != %d"</span>,
<a name="l00351"></a>00351                    primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#61f3cedfb63a80ac5a714f793dadf001">version</a>, <a class="code" href="classdtn_1_1BundleProtocol.html#65e637cab3ab85a59f8e326a79a83856" title="The current version of the bundling protocol.">BundleProtocol::CURRENT_VERSION</a>);
<a name="l00352"></a>00352         <span class="keywordflow">return</span> -1;
<a name="l00353"></a>00353     }
<a name="l00354"></a>00354     
<a name="l00355"></a>00355 <span class="preprocessor">#define PBP_READ_SDNV(location) { \</span>
<a name="l00356"></a>00356 <span class="preprocessor">    int sdnv_len = SDNV::decode(buf, len, location); \</span>
<a name="l00357"></a>00357 <span class="preprocessor">    if (sdnv_len &lt; 0) \</span>
<a name="l00358"></a>00358 <span class="preprocessor">        goto tooshort; \</span>
<a name="l00359"></a>00359 <span class="preprocessor">    buf += sdnv_len; \</span>
<a name="l00360"></a>00360 <span class="preprocessor">    len -= sdnv_len; }</span>
<a name="l00361"></a>00361 <span class="preprocessor"></span>    
<a name="l00362"></a>00362     <span class="comment">// Grab the SDNVs representing the flags and the block length.</span>
<a name="l00363"></a>00363     <a class="code" href="PrimaryBlockProcessor_8cc.html#d91d604c84c78ba383d0919b801f77ad">PBP_READ_SDNV</a>(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>);
<a name="l00364"></a>00364     <a class="code" href="PrimaryBlockProcessor_8cc.html#d91d604c84c78ba383d0919b801f77ad">PBP_READ_SDNV</a>(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a>);
<a name="l00365"></a>00365 
<a name="l00366"></a>00366     log_debug_p(log, <span class="stringliteral">"parsed primary block: version %d length %u"</span>,
<a name="l00367"></a>00367                 primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#61f3cedfb63a80ac5a714f793dadf001">version</a>, block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>());    
<a name="l00368"></a>00368     
<a name="l00369"></a>00369     <span class="comment">// Parse the flags.</span>
<a name="l00370"></a>00370     <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#50097e7812b01ee86d75fa3bf537c4ec">parse_bundle_flags</a>(bundle, primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>);
<a name="l00371"></a>00371     <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#77f98160013cfeaeddce5bfab92033ad">parse_cos_flags</a>(bundle, primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>);
<a name="l00372"></a>00372     <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#894369d093911b3b00adaf38c1953e44">parse_srr_flags</a>(bundle, primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>);
<a name="l00373"></a>00373     
<a name="l00374"></a>00374     <span class="comment">// What remains in the buffer should now be equal to what the block-length</span>
<a name="l00375"></a>00375     <span class="comment">// field advertised.</span>
<a name="l00376"></a>00376     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(len == block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>());
<a name="l00377"></a>00377     
<a name="l00378"></a>00378     <span class="comment">// Read the various SDNVs up to the start of the dictionary.</span>
<a name="l00379"></a>00379     <a class="code" href="PrimaryBlockProcessor_8cc.html#d91d604c84c78ba383d0919b801f77ad">PBP_READ_SDNV</a>(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e000a7721dc9ec46e1c46ec338ac142b">dest_scheme_offset</a>);
<a name="l00380"></a>00380     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#56b10b8316036e4666876b204c395f3d">dest_ssp_offset</a>);
<a name="l00381"></a>00381     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#9c3102b6d048f856d76e9756d47529e0">source_scheme_offset</a>);
<a name="l00382"></a>00382     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#999e6bd31377676bc73705fd507b7dc9">source_ssp_offset</a>);
<a name="l00383"></a>00383     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e717b3248b2fef4ec3b36289374504cd">replyto_scheme_offset</a>);
<a name="l00384"></a>00384     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3baf17b33d2833a32b49e99274129c7a">replyto_ssp_offset</a>);
<a name="l00385"></a>00385     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8b5daa5014dc86c729904d1f64dcb7b9">custodian_scheme_offset</a>);
<a name="l00386"></a>00386     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3620e1a0301accfd0f67f1e7058c043f">custodian_ssp_offset</a>);
<a name="l00387"></a>00387     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8334d024718d794eff9ac9fc8ccaa10f">creation_time</a>);
<a name="l00388"></a>00388     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#04939e86c10b9c03fd5827655dd5200c">creation_sequence</a>);
<a name="l00389"></a>00389     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#94a6e34e16c95daeadbebbce04e8d1ea">lifetime</a>);
<a name="l00390"></a>00390     PBP_READ_SDNV(&amp;primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>);
<a name="l00391"></a>00391     
<a name="l00392"></a>00392     <span class="comment">// Make sure that the creation timestamp parts and the lifetime fit into</span>
<a name="l00393"></a>00393     <span class="comment">// a 32 bit integer.</span>
<a name="l00394"></a>00394     <span class="keywordflow">if</span> (primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8334d024718d794eff9ac9fc8ccaa10f">creation_time</a> &gt; 0xffffffff) {
<a name="l00395"></a>00395         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"creation timestamp time is too large: %llu"</span>,
<a name="l00396"></a>00396                   U64FMT(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8334d024718d794eff9ac9fc8ccaa10f">creation_time</a>));
<a name="l00397"></a>00397         <span class="keywordflow">return</span> -1;
<a name="l00398"></a>00398     }
<a name="l00399"></a>00399 
<a name="l00400"></a>00400     <span class="keywordflow">if</span> (primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#04939e86c10b9c03fd5827655dd5200c">creation_sequence</a> &gt; 0xffffffff) {
<a name="l00401"></a>00401         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"creation timestamp sequence is too large: %llu"</span>,
<a name="l00402"></a>00402                   U64FMT(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#04939e86c10b9c03fd5827655dd5200c">creation_sequence</a>));
<a name="l00403"></a>00403         <span class="keywordflow">return</span> -1;
<a name="l00404"></a>00404     }
<a name="l00405"></a>00405     
<a name="l00406"></a>00406     <span class="keywordflow">if</span> (primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#94a6e34e16c95daeadbebbce04e8d1ea">lifetime</a> &gt; 0xffffffff) {
<a name="l00407"></a>00407         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"lifetime is too large: %llu"</span>, U64FMT(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#94a6e34e16c95daeadbebbce04e8d1ea">lifetime</a>));
<a name="l00408"></a>00408         <span class="keywordflow">return</span> -1;
<a name="l00409"></a>00409     }
<a name="l00410"></a>00410     
<a name="l00411"></a>00411     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#f719a866982138aac40bc5f9ed52fa89" title="Setters and mutable accessors.">set_creation_ts</a>(<a class="code" href="structdtn_1_1BundleTimestamp.html" title="Simple struct definition for bundle creation timestamps.">BundleTimestamp</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8334d024718d794eff9ac9fc8ccaa10f">creation_time</a>,
<a name="l00412"></a>00412                                             primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#04939e86c10b9c03fd5827655dd5200c">creation_sequence</a>));
<a name="l00413"></a>00413     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7623ecfe9e47e5dc075ebd872fb9a237" title="Setters and mutable accessors.">set_expiration</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#94a6e34e16c95daeadbebbce04e8d1ea">lifetime</a>);
<a name="l00414"></a>00414 
<a name="l00415"></a>00415     <span class="comment">/*</span>
<a name="l00416"></a>00416 <span class="comment">     * Verify that we have the whole dictionary.</span>
<a name="l00417"></a>00417 <span class="comment">     */</span>
<a name="l00418"></a>00418     <span class="keywordflow">if</span> (len &lt; primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>) {
<a name="l00419"></a>00419  tooshort:
<a name="l00420"></a>00420         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"primary block advertised incorrect length %u"</span>,
<a name="l00421"></a>00421                   block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>());
<a name="l00422"></a>00422         <span class="keywordflow">return</span> -1;
<a name="l00423"></a>00423     }
<a name="l00424"></a>00424 
<a name="l00425"></a>00425     <span class="comment">/*</span>
<a name="l00426"></a>00426 <span class="comment">     * Make sure that the dictionary ends with a null byte.</span>
<a name="l00427"></a>00427 <span class="comment">     */</span>
<a name="l00428"></a>00428     <span class="keywordflow">if</span> (buf[primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a> - 1] != <span class="charliteral">'\0'</span>) {
<a name="l00429"></a>00429         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"dictionary does not end with a NULL character!"</span>);
<a name="l00430"></a>00430         <span class="keywordflow">return</span> -1;
<a name="l00431"></a>00431     }
<a name="l00432"></a>00432 
<a name="l00433"></a>00433     <span class="comment">/*</span>
<a name="l00434"></a>00434 <span class="comment">     * Now use the dictionary buffer to parse out the various endpoint</span>
<a name="l00435"></a>00435 <span class="comment">     * identifiers, making sure that none of them peeks past the end</span>
<a name="l00436"></a>00436 <span class="comment">     * of the dictionary block.</span>
<a name="l00437"></a>00437 <span class="comment">     */</span>
<a name="l00438"></a>00438     u_char* dictionary = buf;
<a name="l00439"></a>00439     buf += primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>;
<a name="l00440"></a>00440     len -= primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>;
<a name="l00441"></a>00441 
<a name="l00442"></a>00442     dict-&gt;set_dict(dictionary, primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>);
<a name="l00443"></a>00443     dict-&gt;extract_eid(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#69c35928ca050eb4bb2ec67641f1b6bb" title="Setters and mutable accessors.">mutable_source</a>(),
<a name="l00444"></a>00444                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#9c3102b6d048f856d76e9756d47529e0">source_scheme_offset</a>,
<a name="l00445"></a>00445                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#999e6bd31377676bc73705fd507b7dc9">source_ssp_offset</a>);
<a name="l00446"></a>00446     
<a name="l00447"></a>00447     dict-&gt;extract_eid(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#fedf6ad0537f7e3a3f958162d1fc935e" title="Setters and mutable accessors.">mutable_dest</a>(),
<a name="l00448"></a>00448                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e000a7721dc9ec46e1c46ec338ac142b">dest_scheme_offset</a>,
<a name="l00449"></a>00449                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#56b10b8316036e4666876b204c395f3d">dest_ssp_offset</a>);
<a name="l00450"></a>00450     
<a name="l00451"></a>00451     dict-&gt;extract_eid(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7c2091e44637889b9ad6f94a82ae7f83" title="Setters and mutable accessors.">mutable_replyto</a>(),
<a name="l00452"></a>00452                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e717b3248b2fef4ec3b36289374504cd">replyto_scheme_offset</a>,
<a name="l00453"></a>00453                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3baf17b33d2833a32b49e99274129c7a">replyto_ssp_offset</a>);
<a name="l00454"></a>00454     
<a name="l00455"></a>00455     dict-&gt;extract_eid(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#96698085719d88c0b5c86d4cb388324c" title="Setters and mutable accessors.">mutable_custodian</a>(),
<a name="l00456"></a>00456                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8b5daa5014dc86c729904d1f64dcb7b9">custodian_scheme_offset</a>,
<a name="l00457"></a>00457                       primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3620e1a0301accfd0f67f1e7058c043f">custodian_ssp_offset</a>);
<a name="l00458"></a>00458     
<a name="l00459"></a>00459     <span class="comment">// If the bundle is a fragment, grab the fragment offset and original</span>
<a name="l00460"></a>00460     <span class="comment">// bundle size (and make sure they fit in a 32 bit integer).</span>
<a name="l00461"></a>00461     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) {
<a name="l00462"></a>00462         u_int64_t sdnv_buf = 0;
<a name="l00463"></a>00463         PBP_READ_SDNV(&amp;sdnv_buf);
<a name="l00464"></a>00464         <span class="keywordflow">if</span> (sdnv_buf &gt; 0xffffffff) {
<a name="l00465"></a>00465             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"fragment offset is too large: %llu"</span>,
<a name="l00466"></a>00466                       U64FMT(sdnv_buf));
<a name="l00467"></a>00467             <span class="keywordflow">return</span> -1;
<a name="l00468"></a>00468         }
<a name="l00469"></a>00469         
<a name="l00470"></a>00470         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7e050ba82bf916772a0971e118dc31ee" title="Setters and mutable accessors.">set_frag_offset</a>(sdnv_buf);
<a name="l00471"></a>00471         sdnv_buf = 0;
<a name="l00472"></a>00472         
<a name="l00473"></a>00473         PBP_READ_SDNV(&amp;sdnv_buf);
<a name="l00474"></a>00474         <span class="keywordflow">if</span> (sdnv_buf &gt; 0xffffffff) {
<a name="l00475"></a>00475             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"fragment original length is too large: %llu"</span>,
<a name="l00476"></a>00476                       U64FMT(sdnv_buf));
<a name="l00477"></a>00477             <span class="keywordflow">return</span> -1;
<a name="l00478"></a>00478         }
<a name="l00479"></a>00479         
<a name="l00480"></a>00480         bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#ad892616cfb568fbe458106f589ce8d3" title="Setters and mutable accessors.">set_orig_length</a>(sdnv_buf);
<a name="l00481"></a>00481 
<a name="l00482"></a>00482         log_debug_p(log, <span class="stringliteral">"parsed fragmentation info: offset %u orig_len %u"</span>,
<a name="l00483"></a>00483                     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#76cf6a44f566aa22e2a98007bf233ee2" title="Accessors.">frag_offset</a>(), bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#e32f3c57057214a1763dfe7709160cf8" title="Accessors.">orig_length</a>());
<a name="l00484"></a>00484     }
<a name="l00485"></a>00485     
<a name="l00486"></a>00486 <span class="preprocessor">#undef PBP_READ_SDNV</span>
<a name="l00487"></a>00487 <span class="preprocessor"></span>    
<a name="l00488"></a>00488     <span class="keywordflow">return</span> consumed;
<a name="l00489"></a>00489 }
<a name="l00490"></a>00490 
<a name="l00491"></a>00491 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00492"></a>00492 <span class="keywordtype">bool</span>
<a name="l00493"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#2fbc1715b03d51dddd4517414335502c">00493</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#2fbc1715b03d51dddd4517414335502c" title="Virtual from BlockProcessor.">PrimaryBlockProcessor::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="l00494"></a>00494                                 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*           block_list,
<a name="l00495"></a>00495                                 <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="l00496"></a>00496                                 <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="l00497"></a>00497                                 <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="l00498"></a>00498 {
<a name="l00499"></a>00499     (void)block_list;
<a name="l00500"></a>00500     (void)block;
<a name="l00501"></a>00501     (void)reception_reason;
<a name="l00502"></a>00502     <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="l00503"></a>00503     
<a name="l00504"></a>00504     <span class="comment">// Make sure all four EIDs are valid.</span>
<a name="l00505"></a>00505     <span class="keywordtype">bool</span> eids_valid = <span class="keyword">true</span>;
<a name="l00506"></a>00506     eids_valid &amp;= bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>();
<a name="l00507"></a>00507     eids_valid &amp;= bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#507241e8ac766e1900009ed6243e2aa3" title="Accessors.">dest</a>().<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>();
<a name="l00508"></a>00508     eids_valid &amp;= bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#eb68ec729851c7e7221fe7cb61f19875" title="Accessors.">custodian</a>().<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>();
<a name="l00509"></a>00509     eids_valid &amp;= bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#a2ffacc40d2afe751142e9fd64ab5fdf" title="Accessors.">replyto</a>().<a class="code" href="classdtn_1_1EndpointID.html#bbf47839fe5cc8cb425af9a257a92ef5">valid</a>();
<a name="l00510"></a>00510     
<a name="l00511"></a>00511     <span class="keywordflow">if</span> (!eids_valid) {
<a name="l00512"></a>00512         <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"bad value for one or more EIDs"</span>);
<a name="l00513"></a>00513         *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00514"></a>00514         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00515"></a>00515     }
<a name="l00516"></a>00516     
<a name="l00517"></a>00517     <span class="comment">// According to BP section 3.3, there are certain things that a bundle</span>
<a name="l00518"></a>00518     <span class="comment">// with a null source EID should not try to do. Check for these cases</span>
<a name="l00519"></a>00519     <span class="comment">// and reject the bundle if any is true.</span>
<a name="l00520"></a>00520     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>() == <a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &amp;quot;dtn:none&amp;quot;...">EndpointID::NULL_EID</a>()) {
<a name="l00521"></a>00521         <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#9630433ec71903457f7b1429daade560" title="True if any return receipt fields are set.">receipt_requested</a>() || bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7af80fedd28d8a8f7b8b947ec134a310" title="Accessors.">app_acked_rcpt</a>()) { 
<a name="l00522"></a>00522             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log,
<a name="l00523"></a>00523                       <span class="stringliteral">"bundle with null source eid has requested a "</span>
<a name="l00524"></a>00524                       <span class="stringliteral">"report; reject it"</span>);
<a name="l00525"></a>00525             *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00526"></a>00526             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00527"></a>00527         }
<a name="l00528"></a>00528     
<a name="l00529"></a>00529         <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2261b28c9315c50a85bc35c1bcb6ace4" title="Accessors.">custody_requested</a>()) {
<a name="l00530"></a>00530             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log,
<a name="l00531"></a>00531                       <span class="stringliteral">"bundle with null source eid has requested custody "</span>
<a name="l00532"></a>00532                       <span class="stringliteral">"transfer; reject it"</span>);
<a name="l00533"></a>00533             *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00534"></a>00534             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00535"></a>00535         }
<a name="l00536"></a>00536 
<a name="l00537"></a>00537         <span class="keywordflow">if</span> (!bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#1931c2eeed81432743735dd245c8b95d" title="Accessors.">do_not_fragment</a>()) {
<a name="l00538"></a>00538             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log,
<a name="l00539"></a>00539                       <span class="stringliteral">"bundle with null source eid has not set "</span>
<a name="l00540"></a>00540                       <span class="stringliteral">"'do-not-fragment' flag; reject it"</span>);
<a name="l00541"></a>00541             *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00542"></a>00542             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00543"></a>00543         }
<a name="l00544"></a>00544     }
<a name="l00545"></a>00545     
<a name="l00546"></a>00546     <span class="comment">// Admin bundles cannot request custody transfer.</span>
<a name="l00547"></a>00547     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#839db0b56b61020d9f2b3878e6c2d34a" title="Accessors.">is_admin</a>()) {
<a name="l00548"></a>00548         <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#2261b28c9315c50a85bc35c1bcb6ace4" title="Accessors.">custody_requested</a>()) {
<a name="l00549"></a>00549             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log,
<a name="l00550"></a>00550                       <span class="stringliteral">"admin bundle requested custody transfer; "</span>
<a name="l00551"></a>00551                       <span class="stringliteral">"reject it"</span>);
<a name="l00552"></a>00552             *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00553"></a>00553             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00554"></a>00554         }
<a name="l00555"></a>00555 
<a name="l00556"></a>00556         <span class="keywordflow">if</span> ( bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#62e71f87a0f72127045bf18a0284843b" title="Accessors.">receive_rcpt</a>() ||
<a name="l00557"></a>00557              bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#108fb7cb162dcc1fdcfdad3ca477692d" title="Accessors.">custody_rcpt</a>() ||
<a name="l00558"></a>00558              bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#93c641bdb9a4beda553d8f28e60c99fd" title="Accessors.">forward_rcpt</a>() ||
<a name="l00559"></a>00559              bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#a48fd652ab931a694f79cc1c6e47985d" title="Accessors.">delivery_rcpt</a>() ||
<a name="l00560"></a>00560              bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#fa1f7ffd4437c3a9213c60e7bbef39d3" title="Accessors.">deletion_rcpt</a>() ||
<a name="l00561"></a>00561              bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#7af80fedd28d8a8f7b8b947ec134a310" title="Accessors.">app_acked_rcpt</a>() )
<a name="l00562"></a>00562         {
<a name="l00563"></a>00563             <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"admin bundle has requested a report; reject it"</span>);
<a name="l00564"></a>00564             *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>;
<a name="l00565"></a>00565             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00566"></a>00566         }
<a name="l00567"></a>00567     }
<a name="l00568"></a>00568     
<a name="l00569"></a>00569     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00570"></a>00570 }
<a name="l00571"></a>00571 
<a name="l00572"></a>00572 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00573"></a>00573 <span class="keywordtype">int</span>
<a name="l00574"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#75c9dac1627305cebd6401dd1e86e95a">00574</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#75c9dac1627305cebd6401dd1e86e95a" title="Virtual from BlockProcessor.">PrimaryBlockProcessor::generate</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="l00575"></a>00575                                 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>*  xmit_blocks,
<a name="l00576"></a>00576                                 <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="l00577"></a>00577                                 <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="l00578"></a>00578                                 <span class="keywordtype">bool</span>           last)
<a name="l00579"></a>00579 {
<a name="l00580"></a>00580     (void)bundle;
<a name="l00581"></a>00581     (void)link;
<a name="l00582"></a>00582     (void)xmit_blocks;
<a name="l00583"></a>00583     (void)block;
<a name="l00584"></a>00584 
<a name="l00585"></a>00585     <span class="comment">/*</span>
<a name="l00586"></a>00586 <span class="comment">     * The primary can't be last since there must be a payload block</span>
<a name="l00587"></a>00587 <span class="comment">     */</span>
<a name="l00588"></a>00588     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!last);
<a name="l00589"></a>00589 
<a name="l00590"></a>00590     <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>;
<a name="l00591"></a>00591 }
<a name="l00592"></a>00592 
<a name="l00593"></a>00593 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00594"></a>00594 <span class="keywordtype">void</span>
<a name="l00595"></a><a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#541fb8e13968042f46b8d6e699e81941">00595</a> <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#541fb8e13968042f46b8d6e699e81941" title="Virtual from BlockProcessor.">PrimaryBlockProcessor::generate_primary</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="l00596"></a>00596                                         <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* xmit_blocks,
<a name="l00597"></a>00597                                         <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="l00598"></a>00598 {
<a name="l00599"></a>00599     <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="l00600"></a>00600     <span class="comment">// point at the local dictionary</span>
<a name="l00601"></a>00601     <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="l00602"></a>00602     <span class="keywordtype">size_t</span> primary_len = 0;     <span class="comment">// total length of the primary block</span>
<a name="l00603"></a>00603     <a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html" title="The remainder of the fixed-length part of the primary bundle block that immediately...">PrimaryBlock</a> primary;
<a name="l00604"></a>00604     
<a name="l00605"></a>00605     memset(&amp;primary, 0, <span class="keyword">sizeof</span>(primary));
<a name="l00606"></a>00606 
<a name="l00607"></a>00607     <span class="comment">/*</span>
<a name="l00608"></a>00608 <span class="comment">     * Calculate the primary block length and initialize the buffer.</span>
<a name="l00609"></a>00609 <span class="comment">     */</span>
<a name="l00610"></a>00610     primary_len = <a class="code" href="classdtn_1_1PrimaryBlockProcessor.html#49e5f6762a4b65450995e15e3d377864">get_primary_len</a>(bundle, dict, &amp;primary);
<a name="l00611"></a>00611     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;reserve(primary_len);
<a name="l00612"></a>00612     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;set_len(primary_len);
<a name="l00613"></a>00613     block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#38d215397b046a403f252512227c29a9" title="Mutating accessors.">set_data_length</a>(primary_len);
<a name="l00614"></a>00614     
<a name="l00615"></a>00615     <span class="comment">/*</span>
<a name="l00616"></a>00616 <span class="comment">     * Advance buf and decrement len as we go through the process.</span>
<a name="l00617"></a>00617 <span class="comment">     */</span>
<a name="l00618"></a>00618     u_char* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a> = block-&gt;<a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()-&gt;buf();
<a name="l00619"></a>00619     <span class="keywordtype">int</span>     <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = primary_len;
<a name="l00620"></a>00620     
<a name="l00621"></a>00621     (void)log; <span class="comment">// in case NDEBUG is defined</span>
<a name="l00622"></a>00622     log_debug_p(log, <span class="stringliteral">"generating primary: length %zu"</span>, primary_len);
<a name="l00623"></a>00623     
<a name="l00624"></a>00624     <span class="comment">// Stick the version number in the first byte.</span>
<a name="l00625"></a>00625     *buf = <a class="code" href="classdtn_1_1BundleProtocol.html#65e637cab3ab85a59f8e326a79a83856" title="The current version of the bundling protocol.">BundleProtocol::CURRENT_VERSION</a>;
<a name="l00626"></a>00626     ++buf;
<a name="l00627"></a>00627     --len;
<a name="l00628"></a>00628     
<a name="l00629"></a>00629 <span class="preprocessor">#define PBP_WRITE_SDNV(value) { \</span>
<a name="l00630"></a>00630 <span class="preprocessor">    int sdnv_len = SDNV::encode(value, buf, len); \</span>
<a name="l00631"></a>00631 <span class="preprocessor">    ASSERT(sdnv_len &gt; 0); \</span>
<a name="l00632"></a>00632 <span class="preprocessor">    buf += sdnv_len; \</span>
<a name="l00633"></a>00633 <span class="preprocessor">    len -= sdnv_len; }</span>
<a name="l00634"></a>00634 <span class="preprocessor"></span>    
<a name="l00635"></a>00635     <span class="comment">// Write out all of the SDNVs</span>
<a name="l00636"></a>00636     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#27369d5c0c8ff5838886dd16265544e0">processing_flags</a>);
<a name="l00637"></a>00637     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#7df49882074054a2a507ce1594d6fb62">block_length</a>);
<a name="l00638"></a>00638     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e000a7721dc9ec46e1c46ec338ac142b">dest_scheme_offset</a>);
<a name="l00639"></a>00639     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#56b10b8316036e4666876b204c395f3d">dest_ssp_offset</a>);
<a name="l00640"></a>00640     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#9c3102b6d048f856d76e9756d47529e0">source_scheme_offset</a>);
<a name="l00641"></a>00641     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#999e6bd31377676bc73705fd507b7dc9">source_ssp_offset</a>);
<a name="l00642"></a>00642     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#e717b3248b2fef4ec3b36289374504cd">replyto_scheme_offset</a>);
<a name="l00643"></a>00643     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3baf17b33d2833a32b49e99274129c7a">replyto_ssp_offset</a>);
<a name="l00644"></a>00644     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#8b5daa5014dc86c729904d1f64dcb7b9">custodian_scheme_offset</a>);
<a name="l00645"></a>00645     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#3620e1a0301accfd0f67f1e7058c043f">custodian_ssp_offset</a>);
<a name="l00646"></a>00646     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a>);
<a name="l00647"></a>00647     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>().<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a>);
<a name="l00648"></a>00648     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#21879e67b7f065975cbd942807500746" title="Accessors.">expiration</a>());
<a name="l00649"></a>00649     <a class="code" href="PrimaryBlockProcessor_8cc.html#2cdf87afd379cf25f488e19a8513e07c">PBP_WRITE_SDNV</a>(primary.<a class="code" href="structdtn_1_1PrimaryBlockProcessor_1_1PrimaryBlock.html#0048e045a498b1ae922092c52c0cada3">dictionary_length</a>);
<a name="l00650"></a>00650     
<a name="l00651"></a>00651     <span class="comment">// Add the dictionary.</span>
<a name="l00652"></a>00652     memcpy(buf, dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#7cbd6c154f97f5931bf5eb662a628820" title="Accessors.">dict</a>(), dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#40ec3ad601fa0cec1a5c5749c70c3c66" title="Accessors.">length</a>());
<a name="l00653"></a>00653     buf += dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#40ec3ad601fa0cec1a5c5749c70c3c66" title="Accessors.">length</a>();
<a name="l00654"></a>00654     len -= dict-&gt;<a class="code" href="classdtn_1_1Dictionary.html#40ec3ad601fa0cec1a5c5749c70c3c66" title="Accessors.">length</a>();
<a name="l00655"></a>00655     
<a name="l00656"></a>00656     <span class="comment">/*</span>
<a name="l00657"></a>00657 <span class="comment">     * If the bundle is a fragment, stuff in SDNVs for the fragment</span>
<a name="l00658"></a>00658 <span class="comment">     * offset and original length.</span>
<a name="l00659"></a>00659 <span class="comment">     */</span>
<a name="l00660"></a>00660     <span class="keywordflow">if</span> (bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) {
<a name="l00661"></a>00661         PBP_WRITE_SDNV(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#76cf6a44f566aa22e2a98007bf233ee2" title="Accessors.">frag_offset</a>());
<a name="l00662"></a>00662         PBP_WRITE_SDNV(bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#e32f3c57057214a1763dfe7709160cf8" title="Accessors.">orig_length</a>());
<a name="l00663"></a>00663     }
<a name="l00664"></a>00664     
<a name="l00665"></a>00665 <span class="preprocessor">#undef PBP_WRITE_SDNV</span>
<a name="l00666"></a>00666 <span class="preprocessor"></span>    
<a name="l00667"></a>00667     <span class="comment">/*</span>
<a name="l00668"></a>00668 <span class="comment">     * Asuming that get_primary_len is written correctly, len should</span>
<a name="l00669"></a>00669 <span class="comment">     * now be zero since we initialized it to primary_len at the</span>
<a name="l00670"></a>00670 <span class="comment">     * beginning of the function.</span>
<a name="l00671"></a>00671 <span class="comment">     */</span>
<a name="l00672"></a>00672     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(len == 0);
<a name="l00673"></a>00673 }
<a name="l00674"></a>00674 
<a name="l00675"></a>00675 
<a name="l00676"></a>00676 } <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:57 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>