mirror of
https://github.com/ratspeak/ratdeck.git
synced 2026-03-30 22:25:39 +00:00
Fix wrong-recipient message delivery via stale outbound link
When switching between peers, sendDirect() updated _outLinkDestHash to the new destination before the new link was established, while _outLink still held the old peer's active link. On the next retry, the hash check passed (both matched the new peer) but the link object was still connected to the old peer — delivering the message to the wrong recipient. Fix: only update _outLinkDestHash in onOutLinkEstablished() when the new link is actually ready. Use _outLinkPendingHash to track what's being connected to.
This commit is contained in:
@@ -187,7 +187,7 @@ bool LXMFManager::sendDirect(LXMFMessage& msg) {
|
||||
// Background: establish link for future messages to this peer
|
||||
if (!_outLinkPending && (!_outLink || _outLinkDestHash != msg.destHash
|
||||
|| _outLink.status() == RNS::Type::Link::CLOSED)) {
|
||||
_outLinkDestHash = msg.destHash;
|
||||
_outLinkPendingHash = msg.destHash;
|
||||
_outLinkPending = true;
|
||||
Serial.printf("[LXMF] Establishing link to %s for future messages\n",
|
||||
msg.destHash.toHex().substr(0, 8).c_str());
|
||||
@@ -212,6 +212,7 @@ void LXMFManager::onPacketReceived(const RNS::Bytes& data, const RNS::Packet& pa
|
||||
void LXMFManager::onOutLinkEstablished(RNS::Link& link) {
|
||||
if (!_instance) return;
|
||||
_instance->_outLink = link;
|
||||
_instance->_outLinkDestHash = _instance->_outLinkPendingHash;
|
||||
_instance->_outLinkPending = false;
|
||||
Serial.printf("[LXMF] Outbound link established to %s\n",
|
||||
_instance->_outLinkDestHash.toHex().substr(0, 8).c_str());
|
||||
|
||||
@@ -45,7 +45,8 @@ private:
|
||||
|
||||
// Outbound link state (opportunistic-first, link upgrades in background)
|
||||
RNS::Link _outLink{RNS::Type::NONE};
|
||||
RNS::Bytes _outLinkDestHash;
|
||||
RNS::Bytes _outLinkDestHash; // Destination the ACTIVE _outLink is for
|
||||
RNS::Bytes _outLinkPendingHash; // Destination being connected to (not yet established)
|
||||
bool _outLinkPending = false;
|
||||
|
||||
// Deduplication: recently seen message IDs
|
||||
|
||||
Reference in New Issue
Block a user