summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-09-25 03:15:20 +0300
committerDevaev Maxim <[email protected]>2019-09-25 03:15:20 +0300
commit5c4e8f7962fe89ee0dcdea9ba859f7045fa2d6d8 (patch)
tree785b2454f56480464d18c71c2221b262bb92eabb /kvmd/apps
parent5d437c58e342bcb9847e419e46c751b3ed70e747 (diff)
extended msd api for future otg
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/__init__.py1
-rw-r--r--kvmd/apps/kvmd/server.py23
2 files changed, 19 insertions, 5 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 048c2b9d..8014d8f6 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -183,6 +183,7 @@ def _get_config_scheme() -> Dict:
"unix_rm": Option(False, type=valid_bool),
"unix_mode": Option(0, type=valid_unix_mode),
"heartbeat": Option(3.0, type=valid_float_f01),
+ "sync_chunk_size": Option(65536, type=(lambda arg: valid_number(arg, min=1024))),
"access_log_format": Option("[%P / %{X-Real-IP}i] '%r' => %s; size=%b ---"
" referer='%{Referer}i'; user_agent='%{User-Agent}i'"),
},
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 311cb6fd..4f197641 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -67,6 +67,7 @@ from ...validators.kvm import valid_atx_button
from ...validators.kvm import valid_log_seek
from ...validators.kvm import valid_stream_quality
from ...validators.kvm import valid_stream_fps
+from ...validators.kvm import valid_msd_image_name
from ...validators.kvm import valid_hid_key
from ...validators.kvm import valid_hid_mouse_move
from ...validators.kvm import valid_hid_mouse_button
@@ -250,6 +251,7 @@ class Server: # pylint: disable=too-many-instance-attributes
self.__streamer = streamer
self.__heartbeat: Optional[float] = None # Assigned in run() for consistance
+ self.__sync_chunk_size: Optional[int] = None # Ditto
self.__sockets: Set[aiohttp.web.WebSocketResponse] = set()
self.__sockets_lock = asyncio.Lock()
@@ -266,6 +268,7 @@ class Server: # pylint: disable=too-many-instance-attributes
unix_rm: bool,
unix_mode: int,
heartbeat: float,
+ sync_chunk_size: int,
access_log_format: str,
) -> None:
@@ -274,6 +277,7 @@ class Server: # pylint: disable=too-many-instance-attributes
setproctitle.setproctitle("[main] " + setproctitle.getproctitle())
self.__heartbeat = heartbeat
+ self.__sync_chunk_size = sync_chunk_size
assert port or unix_path
if unix_path:
@@ -474,31 +478,40 @@ class Server: # pylint: disable=too-many-instance-attributes
async def __msd_disconnect_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
return _json(await self.__msd.disconnect())
+ @_exposed("POST", "/msd/select")
+ async def __msd_select_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ return _json(await self.__msd.select(valid_msd_image_name(request.query.get("image_name"))))
+
+ @_exposed("POST", "/msd/remove")
+ async def __msd_remove_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ return _json(await self.__msd.remove(valid_msd_image_name(request.query.get("image_name"))))
+
@_exposed("POST", "/msd/write")
async def __msd_write_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ assert self.__sync_chunk_size is not None
logger = get_logger(0)
reader = await request.multipart()
+ image_name = ""
written = 0
try:
async with self.__msd:
name_field = await _get_multipart_field(reader, "image_name")
- image_name = (await name_field.read()).decode("utf-8")[:256]
+ image_name = valid_msd_image_name((await name_field.read()).decode("utf-8"))
data_field = await _get_multipart_field(reader, "image_data")
logger.info("Writing image %r to MSD ...", image_name)
await self.__msd.write_image_info(image_name, False)
- chunk_size = self.__msd.get_chunk_size()
while True:
- chunk = await data_field.read_chunk(chunk_size)
+ chunk = await data_field.read_chunk(self.__sync_chunk_size)
if not chunk:
break
written = await self.__msd.write_image_chunk(chunk)
await self.__msd.write_image_info(image_name, True)
finally:
if written != 0:
- logger.info("Written %d bytes to MSD", written)
- return _json({"written": written})
+ logger.info("Written image %r with size=%d bytes to MSD", image_name, written)
+ return _json({"image": {"name": image_name, "size": written}})
@_exposed("POST", "/msd/reset")
async def __msd_reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response: