Your advice helped considerably. Thank  you.<br><br>Sean M Hollingsworth<br><br><div class="gmail_quote">On Sat, Aug 8, 2009 at 4:49 PM,  <span dir="ltr">&lt;<a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 6 Aug, 03:47 pm, <a href="mailto:smhollingsworth@gmail.com">smhollingsworth@gmail.com</a> wrote:<br>

&gt;I 19ve got an app written that runs as a service using<br>
<div class="im">&gt;twisted.application.service that I need to tunnel through SSH. Right<br>
&gt;now, I<br>
&gt;use a script that makes use of Paramiko (and runs separate from my app)<br>
&gt;to<br>
</div>&gt;set up a tunnel. That more or less works, but I 19ve had some problems<br>
<div class="im">&gt;with<br>
&gt;the tunnel just going away and would like to integrate the tunneling<br>
&gt;into<br>
</div>&gt;the app, using conch. I 19ve found an example of tunneling via conch, at<br>
<div class="im">&gt;<a href="http://twistedmatrix.com/pipermail/twisted-" target="_blank">http://twistedmatrix.com/pipermail/twisted-</a><br>
&gt;python/2009-February/019196.html,<br>
&gt;that I think I can use as a base to add the code to my app.<br>
&gt;<br>
&gt;Right now my app is basically:<br>
&gt;<br>
&gt;class DataPuller(service.Service):<br>
&gt;    ...Code for my app...<br>
&gt;    ... The app pulls data from a database and I can only connect to the<br>
&gt;server via SSH...<br>
&gt;<br>
</div>&gt;application = service.Application( 18Data_puller 19)<br>
<div class="im">&gt;dpService = DataPuller()<br>
&gt;dpService.setServiceParent(application)<br>
&gt;<br>
</div>&gt;My main problems are that I 19m not sure whether or not the example<br>
<div class="im">&gt;linked to<br>
&gt;above is a good one for tunneling with conch and, if it is, how do I<br>
&gt;merge<br>
&gt;the example tunneling code with my app code. From the example, where<br>
&gt;the<br>
&gt;code is:<br>
<br>
</div>The example you linked to sets up the traditional port forwarding<br>
behavior.<br>
A local port is opened and connections to it are tunneled over the SSH<br>
connection, where data is then delivered to some address accessible from<br>
the server on the other end of the SSH connection.<br>
<br>
This is fine and should work, and probably very closely mirrors what<br>
you&#39;re<br>
doing with Paramiko, so if you&#39;re happy with that, you should go for it.<br>
<br>
However, it&#39;s also possible for you to do this tunneling without opening<br>
the extra local port.  Since your application and the SSH client code<br>
are<br>
all in the same process, you don&#39;t need the TCP connection to a local<br>
port<br>
to do this IPC to interact wiht the tunnel.  You can set up the tunnel<br>
part<br>
of things, but instead of binding a local port to accept connections on,<br>
you can just open a connection over the tunnel and write bytes into it<br>
with<br>
API calls.<br>
<br>
I *don&#39;t* have an example of doing things this way, and I don&#39;t even<br>
know<br>
exactly what it involves. ;)  However, the example you linked to gives a<br>
clue about where to start on this approach: when it binds the local<br>
port,<br>
it uses the forwarding.SSHListenForwardingFactory factory, so I&#39;d start<br>
by looking at that class and see what it does.  The rest is just<br>
mimicking<br>
its behavior without actually using reactor.listenTCP.<br>
<div class="im">&gt;class Connection(connection.SSHConnection):<br>
&gt;        .<br>
&gt;        .<br>
&gt;        .<br>
&gt;        def serviceStarted(self):<br>
&gt;<br>
&gt;Do I instantiate my DataPuller class there, in serviceStarted (and not<br>
&gt;subclass from service.Service)? If so, how do I wrap the tunneling code<br>
&gt;so<br>
&gt;that I can make it a service? If not, do I need put the tunneling code<br>
&gt;inside my DataPuller class? What would that look like?<br>
<br>
</div>If you want things to happen when your program starts or when it is<br>
about<br>
to stop, then using service.Service is still a good idea.  That&#39;s the<br>
easy<br>
way to hook into startup and shutdown events.  However, you may not want<br>
to do anything other than set up (or tear down) the SSH connection in<br>
your<br>
service.Service subclass.  Creating your new non-Service DataPuller in<br>
the<br>
Connection&#39;s serviceStarted (or maybe even a little later - after you<br>
actually set up the connection over the tunnel over the connection) then<br>
makes sense.<br>
<br>
Jean-Paul<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br>