Sophie

Sophie

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

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: DTNTunnel.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>DTNTunnel.cc</h1><a href="DTNTunnel_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;stdio.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="APIEndpointIDOpt_8h.html">APIEndpointIDOpt.h</a>"</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;oasys/io/NetUtils.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;oasys/util/Getopt.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;oasys/util/StringBuffer.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;oasys/util/StringUtils.h&gt;</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="DTNTunnel_8h.html">DTNTunnel.h</a>"</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="TCPTunnel_8h.html">TCPTunnel.h</a>"</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="UDPTunnel_8h.html">UDPTunnel.h</a>"</span>
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="namespacedtntunnel.html">00042</a> <span class="keyword">namespace </span>dtntunnel {
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="keyword">template</span> &lt;&gt;
<a name="l00045"></a>00045 <a class="code" href="classdtntunnel_1_1DTNTunnel.html" title="Main wrapper class for the DTN Tunnel.">DTNTunnel</a>* oasys::Singleton&lt;DTNTunnel&gt;::instance_ = 0;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00048"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#93fe38d97f97f33f11dbbd282f7cd1d1">00048</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#93fe38d97f97f33f11dbbd282f7cd1d1" title="Constructor.">DTNTunnel::DTNTunnel</a>()
<a name="l00049"></a>00049     : App(<span class="stringliteral">"DTNTunnel"</span>, <span class="stringliteral">"dtntunnel"</span>),
<a name="l00050"></a>00050       send_lock_(<span class="stringliteral">"/dtntunnel"</span>, oasys::Mutex::TYPE_RECURSIVE, true),
<a name="l00051"></a>00051       listen_(false),
<a name="l00052"></a>00052       custody_(false),
<a name="l00053"></a>00053       expiration_(600),
<a name="l00054"></a>00054       tcp_(true),
<a name="l00055"></a>00055       udp_(false),
<a name="l00056"></a>00056       local_addr_(htonl(INADDR_ANY)),
<a name="l00057"></a>00057       local_port_(0),
<a name="l00058"></a>00058       remote_addr_(htonl(INADDR_NONE)),
<a name="l00059"></a>00059       remote_port_(0),
<a name="l00060"></a>00060       delay_(0),
<a name="l00061"></a>00061       max_size_(32 * 1024),
<a name="l00062"></a>00062       tunnel_spec_(<span class="stringliteral">""</span>),
<a name="l00063"></a>00063       tunnel_spec_set_(false)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065     <span class="comment">// override default logging setting</span>
<a name="l00066"></a>00066     loglevel_ = oasys::LOG_NOTICE;
<a name="l00067"></a>00067     
<a name="l00068"></a>00068     memset(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>));
<a name="l00069"></a>00069     memset(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#da4e439f4c07527c0df574ff7383ca38">dest_eid_</a>,  0, <span class="keyword">sizeof</span>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#da4e439f4c07527c0df574ff7383ca38">dest_eid_</a>));
<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="classdtntunnel_1_1DTNTunnel.html#6785f2711b14f1e0e2158dc83fd5519c">00074</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#6785f2711b14f1e0e2158dc83fd5519c" title="Virtual from oasys::App.">DTNTunnel::fill_options</a>()
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076     App::fill_default_options(DAEMONIZE_OPT);
<a name="l00077"></a>00077     App::set_extra_usage(<span class="stringliteral">"&lt;destination_eid&gt;"</span>);
<a name="l00078"></a>00078     
<a name="l00079"></a>00079     opts_.addopt(
<a name="l00080"></a>00080         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'L'</span>, <span class="stringliteral">"listen"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a22d580bea98de2600e13670c779692d">listen_</a>,
<a name="l00081"></a>00081                            <span class="stringliteral">"run in listen mode for incoming CONN bundles"</span>));
<a name="l00082"></a>00082     
<a name="l00083"></a>00083     opts_.addopt(
<a name="l00084"></a>00084         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'c'</span>, <span class="stringliteral">"custody"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#0059279d328ff14b55d8c4f5caf1f85d">custody_</a>, <span class="stringliteral">"use custody transfer"</span>));
<a name="l00085"></a>00085     
<a name="l00086"></a>00086     opts_.addopt(
<a name="l00087"></a>00087         <span class="keyword">new</span> oasys::UIntOpt(<span class="charliteral">'e'</span>, <span class="stringliteral">"expiration"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#91852c786a634b7ea252d2c559b7ae6d">expiration_</a>, <span class="stringliteral">"&lt;secs&gt;"</span>,
<a name="l00088"></a>00088                            <span class="stringliteral">"expiration time"</span>));
<a name="l00089"></a>00089     
<a name="l00090"></a>00090     opts_.addopt(
<a name="l00091"></a>00091         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'t'</span>, <span class="stringliteral">"tcp"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a>,
<a name="l00092"></a>00092                            <span class="stringliteral">"proxy for TCP connections (default)"</span>));
<a name="l00093"></a>00093     
<a name="l00094"></a>00094     opts_.addopt(
<a name="l00095"></a>00095         <span class="keyword">new</span> oasys::BoolOpt(<span class="charliteral">'u'</span>, <span class="stringliteral">"udp"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#48661fc1a440f23153f1cf31e4ef11cc">udp_</a>,
<a name="l00096"></a>00096                            <span class="stringliteral">"proxy for UDP traffic instead of tcp"</span>));
<a name="l00097"></a>00097     
<a name="l00098"></a>00098     opts_.addopt(
<a name="l00099"></a>00099         <span class="keyword">new</span> <a class="code" href="classdtn_1_1APIEndpointIDOpt.html" title="Extension class to the oasys Opt hierarchy that validates that the option is a DTN...">dtn::APIEndpointIDOpt</a>(<span class="stringliteral">"local_eid"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>, <span class="stringliteral">"&lt;eid&gt;"</span>,
<a name="l00100"></a>00100                                   <span class="stringliteral">"local endpoint id override"</span>));
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     opts_.addopt(
<a name="l00103"></a>00103         <span class="keyword">new</span> oasys::UIntOpt(<span class="charliteral">'D'</span>, <span class="stringliteral">"delay"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#50a15288dff2389e1e833e14468e41d7">delay_</a>, <span class="stringliteral">"&lt;millisecs&gt;"</span>,
<a name="l00104"></a>00104                            <span class="stringliteral">"nagle delay in msecs for stream transports (e.g. tcp)"</span>));
<a name="l00105"></a>00105     
<a name="l00106"></a>00106     opts_.addopt(
<a name="l00107"></a>00107         <span class="keyword">new</span> oasys::UIntOpt(<span class="charliteral">'z'</span>, <span class="stringliteral">"max_size"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#19e38dd2477d233ff368f52f77191316">max_size_</a>, <span class="stringliteral">"&lt;bytes&gt;"</span>,
<a name="l00108"></a>00108                            <span class="stringliteral">"maximum bundle size for stream transports (e.g. tcp)"</span>));
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     opts_.addopt(
<a name="l00111"></a>00111         <span class="keyword">new</span> oasys::StringOpt(<span class="charliteral">'T'</span>, <span class="stringliteral">"tunnel"</span>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#8f707583c0c504a52c7ae14a301b0604">tunnel_spec_</a>, <span class="stringliteral">"&lt;spec&gt;"</span>,
<a name="l00112"></a>00112                              <span class="stringliteral">"tunnel specification [lhost:]lport:rhost:rport"</span>,
<a name="l00113"></a>00113                              &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a1fed5554ab4fa13bcaba05a919d3045">tunnel_spec_set_</a>));
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00117"></a>00117 <span class="keywordtype">void</span>
<a name="l00118"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#7ced4e3188c8c286af77047b544a8590">00118</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#7ced4e3188c8c286af77047b544a8590">DTNTunnel::validate_options</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[], <span class="keywordtype">int</span> remainder)
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#48661fc1a440f23153f1cf31e4ef11cc">udp_</a>) {
<a name="l00121"></a>00121         <a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a> = <span class="keyword">false</span>;
<a name="l00122"></a>00122     }
<a name="l00123"></a>00123     
<a name="l00124"></a>00124     <span class="keywordtype">bool</span> dest_eid_set = <span class="keyword">false</span>;
<a name="l00125"></a>00125     <span class="keywordflow">if</span> (remainder == argc - 1) {
<a name="l00126"></a>00126         <span class="keywordflow">if</span> (<a class="code" href="dtn__api_8c.html#055c8bb8eaa570aacbe6a164ff123c84" title="Parse a string into an endpoint id structure, validating that it is in fact a valid...">dtn_parse_eid_string</a>(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#da4e439f4c07527c0df574ff7383ca38">dest_eid_</a>, argv[argc-1]) == -1) {
<a name="l00127"></a>00127             fprintf(stderr, <span class="stringliteral">"invalid destination endpoint id '%s'\n"</span>,
<a name="l00128"></a>00128                     argv[argc - 1]);
<a name="l00129"></a>00129             print_usage_and_exit();
<a name="l00130"></a>00130         } <span class="keywordflow">else</span> {
<a name="l00131"></a>00131             dest_eid_set = <span class="keyword">true</span>;
<a name="l00132"></a>00132         }
<a name="l00133"></a>00133         
<a name="l00134"></a>00134     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (remainder != argc) {
<a name="l00135"></a>00135         fprintf(stderr, <span class="stringliteral">"invalid argument '%s'\n"</span>, argv[remainder]);
<a name="l00136"></a>00136         print_usage_and_exit();
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     <span class="comment">// parse the tunnel spec</span>
<a name="l00140"></a>00140     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a1fed5554ab4fa13bcaba05a919d3045">tunnel_spec_set_</a>) {
<a name="l00141"></a>00141         std::vector&lt;std::string&gt; tokens;
<a name="l00142"></a>00142         <span class="keywordtype">int</span> ntoks = oasys::tokenize(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#8f707583c0c504a52c7ae14a301b0604">tunnel_spec_</a>, <span class="stringliteral">":"</span>, &amp;tokens);
<a name="l00143"></a>00143         <span class="keywordflow">if</span> (ntoks &lt; 3 || ntoks &gt; 4) {
<a name="l00144"></a>00144             fprintf(stderr, <span class="stringliteral">"invalid tunnel specification %s: bad format\n"</span>,
<a name="l00145"></a>00145                     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#8f707583c0c504a52c7ae14a301b0604">tunnel_spec_</a>.c_str());
<a name="l00146"></a>00146             print_usage_and_exit();
<a name="l00147"></a>00147         }
<a name="l00148"></a>00148 
<a name="l00149"></a>00149         <span class="keywordflow">if</span> (ntoks == 4) {
<a name="l00150"></a>00150             <span class="keywordflow">if</span> (oasys::gethostbyname(tokens[0].c_str(), &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#be701ab15bf218cf0425fd598f15147c">local_addr_</a>) != 0) {
<a name="l00151"></a>00151                 fprintf(stderr,
<a name="l00152"></a>00152                         <span class="stringliteral">"invalid tunnel specification %s: local addr %s invalid\n"</span>,
<a name="l00153"></a>00153                         <a class="code" href="classdtntunnel_1_1DTNTunnel.html#8f707583c0c504a52c7ae14a301b0604">tunnel_spec_</a>.c_str(), tokens[0].c_str());
<a name="l00154"></a>00154                 print_usage_and_exit();
<a name="l00155"></a>00155             }
<a name="l00156"></a>00156         }
<a name="l00157"></a>00157     
<a name="l00158"></a>00158         <a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a> = atoi(tokens[ntoks - 3].c_str());
<a name="l00159"></a>00159 
<a name="l00160"></a>00160         <span class="keywordflow">if</span> (oasys::gethostbyname(tokens[ntoks - 2].c_str(), &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e21b03564a07743056fa5b3ec8cc5497">remote_addr_</a>) != 0) {
<a name="l00161"></a>00161             fprintf(stderr,
<a name="l00162"></a>00162                     <span class="stringliteral">"invalid tunnel specification %s: remote host %s invalid\n"</span>,
<a name="l00163"></a>00163                     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#8f707583c0c504a52c7ae14a301b0604">tunnel_spec_</a>.c_str(), tokens[ntoks - 2].c_str());
<a name="l00164"></a>00164             print_usage_and_exit();
<a name="l00165"></a>00165         }
<a name="l00166"></a>00166     
<a name="l00167"></a>00167         <a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a> = atoi(tokens[ntoks - 1].c_str());
<a name="l00168"></a>00168     }
<a name="l00169"></a>00169 
<a name="l00170"></a>00170 <span class="preprocessor">#define CHECK_OPT(_condition, _err)             \</span>
<a name="l00171"></a>00171 <span class="preprocessor">    if ((_condition)) {                         \</span>
<a name="l00172"></a>00172 <span class="preprocessor">        fprintf(stderr, "error: " _err "\n");   \</span>
<a name="l00173"></a>00173 <span class="preprocessor">        print_usage_and_exit();                 \</span>
<a name="l00174"></a>00174 <span class="preprocessor">    }</span>
<a name="l00175"></a>00175 <span class="preprocessor"></span>
<a name="l00176"></a>00176     <span class="comment">//</span>
<a name="l00177"></a>00177     <span class="comment">// TODO?:  couldn't we use these in listen mode to over-ride</span>
<a name="l00178"></a>00178     <span class="comment">// what is provided at the sender? -kfall.  Also: mcast for udp?</span>
<a name="l00179"></a>00179     <span class="comment">//</span>
<a name="l00180"></a>00180     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a22d580bea98de2600e13670c779692d">listen_</a>) {
<a name="l00181"></a>00181         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(dest_eid_set, <span class="stringliteral">"setting destination eid is "</span>
<a name="l00182"></a>00182                   <span class="stringliteral">"meaningless in listen mode"</span>);
<a name="l00183"></a>00183         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a>  != 0,  <span class="stringliteral">"setting local port is "</span>
<a name="l00184"></a>00184                   <span class="stringliteral">"meaningless in listen mode"</span>);
<a name="l00185"></a>00185         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e21b03564a07743056fa5b3ec8cc5497">remote_addr_</a> != INADDR_NONE, <span class="stringliteral">"setting remote host is "</span>
<a name="l00186"></a>00186                   <span class="stringliteral">"meaningless in listen mode"</span>);
<a name="l00187"></a>00187         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a> != 0,  <span class="stringliteral">"setting remote port is "</span>
<a name="l00188"></a>00188                   <span class="stringliteral">"meaningless in listen mode"</span>);
<a name="l00189"></a>00189     } <span class="keywordflow">else</span> {
<a name="l00190"></a>00190         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(!dest_eid_set, <span class="stringliteral">"must set destination eid "</span>
<a name="l00191"></a>00191                   <span class="stringliteral">"or be in listen mode"</span>);
<a name="l00192"></a>00192         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>((<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a> == <span class="keyword">false</span>) &amp;&amp; (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#48661fc1a440f23153f1cf31e4ef11cc">udp_</a> == <span class="keyword">false</span>),
<a name="l00193"></a>00193                   <span class="stringliteral">"must set either tcp or udp mode"</span>);
<a name="l00194"></a>00194         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>((<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a> != <span class="keyword">false</span>) &amp;&amp; (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#48661fc1a440f23153f1cf31e4ef11cc">udp_</a> != <span class="keyword">false</span>),
<a name="l00195"></a>00195                   <span class="stringliteral">"cannot set both tcp and udp mode"</span>);
<a name="l00196"></a>00196         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#be701ab15bf218cf0425fd598f15147c">local_addr_</a>  == INADDR_NONE, <span class="stringliteral">"local addr is invalid"</span>);
<a name="l00197"></a>00197         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a>  == 0,  <span class="stringliteral">"must set local port"</span>);
<a name="l00198"></a>00198         <a class="code" href="DTNTunnel_8cc.html#1ff7d86a8eae1d5be9dd85132b4272c0">CHECK_OPT</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a> == 0,  <span class="stringliteral">"must set remote port"</span>);
<a name="l00199"></a>00199     }
<a name="l00200"></a>00200     
<a name="l00201"></a>00201 <span class="preprocessor">#undef CHECK_OPT</span>
<a name="l00202"></a>00202 <span class="preprocessor"></span>}
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00205"></a>00205 <span class="keywordtype">void</span>
<a name="l00206"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#d4470c2781140d3f4ee5d8b2909e143e">00206</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#d4470c2781140d3f4ee5d8b2909e143e">DTNTunnel::init_tunnel</a>()
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#b903e1e1b501e9523c31f910dda3ef8a">tcptunnel_</a> = <span class="keyword">new</span> <a class="code" href="classdtntunnel_1_1TCPTunnel.html" title="Class to manage TCP &amp;lt;-&amp;gt; DTN tunnels.">TCPTunnel</a>();
<a name="l00209"></a>00209     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#27f499ca92b3183653c6d1bc4fb11e3f">udptunnel_</a> = <span class="keyword">new</span> <a class="code" href="classdtntunnel_1_1UDPTunnel.html">UDPTunnel</a>();
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (!<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a22d580bea98de2600e13670c779692d">listen_</a>) {
<a name="l00212"></a>00212         <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a>) {
<a name="l00213"></a>00213             <a class="code" href="classdtntunnel_1_1DTNTunnel.html#b903e1e1b501e9523c31f910dda3ef8a">tcptunnel_</a>-&gt;<a class="code" href="classdtntunnel_1_1TCPTunnel.html#17e855174e6624b2426e2b175dc72b13" title="Add a new listening to from the given listening address/port to the given remote...">add_listener</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#be701ab15bf218cf0425fd598f15147c">local_addr_</a>, <a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a>,
<a name="l00214"></a>00214                                      <a class="code" href="classdtntunnel_1_1DTNTunnel.html#e21b03564a07743056fa5b3ec8cc5497">remote_addr_</a>, <a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a>);
<a name="l00215"></a>00215         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#48661fc1a440f23153f1cf31e4ef11cc">udp_</a>) {
<a name="l00216"></a>00216             <a class="code" href="classdtntunnel_1_1DTNTunnel.html#27f499ca92b3183653c6d1bc4fb11e3f">udptunnel_</a>-&gt;<a class="code" href="classdtntunnel_1_1UDPTunnel.html#7c0b986de60aefca660cc1dbe1b91e4c" title="Add a new listener.">add_listener</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#be701ab15bf218cf0425fd598f15147c">local_addr_</a>, <a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a>,
<a name="l00217"></a>00217                                      <a class="code" href="classdtntunnel_1_1DTNTunnel.html#e21b03564a07743056fa5b3ec8cc5497">remote_addr_</a>, <a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a>);
<a name="l00218"></a>00218         }
<a name="l00219"></a>00219     }
<a name="l00220"></a>00220 }
<a name="l00221"></a>00221 
<a name="l00222"></a>00222 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00223"></a>00223 <span class="keywordtype">void</span>
<a name="l00224"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#0742d0cd0fb5f5e4e4284a0c8ffbd754">00224</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#0742d0cd0fb5f5e4e4284a0c8ffbd754">DTNTunnel::init_registration</a>()
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226     <span class="keywordtype">int</span> err = <a class="code" href="dtn__api_8c.html#3afc66b2e2c75fae07a45467df9f74e9" title="Open a new connection to the router.">dtn_open</a>(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>);
<a name="l00227"></a>00227     <span class="keywordflow">if</span> (err != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) {
<a name="l00228"></a>00228         log_crit(<span class="stringliteral">"can't open recv handle to daemon: %s"</span>,
<a name="l00229"></a>00229                  <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(err));
<a name="l00230"></a>00230         notify_and_exit(1);
<a name="l00231"></a>00231     }
<a name="l00232"></a>00232     
<a name="l00233"></a>00233     err = <a class="code" href="dtn__api_8c.html#3afc66b2e2c75fae07a45467df9f74e9" title="Open a new connection to the router.">dtn_open</a>(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#53cb6037273071a48527fa9dd15b1a0c">send_handle_</a>);
<a name="l00234"></a>00234     <span class="keywordflow">if</span> (err != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) {
<a name="l00235"></a>00235         log_crit(<span class="stringliteral">"can't open send handle to daemon: %s"</span>,
<a name="l00236"></a>00236                  <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(err));
<a name="l00237"></a>00237         notify_and_exit(1);
<a name="l00238"></a>00238     }
<a name="l00239"></a>00239 
<a name="l00240"></a>00240     oasys::StaticStringBuffer&lt;128&gt; demux;
<a name="l00241"></a>00241     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#a22d580bea98de2600e13670c779692d">listen_</a>) {
<a name="l00242"></a>00242         demux.appendf(<span class="stringliteral">"dtntunnel"</span>);
<a name="l00243"></a>00243     } <span class="keywordflow">else</span> {
<a name="l00244"></a>00244         demux.appendf(<span class="stringliteral">"dtntunnel?dest_eid=%s&amp;tunnel=%s-%s:%u-%s:%u"</span>,
<a name="l00245"></a>00245                       <a class="code" href="classdtntunnel_1_1DTNTunnel.html#da4e439f4c07527c0df574ff7383ca38">dest_eid_</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>,
<a name="l00246"></a>00246                       <a class="code" href="classdtntunnel_1_1DTNTunnel.html#a249adcc7d7b3e53273ef133f6ee101c">tcp_</a> ? <span class="stringliteral">"tcp"</span> : <span class="stringliteral">"udp"</span>,
<a name="l00247"></a>00247                       intoa(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#be701ab15bf218cf0425fd598f15147c">local_addr_</a>),
<a name="l00248"></a>00248                       <a class="code" href="classdtntunnel_1_1DTNTunnel.html#67f2b14ff139037c3279ec26c5bf4d20">local_port_</a>,
<a name="l00249"></a>00249                       intoa(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e21b03564a07743056fa5b3ec8cc5497">remote_addr_</a>),
<a name="l00250"></a>00250                       <a class="code" href="classdtntunnel_1_1DTNTunnel.html#9ce2c019f219c2a7594ab508325f371c">remote_port_</a>);
<a name="l00251"></a>00251     }
<a name="l00252"></a>00252     
<a name="l00253"></a>00253     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>[0] == <span class="charliteral">'\0'</span>) {
<a name="l00254"></a>00254         err = <a class="code" href="dtn__api_8c.html#0947b9119c69984edf25df43ead8858b" title="Build an appropriate local endpoint id by appending the specified service tag to...">dtn_build_local_eid</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>, demux.c_str());
<a name="l00255"></a>00255         <span class="keywordflow">if</span> (err != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) {
<a name="l00256"></a>00256             log_crit(<span class="stringliteral">"can't build local eid: %s"</span>,
<a name="l00257"></a>00257                      <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00258"></a>00258             notify_and_exit(1);
<a name="l00259"></a>00259         }
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261 
<a name="l00262"></a>00262     log_notice(<span class="stringliteral">"local endpoint id %s"</span>, <a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>);
<a name="l00263"></a>00263 
<a name="l00264"></a>00264     u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>;
<a name="l00265"></a>00265     err = <a class="code" href="dtn__api_8c.html#add060907ae0beceeebb75ac61a8f552" title="Check for an existing registration on the given endpoint id, returning DTN_SUCCSS...">dtn_find_registration</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>, &amp;regid);
<a name="l00266"></a>00266     <span class="keywordflow">if</span> (err == 0) {
<a name="l00267"></a>00267         log_notice(<span class="stringliteral">"found existing registration id %d, calling dtn_bind"</span>,
<a name="l00268"></a>00268                    regid);
<a name="l00269"></a>00269         
<a name="l00270"></a>00270         err = <a class="code" href="dtn__api_8c.html#ab949d76f4c34a202aea5bac853b310b" title="Associate a registration with the current ipc channel.">dtn_bind</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>, regid);
<a name="l00271"></a>00271         <span class="keywordflow">if</span> (err != 0) {
<a name="l00272"></a>00272             log_crit(<span class="stringliteral">"error in dtn_bind: %s"</span>, 
<a name="l00273"></a>00273                      <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00274"></a>00274             notify_and_exit(1);
<a name="l00275"></a>00275         }
<a name="l00276"></a>00276     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>) == <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>) {
<a name="l00277"></a>00277         <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reginfo;
<a name="l00278"></a>00278         memset(&amp;reginfo, 0, <span class="keyword">sizeof</span>(reginfo));
<a name="l00279"></a>00279         <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;reginfo.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>);
<a name="l00280"></a>00280         reginfo.<a class="code" href="structdtn__reg__info__t.html#7bf2e33b713b585bfe1792c40fa8cd6c">flags</a> = <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00d21fdf39ccc69d6790aec0c70ce5f972">DTN_REG_DEFER</a>;
<a name="l00281"></a>00281         reginfo.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 60 * 60 * 24; <span class="comment">// 1 day</span>
<a name="l00282"></a>00282 
<a name="l00283"></a>00283         err = <a class="code" href="dtn__api_8c.html#7384bf592d4aff0892ff948aafa98b0c" title="Create a dtn registration.">dtn_register</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>, &amp;reginfo, &amp;regid);
<a name="l00284"></a>00284         <span class="keywordflow">if</span> (err != 0) {
<a name="l00285"></a>00285             log_crit(<span class="stringliteral">"error in dtn_register: %s"</span>,
<a name="l00286"></a>00286                      <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00287"></a>00287             notify_and_exit(1);
<a name="l00288"></a>00288         }
<a name="l00289"></a>00289     } <span class="keywordflow">else</span> {
<a name="l00290"></a>00290         log_crit(<span class="stringliteral">"error in dtn_find_registration: %s"</span>,
<a name="l00291"></a>00291                  <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00292"></a>00292         notify_and_exit(1);
<a name="l00293"></a>00293     }
<a name="l00294"></a>00294 }
<a name="l00295"></a>00295 
<a name="l00296"></a>00296 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00297"></a>00297 <span class="keywordtype">int</span>
<a name="l00298"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#1b60c68235406847c8bdcacabb834e2a">00298</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#1b60c68235406847c8bdcacabb834e2a" title="Hook for various tunnel classes to send a bundle.">DTNTunnel::send_bundle</a>(<a class="code" href="structdtn_1_1APIBundle.html" title="Small encapsulating structure for API bundles.">dtn::APIBundle</a>* bundle, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a>* dest_eid)
<a name="l00299"></a>00299 {
<a name="l00300"></a>00300     <span class="comment">// lock to coordinate access to the send_handle_ from multiple</span>
<a name="l00301"></a>00301     <span class="comment">// client threads</span>
<a name="l00302"></a>00302     oasys::ScopeLock l(&amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#0a43fde006dfbddd516e7de4bafa21d8">send_lock_</a>, <span class="stringliteral">"DTNTunnel::send_bundle"</span>);
<a name="l00303"></a>00303     
<a name="l00304"></a>00304     <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> spec;
<a name="l00305"></a>00305     memset(&amp;spec, 0, <span class="keyword">sizeof</span>(spec));
<a name="l00306"></a>00306     <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>, &amp;<a class="code" href="classdtntunnel_1_1DTNTunnel.html#e334aad7de5a5648bad034cb565a4b95">local_eid_</a>);
<a name="l00307"></a>00307     <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>,   dest_eid);
<a name="l00308"></a>00308     spec.<a class="code" href="structdtn__bundle__spec__t.html#f44519876b50a9f0b0eb242bea1ed158">priority</a>   = <a class="code" href="dtn__types_8h.html#993858e35739619750a07d5dc1c275e0f5a0479d0c742791ecd3827d8bf82bfc">COS_NORMAL</a>;
<a name="l00309"></a>00309     spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a>      = <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000cb6b7eb0422ee4f6c87a4c1dd3cecee5">DOPTS_NONE</a>;
<a name="l00310"></a>00310     <span class="keywordflow">if</span> (<a class="code" href="classdtntunnel_1_1DTNTunnel.html#0059279d328ff14b55d8c4f5caf1f85d">custody_</a>) {
<a name="l00311"></a>00311         spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000cf365df7de1d4ff463456b4adbafaf0c">DOPTS_CUSTODY</a>;
<a name="l00312"></a>00312     }
<a name="l00313"></a>00313     spec.<a class="code" href="structdtn__bundle__spec__t.html#57f2d6068db6a5b38a73416ea721e814">expiration</a> = <a class="code" href="classdtntunnel_1_1DTNTunnel.html#91852c786a634b7ea252d2c559b7ae6d">expiration_</a>;
<a name="l00314"></a>00314 
<a name="l00315"></a>00315     <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> payload;
<a name="l00316"></a>00316     memset(&amp;payload, 0, <span class="keyword">sizeof</span>(payload));
<a name="l00317"></a>00317 
<a name="l00318"></a>00318     <span class="keywordtype">int</span> err = <a class="code" href="dtn__api_8c.html#21b6d705673aae970524972aca3db99f" title="Sets the value of the given payload structure to either a memory buffer or a file...">dtn_set_payload</a>(&amp;payload,
<a name="l00319"></a>00319                               <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>,
<a name="l00320"></a>00320                               bundle-&gt;<a class="code" href="structdtn_1_1APIBundle.html#3b18eab3d0b009956aa6eb3f5ee06478">payload_</a>.buf(),
<a name="l00321"></a>00321                               bundle-&gt;<a class="code" href="structdtn_1_1APIBundle.html#3b18eab3d0b009956aa6eb3f5ee06478">payload_</a>.len());
<a name="l00322"></a>00322     <span class="keywordflow">if</span> (err != 0) {
<a name="l00323"></a>00323         log_err(<span class="stringliteral">"error setting payload: %s"</span>,
<a name="l00324"></a>00324                 <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00325"></a>00325         <span class="keywordflow">return</span> err;
<a name="l00326"></a>00326     }
<a name="l00327"></a>00327     
<a name="l00328"></a>00328     <a class="code" href="structdtn__bundle__id__t.html" title="Type definition for a unique bundle identifier.">dtn_bundle_id_t</a> <a class="code" href="dtncat_8c.html#0d43174f8d3844aa5df38af2712ccb00">bundle_id</a>;
<a name="l00329"></a>00329     memset(&amp;bundle_id, 0, <span class="keyword">sizeof</span>(bundle_id));
<a name="l00330"></a>00330 
<a name="l00331"></a>00331     err = <a class="code" href="dtn__api_8c.html#9bcce797cfff268e49c0f5b2e5f21788" title="Send a bundle either from memory or from a file.">dtn_send</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#53cb6037273071a48527fa9dd15b1a0c">send_handle_</a>, <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00d21fdf39ccc69d6790aec0c70ce5f972">DTN_REG_DEFER</a>, &amp;spec, &amp;payload, &amp;bundle_id);
<a name="l00332"></a>00332 
<a name="l00333"></a>00333     <span class="keywordflow">if</span> (err != 0) {
<a name="l00334"></a>00334         <span class="keywordflow">return</span> <a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#53cb6037273071a48527fa9dd15b1a0c">send_handle_</a>);
<a name="l00335"></a>00335     }
<a name="l00336"></a>00336     
<a name="l00337"></a>00337     <span class="keywordflow">return</span> <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>;
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339 
<a name="l00340"></a>00340 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00341"></a>00341 <span class="keywordtype">int</span>
<a name="l00342"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#85209bf6d41ad77c86b31d4cb658dfba">00342</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#85209bf6d41ad77c86b31d4cb658dfba" title="Called for arriving bundles.">DTNTunnel::handle_bundle</a>(<a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a>* spec,
<a name="l00343"></a>00343                          <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a>* payload)
<a name="l00344"></a>00344 {
<a name="l00345"></a>00345     <a class="code" href="structdtn_1_1APIBundle.html" title="Small encapsulating structure for API bundles.">dtn::APIBundle</a>* b = <span class="keyword">new</span> <a class="code" href="structdtn_1_1APIBundle.html" title="Small encapsulating structure for API bundles.">dtn::APIBundle</a>();
<a name="l00346"></a>00346     b-&gt;<a class="code" href="structdtn_1_1APIBundle.html#d471b3cf2a0f7ff801f531da478d284b">spec_</a> = *spec;
<a name="l00347"></a>00347     <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(payload-&gt;<a class="code" href="structdtn__bundle__payload__t.html#4877c653f99a90c38ae8fdb4a1774247">location</a> == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>);
<a name="l00348"></a>00348 
<a name="l00349"></a>00349     <span class="keywordtype">int</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = payload-&gt;<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>;
<a name="l00350"></a>00350 
<a name="l00351"></a>00351     <span class="keywordflow">if</span> (len &lt; (<span class="keywordtype">int</span>)<span class="keyword">sizeof</span>(<a class="code" href="structdtntunnel_1_1DTNTunnel_1_1BundleHeader.html" title="Struct to encapsulate the header sent with each tunneled bundle.">BundleHeader</a>)) {
<a name="l00352"></a>00352         log_err(<span class="stringliteral">"too short bundle: len %d &lt; sizeof bundle header"</span>, len);
<a name="l00353"></a>00353         <span class="keyword">delete</span> b;
<a name="l00354"></a>00354         <span class="keywordflow">return</span> -1;
<a name="l00355"></a>00355     }
<a name="l00356"></a>00356     
<a name="l00357"></a>00357     <span class="keywordtype">char</span>* dst = b-&gt;<a class="code" href="structdtn_1_1APIBundle.html#3b18eab3d0b009956aa6eb3f5ee06478">payload_</a>.buf(len);
<a name="l00358"></a>00358     memcpy(dst, payload-&gt;<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#45cd21fd96fced99995450f0fca848d5">buf_val</a>, len);
<a name="l00359"></a>00359     b-&gt;<a class="code" href="structdtn_1_1APIBundle.html#3b18eab3d0b009956aa6eb3f5ee06478">payload_</a>.set_len(len);
<a name="l00360"></a>00360     
<a name="l00361"></a>00361     <a class="code" href="structdtntunnel_1_1DTNTunnel_1_1BundleHeader.html" title="Struct to encapsulate the header sent with each tunneled bundle.">BundleHeader</a>* hdr = (<a class="code" href="structdtntunnel_1_1DTNTunnel_1_1BundleHeader.html" title="Struct to encapsulate the header sent with each tunneled bundle.">BundleHeader</a>*)dst;
<a name="l00362"></a>00362     
<a name="l00363"></a>00363     <span class="keywordflow">switch</span> (hdr-&gt;<a class="code" href="structdtntunnel_1_1DTNTunnel_1_1BundleHeader.html#bdc835468bf4f3754733297e1b0c691f">protocol_</a>) {
<a name="l00364"></a>00364     <span class="keywordflow">case</span> IPPROTO_UDP: <a class="code" href="classdtntunnel_1_1DTNTunnel.html#27f499ca92b3183653c6d1bc4fb11e3f">udptunnel_</a>-&gt;<a class="code" href="classdtntunnel_1_1UDPTunnel.html#358a6151f9569a28c3d0a38a4e76d131" title="Handle a newly arriving bundle.">handle_bundle</a>(b); <span class="keywordflow">break</span>;
<a name="l00365"></a>00365     <span class="keywordflow">case</span> IPPROTO_TCP: <a class="code" href="classdtntunnel_1_1DTNTunnel.html#b903e1e1b501e9523c31f910dda3ef8a">tcptunnel_</a>-&gt;<a class="code" href="classdtntunnel_1_1TCPTunnel.html#9edfdd42b7d3de85e4cebd37af4793ed" title="Handle a newly arriving bundle.">handle_bundle</a>(b); <span class="keywordflow">break</span>;
<a name="l00366"></a>00366     <span class="keywordflow">default</span>:
<a name="l00367"></a>00367         log_err(<span class="stringliteral">"unknown protocol %d in %d byte tunnel bundle"</span>,
<a name="l00368"></a>00368                 hdr-&gt;<a class="code" href="structdtntunnel_1_1DTNTunnel_1_1BundleHeader.html#bdc835468bf4f3754733297e1b0c691f">protocol_</a>, len);
<a name="l00369"></a>00369         <span class="keyword">delete</span> b;
<a name="l00370"></a>00370         <span class="keywordflow">return</span> -1;
<a name="l00371"></a>00371     }
<a name="l00372"></a>00372 
<a name="l00373"></a>00373     <span class="keywordflow">return</span> 0;
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375 
<a name="l00376"></a>00376 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00377"></a>00377 <span class="keywordtype">int</span>
<a name="l00378"></a><a class="code" href="classdtntunnel_1_1DTNTunnel.html#28e31b9cb4c03e4b4e46dc1d2bb5e17b">00378</a> <a class="code" href="classdtntunnel_1_1DTNTunnel.html#28e31b9cb4c03e4b4e46dc1d2bb5e17b" title="Main application loop.">DTNTunnel::main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
<a name="l00379"></a>00379 {
<a name="l00380"></a>00380     init_app(argc, argv);
<a name="l00381"></a>00381 
<a name="l00382"></a>00382     log_notice(<span class="stringliteral">"DTNTunnel starting up..."</span>);
<a name="l00383"></a>00383 
<a name="l00384"></a>00384     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#d4470c2781140d3f4ee5d8b2909e143e">init_tunnel</a>();
<a name="l00385"></a>00385     <a class="code" href="classdtntunnel_1_1DTNTunnel.html#0742d0cd0fb5f5e4e4284a0c8ffbd754">init_registration</a>();
<a name="l00386"></a>00386 
<a name="l00387"></a>00387     <span class="comment">// if we've daemonized, now is the time to notify our parent</span>
<a name="l00388"></a>00388     <span class="comment">// process that we've successfully initialized</span>
<a name="l00389"></a>00389     <span class="keywordflow">if</span> (daemonize_) {
<a name="l00390"></a>00390         daemonizer_.notify_parent(0);
<a name="l00391"></a>00391     }
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     log_debug(<span class="stringliteral">"DTNTunnel starting receive loop..."</span>);
<a name="l00394"></a>00394     
<a name="l00395"></a>00395     <span class="keywordflow">while</span> (1) {
<a name="l00396"></a>00396         <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a>    spec;
<a name="l00397"></a>00397         <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> payload;
<a name="l00398"></a>00398 
<a name="l00399"></a>00399         memset(&amp;spec,    0, <span class="keyword">sizeof</span>(spec));
<a name="l00400"></a>00400         memset(&amp;payload, 0, <span class="keyword">sizeof</span>(payload));
<a name="l00401"></a>00401     
<a name="l00402"></a>00402         log_debug(<span class="stringliteral">"calling dtn_recv..."</span>);
<a name="l00403"></a>00403         <span class="keywordtype">int</span> err = <a class="code" href="dtn__api_8c.html#7005346bb34aabb5b6332690871fe3f4" title="Blocking receive for a bundle, filling in the spec and payload structures with the...">dtn_recv</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>, &amp;spec, <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>, &amp;payload,
<a name="l00404"></a>00404                            <a class="code" href="dtn__types_8h.html#3a0e6ca40c3771f6174cb4e15cff7903" title="An infinite wait is a timeout of -1.">DTN_TIMEOUT_INF</a>);
<a name="l00405"></a>00405         <span class="keywordflow">if</span> (err != 0) {
<a name="l00406"></a>00406             log_err(<span class="stringliteral">"error in dtn_recv: %s"</span>,
<a name="l00407"></a>00407                     <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>)));
<a name="l00408"></a>00408             <span class="keywordflow">break</span>;
<a name="l00409"></a>00409         }
<a name="l00410"></a>00410 
<a name="l00411"></a>00411         
<a name="l00412"></a>00412         log_info(<span class="stringliteral">"got %d byte bundle"</span>, payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>);
<a name="l00413"></a>00413 
<a name="l00414"></a>00414         <a class="code" href="classdtntunnel_1_1DTNTunnel.html#85209bf6d41ad77c86b31d4cb658dfba" title="Called for arriving bundles.">handle_bundle</a>(&amp;spec, &amp;payload);
<a name="l00415"></a>00415 
<a name="l00416"></a>00416         <a class="code" href="dtn__api_8c.html#50a363bf1bf2803892afc1438ab62cff" title="Frees dynamic storage allocated by the xdr for a bundle payload in dtn_recv.">dtn_free_payload</a>(&amp;payload);
<a name="l00417"></a>00417     }
<a name="l00418"></a>00418 
<a name="l00419"></a>00419     <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#28be33dd1f60b5624942163d3631bd1a">recv_handle_</a>);
<a name="l00420"></a>00420     <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(<a class="code" href="classdtntunnel_1_1DTNTunnel.html#53cb6037273071a48527fa9dd15b1a0c">send_handle_</a>);
<a name="l00421"></a>00421     
<a name="l00422"></a>00422     <span class="keywordflow">return</span> 0;
<a name="l00423"></a>00423 }
<a name="l00424"></a>00424 
<a name="l00425"></a>00425 } <span class="comment">// namespace dtntunnel</span>
<a name="l00426"></a>00426 
<a name="l00427"></a>00427 <span class="keywordtype">int</span>
<a name="l00428"></a><a class="code" href="DTNTunnel_8cc.html#3c04138a5bfe5d72780bb7e82a18e627">00428</a> <a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
<a name="l00429"></a>00429 {
<a name="l00430"></a>00430     dtntunnel::DTNTunnel::create();
<a name="l00431"></a>00431     dtntunnel::DTNTunnel::instance()-&gt;main(argc, argv);
<a name="l00432"></a>00432 }
</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>