diff --git a/reticulum_openapi/service.py b/reticulum_openapi/service.py index 4c99ff4..3ce7cd0 100644 --- a/reticulum_openapi/service.py +++ b/reticulum_openapi/service.py @@ -294,11 +294,30 @@ def _handle_registered_link_request( path: Any, request_data: Any, request_id: Any, - *extra: Any, + link_or_identity: Any, + remote_identity_or_requested_at: Any, + requested_at: Any = None, ) -> Optional[bytes]: """Handle link requests dispatched via ``RNS.Destination`` hooks.""" + if requested_at is None: + remote_identity = link_or_identity + link_id = None + requested_timestamp = remote_identity_or_requested_at + else: + link_id = link_or_identity + remote_identity = remote_identity_or_requested_at + requested_timestamp = requested_at + command_candidate = self._extract_command_from_path(path) + + logger.debug( + "Handling link command %s (link=%r remote=%r requested_at=%r)", # Reason: aid diagnostics + command_candidate or path, + link_id, + getattr(remote_identity, "hash", remote_identity), + requested_timestamp, + ) if command_candidate is None: logger.warning("Received link request with invalid path: %r", path) return None diff --git a/tests/test_service.py b/tests/test_service.py index c67de85..548c748 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -335,7 +335,14 @@ def set_link_closed_callback(self, callback): assert callable(request_handler) def _invoke_handler() -> Optional[bytes]: - return request_handler("/commands/PING", b"", object()) + return request_handler( + "/commands/PING", + b"", + object(), + b"lk", + object(), + 123.0, + ) payload = await loop.run_in_executor(None, _invoke_handler) assert msgpack_from_bytes(payload) == {"status": "ok"} diff --git a/tests/test_service_extra.py b/tests/test_service_extra.py index 5bed97a..b12d1a8 100644 --- a/tests/test_service_extra.py +++ b/tests/test_service_extra.py @@ -359,6 +359,9 @@ async def handler(payload): "/commands/CMD", payload, request_id=object(), + link_or_identity=b"lk", + remote_identity_or_requested_at=SimpleNamespace(hash=b"remote"), + requested_at=123.0, ), ) @@ -366,3 +369,18 @@ async def handler(payload): decoded = service_module.msgpack_from_bytes(response) assert decoded["ok"] is True assert decoded["echo"]["value"] == 1 + + legacy_response = await loop.run_in_executor( + None, + lambda: svc._handle_registered_link_request( + "/commands/CMD", + payload, + object(), + SimpleNamespace(hash=b"legacy"), + 321.0, + ), + ) + + assert legacy_response is not None + decoded_legacy = service_module.msgpack_from_bytes(legacy_response) + assert decoded_legacy["ok"] is True