Commit 62fb32d8 authored by ibuler's avatar ibuler

[Feature] support session clone

parent d85e4055
...@@ -9,6 +9,8 @@ import threading ...@@ -9,6 +9,8 @@ import threading
import paramiko import paramiko
import sys import sys
import time
from .utils import ssh_key_gen from .utils import ssh_key_gen
from .interface import SSHInterface from .interface import SSHInterface
from .interactive import InteractiveServer from .interactive import InteractiveServer
...@@ -48,13 +50,13 @@ class SSHServer: ...@@ -48,13 +50,13 @@ class SSHServer:
try: try:
sock, addr = self.sock.accept() sock, addr = self.sock.accept()
logger.info("Get ssh request from {}: {}".format(addr[0], addr[1])) logger.info("Get ssh request from {}: {}".format(addr[0], addr[1]))
thread = threading.Thread(target=self.handle, args=(sock, addr)) thread = threading.Thread(target=self.handle_connection, args=(sock, addr))
thread.daemon = True thread.daemon = True
thread.start() thread.start()
except Exception as e: except Exception as e:
logger.error("Start SSH server error: {}".format(e)) logger.error("Start SSH server error: {}".format(e))
def handle(self, sock, addr): def handle_connection(self, sock, addr):
transport = paramiko.Transport(sock, gss_kex=False) transport = paramiko.Transport(sock, gss_kex=False)
try: try:
transport.load_server_moduli() transport.load_server_moduli()
...@@ -73,17 +75,23 @@ class SSHServer: ...@@ -73,17 +75,23 @@ class SSHServer:
logger.warning("Handle EOF Error") logger.warning("Handle EOF Error")
return return
chan = transport.accept(10) while True:
if chan is None: chan = transport.accept()
logger.warning("No ssh channel get") if chan is None:
return continue
server.event.wait(5)
if not server.event.is_set():
logger.warning("Client not request a valid request, exiting")
return
server.event.wait(5) t = threading.Thread(target=self.handle_chan, args=(chan, request))
if not server.event.is_set(): t.daemon = True
logger.warning("Client not request a valid request, exiting") t.start()
return
def handle_chan(self, chan, request):
client = Client(chan, request) client = Client(chan, request)
print(chan)
print(request)
self.app.add_client(client) self.app.add_client(client)
self.dispatch(client) self.dispatch(client)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment