<!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: CustodySignal.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>CustodySignal.cc</h1><a href="CustodySignal_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 <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></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 <oasys/util/ScratchBuffer.h></span> <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="CustodySignal_8h.html">CustodySignal.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">SDNV.h</a>"</span> <a name="l00024"></a>00024 <a name="l00025"></a>00025 <span class="keyword">namespace </span>dtn { <a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00028"></a>00028 <span class="keywordtype">void</span> <a name="l00029"></a><a class="code" href="classdtn_1_1CustodySignal.html#2fe29b70ddb0f7cf92d417d996c4a8e0">00029</a> <a class="code" href="classdtn_1_1CustodySignal.html#2fe29b70ddb0f7cf92d417d996c4a8e0" title="Constructor-like function to create a new custody signal bundle.">CustodySignal::create_custody_signal</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00030"></a>00030 <span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* orig_bundle, <a name="l00031"></a>00031 <span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>& source_eid, <a name="l00032"></a>00032 <span class="keywordtype">bool</span> succeeded, <a name="l00033"></a>00033 <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490b" title="Custody Signal Reason Codes.">reason_t</a> reason) <a name="l00034"></a>00034 { <a name="l00035"></a>00035 bundle-><a class="code" href="classdtn_1_1Bundle.html#69c35928ca050eb4bb2ec67641f1b6bb" title="Setters and mutable accessors.">mutable_source</a>()-><a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(source_eid); <a name="l00036"></a>00036 <span class="keywordflow">if</span> (orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#eb68ec729851c7e7221fe7cb61f19875" title="Accessors.">custodian</a>().<a class="code" href="classdtn_1_1EndpointID.html#80721c0832c08c5066e6d6276d62d70b" title="Simple equality test function.">equals</a>(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>())) { <a name="l00037"></a>00037 PANIC(<span class="stringliteral">"create_custody_signal(*%p): "</span> <a name="l00038"></a>00038 <span class="stringliteral">"custody signal cannot be generated to null eid"</span>, <a name="l00039"></a>00039 orig_bundle); <a name="l00040"></a>00040 } <a name="l00041"></a>00041 bundle-><a class="code" href="classdtn_1_1Bundle.html#fedf6ad0537f7e3a3f958162d1fc935e" title="Setters and mutable accessors.">mutable_dest</a>()-><a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#eb68ec729851c7e7221fe7cb61f19875" title="Accessors.">custodian</a>()); <a name="l00042"></a>00042 bundle-><a class="code" href="classdtn_1_1Bundle.html#7c2091e44637889b9ad6f94a82ae7f83" title="Setters and mutable accessors.">mutable_replyto</a>()-><a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>()); <a name="l00043"></a>00043 bundle-><a class="code" href="classdtn_1_1Bundle.html#96698085719d88c0b5c86d4cb388324c" title="Setters and mutable accessors.">mutable_custodian</a>()-><a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(<a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>()); <a name="l00044"></a>00044 bundle-><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="l00045"></a>00045 <a name="l00046"></a>00046 <span class="comment">// use the expiration time from the original bundle</span> <a name="l00047"></a>00047 <span class="comment">// XXX/demmer maybe something more clever??</span> <a name="l00048"></a>00048 bundle-><a class="code" href="classdtn_1_1Bundle.html#7623ecfe9e47e5dc075ebd872fb9a237" title="Setters and mutable accessors.">set_expiration</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#21879e67b7f065975cbd942807500746" title="Accessors.">expiration</a>()); <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keywordtype">int</span> <a class="code" href="sdnv-c_8h.html#61025d18c2abbee27eba89034e1fb025" title="Return the number of bytes needed to encode the given value.">sdnv_encoding_len</a> = 0; <a name="l00051"></a>00051 <span class="keywordtype">int</span> signal_len = 0; <a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="comment">// we generally don't expect the Custody Signal length to be > 256 bytes</span> <a name="l00054"></a>00054 oasys::ScratchBuffer<u_char*, 256> scratch; <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="comment">// format of custody signals:</span> <a name="l00057"></a>00057 <span class="comment">//</span> <a name="l00058"></a>00058 <span class="comment">// 1 byte admin payload type and flags</span> <a name="l00059"></a>00059 <span class="comment">// 1 byte status code</span> <a name="l00060"></a>00060 <span class="comment">// SDNV [Fragment Offset (if present)]</span> <a name="l00061"></a>00061 <span class="comment">// SDNV [Fragment Length (if present)]</span> <a name="l00062"></a>00062 <span class="comment">// SDNVx2 Time of custody signal</span> <a name="l00063"></a>00063 <span class="comment">// SDNVx2 Copy of bundle X's Creation Timestamp</span> <a name="l00064"></a>00064 <span class="comment">// SDNV Length of X's source endpoint ID</span> <a name="l00065"></a>00065 <span class="comment">// vari Source endpoint ID of bundle X</span> <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="comment">//</span> <a name="l00068"></a>00068 <span class="comment">// first calculate the length</span> <a name="l00069"></a>00069 <span class="comment">//</span> <a name="l00070"></a>00070 <a name="l00071"></a>00071 <span class="comment">// the non-optional, fixed-length fields above:</span> <a name="l00072"></a>00072 signal_len = 1 + 1; <a name="l00073"></a>00073 <a name="l00074"></a>00074 <span class="comment">// the 2 SDNV fragment fields:</span> <a name="l00075"></a>00075 <span class="keywordflow">if</span> (orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) { <a name="l00076"></a>00076 signal_len += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#76cf6a44f566aa22e2a98007bf233ee2" title="Accessors.">frag_offset</a>()); <a name="l00077"></a>00077 signal_len += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#e32f3c57057214a1763dfe7709160cf8" title="Accessors.">orig_length</a>()); <a name="l00078"></a>00078 } <a name="l00079"></a>00079 <a name="l00080"></a>00080 <span class="comment">// Time field, set to the current time:</span> <a name="l00081"></a>00081 <a class="code" href="structdtn_1_1BundleTimestamp.html" title="Simple struct definition for bundle creation timestamps.">BundleTimestamp</a> now; <a name="l00082"></a>00082 now.<a class="code" href="structdtn_1_1BundleTimestamp.html#02c8a347150620243240655bdcd2f42d" title="Seconds since 1/1/2000.">seconds_</a> = <a class="code" href="structdtn_1_1BundleTimestamp.html#27af1dd8ce1c3d9f361a0149aba6cb0c" title="Return the current time in the correct format for the bundle protocol, i.e.">BundleTimestamp::get_current_time</a>(); <a name="l00083"></a>00083 now.<a class="code" href="structdtn_1_1BundleTimestamp.html#ebc8cea66862d7f6056da450db410347" title="Sub-second sequence number.">seqno_</a> = 0; <a name="l00084"></a>00084 signal_len += <a class="code" href="classdtn_1_1BundleProtocol.html#efd5468219b7a40e33d4d6eaa7fa610e" title="Return the length required to encode the timestamp as two SDNVs.">BundleProtocol::ts_encoding_len</a>(now); <a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="comment">// The bundle's creation timestamp:</span> <a name="l00087"></a>00087 signal_len += <a class="code" href="classdtn_1_1BundleProtocol.html#efd5468219b7a40e33d4d6eaa7fa610e" title="Return the length required to encode the timestamp as two SDNVs.">BundleProtocol::ts_encoding_len</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>()); <a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="comment">// the Source Endpoint ID length and value</span> <a name="l00090"></a>00090 signal_len += <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#3ed7639ed8794ea8045bb5d16128c5f5">length</a>()) + <a name="l00091"></a>00091 orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#3ed7639ed8794ea8045bb5d16128c5f5">length</a>(); <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">//</span> <a name="l00094"></a>00094 <span class="comment">// now format the buffer</span> <a name="l00095"></a>00095 <span class="comment">//</span> <a name="l00096"></a>00096 u_char* bp = scratch.buf(signal_len); <a name="l00097"></a>00097 <span class="keywordtype">int</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = signal_len; <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="comment">// Admin Payload Type and flags</span> <a name="l00100"></a>00100 *bp = (<a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece207e6e1a30d0fed8a953bc65802798f7dd">BundleProtocol::ADMIN_CUSTODY_SIGNAL</a> << 4); <a name="l00101"></a>00101 <span class="keywordflow">if</span> (orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) { <a name="l00102"></a>00102 *bp |= <a class="code" href="classdtn_1_1BundleProtocol.html#f827c0a9dff8115434bc273dc53b7df1951511bc017d452550ea77dd9a15306b">BundleProtocol::ADMIN_IS_FRAGMENT</a>; <a name="l00103"></a>00103 } <a name="l00104"></a>00104 bp++; <a name="l00105"></a>00105 len--; <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="comment">// Success flag and reason code</span> <a name="l00108"></a>00108 *bp++ = ((succeeded ? 1 : 0) << 7) | (reason & 0x7f); <a name="l00109"></a>00109 len--; <a name="l00110"></a>00110 <a name="l00111"></a>00111 <span class="comment">// The 2 Fragment Fields</span> <a name="l00112"></a>00112 <span class="keywordflow">if</span> (orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#d6c74eba219bfe55854cf7a90e210cca" title="Accessors.">is_fragment</a>()) { <a name="l00113"></a>00113 sdnv_encoding_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#76cf6a44f566aa22e2a98007bf233ee2" title="Accessors.">frag_offset</a>(), bp, len); <a name="l00114"></a>00114 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_encoding_len > 0); <a name="l00115"></a>00115 bp += sdnv_encoding_len; <a name="l00116"></a>00116 len -= sdnv_encoding_len; <a name="l00117"></a>00117 <a name="l00118"></a>00118 sdnv_encoding_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#e32f3c57057214a1763dfe7709160cf8" title="Accessors.">orig_length</a>(), bp, len); <a name="l00119"></a>00119 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_encoding_len > 0); <a name="l00120"></a>00120 bp += sdnv_encoding_len; <a name="l00121"></a>00121 len -= sdnv_encoding_len; <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a>00124 sdnv_encoding_len = <a class="code" href="classdtn_1_1BundleProtocol.html#c590d33b1e828121f9d096860d4cad9a" title="Store a DTN timestamp into a 64-bit value suitable for transmission over the network...">BundleProtocol::set_timestamp</a>(bp, len, now); <a name="l00125"></a>00125 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_encoding_len > 0); <a name="l00126"></a>00126 bp += sdnv_encoding_len; <a name="l00127"></a>00127 len -= sdnv_encoding_len; <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="comment">// Copy of bundle X's Creation Timestamp</span> <a name="l00130"></a>00130 sdnv_encoding_len = <a name="l00131"></a>00131 <a class="code" href="classdtn_1_1BundleProtocol.html#c590d33b1e828121f9d096860d4cad9a" title="Store a DTN timestamp into a 64-bit value suitable for transmission over the network...">BundleProtocol::set_timestamp</a>(bp, len, orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#13cd9ab7b010f09562170e2a57242209" title="Accessors.">creation_ts</a>()); <a name="l00132"></a>00132 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_encoding_len > 0); <a name="l00133"></a>00133 bp += sdnv_encoding_len; <a name="l00134"></a>00134 len -= sdnv_encoding_len; <a name="l00135"></a>00135 <a name="l00136"></a>00136 <span class="comment">// The Endpoint ID length and data</span> <a name="l00137"></a>00137 sdnv_encoding_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#3ed7639ed8794ea8045bb5d16128c5f5">length</a>(), bp, len); <a name="l00138"></a>00138 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_encoding_len > 0); <a name="l00139"></a>00139 len -= sdnv_encoding_len; <a name="l00140"></a>00140 bp += sdnv_encoding_len; <a name="l00141"></a>00141 <a name="l00142"></a>00142 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((u_int)len == orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#3ed7639ed8794ea8045bb5d16128c5f5">length</a>()); <a name="l00143"></a>00143 memcpy(bp, orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#c9d8a72806359621f4d2850c1e78269c">c_str</a>(), orig_bundle-><a class="code" href="classdtn_1_1Bundle.html#2dae8a97270a95799acf45d859eaf866" title="Accessors.">source</a>().<a class="code" href="classdtn_1_1EndpointID.html#3ed7639ed8794ea8045bb5d16128c5f5">length</a>()); <a name="l00144"></a>00144 <a name="l00145"></a>00145 <span class="comment">// </span> <a name="l00146"></a>00146 <span class="comment">// Finished generating the payload</span> <a name="l00147"></a>00147 <span class="comment">//</span> <a name="l00148"></a>00148 bundle-><a class="code" href="classdtn_1_1Bundle.html#857079bad68497626f75c2985b69052f" title="Setters and mutable accessors.">mutable_payload</a>()-><a class="code" href="classdtn_1_1BundlePayload.html#8abce553a70ab4bff48443d3faf49b2e" title="Set the payload data and length.">set_data</a>(scratch.buf(), signal_len); <a name="l00149"></a>00149 } <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00152"></a>00152 <span class="keywordtype">bool</span> <a name="l00153"></a><a class="code" href="classdtn_1_1CustodySignal.html#854ca4797421b5399d6260d1ab9efcb4">00153</a> CustodySignal::parse_custody_signal(<a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html" title="Struct to hold the payload data of the custody signal.">data_t</a>* data, <a name="l00154"></a>00154 <span class="keyword">const</span> u_char* bp, u_int <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>) <a name="l00155"></a>00155 { <a name="l00156"></a>00156 <span class="comment">// 1 byte Admin Payload Type + Flags:</span> <a name="l00157"></a>00157 <span class="keywordflow">if</span> (len < 1) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00158"></a>00158 data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#ee10cd35c41e68f61dacdb92746aca3d">admin_type_</a> = (*bp >> 4); <a name="l00159"></a>00159 data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#a69b2abd004398671ef3075418d70900">admin_flags_</a> = *bp & 0xf; <a name="l00160"></a>00160 bp++; <a name="l00161"></a>00161 len--; <a name="l00162"></a>00162 <a name="l00163"></a>00163 <span class="comment">// validate the admin type</span> <a name="l00164"></a>00164 <span class="keywordflow">if</span> (data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#ee10cd35c41e68f61dacdb92746aca3d">admin_type_</a> != <a class="code" href="classdtn_1_1BundleProtocol.html#35e3c05cad3ebc9ec0f4d9b0f88ece207e6e1a30d0fed8a953bc65802798f7dd">BundleProtocol::ADMIN_CUSTODY_SIGNAL</a>) { <a name="l00165"></a>00165 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00166"></a>00166 } <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="comment">// Success flag and reason code</span> <a name="l00169"></a>00169 <span class="keywordflow">if</span> (len < 1) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00170"></a>00170 data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#e6e11f65859d8662d2115c211a44aed4">succeeded_</a> = (*bp >> 7); <a name="l00171"></a>00171 data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#a51d3016cfedaef076bb6779adb4edb2">reason_</a> = (*bp & 0x7f); <a name="l00172"></a>00172 bp++; <a name="l00173"></a>00173 len--; <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="comment">// Fragment SDNV Fields (offset & length), if present:</span> <a name="l00176"></a>00176 <span class="keywordflow">if</span> (data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#a69b2abd004398671ef3075418d70900">admin_flags_</a> & <a class="code" href="classdtn_1_1BundleProtocol.html#f827c0a9dff8115434bc273dc53b7df1951511bc017d452550ea77dd9a15306b">BundleProtocol::ADMIN_IS_FRAGMENT</a>) <a name="l00177"></a>00177 { <a name="l00178"></a>00178 <span class="keywordtype">int</span> sdnv_bytes = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(bp, len, &data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#1570a98b95b2df91845aee1583275c1a">orig_frag_offset_</a>); <a name="l00179"></a>00179 <span class="keywordflow">if</span> (sdnv_bytes == -1) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00180"></a>00180 bp += sdnv_bytes; <a name="l00181"></a>00181 len -= sdnv_bytes; <a name="l00182"></a>00182 <a name="l00183"></a>00183 sdnv_bytes = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(bp, len, &data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#f3a8cef680803f103257b0a5881ed8bd">orig_frag_length_</a>); <a name="l00184"></a>00184 <span class="keywordflow">if</span> (sdnv_bytes == -1) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00185"></a>00185 bp += sdnv_bytes; <a name="l00186"></a>00186 len -= sdnv_bytes; <a name="l00187"></a>00187 } <a name="l00188"></a>00188 <a name="l00189"></a>00189 <span class="keywordtype">int</span> ts_len; <a name="l00190"></a>00190 <a name="l00191"></a>00191 <span class="comment">// The signal timestamp</span> <a name="l00192"></a>00192 ts_len = <a class="code" href="classdtn_1_1BundleProtocol.html#09d040740695f886e1e09bd9065767ab" title="Retrieve a DTN timestamp from a 64-bit value that was transmitted over the network...">BundleProtocol::get_timestamp</a>(&data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#d066106605dcd0ed17cb2ba0c304c093">custody_signal_tv_</a>, bp, len); <a name="l00193"></a>00193 <span class="keywordflow">if</span> (ts_len < 0) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00194"></a>00194 bp += ts_len; <a name="l00195"></a>00195 len -= ts_len; <a name="l00196"></a>00196 <a name="l00197"></a>00197 <span class="comment">// Bundle Creation Timestamp</span> <a name="l00198"></a>00198 ts_len = <a class="code" href="classdtn_1_1BundleProtocol.html#09d040740695f886e1e09bd9065767ab" title="Retrieve a DTN timestamp from a 64-bit value that was transmitted over the network...">BundleProtocol::get_timestamp</a>(&data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#850387bcc745b3911dbdf5e14ed2baff">orig_creation_tv_</a>, bp, len); <a name="l00199"></a>00199 <span class="keywordflow">if</span> (ts_len < 0) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00200"></a>00200 bp += ts_len; <a name="l00201"></a>00201 len -= ts_len; <a name="l00202"></a>00202 <a name="l00203"></a>00203 <span class="comment">// Source Endpoint ID of Bundle</span> <a name="l00204"></a>00204 u_int64_t EID_len; <a name="l00205"></a>00205 <span class="keywordtype">int</span> num_bytes = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(bp, len, &EID_len); <a name="l00206"></a>00206 <span class="keywordflow">if</span> (num_bytes == -1) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00207"></a>00207 bp += num_bytes; <a name="l00208"></a>00208 len -= num_bytes; <a name="l00209"></a>00209 <a name="l00210"></a>00210 <span class="keywordflow">if</span> (len != EID_len) { <span class="keywordflow">return</span> <span class="keyword">false</span>; } <a name="l00211"></a>00211 <span class="keywordtype">bool</span> ok = data-><a class="code" href="structdtn_1_1CustodySignal_1_1data__t.html#21be3f276fe52bd85f0fd3c2f4e1ff63">orig_source_eid_</a>.<a class="code" href="classdtn_1_1EndpointID.html#ec39752e4da3107b16ff5da58d2aa5ab" title="Assign this endpoint ID as a copy of the other.">assign</a>(std::string((<span class="keyword">const</span> <span class="keywordtype">char</span>*)bp, len)); <a name="l00212"></a>00212 <span class="keywordflow">if</span> (!ok) { <a name="l00213"></a>00213 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <a name="l00216"></a>00216 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00217"></a>00217 } <a name="l00218"></a>00218 <a name="l00219"></a>00219 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00220"></a>00220 <span class="keyword">const</span> <span class="keywordtype">char</span>* <a name="l00221"></a><a class="code" href="classdtn_1_1CustodySignal.html#af7a2262319a7b2a348d1f8dc5415c2f">00221</a> <a class="code" href="classdtn_1_1CustodySignal.html#af7a2262319a7b2a348d1f8dc5415c2f" title="Pretty printer for custody signal reasons.">CustodySignal::reason_to_str</a>(u_int8_t reason) <a name="l00222"></a>00222 { <a name="l00223"></a>00223 <span class="keywordflow">switch</span> (reason) { <a name="l00224"></a>00224 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490bf974eaaa8cbe4e66aeaf238a454cecf1">BundleProtocol::CUSTODY_NO_ADDTL_INFO</a>: <a name="l00225"></a>00225 <span class="keywordflow">return</span> <span class="stringliteral">"no additional info"</span>; <a name="l00226"></a>00226 <a name="l00227"></a>00227 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490b0a6d60329683ef33d75edbce647fb245">BundleProtocol::CUSTODY_REDUNDANT_RECEPTION</a>: <a name="l00228"></a>00228 <span class="keywordflow">return</span> <span class="stringliteral">"redundant reception"</span>; <a name="l00229"></a>00229 <a name="l00230"></a>00230 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490b870861df82a7d42686c4b64887e2e8e7">BundleProtocol::CUSTODY_DEPLETED_STORAGE</a>: <a name="l00231"></a>00231 <span class="keywordflow">return</span> <span class="stringliteral">"depleted storage"</span>; <a name="l00232"></a>00232 <a name="l00233"></a>00233 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490bf04d881f698e458b945dbefb9163a7a4">BundleProtocol::CUSTODY_ENDPOINT_ID_UNINTELLIGIBLE</a>: <a name="l00234"></a>00234 <span class="keywordflow">return</span> <span class="stringliteral">"eid unintelligible"</span>; <a name="l00235"></a>00235 <a name="l00236"></a>00236 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490bae630a36e16e37e3aec296c18f1a12b2">BundleProtocol::CUSTODY_NO_ROUTE_TO_DEST</a>: <a name="l00237"></a>00237 <span class="keywordflow">return</span> <span class="stringliteral">"no route to dest"</span>; <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490bbb74fb4f2a0579bd6b56206cfeffaec2">BundleProtocol::CUSTODY_NO_TIMELY_CONTACT</a>: <a name="l00240"></a>00240 <span class="keywordflow">return</span> <span class="stringliteral">"no timely contact"</span>; <a name="l00241"></a>00241 <a name="l00242"></a>00242 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1BundleProtocol.html#e339b3a1104cd188459059e46543490bf28ea7f5e87b6196687b5d0f3bf57d4f">BundleProtocol::CUSTODY_BLOCK_UNINTELLIGIBLE</a>: <a name="l00243"></a>00243 <span class="keywordflow">return</span> <span class="stringliteral">"block unintelligible"</span>; <a name="l00244"></a>00244 } <a name="l00245"></a>00245 <a name="l00246"></a>00246 <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>[64]; <a name="l00247"></a>00247 snprintf(buf, 64, <span class="stringliteral">"unknown reason %d"</span>, reason); <a name="l00248"></a>00248 <span class="keywordflow">return</span> buf; <a name="l00249"></a>00249 } <a name="l00250"></a>00250 <a name="l00251"></a>00251 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:39 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>