Skip to content

Commit

Permalink
Revert "Separate host/port before checking for private IP (meshtastic…
Browse files Browse the repository at this point in the history
…#5630)" (meshtastic#5635)

This reverts commit 398d290.
  • Loading branch information
thebentern authored Dec 21, 2024
1 parent f39a9c5 commit d9b2878
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,6 @@ bool isPrivateIpAddress(const IPAddress &ip)
}
return false;
}

std::pair<std::string, uint16_t> parseHostAndPort(std::string address, uint16_t port = 0)
{
const size_t delimIndex = address.find_first_of(':');
if (delimIndex > 0) {
port = std::stoul(address.substr(delimIndex + 1, address.length()));
address.resize(delimIndex);
}
return std::make_pair(std::move(address), port);
}
} // namespace

void MQTT::mqttCallback(char *topic, byte *payload, unsigned int length)
Expand Down Expand Up @@ -318,8 +308,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
}

IPAddress ip;
isMqttServerAddressPrivate =
ip.fromString(parseHostAndPort(moduleConfig.mqtt.address).first.c_str()) && isPrivateIpAddress(ip);
isMqttServerAddressPrivate = ip.fromString(moduleConfig.mqtt.address) && isPrivateIpAddress(ip);

#if HAS_NETWORKING
if (!moduleConfig.mqtt.proxy_to_client_enabled)
Expand Down Expand Up @@ -435,9 +424,14 @@ void MQTT::reconnect()
pubSub.setClient(mqttClient);
#endif

std::pair<std::string, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
serverAddr = hostAndPort.first.c_str();
serverPort = hostAndPort.second;
String server = String(serverAddr);
int delimIndex = server.indexOf(':');
if (delimIndex > 0) {
String port = server.substring(delimIndex + 1, server.length());
server[delimIndex] = 0;
serverPort = port.toInt();
serverAddr = server.c_str();
}
pubSub.setServer(serverAddr, serverPort);
pubSub.setBufferSize(512);

Expand Down

0 comments on commit d9b2878

Please sign in to comment.