2021-06-27 17:56:28 +00:00
|
|
|
#include "FloodingRouter.h"
|
2024-07-30 01:16:47 +00:00
|
|
|
#include "../userPrefs.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
|
|
|
|
*/
|
2023-01-21 17:22:19 +00:00
|
|
|
ErrorCode FloodingRouter::send(meshtastic_MeshPacket *p)
|
2020-04-17 18:52:20 +00:00
|
|
|
{
|
2020-05-21 19:47:41 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
|
2020-04-17 18:52:20 +00:00
|
|
|
{
|
2020-05-25 18:55:42 +00:00
|
|
|
if (wasSeenRecently(p)) { // Note: this will also add a recent packet record
|
2024-10-01 20:38:36 +00:00
|
|
|
printPacket("Ignoring dupe incoming msg", p);
|
2024-02-21 19:00:14 +00:00
|
|
|
if (config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER &&
|
2023-07-06 11:43:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-05-23 16:24:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-05-19 00:35:23 +00:00
|
|
|
|
2020-05-23 16:24:22 +00:00
|
|
|
return Router::shouldFilterReceived(p);
|
|
|
|
}
|
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c)
|
2020-05-23 16:24:22 +00:00
|
|
|
{
|
2024-05-01 01:07:15 +00:00
|
|
|
bool isAckorReply = (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) && (p->decoded.request_id != 0);
|
|
|
|
if (isAckorReply && p->to != getNodeNum() && p->to != NODENUM_BROADCAST) {
|
|
|
|
// do not flood direct message that is ACKed or replied to
|
2024-10-01 20:38:36 +00:00
|
|
|
LOG_DEBUG("Rxd an ACK/reply not for me, cancel rebroadcast.\n");
|
2023-01-21 13:34:29 +00:00
|
|
|
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())) {
|
2020-05-23 16:24:22 +00:00
|
|
|
if (p->id != 0) {
|
2023-01-21 17:22:19 +00:00
|
|
|
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
|
2020-05-23 16:24:22 +00:00
|
|
|
|
2022-03-30 05:02:21 +00:00
|
|
|
tosend->hop_limit--; // bump down the hop count
|
2024-10-02 11:14:24 +00:00
|
|
|
#if USERPREFS_EVENT_MODE
|
2024-07-30 01:16:47 +00:00
|
|
|
if (tosend->hop_limit > 2) {
|
|
|
|
// if we are "correcting" the hop_limit, "correct" the hop_start by the same amount to preserve hops away.
|
|
|
|
tosend->hop_start -= (tosend->hop_limit - 2);
|
|
|
|
tosend->hop_limit = 2;
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-23 16:24:22 +00:00
|
|
|
|
2024-10-01 20:38:36 +00:00
|
|
|
LOG_INFO("Rebroadcasting received floodmsg\n");
|
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
|
|
|
}
|
2020-05-23 16:24:22 +00:00
|
|
|
} else {
|
2024-10-01 20:38:36 +00:00
|
|
|
LOG_DEBUG("Ignoring 0 id broadcast\n");
|
2020-05-23 16:24:22 +00:00
|
|
|
}
|
2020-05-19 00:35:23 +00:00
|
|
|
}
|
2020-05-23 16:24:22 +00:00
|
|
|
// handle the packet as normal
|
2021-02-17 05:06:23 +00:00
|
|
|
Router::sniffReceived(p, c);
|
2023-06-01 18:36:30 +00:00
|
|
|
}
|