From 71041e86742baf93b363620e15334db0c3ff897b Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 19 May 2020 15:51:07 -0700 Subject: [PATCH] reliable unicast 1 hop works! --- docs/software/mesh-alg.md | 5 +++-- src/mesh/PacketHistory.cpp | 19 +++++++++++-------- src/mesh/PacketHistory.h | 4 +++- src/mesh/RadioLibInterface.cpp | 2 +- src/mesh/ReliableRouter.cpp | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/software/mesh-alg.md b/docs/software/mesh-alg.md index fe5d9752e..78f5eba86 100644 --- a/docs/software/mesh-alg.md +++ b/docs/software/mesh-alg.md @@ -14,7 +14,8 @@ reliable messaging tasks (stage one for DSR): - DONE delay some random time for each retry (large enough to allow for acks to come in) - DONE once an ack comes in, remove the packet from the retry list and deliver the ack to the original sender - DONE after three retries, deliver a no-ack packet to the original sender (i.e. the phone app or mesh router service) -- test one hop ack/nak with the python framework +- DONE test one hop ack/nak with the python framework +- Do stress test with acks dsr tasks @@ -22,7 +23,7 @@ dsr tasks - when sending, if destnodeinfo.next_hop is zero (and no message is already waiting for an arp for that node), startRouteDiscovery() for that node. Queue the message in the 'waiting for arp queue' so we can send it later when then the arp completes. - otherwise, use next_hop and start sending a message (with ack request) towards that node. - Don't use broadcasts for the network pings (close open github issue) -- add ignoreSenders to myNodeInfo to allow testing different mesh topologies by refusing to see certain senders +- add ignoreSenders to radioconfig to allow testing different mesh topologies by refusing to see certain senders - test multihop delivery with the python framework optimizations / low priority: diff --git a/src/mesh/PacketHistory.cpp b/src/mesh/PacketHistory.cpp index 9a5704f66..30a448f97 100644 --- a/src/mesh/PacketHistory.cpp +++ b/src/mesh/PacketHistory.cpp @@ -13,7 +13,7 @@ PacketHistory::PacketHistory() /** * Update recentBroadcasts and return true if we have already seen this packet */ -bool PacketHistory::wasSeenRecently(const MeshPacket *p) +bool PacketHistory::wasSeenRecently(const MeshPacket *p, bool withUpdate) { if (p->id == 0) { DEBUG_MSG("Ignoring message with zero id\n"); @@ -32,7 +32,8 @@ bool PacketHistory::wasSeenRecently(const MeshPacket *p) DEBUG_MSG("Found existing broadcast record for fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id); // Update the time on this record to now - r.rxTimeMsec = now; + if (withUpdate) + r.rxTimeMsec = now; return true; } @@ -41,12 +42,14 @@ bool PacketHistory::wasSeenRecently(const MeshPacket *p) } // Didn't find an existing record, make one - PacketRecord r; - r.id = p->id; - r.sender = p->from; - r.rxTimeMsec = now; - recentPackets.push_back(r); - DEBUG_MSG("Adding broadcast record for fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id); + if (withUpdate) { + PacketRecord r; + r.id = p->id; + r.sender = p->from; + r.rxTimeMsec = now; + recentPackets.push_back(r); + DEBUG_MSG("Adding broadcast record for fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id); + } return false; } \ No newline at end of file diff --git a/src/mesh/PacketHistory.h b/src/mesh/PacketHistory.h index 22470f4fc..38edf7d77 100644 --- a/src/mesh/PacketHistory.h +++ b/src/mesh/PacketHistory.h @@ -61,6 +61,8 @@ class PacketHistory /** * Update recentBroadcasts and return true if we have already seen this packet + * + * @param withUpdate if true and not found we add an entry to recentPackets */ - bool wasSeenRecently(const MeshPacket *p); + bool wasSeenRecently(const MeshPacket *p, bool withUpdate = true); }; diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 5bf3b5eea..9d2710716 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -315,7 +315,7 @@ void RadioLibInterface::handleReceiveInterrupt() /** start an immediate transmit */ void RadioLibInterface::startSend(MeshPacket *txp) { - DEBUG_MSG("Starting low level send from=0x%x, id=%u!\n", txp->from, txp->id); + DEBUG_MSG("Starting low level send from=0x%x, id=%u, want_ack=%d\n", txp->from, txp->id, txp->want_ack); setStandby(); // Cancel any already in process receives size_t numbytes = beginSending(txp); diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 02833f8ce..eb6fc248a 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -46,7 +46,7 @@ void ReliableRouter::handleReceived(MeshPacket *p) // we are careful to only read/update wasSeenRecently _after_ confirming this is an ack (to not mess // up broadcasts) - if ((ackId || nakId) && !wasSeenRecently(p)) { + if ((ackId || nakId) && !wasSeenRecently(p, false)) { if (ackId) { DEBUG_MSG("Received a ack=%d, stopping retransmissions\n", ackId); stopRetransmission(p->to, ackId);