when flooding, randomly delay sent packets to decrease chances of...

stomping on other senders that we can't even hear.
This commit is contained in:
geeksville
2020-04-25 11:43:28 -07:00
parent 64f6c0f5c0
commit 3f3a1a11df
3 changed files with 46 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include "PeriodicTask.h"
#include "Router.h"
#include <vector>
@@ -35,11 +36,19 @@ struct BroadcastRecord {
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
class FloodingRouter : public Router, public PeriodicTask
{
private:
/** FIXME: really should be a std::unordered_set with the key being sender,id.
* This would make checking packets in wasSeenRecently faster.
*/
std::vector<BroadcastRecord> recentBroadcasts;
/**
* Packets we've received that we need to resend after a short delay
*/
PointerQueue<MeshPacket> toResend;
public:
/**
* Constructor
@@ -64,6 +73,8 @@ class FloodingRouter : public Router
*/
virtual void handleReceived(MeshPacket *p);
virtual void doTask();
private:
/**
* Update recentBroadcasts and return true if we have already seen this packet