Update to latest upstream QtZeroConf
parent
8f6fa4ee90
commit
4f218ab981
|
|
@ -1 +1 @@
|
|||
Subproject commit 1632db0b7f9f637b1a6325a267fa404c40fa6693
|
||||
Subproject commit 1e36e430e98ecec6e15ab06f56467567f22f9e8a
|
||||
|
|
@ -11,7 +11,6 @@ ZeroconfDiscovery::ZeroconfDiscovery(NymeaHosts *nymeaHosts, QObject *parent) :
|
|||
#ifdef WITH_ZEROCONF
|
||||
// NOTE: There seem to be too many issues in QtZeroConf and IPv6.
|
||||
// See https://github.com/jbagg/QtZeroConf/issues/22
|
||||
// IPv6 resolving is disabled completely for android in avahicore.cpp for now
|
||||
// Limiting this to IPv4 for now...
|
||||
|
||||
m_zeroconfJsonRPC = new QZeroConf(this);
|
||||
|
|
@ -54,40 +53,30 @@ bool ZeroconfDiscovery::discovering() const
|
|||
#ifdef WITH_ZEROCONF
|
||||
void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry)
|
||||
{
|
||||
if (!entry.name().startsWith("nymea")) {
|
||||
if (!entry->name().startsWith("nymea")) {
|
||||
// Skip non-nymea services altogether
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry.ip() << entry.ipv6() << entry.txt() << entry.type();
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry->ip() << entry->txt() << entry->type();
|
||||
return;
|
||||
}
|
||||
if (entry.ip().isNull() && entry.ipv6().isNull()) {
|
||||
if (entry->ip().isNull()) {
|
||||
// Skip entries that don't have an ip address at all for some reason
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry.ip() << entry.ipv6() << entry.txt() << entry.type();
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry->ip() << entry->txt() << entry->type();
|
||||
return;
|
||||
}
|
||||
if (entry.ip().isNull() && entry.ipv6().toString().startsWith("fe80")) {
|
||||
// Skip link-local-IPv6-only results
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry.ip() << entry.ipv6() << entry.txt() << entry.type();
|
||||
if (entry->ip().toString().startsWith("fe80")) {
|
||||
// Skip link-local-IPv6 results
|
||||
qDebug() << "Skipping Avahi entry:" << entry << entry->ip() << entry->txt() << entry->type();
|
||||
return;
|
||||
}
|
||||
|
||||
// Workaround a bug in deeper layers (I believe it's avahi, but could be QtZeroConf too):
|
||||
// Sometimes the ip() field contains an IPv6 address. In that case the entry is likely garbage as
|
||||
// it does not mean the host necessarily exports the services on IPv6.
|
||||
bool isIPv4;
|
||||
entry.ip().toIPv4Address(&isIPv4);
|
||||
if (!isIPv4) {
|
||||
qDebug() << "Skipping invalid Avahi entry: IPv4:" << entry.ip();
|
||||
return;
|
||||
}
|
||||
|
||||
// qDebug() << "zeroconf service discovered" << entry.type() << entry.name() << " IP:" << entry.ip() << "IPv6:" << entry.ipv6() << entry.txt();
|
||||
qDebug() << "zeroconf service discovered" << entry->type() << entry->name() << " IP:" << entry->ip().toString() << entry->txt();
|
||||
|
||||
QString uuid;
|
||||
bool sslEnabled = false;
|
||||
QString serverName;
|
||||
QString version;
|
||||
foreach (const QByteArray &key, entry.txt().keys()) {
|
||||
QPair<QString, QString> txtRecord = qMakePair<QString, QString>(key, entry.txt().value(key));
|
||||
foreach (const QByteArray &key, entry->txt().keys()) {
|
||||
QPair<QString, QString> txtRecord = qMakePair<QString, QString>(key, entry->txt().value(key));
|
||||
if (!sslEnabled && txtRecord.first == "sslEnabled") {
|
||||
sslEnabled = (txtRecord.second == "true");
|
||||
}
|
||||
|
|
@ -108,37 +97,37 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry)
|
|||
if (!host) {
|
||||
host = new NymeaHost(m_nymeaHosts);
|
||||
host->setUuid(uuid);
|
||||
// qDebug() << "ZeroConf: Adding new host:" << serverName << uuid;
|
||||
qDebug() << "ZeroConf: Adding new host:" << serverName << uuid;
|
||||
m_nymeaHosts->addHost(host);
|
||||
}
|
||||
host->setName(serverName);
|
||||
host->setVersion(version);
|
||||
QUrl url;
|
||||
// NOTE: On linux this is "_jsonrpc._tcp" while on apple systems this is "_jsonrpc._tcp."
|
||||
if (entry.type().startsWith("_jsonrpc._tcp")) {
|
||||
if (entry->type().startsWith("_jsonrpc._tcp")) {
|
||||
url.setScheme(sslEnabled ? "nymeas" : "nymea");
|
||||
} else if (entry.type().startsWith("_ws._tcp")) {
|
||||
} else if (entry->type().startsWith("_ws._tcp")) {
|
||||
url.setScheme(sslEnabled ? "wss" : "ws");
|
||||
}
|
||||
url.setHost(!entry.ip().isNull() ? entry.ip().toString() : entry.ipv6().toString());
|
||||
url.setPort(entry.port());
|
||||
url.setHost(entry->ip().toString());
|
||||
url.setPort(entry->port());
|
||||
Connection *connection = host->connections()->find(url);
|
||||
if (!connection) {
|
||||
// qDebug() << "Zeroconf: Adding new connection to host:" << host->name() << url.toString();
|
||||
qDebug() << "Zeroconf: Adding new connection to host:" << host->name() << url.toString();
|
||||
QString displayName = QString("%1:%2").arg(url.host()).arg(url.port());
|
||||
Connection::BearerType bearerType = QHostAddress(url.host()).isLoopback() ? Connection::BearerTypeLoopback : Connection::BearerTypeLan;
|
||||
connection = new Connection(url, bearerType, sslEnabled, displayName);
|
||||
connection->setOnline(true);
|
||||
host->connections()->addConnection(connection);
|
||||
} else {
|
||||
// qDebug() << "Zeroconf: Setting connection online:" << host->name() << url.toString();
|
||||
qDebug() << "Zeroconf: Setting connection online:" << host->name() << url.toString();
|
||||
connection->setOnline(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry)
|
||||
{
|
||||
if (!entry.name().startsWith("nymea") || (entry.ip().isNull() && entry.ipv6().isNull())) {
|
||||
if (!entry->name().startsWith("nymea") || entry->ip().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -146,8 +135,8 @@ void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry)
|
|||
bool sslEnabled = false;
|
||||
QString serverName;
|
||||
QString version;
|
||||
foreach (const QByteArray &key, entry.txt().keys()) {
|
||||
QPair<QString, QString> txtRecord = qMakePair<QString, QString>(key, entry.txt().value(key));
|
||||
foreach (const QByteArray &key, entry->txt().keys()) {
|
||||
QPair<QString, QString> txtRecord = qMakePair<QString, QString>(key, entry->txt().value(key));
|
||||
if (!sslEnabled && txtRecord.first == "sslEnabled") {
|
||||
sslEnabled = (txtRecord.second == "true");
|
||||
}
|
||||
|
|
@ -162,7 +151,7 @@ void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry)
|
|||
}
|
||||
}
|
||||
|
||||
// qDebug() << "Zeroconf: Service entry removed" << entry.name();
|
||||
// qDebug() << "Zeroconf: Service entry removed" << entry->name();
|
||||
|
||||
NymeaHost* host = m_nymeaHosts->find(uuid);
|
||||
if (!host) {
|
||||
|
|
@ -171,13 +160,13 @@ void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry)
|
|||
}
|
||||
|
||||
QUrl url;
|
||||
if (entry.type() == "_jsonrpc._tcp") {
|
||||
if (entry->type() == "_jsonrpc._tcp") {
|
||||
url.setScheme(sslEnabled ? "nymeas" : "nymea");
|
||||
} else {
|
||||
url.setScheme(sslEnabled ? "wss" : "ws");
|
||||
}
|
||||
url.setHost(!entry.ip().isNull() ? entry.ip().toString() : entry.ipv6().toString());
|
||||
url.setPort(entry.port());
|
||||
url.setHost(entry->ip().toString());
|
||||
url.setPort(entry->port());
|
||||
Connection *connection = host->connections()->find(url);
|
||||
if (!connection){
|
||||
// Connection url not found...
|
||||
|
|
|
|||
|
|
@ -255,9 +255,9 @@ void DeviceManager::getConfiguredDevicesResponse(const QVariantMap ¶ms)
|
|||
device->setStateValue(stateTypeId, value);
|
||||
// qDebug() << "Set device state value:" << device->stateValue(stateTypeId) << value;
|
||||
}
|
||||
qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
||||
// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
||||
devices()->addDevice(device);
|
||||
qDebug() << "*** Added device:" << endl << device;
|
||||
// qDebug() << "*** Added device:" << endl << device;
|
||||
}
|
||||
}
|
||||
m_fetchingData = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue