2020-04-17 18:52:20 +00:00
|
|
|
#include "FloodingRouter.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
#include "mesh-pb-constants.h"
|
|
|
|
|
2020-05-11 23:19:44 +00:00
|
|
|
FloodingRouter::FloodingRouter() : toResend(MAX_NUM_NODES) {}
|
2020-04-17 18:52:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
ErrorCode FloodingRouter::send(MeshPacket *p)
|
|
|
|
{
|
2020-05-19 00:35:23 +00:00
|
|
|
wasSeenRecently(p);
|
2020-04-17 18:52:20 +00:00
|
|
|
|
|
|
|
return Router::send(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from loop()
|
|
|
|
* Handle any packet that is received by an interface on this node.
|
|
|
|
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
|
|
|
*
|
|
|
|
* Note: this method will free the provided packet
|
|
|
|
*/
|
|
|
|
void FloodingRouter::handleReceived(MeshPacket *p)
|
|
|
|
{
|
2020-05-19 00:35:23 +00:00
|
|
|
if (wasSeenRecently(p)) {
|
|
|
|
DEBUG_MSG("Ignoring incoming msg, because we've already seen it\n");
|
|
|
|
packetPool.release(p);
|
|
|
|
} else {
|
|
|
|
if (p->to == NODENUM_BROADCAST && p->hop_limit > 0) {
|
|
|
|
if (p->id != 0) {
|
|
|
|
MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
|
|
|
|
|
|
|
tosend->hop_limit--; // bump down the hop count
|
|
|
|
|
|
|
|
DEBUG_MSG("Rebroadcasting received floodmsg to neighbors, fr=0x%x,to=0x%x,id=%d,hop_limit=%d\n", p->from, p->to,
|
|
|
|
p->id, tosend->hop_limit);
|
|
|
|
// Note: we are careful to resend using the original senders node id
|
|
|
|
// We are careful not to call our hooked version of send() - because we don't want to check this again
|
|
|
|
Router::send(tosend);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DEBUG_MSG("Ignoring a simple (0 id) broadcast\n");
|
2020-04-17 19:41:01 +00:00
|
|
|
}
|
2020-05-03 02:53:58 +00:00
|
|
|
}
|
2020-05-19 00:35:23 +00:00
|
|
|
|
|
|
|
// handle the packet as normal
|
2020-04-17 18:52:20 +00:00
|
|
|
Router::handleReceived(p);
|
2020-05-19 00:35:23 +00:00
|
|
|
}
|
2020-04-17 18:52:20 +00:00
|
|
|
}
|