mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
use contact path for anon requests, defaults to 0 hop
This commit is contained in:
@@ -192,6 +192,18 @@ class CommandHandlerBase:
|
|||||||
dst_bytes = _validate_destination(dst, prefix_length=32)
|
dst_bytes = _validate_destination(dst, prefix_length=32)
|
||||||
pubkey_prefix = _validate_destination(dst, prefix_length=6)
|
pubkey_prefix = _validate_destination(dst, prefix_length=6)
|
||||||
logger.debug(f"Anon Binary request to {dst_bytes.hex()}")
|
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"")
|
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])
|
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
|
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)
|
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
|
return result
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ class ContactCommands(CommandHandlerBase):
|
|||||||
|
|
||||||
async def reset_path(self, key: DestinationType) -> Event:
|
async def reset_path(self, key: DestinationType) -> Event:
|
||||||
key_bytes = _validate_destination(key, prefix_length=32)
|
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()}")
|
logger.debug(f"Resetting path for contact: {key_bytes.hex()}")
|
||||||
data = b"\x0d" + key_bytes
|
data = b"\x0d" + key_bytes
|
||||||
return await self.send(data, [EventType.OK, EventType.ERROR])
|
return await self.send(data, [EventType.OK, EventType.ERROR])
|
||||||
|
|||||||
Reference in New Issue
Block a user