Skip to content

Commit

Permalink
Correctly initialize connection to VPCS console
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-duponchelle committed Nov 8, 2016
1 parent db8296f commit 69f154d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
1 change: 1 addition & 0 deletions gns3server/compute/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def start_wrap_console(self):
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)

Expand Down
57 changes: 36 additions & 21 deletions gns3server/utils/asyncio/telnet_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,48 @@ def __init__(self, reader=None, writer=None, binary=True, echo=False):
# 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:
Expand Down Expand Up @@ -149,7 +165,6 @@ def _process(self, network_reader, network_writer):
return_when=asyncio.FIRST_COMPLETED)
for coro in done:
data = coro.result()

if coro == network_read:
if network_reader.at_eof():
raise ConnectionResetError()
Expand Down

0 comments on commit 69f154d

Please sign in to comment.