Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion reticulum_openapi/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
18 changes: 18 additions & 0 deletions tests/test_service_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,28 @@ 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,
),
)

assert response is not None
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
Loading