More accurately determine if MQTT uses the default server

This commit is contained in:
Eric Severance 2024-12-24 11:38:02 -08:00
parent 175ff218f1
commit e9197da8a9
No known key found for this signature in database
GPG Key ID: F19AABB5E1EA1B5F

View File

@ -46,6 +46,7 @@ constexpr int reconnectMax = 5;
static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for channel name and 16 for nodeid static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for channel name and 16 for nodeid
static bool isMqttServerAddressPrivate = false; static bool isMqttServerAddressPrivate = false;
static bool isDefaultMqttServer;
// meshtastic_ServiceEnvelope that automatically releases dynamically allocated memory when it goes out of scope. // meshtastic_ServiceEnvelope that automatically releases dynamically allocated memory when it goes out of scope.
struct DecodedServiceEnvelope : public meshtastic_ServiceEnvelope { struct DecodedServiceEnvelope : public meshtastic_ServiceEnvelope {
@ -324,9 +325,10 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs); moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs);
} }
String host = parseHostAndPort(moduleConfig.mqtt.address).first;
isDefaultMqttServer = host.length() == 0 || host == default_mqtt_address;
IPAddress ip; IPAddress ip;
isMqttServerAddressPrivate = isMqttServerAddressPrivate = ip.fromString(host.c_str()) && isPrivateIpAddress(ip);
ip.fromString(parseHostAndPort(moduleConfig.mqtt.address).first.c_str()) && isPrivateIpAddress(ip);
#if HAS_NETWORKING #if HAS_NETWORKING
if (!moduleConfig.mqtt.proxy_to_client_enabled) if (!moduleConfig.mqtt.proxy_to_client_enabled)
@ -633,8 +635,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me
return; return;
} }
if (strcmp(moduleConfig.mqtt.address, default_mqtt_address) == 0 && if (isDefaultMqttServer && (mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP ||
(mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP ||
mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) { mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) {
LOG_DEBUG("MQTT onSend - Ignoring range test or detection sensor message on public mqtt"); LOG_DEBUG("MQTT onSend - Ignoring range test or detection sensor message on public mqtt");
return; return;