use contact path for anon requests, defaults to 0 hop

This commit is contained in:
Florent 2026-02-03 15:19:21 -04:00
parent ce6d14d618
commit b11a54eaf9
2 changed files with 19 additions and 0 deletions

View file

@ -192,6 +192,18 @@ class CommandHandlerBase:
dst_bytes = _validate_destination(dst, prefix_length=32)
pubkey_prefix = _validate_destination(dst, prefix_length=6)
logger.debug(f"Anon Binary request to {dst_bytes.hex()}")
contact = self._get_contact_by_prefix(dst_bytes.hex()) # need a contact for return path
if contact is None:
logger.error("No contact found")
zero_hop = False
if contact["out_path_len"] == -1:
logger.info("No path set trying zero hop")
zero_hop = True
await self.change_contact_path(contact, "")
data = contact["out_path_len"].to_bytes(1, "little") + bytes.fromhex(contact["out_path"])[::-1]
data = b"\x39" + dst_bytes + request_type.value.to_bytes(1, "little", signed=False) + (data if data else b"")
result = await self.send(data, [EventType.MSG_SENT, EventType.ERROR])
@ -207,4 +219,7 @@ class CommandHandlerBase:
actual_timeout = min_timeout if actual_timeout < min_timeout else actual_timeout
self._reader.register_binary_request(pubkey_prefix.hex(), exp_tag, request_type, actual_timeout, context=context, is_anon=True)
if zero_hop:
await self.reset_path(contact)
return result

View file

@ -71,6 +71,10 @@ class ContactCommands(CommandHandlerBase):
async def reset_path(self, key: DestinationType) -> Event:
key_bytes = _validate_destination(key, prefix_length=32)
contact = self._get_contact_by_prefix(key_bytes.hex()) # need a contact for return path
if not contact is None:
contact["out_path_len"] = -1
contact["out_path"] = ""
logger.debug(f"Resetting path for contact: {key_bytes.hex()}")
data = b"\x0d" + key_bytes
return await self.send(data, [EventType.OK, EventType.ERROR])