From a08e9517622412348bc683d1fed586d1f554d84c Mon Sep 17 00:00:00 2001 From: redPanther Date: Wed, 22 Mar 2017 23:08:01 +0100 Subject: [PATCH] zeroconf updates (#421) * zeroconf: add ip make names more uniq * tune dns name for webconfig --- include/bonjour/bonjourrecord.h | 1 + libsrc/bonjour/bonjourservicebrowser.cpp | 2 +- libsrc/hyperion/Hyperion.cpp | 1 + libsrc/jsonserver/JsonClientConnection.cpp | 1 + libsrc/webconfig/StaticFileServing.cpp | 4 ++-- libsrc/webconfig/WebConfig.cpp | 2 +- src/hyperiond/hyperiond.cpp | 22 +++++++--------------- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/include/bonjour/bonjourrecord.h b/include/bonjour/bonjourrecord.h index 63ed17ab..0b8a522e 100755 --- a/include/bonjour/bonjourrecord.h +++ b/include/bonjour/bonjourrecord.h @@ -55,6 +55,7 @@ public: QString registeredType; QString replyDomain; QString hostName; + QString address; int port; bool operator==(const BonjourRecord &other) const diff --git a/libsrc/bonjour/bonjourservicebrowser.cpp b/libsrc/bonjour/bonjourservicebrowser.cpp index 34024db9..5b7664dd 100644 --- a/libsrc/bonjour/bonjourservicebrowser.cpp +++ b/libsrc/bonjour/bonjourservicebrowser.cpp @@ -90,7 +90,7 @@ void BonjourServiceBrowser::bonjourBrowseReply(DNSServiceRef , DNSServiceFlags f else { BonjourRecord bonjourRecord(serviceName, regType, replyDomain); - if (flags & kDNSServiceFlagsAdd) + if ((flags & kDNSServiceFlagsAdd) != 0) { if (!serviceBrowser->bonjourRecords.contains(bonjourRecord)) { diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 2c136c28..a28d6cef 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -505,6 +505,7 @@ void Hyperion::bonjourRecordResolved(const QHostInfo &hostInfo, int port) } _hyperionSessions[_bonjourCurrentServiceToResolve].hostName = host; _hyperionSessions[_bonjourCurrentServiceToResolve].port = port; + _hyperionSessions[_bonjourCurrentServiceToResolve].address = hostInfo.addresses().isEmpty() ? "" : hostInfo.addresses().first().toString(); Debug(_log, "found hyperion session: %s:%d",QSTRING_CSTR(hostInfo.hostName()), port); } } diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 3ce54531..cfd0bcd0 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -841,6 +841,7 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt item["type"] = session.registeredType; item["domain"] = session.replyDomain; item["host"] = session.hostName; + item["address"]= session.address; item["port"] = session.port; sessions.append(item); } diff --git a/libsrc/webconfig/StaticFileServing.cpp b/libsrc/webconfig/StaticFileServing.cpp index a83b0e41..396b1b46 100644 --- a/libsrc/webconfig/StaticFileServing.cpp +++ b/libsrc/webconfig/StaticFileServing.cpp @@ -44,8 +44,8 @@ StaticFileServing::~StaticFileServing () void StaticFileServing::onServerStarted (quint16 port) { Info(_log, "started on port %d name '%s'", port ,_server->getServerName().toStdString().c_str()); - - const QString mDNSDescr = _server->getServerName() + "@" + QHostInfo::localHostName(); + const QJsonObject & generalConfig = _hyperion->getQJsonConfig()["general"].toObject(); + const QString mDNSDescr = generalConfig["name"].toString("") + "@" + QHostInfo::localHostName() + ":" + QString::number(port); BonjourServiceRegister *bonjourRegister_http = new BonjourServiceRegister(); bonjourRegister_http->registerService( diff --git a/libsrc/webconfig/WebConfig.cpp b/libsrc/webconfig/WebConfig.cpp index 6d1f0696..36c9cf71 100644 --- a/libsrc/webconfig/WebConfig.cpp +++ b/libsrc/webconfig/WebConfig.cpp @@ -19,7 +19,7 @@ WebConfig::WebConfig(QObject * parent) { const QJsonObject webconfigConfig = config["webConfig"].toObject(); webconfigEnable = webconfigConfig["enable"].toBool(true); - _port = webconfigConfig["port"].toInt(_port); + _port = webconfigConfig["port"].toInt(_port); _baseUrl = webconfigConfig["document_root"].toString(_baseUrl); } diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 453b738d..21e0ac0f 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -368,35 +368,27 @@ void HyperionDaemon::startNetworkServices() // zeroconf description - $leddevicename@$hostname const QJsonObject & generalConfig = _qconfig["general"].toObject(); - const std::string mDNSDescr = ( generalConfig["name"].toString("").toStdString() - + "@" + - QHostInfo::localHostName().toStdString() - ); + const QString mDNSDescr = generalConfig["name"].toString("") + "@" + QHostInfo::localHostName(); // zeroconf udp listener - if (_udpListener != nullptr) { + if (_udpListener != nullptr) + { BonjourServiceRegister *bonjourRegister_udp = new BonjourServiceRegister(); bonjourRegister_udp->registerService( - BonjourRecord(mDNSDescr.c_str(), "_hyperiond-udp._udp", QString()), - _udpListener->getPort() - ); + BonjourRecord(mDNSDescr + ":" + QString::number(_udpListener->getPort()), "_hyperiond-udp._udp", QString()), _udpListener->getPort() ); Debug(_log, "UDP LIstener mDNS responder started"); } // zeroconf json BonjourServiceRegister *bonjourRegister_json = new BonjourServiceRegister(); - bonjourRegister_json->registerService( - BonjourRecord(mDNSDescr.c_str(), "_hyperiond-json._tcp", QString()), - _jsonServer->getPort() - ); + bonjourRegister_json->registerService( + BonjourRecord(mDNSDescr + ":" + QString::number(_jsonServer->getPort()), "_hyperiond-json._tcp", QString()), _jsonServer->getPort()); Debug(_log, "Json mDNS responder started"); // zeroconf proto BonjourServiceRegister *bonjourRegister_proto = new BonjourServiceRegister(); bonjourRegister_proto->registerService( - BonjourRecord(mDNSDescr.c_str(), "_hyperiond-proto._tcp", QString()), - _protoServer->getPort() - ); + BonjourRecord(mDNSDescr + ":" + QString::number(_jsonServer->getPort()), "_hyperiond-proto._tcp", QString()), _protoServer->getPort()); Debug(_log, "Proto mDNS responder started"); }