Files
firmware/src/mesh/FloodingRouter.cpp

65 lines
2.8 KiB
C++
Raw Normal View History

#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(meshtastic_MeshPacket *p)
2020-04-17 11:52:20 -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);
}
bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
2020-04-17 11:52:20 -07:00
{
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
printPacket("Ignoring incoming msg, because we've already seen it", p);
if (config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER &&
config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT &&
config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) {
// cancel rebroadcast of this message *if* there was already one, unless we're a router/repeater!
Router::cancelSending(p->from, p->id);
}
return true;
}
return Router::shouldFilterReceived(p);
}
void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c)
{
2023-01-21 18:39:58 +01:00
bool isAck =
((c && c->error_reason == meshtastic_Routing_Error_NONE)); // consider only ROUTING_APP message without error as ACK
2022-11-04 19:56:44 +01:00
if (isAck && p->to != getNodeNum()) {
2023-01-21 14:34:29 +01:00
// do not flood direct message that is ACKed
2022-12-29 20:41:37 -06:00
LOG_DEBUG("Receiving an ACK not for me, but don't need to rebroadcast this direct message anymore.\n");
2023-01-21 14:34:29 +01:00
Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM
}
2022-12-16 19:31:20 +01:00
if ((p->to != getNodeNum()) && (p->hop_limit > 0) && (getFrom(p) != getNodeNum())) {
if (p->id != 0) {
if (config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE) {
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it
2022-03-29 22:02:21 -07:00
tosend->hop_limit--; // bump down the hop count
2023-01-28 13:40:14 -06:00
LOG_INFO("Rebroadcasting received floodmsg to neighbors\n");
2022-03-29 22:02:21 -07: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-29 20:41:37 -06:00
LOG_DEBUG("Not rebroadcasting. Role = Role_ClientMute\n");
2022-03-29 22:02:21 -07:00
}
} else {
2022-12-29 20:41:37 -06:00
LOG_DEBUG("Ignoring a simple (0 id) broadcast\n");
}
}
// handle the packet as normal
2021-02-17 13:06:23 +08:00
Router::sniffReceived(p, c);
}