mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
Merge branch '2.1' into 2.2
# Conflicts: # gns3server/compute/docker/docker_vm.py # gns3server/utils/asyncio/telnet_server.py
This commit is contained in:
commit
56412b35e0
3 files changed
+42
-17
No files matched your search
@@ -59,10 +59,11 @@ READ_SIZE = 1024
|
||||
|
||||
class TelnetConnection(object):
|
||||
"""Default implementation of telnet connection which may but may not be used."""
|
||||
def __init__(self, reader, writer):
|
||||
def __init__(self, reader, writer, window_size_changed_callback=None):
|
||||
self.is_closing = False
|
||||
self._reader = reader
|
||||
self._writer = writer
|
||||
self._window_size_changed_callback = window_size_changed_callback
|
||||
|
||||
@property
|
||||
def reader(self):
|
||||
@@ -80,10 +81,12 @@ class TelnetConnection(object):
|
||||
"""Method called when client is disconnecting"""
|
||||
pass
|
||||
|
||||
def window_size_changed(self, columns, rows):
|
||||
async def window_size_changed(self, columns, rows):
|
||||
"""Method called when window size changed, only can occur when
|
||||
`naws` flag is enable in server configuration."""
|
||||
pass
|
||||
|
||||
if self._window_size_changed_callback:
|
||||
await self._window_size_changed_callback(columns, rows)
|
||||
|
||||
async def feed(self, data):
|
||||
"""
|
||||
@@ -110,7 +113,7 @@ class TelnetConnection(object):
|
||||
class AsyncioTelnetServer:
|
||||
MAX_NEGOTIATION_READ = 10
|
||||
|
||||
def __init__(self, reader=None, writer=None, binary=True, echo=False, naws=False, connection_factory=None):
|
||||
def __init__(self, reader=None, writer=None, binary=True, echo=False, naws=False, window_size_changed_callback=None, connection_factory=None):
|
||||
"""
|
||||
Initializes telnet server
|
||||
:param naws when True make a window size negotiation
|
||||
@@ -125,6 +128,7 @@ class AsyncioTelnetServer:
|
||||
self._lock = asyncio.Lock()
|
||||
self._reader_process = None
|
||||
self._current_read = None
|
||||
self._window_size_changed_callback = window_size_changed_callback
|
||||
|
||||
self._binary = binary
|
||||
# If echo is true when the client send data
|
||||
@@ -133,8 +137,8 @@ class AsyncioTelnetServer:
|
||||
self._echo = echo
|
||||
self._naws = naws
|
||||
|
||||
def default_connection_factory(reader, writer):
|
||||
return TelnetConnection(reader, writer)
|
||||
def default_connection_factory(reader, writer, window_size_changed_callback):
|
||||
return TelnetConnection(reader, writer, window_size_changed_callback)
|
||||
|
||||
if connection_factory is None:
|
||||
connection_factory = default_connection_factory
|
||||
@@ -181,7 +185,7 @@ class AsyncioTelnetServer:
|
||||
|
||||
async def run(self, network_reader, network_writer):
|
||||
# Keep track of connected clients
|
||||
connection = self._connection_factory(network_reader, network_writer)
|
||||
connection = self._connection_factory(network_reader, network_writer, self._window_size_changed_callback)
|
||||
self._connections[network_writer] = connection
|
||||
|
||||
try:
|
||||
@@ -293,14 +297,14 @@ class AsyncioTelnetServer:
|
||||
cmd.append(buffer[location])
|
||||
return op
|
||||
|
||||
def _negotiate(self, data, connection):
|
||||
async def _negotiate(self, data, connection):
|
||||
""" Performs negotiation commands"""
|
||||
|
||||
command, payload = data[0], data[1:]
|
||||
if command == NAWS:
|
||||
if len(payload) == 4:
|
||||
columns, rows = struct.unpack(str('!HH'), bytes(payload))
|
||||
connection.window_size_changed(columns, rows)
|
||||
await connection.window_size_changed(columns, rows)
|
||||
else:
|
||||
log.warning('Wrong number of NAWS bytes')
|
||||
else:
|
||||
@@ -358,7 +362,7 @@ class AsyncioTelnetServer:
|
||||
break
|
||||
|
||||
# SE command is followed by IAC, remove the last two operations from stack
|
||||
self._negotiate(negotiation[0:-2], connection)
|
||||
await self._negotiate(negotiation[0:-2], connection)
|
||||
|
||||
# This must be a 3-byte TELNET command
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user