mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-30 09:38:53 +00:00
Correctly initialize connection to VPCS console
This commit is contained in:
parent
db8296f548
commit
69f154d9cc
@ -332,6 +332,7 @@ class BaseNode:
|
||||
if not self._wrap_console:
|
||||
return
|
||||
(reader, writer) = yield from asyncio.open_connection(host="127.0.0.1", port=self._internal_console_port)
|
||||
yield from AsyncioTelnetServer.write_client_intro(writer, echo=True)
|
||||
server = AsyncioTelnetServer(reader=reader, writer=writer, binary=True, echo=True)
|
||||
self._wrapper_telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)
|
||||
|
||||
|
@ -73,32 +73,48 @@ class AsyncioTelnetServer:
|
||||
# it's our job (or the wrapped app) to send back the data
|
||||
self._echo = echo
|
||||
|
||||
@staticmethod
|
||||
@asyncio.coroutine
|
||||
def write_client_intro(writer, echo=False):
|
||||
# Send initial telnet session opening
|
||||
if echo:
|
||||
writer.write(bytes([IAC, WILL, ECHO]))
|
||||
else:
|
||||
writer.write(bytes([
|
||||
IAC, WONT, ECHO,
|
||||
IAC, DONT, ECHO]))
|
||||
yield from writer.drain()
|
||||
|
||||
@asyncio.coroutine
|
||||
def _write_intro(self, writer, binary=False, echo=False):
|
||||
# Send initial telnet session opening
|
||||
if echo:
|
||||
writer.write(bytes([IAC, WILL, ECHO]))
|
||||
else:
|
||||
writer.write(bytes([
|
||||
IAC, WONT, ECHO,
|
||||
IAC, DONT, ECHO]))
|
||||
|
||||
if binary:
|
||||
writer.write(bytes([
|
||||
IAC, WILL, SGA,
|
||||
IAC, WILL, BINARY,
|
||||
IAC, DO, BINARY]))
|
||||
else:
|
||||
writer.write(bytes([
|
||||
IAC, WONT, SGA,
|
||||
IAC, DONT, SGA,
|
||||
IAC, WONT, BINARY,
|
||||
IAC, DONT, BINARY]))
|
||||
yield from writer.drain()
|
||||
|
||||
@asyncio.coroutine
|
||||
def run(self, network_reader, network_writer):
|
||||
# Keep track of connected clients
|
||||
self._clients.add(network_writer)
|
||||
|
||||
try:
|
||||
# Send initial telnet session opening
|
||||
if self._echo:
|
||||
network_writer.write(bytes([IAC, WILL, ECHO]))
|
||||
else:
|
||||
network_writer.write(bytes([
|
||||
IAC, WONT, ECHO,
|
||||
IAC, DONT, ECHO]))
|
||||
|
||||
if self._binary:
|
||||
network_writer.write(bytes([
|
||||
IAC, WILL, SGA,
|
||||
IAC, WILL, BINARY,
|
||||
IAC, DO, BINARY]))
|
||||
else:
|
||||
network_writer.write(bytes([
|
||||
IAC, WONT, SGA,
|
||||
IAC, DONT, SGA,
|
||||
IAC, WONT, BINARY,
|
||||
IAC, DONT, BINARY]))
|
||||
yield from network_writer.drain()
|
||||
yield from self._write_intro(network_writer, echo=self._echo, binary=self._binary)
|
||||
|
||||
yield from self._process(network_reader, network_writer)
|
||||
except ConnectionResetError:
|
||||
@ -149,7 +165,6 @@ class AsyncioTelnetServer:
|
||||
return_when=asyncio.FIRST_COMPLETED)
|
||||
for coro in done:
|
||||
data = coro.result()
|
||||
|
||||
if coro == network_read:
|
||||
if network_reader.at_eof():
|
||||
raise ConnectionResetError()
|
||||
|
Loading…
Reference in New Issue
Block a user