summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-07-23 11:38:27 +0300
committerDevaev Maxim <[email protected]>2020-07-23 11:38:27 +0300
commitca3641c85b4231106acb259c9cdae6fca40e2fef (patch)
tree880df9fd8f42edfc309aa717f4f18c3042d255e0 /kvmd
parent1d7f949b9e33195ec584382cf9bdb73829341c45 (diff)
client port
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/vnc/rfb/__init__.py22
-rw-r--r--kvmd/apps/vnc/rfb/stream.py2
-rw-r--r--kvmd/apps/vnc/server.py20
3 files changed, 22 insertions, 22 deletions
diff --git a/kvmd/apps/vnc/rfb/__init__.py b/kvmd/apps/vnc/rfb/__init__.py
index 96e70895..6deddbb1 100644
--- a/kvmd/apps/vnc/rfb/__init__.py
+++ b/kvmd/apps/vnc/rfb/__init__.py
@@ -83,7 +83,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
async def _run(self, **coros: Coroutine) -> None:
logger = get_logger(0)
- logger.info("[entry] [%s]: Starting client tasks ...", self._remote)
+ logger.info("[entry] %s: Starting client tasks ...", self._remote)
tasks = list(map(asyncio.create_task, [ # type: ignore # Я хз, почему github action фейлится здесь
self.__wrapper(name, coro)
for (name, coro) in {"main": self.__main_task_loop(), **coros}.items()
@@ -95,7 +95,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
await self._close()
- logger.info("[entry] [%s]: Connection closed", self._remote)
+ logger.info("[entry] %s: Connection closed", self._remote)
async def __wrapper(self, name: str, coro: Coroutine) -> None:
logger = get_logger(0)
@@ -103,14 +103,14 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
await coro
raise RuntimeError("Subtask just finished without any exception")
except asyncio.CancelledError:
- logger.info("[%s] [%s]: Cancelling subtask ...", name, self._remote)
+ logger.info("[%s] %s: Cancelling subtask ...", name, self._remote)
raise
except RfbConnectionError as err:
- logger.info("[%s] [%s]: Gone: %s", name, self._remote, err)
+ logger.info("[%s] %s: Gone: %s", name, self._remote, err)
except (RfbError, ssl.SSLError) as err:
- logger.error("[%s] [%s]: Error: %s", name, self._remote, err)
+ logger.error("[%s] %s: Error: %s", name, self._remote, err)
except Exception:
- logger.exception("[%s] [%s]: Unhandled exception", name, self._remote)
+ logger.exception("[%s] %s: Unhandled exception", name, self._remote)
async def __main_task_loop(self) -> None:
await self.__handshake_version()
@@ -200,7 +200,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
except ValueError:
raise RfbError(f"Invalid version response: {response!r}")
self.__rfb_version = (3 if version == 5 else version)
- get_logger(0).info("[main] [%s]: Using RFB version 3.%d", self._remote, self.__rfb_version)
+ get_logger(0).info("[main] %s: Using RFB version 3.%d", self._remote, self.__rfb_version)
# =====
@@ -225,7 +225,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
raise RfbError(f"Invalid security type: {sec_type}")
(sec_name, handler) = sec_types[sec_type]
- get_logger(0).info("[main] [%s]: Using %s security type", self._remote, sec_name)
+ get_logger(0).info("[main] %s: Using %s security type", self._remote, sec_name)
await handler()
async def __handshake_security_vencrypt(self) -> None:
@@ -265,7 +265,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
raise RfbError(f"Invalid VeNCrypt auth type: {auth_type}")
(auth_name, tls, handler) = auth_types[auth_type]
- get_logger(0).info("[main] [%s]: Using %s auth type", self._remote, auth_name)
+ get_logger(0).info("[main] %s: Using %s auth type", self._remote, auth_name)
if tls:
await self._write_struct("B", 1) # Ack
@@ -322,7 +322,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
async def __handshake_security_send_result(self, allow: bool, allow_msg: str, deny_msg: str, deny_reason: str) -> None:
if allow:
- get_logger(0).info("[main] [%s]: %s", self._remote, allow_msg)
+ get_logger(0).info("[main] %s: %s", self._remote, allow_msg)
await self._write_struct("L", 0)
else:
await self._write_struct("L", 1, drain=(self.__rfb_version < 8))
@@ -381,7 +381,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
if encodings_count > 1024:
raise RfbError(f"Too many encodings: {encodings_count}")
self._encodings = RfbClientEncodings(frozenset(await self._read_struct("l" * encodings_count)))
- get_logger(0).info("[main] [%s]: Features: resize=%d; rename=%d; leds=%d",
+ get_logger(0).info("[main] %s: Features: resize=%d; rename=%d; leds=%d",
self._remote, self._encodings.has_resize, self._encodings.has_rename, self._encodings.has_leds_state)
self.__check_tight_jpeg()
await self._on_set_encodings()
diff --git a/kvmd/apps/vnc/rfb/stream.py b/kvmd/apps/vnc/rfb/stream.py
index f08da178..3f2d38b8 100644
--- a/kvmd/apps/vnc/rfb/stream.py
+++ b/kvmd/apps/vnc/rfb/stream.py
@@ -32,7 +32,7 @@ from .errors import RfbConnectionError
# =====
def rfb_format_remote(writer: asyncio.StreamWriter) -> str:
- return str(writer.transport.get_extra_info("peername")[0])
+ return "[%s]:%d" % (writer.transport.get_extra_info("peername")[:2])
async def rfb_close_writer(writer: asyncio.StreamWriter) -> bool:
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index 55ff4e7c..2ab03f36 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -140,7 +140,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
assert self.__kvmd_session
try:
async with self.__kvmd_session.ws() as self.__kvmd_ws:
- logger.info("[kvmd] [%s]: Connected to KVMD websocket", self._remote)
+ logger.info("[kvmd] %s: Connected to KVMD websocket", self._remote)
self.__ws_connected.set_result(None)
async for event in self.__kvmd_ws.communicate():
await self.__process_ws_event(event)
@@ -177,14 +177,14 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
streaming = False
async for (online, width, height, jpeg) in self.__streamer.read_stream():
if not streaming:
- logger.info("[streamer] [%s]: Streaming ...", self._remote)
+ logger.info("[streamer] %s: Streaming ...", self._remote)
streaming = True
if online:
await self.__send_fb_real(width, height, jpeg)
else:
await self.__send_fb_stub("No signal")
except StreamerError as err:
- logger.info("[streamer] [%s]: Waiting for stream: %s", self._remote, err)
+ logger.info("[streamer] %s: Waiting for stream: %s", self._remote, err)
await self.__send_fb_stub("Waiting for stream ...")
await asyncio.sleep(1)
@@ -260,7 +260,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
assert self.__authorized.done()
assert self.__kvmd_session
logger = get_logger(0)
- logger.info("[main] [%s]: Printing %d characters ...", self._remote, len(text))
+ logger.info("[main] %s: Printing %d characters ...", self._remote, len(text))
try:
(default, available) = await self.__kvmd_session.hid.get_keymaps()
await self.__kvmd_session.hid.print(
@@ -269,12 +269,12 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
keymap_name=(self.__keymap_name if self.__keymap_name in available else default),
)
except Exception:
- logger.exception("[main] [%s]: Can't print characters", self._remote)
+ logger.exception("[main] %s: Can't print characters", self._remote)
async def _on_set_encodings(self) -> None:
assert self.__authorized.done()
assert self.__kvmd_session
- get_logger(0).info("[main] [%s]: Applying streamer params: quality=%d%%; desired_fps=%d ...",
+ get_logger(0).info("[main] %s: Applying streamer params: quality=%d%%; desired_fps=%d ...",
self._remote, self._encodings.tight_jpeg_quality, self.__desired_fps)
await self.__kvmd_session.streamer.set_params(self._encodings.tight_jpeg_quality, self.__desired_fps)
@@ -322,7 +322,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
async def handle_client(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
logger = get_logger(0)
remote = rfb_format_remote(writer)
- logger.info("[entry] [%s]: Connected client", remote)
+ logger.info("[entry] %s: Connected client", remote)
try:
sock = writer.get_extra_info("socket")
if no_delay:
@@ -341,7 +341,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
async with kvmd.make_session("", "") as kvmd_session:
none_auth_only = await kvmd_session.auth.check()
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
- logger.error("[entry] [%s]: Can't check KVMD auth mode: %s: %s", remote, type(err).__name__, err)
+ logger.error("[entry] %s: Can't check KVMD auth mode: %s: %s", remote, type(err).__name__, err)
return
await _Client(
@@ -359,10 +359,10 @@ class VncServer: # pylint: disable=too-many-instance-attributes
shared_params=shared_params,
).run()
except Exception:
- logger.exception("[entry] [%s]: Unhandled exception in client task", remote)
+ logger.exception("[entry] %s: Unhandled exception in client task", remote)
finally:
if (await rfb_close_writer(writer)):
- logger.info("[entry] [%s]: Connection is closed in an emergency", remote)
+ logger.info("[entry] %s: Connection is closed in an emergency", remote)
self.__handle_client = handle_client