From 5a180dd05046499ae0867842bfb3913796b6bd39 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Thu, 24 Sep 2026 12:51:39 +0200 Subject: refactor(node): run signed operations through a table of executors _do_admin_response looked each operation up in a 28-branch elif, every branch the same call. The admin cases of the dispatch golden are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../src/meshbay_node/transport/webrtc/admin.py | 122 +++++++-------------- 1 file changed, 37 insertions(+), 85 deletions(-) (limited to 'packages') diff --git a/packages/meshbay-node/src/meshbay_node/transport/webrtc/admin.py b/packages/meshbay-node/src/meshbay_node/transport/webrtc/admin.py index 1600896..f42d8e8 100644 --- a/packages/meshbay-node/src/meshbay_node/transport/webrtc/admin.py +++ b/packages/meshbay-node/src/meshbay_node/transport/webrtc/admin.py @@ -42,6 +42,39 @@ from meshbay_common.adminop import ( from meshbay_common.crypto import pk_to_b64 from meshbay_common.protocol import MNP +# Which executor runs each signed operation once its signature has been +# checked. Every one runs as a task of the session. +_ADMIN_EXECUTORS = { + OP_FILE_DELETE: "_admin_exec_file_delete", + OP_DIR_DELETE: "_admin_exec_dir_delete", + OP_MEMBER_REVOKE: "_admin_exec_member_revoke", + OP_INVITE_CREATE: "_admin_exec_invite_create", + OP_INVITE_LINK_CREATE: "_admin_exec_invite_link_create", + OP_INVITE_CANCEL: "_admin_exec_invite_cancel", + OP_GEK_ROTATE: "_admin_exec_gek_rotate", + OP_MEMBER_UNPIN: "_admin_exec_member_unpin", + OP_APPS_ENABLED: "_admin_exec_apps_enabled", + OP_TRANSFER_LIMITS: "_admin_exec_transfer_limits", + OP_SET_SCAN_SETTINGS: "_admin_exec_set_scan_settings", + OP_TMDB_CONFIG: "_admin_exec_tmdb_config", + OP_TMDB_ENABLED: "_admin_exec_tmdb_enabled", + OP_TMDB_OVERRIDE: "_admin_exec_tmdb_override", + OP_TMDB_REMATCH: "_admin_exec_tmdb_rematch", + OP_MUSICBRAINZ_ENABLED: "_admin_exec_musicbrainz_enabled", + OP_ROOT_ADD: "_admin_exec_root_add", + OP_ROOT_REMOVE: "_admin_exec_root_remove", + OP_APP_DIRECTORIES: "_admin_exec_app_directories", + OP_CHAT_DIRECTORY: "_admin_exec_chat_directory", + OP_CHAT_LINK_PREVIEW: "_admin_exec_chat_link_preview", + OP_SEARCH_LISTED: "_admin_exec_search_listed", + OP_CHAT_EPOCH: "_admin_exec_chat_epoch", + OP_ROOT_UPDATE: "_admin_exec_root_update", + OP_ROOT_EJECT: "_admin_exec_root_eject", + OP_ROOT_PLUG: "_admin_exec_root_plug", + OP_GROUP_ATTACH: "_admin_exec_group_attach", + OP_GROUP_DETACH: "_admin_exec_group_detach", +} + class AdminMixin: # ── Admin operation challenge/response (finding H5) ────────────────────── @@ -228,89 +261,8 @@ class AdminMixin: ts=pending["ts"], ) - if pending["op"] == OP_FILE_DELETE: - self._spawn( - self._admin_exec_file_delete(pending, transcript, sig_bytes)) - elif pending["op"] == OP_DIR_DELETE: - self._spawn( - self._admin_exec_dir_delete(pending, transcript, sig_bytes)) - elif pending["op"] == OP_MEMBER_REVOKE: - self._spawn( - self._admin_exec_member_revoke(pending, transcript, sig_bytes)) - elif pending["op"] == OP_INVITE_CREATE: - self._spawn( - self._admin_exec_invite_create(pending, transcript, sig_bytes)) - elif pending["op"] == OP_INVITE_LINK_CREATE: - self._spawn( - self._admin_exec_invite_link_create(pending, transcript, sig_bytes)) - elif pending["op"] == OP_INVITE_CANCEL: - self._spawn( - self._admin_exec_invite_cancel(pending, transcript, sig_bytes)) - elif pending["op"] == OP_GEK_ROTATE: - self._spawn( - self._admin_exec_gek_rotate(pending, transcript, sig_bytes)) - elif pending["op"] == OP_MEMBER_UNPIN: - self._spawn( - self._admin_exec_member_unpin(pending, transcript, sig_bytes)) - elif pending["op"] == OP_APPS_ENABLED: - self._spawn( - self._admin_exec_apps_enabled(pending, transcript, sig_bytes)) - elif pending["op"] == OP_TRANSFER_LIMITS: - self._spawn( - self._admin_exec_transfer_limits(pending, transcript, sig_bytes)) - elif pending["op"] == OP_SET_SCAN_SETTINGS: - self._spawn( - self._admin_exec_set_scan_settings(pending, transcript, sig_bytes)) - elif pending["op"] == OP_TMDB_CONFIG: - self._spawn( - self._admin_exec_tmdb_config(pending, transcript, sig_bytes)) - elif pending["op"] == OP_TMDB_ENABLED: - self._spawn( - self._admin_exec_tmdb_enabled(pending, transcript, sig_bytes)) - elif pending["op"] == OP_TMDB_OVERRIDE: - self._spawn( - self._admin_exec_tmdb_override(pending, transcript, sig_bytes)) - elif pending["op"] == OP_TMDB_REMATCH: - self._spawn( - self._admin_exec_tmdb_rematch(pending, transcript, sig_bytes)) - elif pending["op"] == OP_MUSICBRAINZ_ENABLED: - self._spawn( - self._admin_exec_musicbrainz_enabled(pending, transcript, sig_bytes)) - elif pending["op"] == OP_ROOT_ADD: - self._spawn( - self._admin_exec_root_add(pending, transcript, sig_bytes)) - elif pending["op"] == OP_ROOT_REMOVE: - self._spawn( - self._admin_exec_root_remove(pending, transcript, sig_bytes)) - elif pending["op"] == OP_APP_DIRECTORIES: - self._spawn( - self._admin_exec_app_directories(pending, transcript, sig_bytes)) - elif pending["op"] == OP_CHAT_DIRECTORY: - self._spawn( - self._admin_exec_chat_directory(pending, transcript, sig_bytes)) - elif pending["op"] == OP_CHAT_LINK_PREVIEW: - self._spawn( - self._admin_exec_chat_link_preview(pending, transcript, sig_bytes)) - elif pending["op"] == OP_SEARCH_LISTED: - self._spawn( - self._admin_exec_search_listed(pending, transcript, sig_bytes)) - elif pending["op"] == OP_CHAT_EPOCH: - self._spawn( - self._admin_exec_chat_epoch(pending, transcript, sig_bytes)) - elif pending["op"] == OP_ROOT_UPDATE: - self._spawn( - self._admin_exec_root_update(pending, transcript, sig_bytes)) - elif pending["op"] == OP_ROOT_EJECT: - self._spawn( - self._admin_exec_root_eject(pending, transcript, sig_bytes)) - elif pending["op"] == OP_ROOT_PLUG: - self._spawn( - self._admin_exec_root_plug(pending, transcript, sig_bytes)) - elif pending["op"] == OP_GROUP_ATTACH: - self._spawn( - self._admin_exec_group_attach(pending, transcript, sig_bytes)) - elif pending["op"] == OP_GROUP_DETACH: - self._spawn( - self._admin_exec_group_detach(pending, transcript, sig_bytes)) - else: + executor = _ADMIN_EXECUTORS.get(pending["op"]) + if executor is None: self._send({"type": "error", "detail": "Unknown admin operation"}) + else: + self._spawn(getattr(self, executor)(pending, transcript, sig_bytes)) -- cgit v1.2.3