mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-05-21 15:14:45 +02:00
fix: Switch to delay-based delivery — wantAck firmware retries cause duplicates
This commit is contained in:
parent
a80ed6cc7c
commit
914c21e167
1 changed files with 53 additions and 93 deletions
|
|
@ -24,12 +24,7 @@ class Responder:
|
||||||
destination: Optional[str] = None,
|
destination: Optional[str] = None,
|
||||||
channel: int = 0,
|
channel: int = 0,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Send response messages with ACK-accelerated delivery.
|
"""Send response messages with randomized delay pacing."""
|
||||||
|
|
||||||
DMs: Send -> wait for ACK -> if ACK, send next immediately.
|
|
||||||
If no ACK, retry once -> if still no ACK, abort.
|
|
||||||
Broadcasts: delay-based pacing (no ACK available).
|
|
||||||
"""
|
|
||||||
if isinstance(messages, str):
|
if isinstance(messages, str):
|
||||||
messages = [messages]
|
messages = [messages]
|
||||||
|
|
||||||
|
|
@ -37,57 +32,22 @@ class Responder:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
is_dm = destination is not None
|
|
||||||
|
|
||||||
for i, msg in enumerate(messages):
|
for i, msg in enumerate(messages):
|
||||||
if is_dm and hasattr(self.connector, 'send_and_wait_ack'):
|
if i > 0:
|
||||||
# Send and wait for ACK
|
delay = random.uniform(self.config.delay_min, self.config.delay_max)
|
||||||
ack = await asyncio.get_event_loop().run_in_executor(
|
await asyncio.sleep(delay)
|
||||||
None,
|
|
||||||
self.connector.send_and_wait_ack,
|
|
||||||
msg, destination, channel, 30.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
if ack:
|
sent = self.connector.send_message(
|
||||||
# ACK received - next message sends immediately (no delay)
|
text=msg,
|
||||||
logger.debug(f"ACK msg {i+1}/{len(messages)}: {msg[:50]}...")
|
destination=destination,
|
||||||
continue
|
channel=channel,
|
||||||
|
)
|
||||||
# No ACK - retry same message once after short pause
|
if not sent:
|
||||||
logger.warning(f"No ACK for msg {i+1}/{len(messages)}, retrying...")
|
logger.error(f"Failed to send message {i+1}/{len(messages)}")
|
||||||
await asyncio.sleep(2.0)
|
|
||||||
|
|
||||||
ack = await asyncio.get_event_loop().run_in_executor(
|
|
||||||
None,
|
|
||||||
self.connector.send_and_wait_ack,
|
|
||||||
msg, destination, channel, 30.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
if ack:
|
|
||||||
logger.debug(f"ACK on retry msg {i+1}/{len(messages)}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Double failure - abort
|
|
||||||
logger.error(f"No ACK after retry msg {i+1}/{len(messages)}, aborting remaining")
|
|
||||||
success = False
|
success = False
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
logger.debug(f"Sent msg {i+1}/{len(messages)}: {msg[:50]}...")
|
||||||
# Broadcasts or fallback: delay-based pacing
|
|
||||||
if i > 0:
|
|
||||||
delay = random.uniform(self.config.delay_min, self.config.delay_max)
|
|
||||||
await asyncio.sleep(delay)
|
|
||||||
|
|
||||||
sent = self.connector.send_message(
|
|
||||||
text=msg,
|
|
||||||
destination=destination,
|
|
||||||
channel=channel,
|
|
||||||
)
|
|
||||||
if not sent:
|
|
||||||
logger.error(f"Failed to send message {i+1}/{len(messages)}")
|
|
||||||
success = False
|
|
||||||
break
|
|
||||||
|
|
||||||
logger.debug(f"Sent msg {i+1}/{len(messages)}: {msg[:50]}...")
|
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue