Sophie

Sophie

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

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: FileConvergenceLayer.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>FileConvergenceLayer.cc</h1><a href="FileConvergenceLayer_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2004-2006 Intel Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;dirent.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;netinet/in.h&gt;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;oasys/io/IO.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;oasys/util/StringBuffer.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;oasys/util/URI.h&gt;</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="FileConvergenceLayer_8h.html">FileConvergenceLayer.h</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">bundling/Bundle.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="BundleEvent_8h.html">bundling/BundleEvent.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="bundling_2BundleList_8h.html">bundling/BundleList.h</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="BundleProtocol_8h.html">bundling/BundleProtocol.h</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">namespace </span>dtn {
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="comment">/******************************************************************************</span>
<a name="l00043"></a>00043 <span class="comment"> *</span>
<a name="l00044"></a>00044 <span class="comment"> * FileConvergenceLayer</span>
<a name="l00045"></a>00045 <span class="comment"> *</span>
<a name="l00046"></a>00046 <span class="comment"> *****************************************************************************/</span>
<a name="l00047"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#38bec4f813195bce0ad2b221c3f3bd26">00047</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#38bec4f813195bce0ad2b221c3f3bd26" title="Constructor.">FileConvergenceLayer::FileConvergenceLayer</a>()
<a name="l00048"></a>00048     : <a class="code" href="classdtn_1_1ConvergenceLayer.html" title="The abstract interface for a convergence layer.">ConvergenceLayer</a>(<span class="stringliteral">"FileConvergenceLayer"</span>, <span class="stringliteral">"file"</span>)
<a name="l00049"></a>00049 {
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00055"></a>00055 <span class="keywordtype">bool</span>
<a name="l00056"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#aebe7c76dfff8e796631603aa1af2d1a">00056</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#aebe7c76dfff8e796631603aa1af2d1a" title="Pull a filesystem directory out of the next hop admin address.">FileConvergenceLayer::extract_dir</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* nexthop, std::string* dirp)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 
<a name="l00059"></a>00059     PANIC(<span class="stringliteral">"XXX/demmer fix this implementation"</span>);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061     <a class="code" href="namespacedtn.html#0b3883e065c5b300f2581971eee1c009">oasys::URI</a> uri(nexthop);
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     <span class="keywordflow">if</span> (!uri.valid()) {
<a name="l00064"></a>00064         log_err(<span class="stringliteral">"FileConvergenceLayer::extract_dir: "</span>
<a name="l00065"></a>00065                 <span class="stringliteral">"next hop ssp '%s' not a valid uri"</span>, nexthop);
<a name="l00066"></a>00066         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00067"></a>00067     }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     <span class="comment">// the ssp part of the URI should be of the form:</span>
<a name="l00070"></a>00070     <span class="comment">// /path1/path2</span>
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="comment">// validate that the "host" part of the uri is empty, i.e. that</span>
<a name="l00073"></a>00073     <span class="comment">// the filesystem path is absolute</span>
<a name="l00074"></a>00074     <span class="keywordflow">if</span> (uri.host().length() != 0) {
<a name="l00075"></a>00075         log_err(<span class="stringliteral">"interface eid '%s' specifies a non-absolute path"</span>,
<a name="l00076"></a>00076                 nexthop);
<a name="l00077"></a>00077         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     <span class="comment">// and make sure there wasn't a port that was parsed out</span>
<a name="l00081"></a>00081     <span class="keywordflow">if</span> (!uri.port().empty()) {
<a name="l00082"></a>00082         log_err(<span class="stringliteral">"interface eid '%s' specifies a port"</span>, nexthop);
<a name="l00083"></a>00083         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     dirp-&gt;assign(<span class="stringliteral">"/"</span>);
<a name="l00087"></a>00087     dirp-&gt;append(uri.path());
<a name="l00088"></a>00088     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 
<a name="l00095"></a>00095 <span class="keywordtype">bool</span>
<a name="l00096"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#5abd1055ec64a0d16ad26554d138bb26">00096</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#5abd1055ec64a0d16ad26554d138bb26" title="Validate that a given directory exists and that the permissions are correct.">FileConvergenceLayer::validate_dir</a>(<span class="keyword">const</span> std::string&amp; dir)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098     <span class="keyword">struct </span>stat st;
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (stat(dir.c_str(), &amp;st) != 0) {
<a name="l00100"></a>00100         log_err(<span class="stringliteral">"error running stat on %s: %s"</span>, dir.c_str(), strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>));
<a name="l00101"></a>00101         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103 
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (!S_ISDIR(st.st_mode)) {
<a name="l00105"></a>00105         log_err(<span class="stringliteral">"error: %s not a directory"</span>, dir.c_str());
<a name="l00106"></a>00106         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00107"></a>00107     }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     <span class="comment">// XXX/demmer check permissions</span>
<a name="l00110"></a>00110 
<a name="l00111"></a>00111     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00117"></a>00117 <span class="keywordtype">bool</span>
<a name="l00118"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#8d9881cfbe25bfb327e2367399f9d0d7">00118</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#8d9881cfbe25bfb327e2367399f9d0d7" title="Bring up a new interface.">FileConvergenceLayer::interface_up</a>(<a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface,
<a name="l00119"></a>00119                                    <span class="keywordtype">int</span> argc, <span class="keyword">const</span> <span class="keywordtype">char</span>* argv[])
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121     (void)iface;
<a name="l00122"></a>00122     (void)argc;
<a name="l00123"></a>00123     (void)argv;
<a name="l00124"></a>00124     
<a name="l00125"></a>00125     NOTIMPLEMENTED;
<a name="l00126"></a>00126     
<a name="l00127"></a>00127 <span class="comment">//     // parse out the directory from the interface</span>
<a name="l00128"></a>00128 <span class="comment">//     std::string dir;</span>
<a name="l00129"></a>00129 <span class="comment">//     if (!extract_dir(iface-&gt;eid().c_str(), &amp;dir)) {</span>
<a name="l00130"></a>00130 <span class="comment">//         return false;</span>
<a name="l00131"></a>00131 <span class="comment">//     }</span>
<a name="l00132"></a>00132     
<a name="l00133"></a>00133 <span class="comment">//     // make sure the directory exists and is readable / executable</span>
<a name="l00134"></a>00134 <span class="comment">//     if (!validate_dir(dir)) {</span>
<a name="l00135"></a>00135 <span class="comment">//         return false;</span>
<a name="l00136"></a>00136 <span class="comment">//     }</span>
<a name="l00137"></a>00137     
<a name="l00138"></a>00138 <span class="comment">//     // XXX/demmer parse argv for frequency</span>
<a name="l00139"></a>00139 <span class="comment">//     int secs_per_scan = 5;</span>
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 <span class="comment">//     // create a new thread to scan for new bundle files</span>
<a name="l00142"></a>00142 <span class="comment">//     Scanner* scanner = new Scanner(secs_per_scan, dir);</span>
<a name="l00143"></a>00143 <span class="comment">//     scanner-&gt;start();</span>
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 <span class="comment">//     // store the new scanner in the cl specific part of the interface</span>
<a name="l00146"></a>00146 <span class="comment">//     iface-&gt;set_cl_info(scanner);</span>
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     
<a name="l00149"></a>00149     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00155"></a>00155 <span class="keywordtype">bool</span>
<a name="l00156"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#b13b8ef7972ad45e7581299a57573189">00156</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#b13b8ef7972ad45e7581299a57573189" title="Bring down the interface.">FileConvergenceLayer::interface_down</a>(<a class="code" href="classdtn_1_1Interface.html" title="Abstraction of a local dtn interface.">Interface</a>* iface)
<a name="l00157"></a>00157 {
<a name="l00158"></a>00158     <a class="code" href="classdtn_1_1CLInfo.html" title="Abstract base class for convergence layer specific state stored in an interface /...">CLInfo</a> *cli = iface-&gt;<a class="code" href="classdtn_1_1Interface.html#cd9858714c6404a4e8b37e15cf3241a2">cl_info</a>();
<a name="l00159"></a>00159     <a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html" title="Helper class (and thread) that periodically scans a directory for new bundle files...">Scanner</a> *scanner = (<a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html" title="Helper class (and thread) that periodically scans a directory for new bundle files...">Scanner</a> *)cli;
<a name="l00160"></a>00160     scanner-&gt;<a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#d9338020486ba3e94c52b920cad0d873" title="Set the flag to ask it to stop next loop.">stop</a>();
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <span class="comment">// We cannot "delete scanner;" because it is still running</span>
<a name="l00163"></a>00163     <span class="comment">// right now. oasys::Thread::thread_run deletes the Scanner object</span>
<a name="l00164"></a>00164     <span class="comment">// when Scanner::run() returns </span>
<a name="l00165"></a>00165 
<a name="l00166"></a>00166     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168  
<a name="l00172"></a>00172 <span class="keywordtype">bool</span>
<a name="l00173"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#d0bf3977a6a40400d63c7a1c19805490">00173</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#d0bf3977a6a40400d63c7a1c19805490" title="Validate that the contact eid specifies a legit directory.">FileConvergenceLayer::open_contact</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#5f869544c85c75b5a85a14d6e90d7ff7" title="Typedef for a reference on a contact.">ContactRef</a>&amp; contact)
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175     <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a> link = contact-&gt;link();
<a name="l00176"></a>00176     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link != NULL);
<a name="l00177"></a>00177     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!link-&gt;isdeleted());
<a name="l00178"></a>00178 
<a name="l00179"></a>00179     <span class="comment">// XXX/demmer fixme</span>
<a name="l00180"></a>00180     
<a name="l00181"></a>00181     <span class="comment">// parse out the directory from the contact</span>
<a name="l00182"></a>00182 <span class="comment">//     std::string dir;</span>
<a name="l00183"></a>00183 <span class="comment">//     if (!extract_dir(contact-&gt;nexthop(), &amp;dir)) {</span>
<a name="l00184"></a>00184 <span class="comment">//         return false;</span>
<a name="l00185"></a>00185 <span class="comment">//     }</span>
<a name="l00186"></a>00186     
<a name="l00187"></a>00187 <span class="comment">//     // make sure the directory exists and is readable / executable</span>
<a name="l00188"></a>00188 <span class="comment">//     if (!validate_dir(dir)) {</span>
<a name="l00189"></a>00189 <span class="comment">//         return false;</span>
<a name="l00190"></a>00190 <span class="comment">//     }</span>
<a name="l00191"></a>00191 
<a name="l00192"></a>00192     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 
<a name="l00198"></a>00198 <span class="keywordtype">bool</span>
<a name="l00199"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#eb188fa883a317e65dec1037ea77e495">00199</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#eb188fa883a317e65dec1037ea77e495" title="Close the connnection to the contact.">FileConvergenceLayer::close_contact</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#5f869544c85c75b5a85a14d6e90d7ff7" title="Typedef for a reference on a contact.">ContactRef</a>&amp; contact)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201     (void)contact;
<a name="l00202"></a>00202     <span class="comment">// nothing to do</span>
<a name="l00203"></a>00203     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205     
<a name="l00209"></a>00209 <span class="keywordtype">void</span>
<a name="l00210"></a><a class="code" href="classdtn_1_1FileConvergenceLayer.html#16e756b8cc2394df24a67cff5c79c6af">00210</a> <a class="code" href="classdtn_1_1FileConvergenceLayer.html#16e756b8cc2394df24a67cff5c79c6af" title="Try to send the bundles queued up for the given contact.">FileConvergenceLayer::send_bundle</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#5f869544c85c75b5a85a14d6e90d7ff7" title="Typedef for a reference on a contact.">ContactRef</a>&amp; contact, <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     (void)contact;
<a name="l00213"></a>00213     (void)bundle;
<a name="l00214"></a>00214 
<a name="l00215"></a>00215     <span class="comment">// XXX/demmer fix this at some point</span>
<a name="l00216"></a>00216     NOTIMPLEMENTED;
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 <span class="preprocessor">#ifdef notimplemented</span>
<a name="l00219"></a>00219 <span class="preprocessor"></span>    std::string dir;
<a name="l00220"></a>00220     <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1FileConvergenceLayer.html#aebe7c76dfff8e796631603aa1af2d1a" title="Pull a filesystem directory out of the next hop admin address.">extract_dir</a>(contact-&gt;nexthop(), &amp;dir)) {
<a name="l00221"></a>00221         PANIC(<span class="stringliteral">"contact should have already been validated"</span>);
<a name="l00222"></a>00222     }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html" title="Framing header at the beginning of each bundle file.">FileHeader</a> filehdr;
<a name="l00225"></a>00225     <span class="keywordtype">int</span> iovcnt = BundleProtocol::MAX_IOVCNT + 2;
<a name="l00226"></a>00226     <span class="keyword">struct </span>iovec iov[iovcnt];
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     filehdr.<a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html#a655d9424540f8165fe0c777c7dd3dd2" title="framing protocol version">version</a> = <a class="code" href="classdtn_1_1FileConvergenceLayer.html#fd5ae6a7a99000a59029a2a5b4f7da99" title="Current version of the file cl protocol.">CURRENT_VERSION</a>;
<a name="l00229"></a>00229     
<a name="l00230"></a>00230     oasys::StringBuffer fname(<span class="stringliteral">"%s/bundle-XXXXXX"</span>, dir.c_str());
<a name="l00231"></a>00231     
<a name="l00232"></a>00232     iov[0].iov_base = (<span class="keywordtype">char</span>*)&amp;filehdr;
<a name="l00233"></a>00233     iov[0].iov_len  = <span class="keyword">sizeof</span>(<a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html" title="Framing header at the beginning of each bundle file.">FileHeader</a>);
<a name="l00234"></a>00234 
<a name="l00235"></a>00235     <span class="comment">// fill in the bundle header portion</span>
<a name="l00236"></a>00236     u_int16_t header_len =
<a name="l00237"></a>00237         BundleProtocol::format_header_blocks(bundle, &amp;iov[1], &amp;iovcnt);
<a name="l00238"></a>00238 
<a name="l00239"></a>00239     <span class="comment">// fill in the file header</span>
<a name="l00240"></a>00240     <span class="keywordtype">size_t</span> payload_len = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#5240281e3072cc451bba55e716a3257e" title="Reference to the payload.">payload_</a>.<a class="code" href="classdtn_1_1BundlePayload.html#56b3851ad789c4dbf019a32d557b7453" title="The payload length.">length</a>();
<a name="l00241"></a>00241     filehdr.<a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html#7ea447d2a1db519047c591bcfb09475d" title="length of the bundle header">header_length</a> = htons(header_len);
<a name="l00242"></a>00242     filehdr.<a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html#0bb2b0890592bfbc1880fefc9de7faea" title="length of the bundle + headers">bundle_length</a> = htonl(header_len + payload_len);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244     <span class="comment">// and tack on the payload (adding one to iovcnt for the</span>
<a name="l00245"></a>00245     <span class="comment">// FileHeader, then one for the payload)</span>
<a name="l00246"></a>00246     iovcnt++;
<a name="l00247"></a>00247     PANIC(<span class="stringliteral">"XXX/demmer fix me"</span>);
<a name="l00248"></a>00248     <span class="comment">//iov[iovcnt].iov_base = (void*)bundle-&gt;payload_.data();</span>
<a name="l00249"></a>00249     iov[iovcnt].iov_len  = payload_len;
<a name="l00250"></a>00250     iovcnt++;
<a name="l00251"></a>00251 
<a name="l00252"></a>00252     <span class="comment">// open the bundle file </span>
<a name="l00253"></a>00253     <span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#6f8059414f0228f0256115e024eeed4b">fd</a> = mkstemp(fname.c_str());
<a name="l00254"></a>00254     <span class="keywordflow">if</span> (fd == -1) {
<a name="l00255"></a>00255         log_err(<span class="stringliteral">"error opening temp file in %s: %s"</span>,
<a name="l00256"></a>00256                 fname.c_str(), strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>));
<a name="l00257"></a>00257         <span class="comment">// XXX/demmer report error here?</span>
<a name="l00258"></a>00258         <span class="keywordflow">return</span>;
<a name="l00259"></a>00259     }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261     log_debug(<span class="stringliteral">"opened temp file %s for bundle id %d "</span>
<a name="l00262"></a>00262               <span class="stringliteral">"fd %d header_length %zu payload_length %zu"</span>,
<a name="l00263"></a>00263               fname.c_str(), bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#351580b526d962c1e8bd730157b4c969" title="Local bundle identifier.">bundleid_</a>, fd,
<a name="l00264"></a>00264               header_len, payload_len);
<a name="l00265"></a>00265 
<a name="l00266"></a>00266     <span class="comment">// now write everything out</span>
<a name="l00267"></a>00267     <span class="keywordtype">int</span> total = <span class="keyword">sizeof</span>(<a class="code" href="structdtn_1_1FileConvergenceLayer_1_1FileHeader.html" title="Framing header at the beginning of each bundle file.">FileHeader</a>) + header_len + payload_len;
<a name="l00268"></a>00268     <span class="keywordtype">int</span> cc = oasys::IO::writevall(fd, iov, iovcnt, logpath_);
<a name="l00269"></a>00269     <span class="keywordflow">if</span> (cc != total) {
<a name="l00270"></a>00270         log_err(<span class="stringliteral">"error writing out bundle (wrote %d/%d): %s"</span>,
<a name="l00271"></a>00271                 cc, total, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>));
<a name="l00272"></a>00272     }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274     <span class="comment">// free up the iovec data</span>
<a name="l00275"></a>00275     BundleProtocol::free_header_iovmem(bundle, &amp;iov[1], iovcnt - 2);
<a name="l00276"></a>00276         
<a name="l00277"></a>00277     <span class="comment">// close the file descriptor</span>
<a name="l00278"></a>00278     close(fd);
<a name="l00279"></a>00279 
<a name="l00280"></a>00280     <span class="comment">// cons up a transmission event and pass it to the router</span>
<a name="l00281"></a>00281     <span class="keywordtype">bool</span> acked = <span class="keyword">false</span>;
<a name="l00282"></a>00282     <span class="comment">// XXX/demmer total_len</span>
<a name="l00283"></a>00283     <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(
<a name="l00284"></a>00284         <span class="keyword">new</span> <a class="code" href="classdtn_1_1BundleTransmittedEvent.html" title="Event class for bundle or fragment transmission.">BundleTransmittedEvent</a>(bundle, contact, total_len, acked));
<a name="l00285"></a>00285         
<a name="l00286"></a>00286     log_debug(<span class="stringliteral">"bundle id %d successfully transmitted"</span>, bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#351580b526d962c1e8bd730157b4c969" title="Local bundle identifier.">bundleid_</a>);
<a name="l00287"></a>00287 <span class="preprocessor">#endif // notimplemented</span>
<a name="l00288"></a>00288 <span class="preprocessor"></span>}
<a name="l00289"></a>00289 
<a name="l00290"></a>00290 <span class="comment">/******************************************************************************</span>
<a name="l00291"></a>00291 <span class="comment"> *</span>
<a name="l00292"></a>00292 <span class="comment"> * FileConvergenceLayer::Scanner</span>
<a name="l00293"></a>00293 <span class="comment"> *</span>
<a name="l00294"></a>00294 <span class="comment"> *****************************************************************************/</span>
<a name="l00295"></a><a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#b1f03477810cc672dcbf134210650a9b">00295</a> <a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#b1f03477810cc672dcbf134210650a9b" title="Constructor.">FileConvergenceLayer::Scanner::Scanner</a>(<span class="keywordtype">int</span> secs_per_scan, 
<a name="l00296"></a>00296                                        <span class="keyword">const</span> std::string&amp; dir)
<a name="l00297"></a>00297     : <a class="code" href="classoasys_1_1Logger.html">Logger</a>(<span class="stringliteral">"FileConvergenceLayer::Scanner"</span>,
<a name="l00298"></a>00298              <span class="stringliteral">"/dtn/cl/file/scanner"</span>), 
<a name="l00299"></a>00299       Thread(<span class="stringliteral">"FileConvergenceLayer::Scanner"</span>), 
<a name="l00300"></a>00300       secs_per_scan_(secs_per_scan), 
<a name="l00301"></a>00301       dir_(dir), 
<a name="l00302"></a>00302       run_(true)
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304     set_flag(DELETE_ON_EXIT);
<a name="l00305"></a>00305 }
<a name="l00306"></a>00306 
<a name="l00310"></a>00310 <span class="keywordtype">void</span>
<a name="l00311"></a><a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#2e2106951825c94de9c7225413a98c9d">00311</a> <a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#2e2106951825c94de9c7225413a98c9d" title="Main thread function.">FileConvergenceLayer::Scanner::run</a>()
<a name="l00312"></a>00312 {
<a name="l00313"></a>00313     <span class="comment">// XXX/demmer fix me </span>
<a name="l00314"></a>00314     NOTIMPLEMENTED;
<a name="l00315"></a>00315     
<a name="l00316"></a>00316     <span class="comment">/*</span>
<a name="l00317"></a>00317 <span class="comment">    FileHeader filehdr;</span>
<a name="l00318"></a>00318 <span class="comment">    DIR* dir = opendir(dir_.c_str());</span>
<a name="l00319"></a>00319 <span class="comment">    struct dirent* dirent;</span>
<a name="l00320"></a>00320 <span class="comment">    const char* fname;</span>
<a name="l00321"></a>00321 <span class="comment">    u_char* buf;</span>
<a name="l00322"></a>00322 <span class="comment">    int fd;</span>
<a name="l00323"></a>00323 <span class="comment"></span>
<a name="l00324"></a>00324 <span class="comment">    if (!dir) {</span>
<a name="l00325"></a>00325 <span class="comment">        // XXX/demmer signal cl somehow?</span>
<a name="l00326"></a>00326 <span class="comment">        log_err("error in opendir");</span>
<a name="l00327"></a>00327 <span class="comment">        return;</span>
<a name="l00328"></a>00328 <span class="comment">    }</span>
<a name="l00329"></a>00329 <span class="comment"></span>
<a name="l00330"></a>00330 <span class="comment">    while (run_) {</span>
<a name="l00331"></a>00331 <span class="comment">        seekdir(dir, 0);</span>
<a name="l00332"></a>00332 <span class="comment"></span>
<a name="l00333"></a>00333 <span class="comment">        while ((dirent = readdir(dir)) != 0) {</span>
<a name="l00334"></a>00334 <span class="comment">            fname = dirent-&gt;d_name;</span>
<a name="l00335"></a>00335 <span class="comment"></span>
<a name="l00336"></a>00336 <span class="comment">            if ((fname[0] == '.') &amp;&amp;</span>
<a name="l00337"></a>00337 <span class="comment">                ((fname[1] == '\0') ||</span>
<a name="l00338"></a>00338 <span class="comment">                 (fname[1] == '.' &amp;&amp; fname[2] == '\0')))</span>
<a name="l00339"></a>00339 <span class="comment">            {</span>
<a name="l00340"></a>00340 <span class="comment">                continue;</span>
<a name="l00341"></a>00341 <span class="comment">            }</span>
<a name="l00342"></a>00342 <span class="comment">            </span>
<a name="l00343"></a>00343 <span class="comment">            log_debug("scan found file %s", fname);</span>
<a name="l00344"></a>00344 <span class="comment"></span>
<a name="l00345"></a>00345 <span class="comment">            // cons up the full path</span>
<a name="l00346"></a>00346 <span class="comment">            oasys::StringBuffer path("%s/%s", dir_.c_str(), fname);</span>
<a name="l00347"></a>00347 <span class="comment"></span>
<a name="l00348"></a>00348 <span class="comment">            // malloc a buffer for it, open a file descriptor, and</span>
<a name="l00349"></a>00349 <span class="comment">            // read in the header</span>
<a name="l00350"></a>00350 <span class="comment">            if ((fd = open(path.c_str(), 0)) == -1) {</span>
<a name="l00351"></a>00351 <span class="comment">                log_err("error opening file %s: %s", path.c_str(), strerror(errno));</span>
<a name="l00352"></a>00352 <span class="comment">                continue;</span>
<a name="l00353"></a>00353 <span class="comment">            }</span>
<a name="l00354"></a>00354 <span class="comment"></span>
<a name="l00355"></a>00355 <span class="comment">            int cc = oasys::IO::readall(fd, (char*)&amp;filehdr, sizeof(FileHeader));</span>
<a name="l00356"></a>00356 <span class="comment">            if (cc != sizeof(FileHeader)) {</span>
<a name="l00357"></a>00357 <span class="comment">                log_warn("can't read in FileHeader (read %d/%zu): %s",</span>
<a name="l00358"></a>00358 <span class="comment">                         cc, sizeof(FileHeader), strerror(errno));</span>
<a name="l00359"></a>00359 <span class="comment">                continue;</span>
<a name="l00360"></a>00360 <span class="comment">            }</span>
<a name="l00361"></a>00361 <span class="comment"></span>
<a name="l00362"></a>00362 <span class="comment">            if (filehdr.version != CURRENT_VERSION) {</span>
<a name="l00363"></a>00363 <span class="comment">                log_warn("framing protocol version mismatch: %d != current %d",</span>
<a name="l00364"></a>00364 <span class="comment">                         filehdr.version, CURRENT_VERSION);</span>
<a name="l00365"></a>00365 <span class="comment">                continue;</span>
<a name="l00366"></a>00366 <span class="comment">            }</span>
<a name="l00367"></a>00367 <span class="comment"></span>
<a name="l00368"></a>00368 <span class="comment">            u_int16_t header_len = ntohs(filehdr.header_length);</span>
<a name="l00369"></a>00369 <span class="comment">            size_t bundle_len = ntohl(filehdr.bundle_length);</span>
<a name="l00370"></a>00370 <span class="comment">            </span>
<a name="l00371"></a>00371 <span class="comment">            log_debug("found bundle file %s: header_length %u bundle_length %zu",</span>
<a name="l00372"></a>00372 <span class="comment">                      path.c_str(), header_len, bundle_len);</span>
<a name="l00373"></a>00373 <span class="comment"></span>
<a name="l00374"></a>00374 <span class="comment">            // read in and parse the headers</span>
<a name="l00375"></a>00375 <span class="comment">            buf = (u_char*)malloc(header_len);</span>
<a name="l00376"></a>00376 <span class="comment">            cc = oasys::IO::readall(fd, (char*)buf, header_len);</span>
<a name="l00377"></a>00377 <span class="comment">            if (cc != header_len) {</span>
<a name="l00378"></a>00378 <span class="comment">                log_err("error reading file %s header (read %d/%d): %s",</span>
<a name="l00379"></a>00379 <span class="comment">                        path.c_str(), cc, header_len, strerror(errno));</span>
<a name="l00380"></a>00380 <span class="comment">                free(buf);</span>
<a name="l00381"></a>00381 <span class="comment">                continue;</span>
<a name="l00382"></a>00382 <span class="comment">            }</span>
<a name="l00383"></a>00383 <span class="comment"></span>
<a name="l00384"></a>00384 <span class="comment">            Bundle* bundle = new Bundle();</span>
<a name="l00385"></a>00385 <span class="comment">            if (! BundleProtocol::parse_header_blocks(bundle, buf, header_len)) {</span>
<a name="l00386"></a>00386 <span class="comment">                log_err("error parsing bundle headers in file %s", path.c_str());</span>
<a name="l00387"></a>00387 <span class="comment">                free(buf);</span>
<a name="l00388"></a>00388 <span class="comment">                delete bundle;</span>
<a name="l00389"></a>00389 <span class="comment">                continue;</span>
<a name="l00390"></a>00390 <span class="comment">            }</span>
<a name="l00391"></a>00391 <span class="comment">            free(buf);</span>
<a name="l00392"></a>00392 <span class="comment"></span>
<a name="l00393"></a>00393 <span class="comment">            // Now validate the lengths</span>
<a name="l00394"></a>00394 <span class="comment">            size_t payload_len = bundle-&gt;payload_.length();</span>
<a name="l00395"></a>00395 <span class="comment">            if (bundle_len != header_len + payload_len) {</span>
<a name="l00396"></a>00396 <span class="comment">                log_err("error in bundle lengths in file %s: "</span>
<a name="l00397"></a>00397 <span class="comment">                        "bundle_length %zu, header_length %u, payload_length %zu",</span>
<a name="l00398"></a>00398 <span class="comment">                        path.c_str(), bundle_len, header_len, payload_len);</span>
<a name="l00399"></a>00399 <span class="comment">                delete bundle;</span>
<a name="l00400"></a>00400 <span class="comment">                continue;</span>
<a name="l00401"></a>00401 <span class="comment">            }</span>
<a name="l00402"></a>00402 <span class="comment"></span>
<a name="l00403"></a>00403 <span class="comment">            // Looks good, now read in and assign the data</span>
<a name="l00404"></a>00404 <span class="comment">            buf = (u_char*)malloc(payload_len);</span>
<a name="l00405"></a>00405 <span class="comment">            cc = oasys::IO::readall(fd, (char*)buf, payload_len);</span>
<a name="l00406"></a>00406 <span class="comment">            if (cc != (int)payload_len) {</span>
<a name="l00407"></a>00407 <span class="comment">                log_err("error reading file %s payload (read %d/%zu): %s",</span>
<a name="l00408"></a>00408 <span class="comment">                        path.c_str(), cc, payload_len, strerror(errno));</span>
<a name="l00409"></a>00409 <span class="comment">                delete bundle;</span>
<a name="l00410"></a>00410 <span class="comment">                continue;</span>
<a name="l00411"></a>00411 <span class="comment">            }</span>
<a name="l00412"></a>00412 <span class="comment">            bundle-&gt;payload_.set_data(buf, payload_len);</span>
<a name="l00413"></a>00413 <span class="comment">            free(buf);</span>
<a name="l00414"></a>00414 <span class="comment">            </span>
<a name="l00415"></a>00415 <span class="comment">            // close the file descriptor and remove the file</span>
<a name="l00416"></a>00416 <span class="comment">            if (close(fd) != 0) {</span>
<a name="l00417"></a>00417 <span class="comment">                log_err("error closing file %s: %s",</span>
<a name="l00418"></a>00418 <span class="comment">                        path.c_str(), strerror(errno));</span>
<a name="l00419"></a>00419 <span class="comment">            }</span>
<a name="l00420"></a>00420 <span class="comment">            </span>
<a name="l00421"></a>00421 <span class="comment">            if (unlink(path.c_str()) != 0) {</span>
<a name="l00422"></a>00422 <span class="comment">                log_err("error removing file %s: %s",</span>
<a name="l00423"></a>00423 <span class="comment">                        path.c_str(), strerror(errno));</span>
<a name="l00424"></a>00424 <span class="comment">            }</span>
<a name="l00425"></a>00425 <span class="comment"></span>
<a name="l00426"></a>00426 <span class="comment">            // all set, notify the router</span>
<a name="l00427"></a>00427 <span class="comment">            // XXX/demmer need length here</span>
<a name="l00428"></a>00428 <span class="comment">            BundleDaemon::post(</span>
<a name="l00429"></a>00429 <span class="comment">                new BundleReceivedEvent(bundle, EVENTSRC_PEER));</span>
<a name="l00430"></a>00430 <span class="comment">        }</span>
<a name="l00431"></a>00431 <span class="comment">            </span>
<a name="l00432"></a>00432 <span class="comment">        sleep(secs_per_scan_);</span>
<a name="l00433"></a>00433 <span class="comment">    }</span>
<a name="l00434"></a>00434 <span class="comment">    */</span>
<a name="l00435"></a>00435     log_info(<span class="stringliteral">"exiting"</span>);
<a name="l00436"></a>00436 }
<a name="l00437"></a>00437 
<a name="l00441"></a><a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#d9338020486ba3e94c52b920cad0d873">00441</a> <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#d9338020486ba3e94c52b920cad0d873" title="Set the flag to ask it to stop next loop.">FileConvergenceLayer::Scanner::stop</a>() {
<a name="l00442"></a>00442     <a class="code" href="classdtn_1_1FileConvergenceLayer_1_1Scanner.html#f10f457d9dc8d0cb257a6c70767bbf7a" title="keep running?">run_</a> = <span class="keyword">false</span>;
<a name="l00443"></a>00443 }
<a name="l00444"></a>00444 
<a name="l00445"></a>00445 } <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:56 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>