2020-04-17 19:41:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-05-11 23:14:53 +00:00
|
|
|
#include "PacketHistory.h"
|
2020-04-17 19:41:01 +00:00
|
|
|
#include "Router.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a mixin that extends Router with the ability to do Naive Flooding (in the standard mesh protocol sense)
|
|
|
|
*
|
|
|
|
* Rules for broadcasting (listing here for now, will move elsewhere eventually):
|
|
|
|
|
|
|
|
If to==BROADCAST and id==0, this is a simple broadcast (0 hops). It will be
|
|
|
|
sent only by the current node and other nodes will not attempt to rebroadcast
|
|
|
|
it.
|
|
|
|
|
|
|
|
If to==BROADCAST and id!=0, this is a "naive flooding" broadcast. The initial
|
|
|
|
node will send it on all local interfaces.
|
|
|
|
|
|
|
|
When other nodes receive this message, they will
|
|
|
|
first check if their recentBroadcasts table contains the (from, id) pair that
|
|
|
|
indicates this message. If so, we've already seen it - so we discard it. If
|
|
|
|
not, we add it to the table and then resend this message on all interfaces.
|
|
|
|
When resending we are careful to use the "from" ID of the original sender. Not
|
|
|
|
our own ID. When resending we pick a random delay between 0 and 10 seconds to
|
|
|
|
decrease the chance of collisions with transmitters we can not even hear.
|
|
|
|
|
|
|
|
Any entries in recentBroadcasts that are older than X seconds (longer than the
|
|
|
|
max time a flood can take) will be discarded.
|
|
|
|
*/
|
2020-05-19 18:56:17 +00:00
|
|
|
class FloodingRouter : public Router, protected PacketHistory
|
2020-04-17 19:41:01 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
FloodingRouter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet on a suitable interface. This routine will
|
|
|
|
* later free() the packet to pool. This routine is not allowed to stall.
|
|
|
|
* If the txmit queue is full it might return an error
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual ErrorCode send(MeshPacket *p) override;
|
2020-04-17 19:41:01 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
2020-05-23 16:24:22 +00:00
|
|
|
* Should this incoming filter be dropped?
|
2020-04-17 19:41:01 +00:00
|
|
|
*
|
2020-05-23 16:24:22 +00:00
|
|
|
* Called immedately on receiption, before any further processing.
|
|
|
|
* @return true to abandon the packet
|
2020-04-17 19:41:01 +00:00
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool shouldFilterReceived(MeshPacket *p) override;
|
2020-05-23 16:24:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Look for broadcasts we need to rebroadcast
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void sniffReceived(const MeshPacket *p, const Routing *c) override;
|
2020-04-17 19:41:01 +00:00
|
|
|
};
|