From ada755cd4be1621d968a8dcdfef8f8269892b084 Mon Sep 17 00:00:00 2001 From: John Fleming Date: Sun, 28 Jan 2024 08:58:01 -0500 Subject: [PATCH] Add SFTelnetProxyMuxer support to start --- gns3server/compute/base_node.py | 64 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/gns3server/compute/base_node.py b/gns3server/compute/base_node.py index efdfaf18..fff28c00 100644 --- a/gns3server/compute/base_node.py +++ b/gns3server/compute/base_node.py @@ -31,7 +31,7 @@ from aiohttp.web import WebSocketResponse from gns3server.utils.interfaces import interfaces from ..compute.port_manager import PortManager from ..utils.asyncio import wait_run_in_executor, locking -#from ..utils.asyncio.telnet_server import AsyncioTelnet +from ..utils.asyncio.telnet_server import AsyncioTelnetServer from ..utils.asyncio.sftelnetproxymuxer import SFTelnetProxyMuxer from ..ubridge.hypervisor import Hypervisor from ..ubridge.ubridge_error import UbridgeError @@ -375,36 +375,42 @@ class BaseNode: if not self._wrap_console or self._console_type != "telnet": return - remaining_trial = 60 - log.info(f"Internal_console_port: {self._internal_console_port}") - while True: - try: - (self._wrap_console_reader, self._wrap_console_writer) = await asyncio.open_connection( - host="127.0.0.1", - port=self._internal_console_port - ) - break - except (OSError, ConnectionRefusedError) as e: - if remaining_trial <= 0: - raise e - await asyncio.sleep(0.1) - remaining_trial -= 1 + #remaining_trial = 60 + #log.info(f"Internal_console_port: {self._internal_console_port}") + # self._internal_console_port == qemu listner port for example + #while True: + # try: + # (self._wrap_console_reader, self._wrap_console_writer) = await asyncio.open_connection( + # host="127.0.0.1", + # port=self._internal_console_port + # ) + # break + # except (OSError, ConnectionRefusedError) as e: + # if remaining_trial <= 0: + # raise e + # await asyncio.sleep(0.1) + # remaining_trial -= 1 ## no longer needed. SFTelnetProxyMuxer handles client handshake - await AsyncioTelnetServer.write_client_intro(self._wrap_console_writer, echo=True) - server = AsyncioTelnetServer( - reader=self._wrap_console_reader, - writer=self._wrap_console_writer, - binary=True, - echo=True - ) + #await AsyncioTelnetServer.write_client_intro(self._wrap_console_writer, echo=True) + #server = AsyncioTelnetServer( + # reader=self._wrap_console_reader, + # writer=self._wrap_console_writer, + # binary=True, + # echo=True + #) + server = SFTelnetProxyMuxer(binary=True, echo=True, remote_port=self._internal_console_port, listen_port=self.console) + await server.start_proxy() # warning: this will raise OSError exception if there is a problem... - log.info(f"self._manager.port_manager.console_host: {self._manager.port_manager.console_host}") - log.info(f"self.console {self.console}") - self._wrapper_telnet_server = await asyncio.start_server( - server.run, - self._manager.port_manager.console_host, - self.console - ) + #log.info(f"self._manager.port_manager.console_host: {self._manager.port_manager.console_host}") + #log.info(f"self.console {self.console}") + # self._manager.port_manager.console_host == bind ip + # self.console == bind port + #self._wrapper_telnet_server = await asyncio.start_server( + # server.run, + # self._manager.port_manager.console_host, + # self.console + #) + async def stop_wrap_console(self): """