2021-06-27 10:56:28 -07:00
|
|
|
#include "FloodingRouter.h"
|
2022-03-02 18:55:11 -08:00
|
|
|
#include "configuration.h"
|
2020-04-17 11:52:20 -07:00
|
|
|
#include "mesh-pb-constants.h"
|
|
|
|
|
|
2020-05-19 10:27:28 -07:00
|
|
|
FloodingRouter::FloodingRouter() {}
|
2020-04-17 11:52:20 -07: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-21 12:47:41 -07:00
|
|
|
// Add any messages _we_ send to the seen message list (so we will ignore all retransmissions we see)
|
2020-05-19 10:27:28 -07:00
|
|
|
wasSeenRecently(p); // FIXME, move this to a sniffSent method
|
2020-04-17 11:52:20 -07:00
|
|
|
|
|
|
|
|
return Router::send(p);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 21:31:12 -05:00
|
|
|
bool FloodingRouter::shouldFilterReceived(MeshPacket *p)
|
2020-04-17 11:52:20 -07:00
|
|
|
{
|
2020-05-25 11:55:42 -07:00
|
|
|
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
|
2020-12-17 10:53:29 +08:00
|
|
|
printPacket("Ignoring incoming msg, because we've already seen it", p);
|
2020-05-23 09:24:22 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-05-18 17:35:23 -07:00
|
|
|
|
2020-05-23 09:24:22 -07:00
|
|
|
return Router::shouldFilterReceived(p);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 12:59:47 +08:00
|
|
|
void FloodingRouter::sniffReceived(const MeshPacket *p, const Routing *c)
|
2020-05-23 09:24:22 -07:00
|
|
|
{
|
2022-11-02 20:32:18 +01:00
|
|
|
bool isAck = ((c && c->error_reason == Routing_Error_NONE)); // consider only ROUTING_APP message without error as ACK
|
|
|
|
|
if (isAck && p->to != getNodeNum()) {
|
2022-08-01 23:59:50 +02:00
|
|
|
// do not flood direct message that is ACKed
|
|
|
|
|
DEBUG_MSG("Receiving an ACK not for me, but don't need to rebroadcast this direct message anymore.\n");
|
|
|
|
|
Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM
|
|
|
|
|
} else if ((p->to != getNodeNum()) && (p->hop_limit > 0) && (getFrom(p) != getNodeNum())) {
|
2020-05-23 09:24:22 -07:00
|
|
|
if (p->id != 0) {
|
2022-09-09 12:51:41 +02:00
|
|
|
if (config.device.role != Config_DeviceConfig_Role_CLIENT_MUTE) {
|
2022-03-29 22:02:21 -07:00
|
|
|
MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
|
2020-05-23 09:24:22 -07:00
|
|
|
|
2022-03-29 22:02:21 -07:00
|
|
|
tosend->hop_limit--; // bump down the hop count
|
2020-05-23 09:24:22 -07:00
|
|
|
|
2022-03-29 22:02:21 -07:00
|
|
|
printPacket("Rebroadcasting received floodmsg to neighbors", p);
|
|
|
|
|
// 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("Not rebroadcasting. Role = Role_ClientMute\n");
|
|
|
|
|
}
|
2020-05-23 09:24:22 -07:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_MSG("Ignoring a simple (0 id) broadcast\n");
|
|
|
|
|
}
|
2020-05-18 17:35:23 -07:00
|
|
|
}
|
2020-05-23 09:24:22 -07:00
|
|
|
|
|
|
|
|
// handle the packet as normal
|
2021-02-17 13:06:23 +08:00
|
|
|
Router::sniffReceived(p, c);
|
2020-04-17 11:52:20 -07:00
|
|
|
}
|