diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index 11c2c4727..25d674e6b 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -1,6 +1,5 @@ #pragma once -#include "PacketHistory.h" #include "Router.h" /** @@ -26,7 +25,7 @@ Any entries in recentBroadcasts that are older than X seconds (longer than the max time a flood can take) will be discarded. */ -class FloodingRouter : public Router, protected PacketHistory +class FloodingRouter : public Router { private: public: @@ -59,4 +58,4 @@ class FloodingRouter : public Router, protected PacketHistory // Return true if we are a rebroadcaster bool isRebroadcaster(); -}; +}; \ No newline at end of file diff --git a/src/mesh/PacketHistory.cpp b/src/mesh/PacketHistory.cpp index 430ac6b99..91e395d9c 100644 --- a/src/mesh/PacketHistory.cpp +++ b/src/mesh/PacketHistory.cpp @@ -70,7 +70,7 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd recentPackets.erase(found); // as unsorted_set::iterator is const (can't update - so re-insert..) } recentPackets.insert(r); - printPacket("Add packet record", p); + LOG_DEBUG("Add packet record fr=0x%x, id=0x%x", p->from, p->id); } // Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity @@ -118,4 +118,32 @@ bool PacketHistory::wasRelayer(const uint8_t relayer, const uint32_t id, const N return true; } } +} + +// Remove a relayer from the list of relayers of a packet in the history given an ID and sender +void PacketHistory::removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender) +{ + PacketRecord r; + r.id = id; + r.sender = sender; + auto found = recentPackets.find(r); + + if (found == recentPackets.end()) { + return; + } + // Make a copy of the found record + r.next_hop = found->next_hop; + r.rxTimeMsec = found->rxTimeMsec; + + // Only add the relayers that are not the one we want to remove + uint8_t j = 0; + for (uint8_t i = 0; i < NUM_RELAYERS; i++) { + if (found->relayed_by[i] != relayer) { + r.relayed_by[j] = found->relayed_by[i]; + j++; + } + } + + recentPackets.erase(found); + recentPackets.insert(r); } \ No newline at end of file diff --git a/src/mesh/PacketHistory.h b/src/mesh/PacketHistory.h index f89462ea5..adde4b27d 100644 --- a/src/mesh/PacketHistory.h +++ b/src/mesh/PacketHistory.h @@ -1,6 +1,6 @@ #pragma once -#include "Router.h" +#include "NodeDB.h" #include /// We clear our old flood record 10 minutes after we see the last of it @@ -51,4 +51,7 @@ class PacketHistory /* Check if a certain node was a relayer of a packet in the history given an ID and sender * @return true if node was indeed a relayer, false if not */ bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender); + + // Remove a relayer from the list of relayers of a packet in the history given an ID and sender + void removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender); }; \ No newline at end of file diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 246612500..5fa40d539 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -290,7 +290,12 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) /** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */ bool Router::cancelSending(NodeNum from, PacketId id) { - return iface ? iface->cancelSending(from, id) : false; + if (iface && iface->cancelSending(from, id)) { + // We are not a relayer of this packet anymore + removeRelayer(nodeDB->getLastByteOfNodeNum(nodeDB->getNodeNum()), id, from); + return true; + } + return false; } /** @@ -672,4 +677,4 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) // cache/learn of the existence of nodes (i.e. FloodRouter) that they should not handleReceived(p); packetPool.release(p); -} +} \ No newline at end of file diff --git a/src/mesh/Router.h b/src/mesh/Router.h index da44d67df..14ce4810b 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -4,6 +4,7 @@ #include "MemoryPool.h" #include "MeshTypes.h" #include "Observer.h" +#include "PacketHistory.h" #include "PointerQueue.h" #include "RadioInterface.h" #include "concurrency/OSThread.h" @@ -11,7 +12,7 @@ /** * A mesh aware router that supports multiple interfaces. */ -class Router : protected concurrency::OSThread +class Router : protected concurrency::OSThread, protected PacketHistory { private: /// Packets which have just arrived from the radio, ready to be processed by this service and possibly