firmware/src/mesh/FloodingRouter.cpp

67 lines
2.6 KiB
C++
Raw Normal View History

#include "FloodingRouter.h"
2022-03-03 02:55:11 +00:00
#include "configuration.h"
2020-04-17 18:52:20 +00:00
#include "mesh-pb-constants.h"
2020-05-19 17:27:28 +00:00
FloodingRouter::FloodingRouter() {}
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)
{
// Add any messages _we_ send to the seen message list (so we will ignore all retransmissions we see)
2020-05-19 17:27:28 +00:00
wasSeenRecently(p); // FIXME, move this to a sniffSent method
2020-04-17 18:52:20 +00:00
return Router::send(p);
}
bool FloodingRouter::shouldFilterReceived(const MeshPacket *p)
2020-04-17 18:52:20 +00:00
{
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
printPacket("Ignoring incoming msg, because we've already seen it", p);
return true;
}
return Router::shouldFilterReceived(p);
}
2021-02-21 04:59:47 +00:00
void FloodingRouter::sniffReceived(const MeshPacket *p, const Routing *c)
{
2022-11-04 18:56:44 +00:00
bool isAck = ((c && c->error_reason == Routing_Error_NONE)); // consider only ROUTING_APP message without error as ACK
if (isAck && p->to != getNodeNum()) {
// do not flood direct message that is ACKed
2022-12-30 02:41:37 +00:00
LOG_DEBUG("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
2022-12-16 18:31:20 +00:00
}
if ((p->to != getNodeNum()) && (p->hop_limit > 0) && (getFrom(p) != getNodeNum())) {
if (p->id != 0) {
if (config.device.role != Config_DeviceConfig_Role_CLIENT_MUTE) {
2022-03-30 05:02:21 +00:00
MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
2022-03-30 05:02:21 +00:00
tosend->hop_limit--; // bump down the hop count
2022-12-05 19:38:06 +00:00
// If it is a traceRoute request, update the route that it went via me
if (p->which_payload_variant == MeshPacket_decoded_tag && traceRouteModule->wantPacket(p)) {
traceRouteModule->updateRoute(tosend);
}
LOG_INFO("Rebroadcasting received floodmsg to neighbors", p);
2022-03-30 05:02:21 +00:00
// 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 {
2022-12-30 02:41:37 +00:00
LOG_DEBUG("Not rebroadcasting. Role = Role_ClientMute\n");
2022-03-30 05:02:21 +00:00
}
} else {
2022-12-30 02:41:37 +00:00
LOG_DEBUG("Ignoring a simple (0 id) broadcast\n");
}
}
// handle the packet as normal
2021-02-17 05:06:23 +00:00
Router::sniffReceived(p, c);
2020-04-17 18:52:20 +00:00
}