Remove relayer if we cancel a transmission

This commit is contained in:
GUVWAF 2024-11-05 19:40:00 +01:00
parent 790801f8e7
commit bb64b1480b
5 changed files with 44 additions and 8 deletions

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "PacketHistory.h"
#include "Router.h" #include "Router.h"
/** /**
@ -26,7 +25,7 @@
Any entries in recentBroadcasts that are older than X seconds (longer than the Any entries in recentBroadcasts that are older than X seconds (longer than the
max time a flood can take) will be discarded. max time a flood can take) will be discarded.
*/ */
class FloodingRouter : public Router, protected PacketHistory class FloodingRouter : public Router
{ {
private: private:
public: public:

View File

@ -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.erase(found); // as unsorted_set::iterator is const (can't update - so re-insert..)
} }
recentPackets.insert(r); 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 // Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity
@ -119,3 +119,31 @@ bool PacketHistory::wasRelayer(const uint8_t relayer, const uint32_t id, const N
} }
} }
} }
// 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);
}

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Router.h" #include "NodeDB.h"
#include <unordered_set> #include <unordered_set>
/// We clear our old flood record 10 minutes after we see the last of it /// 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 /* 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 */ * @return true if node was indeed a relayer, false if not */
bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender); 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);
}; };

View File

@ -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 */ /** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
bool Router::cancelSending(NodeNum from, PacketId id) 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;
} }
/** /**

View File

@ -4,6 +4,7 @@
#include "MemoryPool.h" #include "MemoryPool.h"
#include "MeshTypes.h" #include "MeshTypes.h"
#include "Observer.h" #include "Observer.h"
#include "PacketHistory.h"
#include "PointerQueue.h" #include "PointerQueue.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "concurrency/OSThread.h" #include "concurrency/OSThread.h"
@ -11,7 +12,7 @@
/** /**
* A mesh aware router that supports multiple interfaces. * A mesh aware router that supports multiple interfaces.
*/ */
class Router : protected concurrency::OSThread class Router : protected concurrency::OSThread, protected PacketHistory
{ {
private: private:
/// Packets which have just arrived from the radio, ready to be processed by this service and possibly /// Packets which have just arrived from the radio, ready to be processed by this service and possibly