Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rebroadcast mode NONE #5040

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/mesh/FloodingRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p)
return Router::shouldFilterReceived(p);
}

bool FloodingRouter::isRebroadcaster()
{
return config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE &&
config.device.rebroadcast_mode != meshtastic_Config_DeviceConfig_RebroadcastMode_NONE;
}

void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c)
{
bool isAckorReply = (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) && (p->decoded.request_id != 0);
Expand All @@ -45,7 +51,7 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas
}
if (!isToUs(p) && (p->hop_limit > 0) && !isFromUs(p)) {
if (p->id != 0) {
if (config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE) {
if (isRebroadcaster()) {
GUVWAF marked this conversation as resolved.
Show resolved Hide resolved
meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it

tosend->hop_limit--; // bump down the hop count
Expand Down
2 changes: 2 additions & 0 deletions src/mesh/FloodingRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
class FloodingRouter : public Router, protected PacketHistory
{
private:
bool isRebroadcaster();

public:
/**
* Constructor
Expand Down
17 changes: 17 additions & 0 deletions src/modules/AdminModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
requiresReboot = false;
}
config.device = c.payload_variant.device;
if (config.device.rebroadcast_mode == meshtastic_Config_DeviceConfig_RebroadcastMode_NONE &&
IS_ONE_OF(config.device.role, meshtastic_Config_DeviceConfig_Role_ROUTER,
meshtastic_Config_DeviceConfig_Role_REPEATER)) {
config.device.rebroadcast_mode = meshtastic_Config_DeviceConfig_RebroadcastMode_ALL;
const char *warning = "Rebroadcast mode can't be set to NONE for a router or repeater\n";
LOG_WARN(warning);
sendWarning(warning);
}
// If we're setting router role for the first time, install its intervals
if (existingRole != c.payload_variant.device.role)
nodeDB->installRoleDefaults(c.payload_variant.device.role);
Expand Down Expand Up @@ -1064,6 +1072,15 @@ bool AdminModule::messageIsRequest(const meshtastic_AdminMessage *r)
return false;
}

void AdminModule::sendWarning(const char *message)
{
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
cn->level = meshtastic_LogRecord_Level_WARNING;
cn->time = getValidTime(RTCQualityFromNet);
strncpy(cn->message, message, sizeof(cn->message));
service->sendClientNotification(cn);
}

void disableBluetooth()
{
#if HAS_BLUETOOTH
Expand Down
1 change: 1 addition & 0 deletions src/modules/AdminModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser

bool messageIsResponse(const meshtastic_AdminMessage *r);
bool messageIsRequest(const meshtastic_AdminMessage *r);
void sendWarning(const char *message);
};

extern AdminModule *adminModule;
Expand Down
Loading