use dstType instead of contact

This commit is contained in:
Florent 2025-09-05 23:36:02 +02:00
parent 0664522deb
commit b644bd12d9
3 changed files with 12 additions and 5 deletions

View file

@ -76,6 +76,10 @@ class CommandHandlerBase:
def set_dispatcher(self, dispatcher: EventDispatcher) -> None:
self.dispatcher = dispatcher
def set_contact_getter_by_prefix(self, func: Callable[[str], Optional[Dict[str,Any]]]
)-> None:
self._get_contact_by_prefix = func
async def send(
self,
data: bytes,
@ -166,4 +170,4 @@ class CommandHandlerBase:
actual_timeout = timeout if timeout is not None and timeout > 0 else result.payload.get("suggested_timeout", 4000) / 800.0
self._reader.register_binary_request(pubkey_prefix.hex(), exp_tag, request_type, actual_timeout)
return result
return result

View file

@ -79,11 +79,14 @@ class MessagingCommands(CommandHandlerBase):
)
return await self.send(data, [EventType.MSG_SENT, EventType.ERROR])
async def send_msg_reliable(
self, contact, msg: str, timestamp: Optional[int] = None,
async def send_msg_with_retry (
self, dst: DestinationType, msg: str, timestamp: Optional[int] = None,
max_attempts=3, flood_after=2, timeout=0
) -> Event:
dst_bytes = _validate_destination(dst)
contact = self._get_contact_by_prefix(dst_bytes.hex())
attempts = 0
res = None
while attempts < max_attempts and res is None:
@ -101,8 +104,7 @@ class MessagingCommands(CommandHandlerBase):
result = await self.send_msg(contact, msg, timestamp, attempt=attempts)
if result.type == EventType.ERROR:
print(f"⚠️ Failed to send message: {result.payload}")
return None
logger.error(f"⚠️ Failed to send message: {result.payload}")
exp_ack = result.payload["expected_ack"].hex()
timeout = result.payload["suggested_timeout"] / 1000 * 1.2 if timeout==0 else timeout

View file

@ -37,6 +37,7 @@ class MeshCore:
self._reader = MessageReader(self.dispatcher)
self.commands = CommandHandler(default_timeout=default_timeout)
self.commands.set_contact_getter_by_prefix(self.get_contact_by_key_prefix)
# Set up logger
if debug: