More comprehensive client proxy queue guards (#3414)

* More comprehensive MQTT thread and queue guards

* Consolidate logic

* Remove channel check

* Check for map_reporting_enabled as well

* Update message

* Remove channel check from here as well

* One liner

* Start the mqtt thread back up when channels change and we want mqtt
This commit is contained in:
Ben Meadors
2024-03-15 16:17:47 -05:00
committed by GitHub
parent 4d0d82f7e7
commit 52cfec29fc
5 changed files with 32 additions and 18 deletions

View File

@@ -371,22 +371,9 @@ void MQTT::sendSubscriptions()
bool MQTT::wantsLink() const
{
bool hasChannelorMapReport = false;
bool hasChannelorMapReport =
moduleConfig.mqtt.enabled && (moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled());
if (moduleConfig.mqtt.enabled) {
hasChannelorMapReport = moduleConfig.mqtt.map_reporting_enabled;
if (!hasChannelorMapReport) {
// No need for link if no channel needed it
size_t numChan = channels.getNumChannels();
for (size_t i = 0; i < numChan; i++) {
const auto &ch = channels.getByIndex(i);
if (ch.settings.uplink_enabled || ch.settings.downlink_enabled) {
hasChannelorMapReport = true;
break;
}
}
}
}
if (hasChannelorMapReport && moduleConfig.mqtt.proxy_to_client_enabled)
return true;
@@ -401,7 +388,7 @@ bool MQTT::wantsLink() const
int32_t MQTT::runOnce()
{
if (!moduleConfig.mqtt.enabled)
if (!moduleConfig.mqtt.enabled || !(moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled()))
return disable();
bool wantConnection = wantsLink();
@@ -915,4 +902,4 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json)
(json["from"]->AsNumber() == nodeDB.getNodeNum()) && // only accept message if the "from" is us
(json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type
(json.find("payload") != json.end()); // should have a payload
}
}