Discussion:
Howto know channel is open after check_channel_direct_tcpip_request()?
Graham Lee Bevan
2010-06-27 14:15:44 UTC
Permalink
Hi,
I'm trying to have a paramiko Server open a tunnel, in hook
check_channel_direct_tcpip_request() I create a new thread to handle the
request - however the channel is not open until paramiko (Transport)
accepts the connection (from the server_accepts queue). How can my
thread know when the accept is complete and the channel has a valid
descriptor to start a select() on?

...
def check_channel_direct_tcpip_request(self, chanid, origin,
destination):
# start the Local tunnel handler thread
self.ltunthread = LTunHandler(transport=self.transport,
destination=destination, chanid=chanid, debug=True)
self.ltunthread.start()
return paramiko.OPEN_SUCCEEDED

class LTunHandler(threading.Thread):
'''Thread to handle the Local tunnel'''
def __init__(self, name="Local Tunnel handler", transport=None,
destination=None, chanid=None, debug=False):
self.t = transport
self.destination = destination
self.chanid = chanid
self.sshserver = self.t.server_object
self.debug = debug
self._stopevent = threading.Event()
threading.Thread.__init__(self, name=name)

def run(self):
#self.sshserver.tunevent.wait()
#time.sleep(0.1) <<<< Works if I uncomment this <<<<
self.chan = self.t._channels.get(self.chanid)
destination = self.destination

self.lsender = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.lsender.connect(destination)

while not self._stopevent.isSet():
r, w, x = select.select([self.chan, self.lsender],[],[])
for fd in r:
etc...

Without the time.sleep(0.1) this fails with

Exception in thread Local Tunnel handler:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
File
"/usr/lib/python2.6/site-packages/pyXMLRPCssh/sshxmlrpc_sshserver.py",
line 168, in run
r, w, x = select.select([self.chan, self.lsender],[],[])
TypeError: argument must be an int, or have a fileno() method.

because the channel hasn't been accepted yet in Transport.

I'm clearly doing this wrong... Any ideas please?

Regards
glbevan

Loading...