This commit is contained in:
geeksville
2020-05-23 15:48:23 -07:00
parent e89fe2f7d9
commit fb3b62f8f0
9 changed files with 117 additions and 37 deletions

View File

@@ -50,7 +50,8 @@ void ReliableRouter::sniffReceived(const MeshPacket *p)
DEBUG_MSG("Someone is retransmitting for us, generate implicit ack\n");
sendAckNak(true, p->from, p->id);
}
} else if (p->to == ourNode) { // ignore ack/nak/want_ack packets that are not address to us (for now)
} else if (p->to == ourNode) { // ignore ack/nak/want_ack packets that are not address to us (we only handle 0 hop reliability
// - not DSR routing)
if (p->want_ack) {
sendAckNak(true, p->from, p->id);
}
@@ -60,8 +61,7 @@ void ReliableRouter::sniffReceived(const MeshPacket *p)
PacketId ackId = p->decoded.which_ack == SubPacket_success_id_tag ? p->decoded.ack.success_id : 0;
PacketId nakId = p->decoded.which_ack == SubPacket_fail_id_tag ? p->decoded.ack.fail_id : 0;
// we are careful to only read/update wasSeenRecently _after_ confirming this is an ack (to not mess
// up broadcasts)
// we are careful to only read wasSeenRecently - not update it (to not mess up broadcasts)
if ((ackId || nakId) && !wasSeenRecently(p, false)) {
if (ackId) {
DEBUG_MSG("Received a ack=%d, stopping retransmissions\n", ackId);
@@ -107,6 +107,14 @@ PendingPacket::PendingPacket(MeshPacket *p)
setNextTx();
}
PendingPacket *ReliableRouter::findPendingPacket(GlobalPacketId key)
{
auto old = pending.find(key); // If we have an old record, someone messed up because id got reused
if (old != pending.end()) {
return &old->second;
} else
return NULL;
}
/**
* Stop any retransmissions we are doing of the specified node/packet ID pair
*/
@@ -118,15 +126,16 @@ bool ReliableRouter::stopRetransmission(NodeNum from, PacketId id)
bool ReliableRouter::stopRetransmission(GlobalPacketId key)
{
auto old = pending.find(key); // If we have an old record, someone messed up because id got reused
if (old != pending.end()) {
auto old = findPendingPacket(key);
if (old) {
auto numErased = pending.erase(key);
assert(numErased == 1);
packetPool.release(old->second.packet);
packetPool.release(old->packet);
return true;
} else
return false;
}
/**
* Add p to the list of packets to retransmit occasionally. We will free it once we stop retransmitting.
*/
@@ -158,7 +167,9 @@ void ReliableRouter::doRetransmissions()
DEBUG_MSG("Reliable send failed, returning a nak fr=0x%x,to=0x%x,id=%d\n", p.packet->from, p.packet->to,
p.packet->id);
sendAckNak(false, p.packet->from, p.packet->id);
stopRetransmission(it->first);
// Note: we don't stop retransmission here, instead the Nak packet gets processed in sniffReceived - which
// allows the DSR version to still be able to look at the PendingPacket
// stopRetransmission(it->first);
} else {
DEBUG_MSG("Sending reliable retransmission fr=0x%x,to=0x%x,id=%d, tries left=%d\n", p.packet->from, p.packet->to,
p.packet->id, p.numRetransmissions);