Skip to content

Commit 76947b9

Browse files
FEAT(client/server): use native mDNS/DNS-SD API on Windows, if available
This allows: - The client to find servers advertized via zeroconf without the need for Bonjour to be installed. - The server to advertize itself via zeroconf without the need for Bonjour to be installed. The Win32 API was introduced in the version 10.0.18362.0 (1903/19H1) of Windows SDK. Before that, only the UWP interface was available (introduced in Windows 10 1507). This commit was successfully tested on Windows 10 1809, which probably means that the API can be used on previous versions as well. Even if that isn't the case, it's not a problem: if the code fails to load the required symbols, it falls back to Bonjour. "Q_OS_WIN64" is used instead of "Q_OS_WIN" because of an issue that appears when certain DNS functions are used in an x86 (32 bit) build: This means that until the issue is fixed we can safely use the native mDNS-DNS-SD API only on x86_64 (64 bit).
1 parent e33b72e commit 76947b9

File tree

7 files changed

+555
-68
lines changed

7 files changed

+555
-68
lines changed

src/mumble/ConnectDialog.cpp

+18-27
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#ifdef USE_ZEROCONF
99
# include "Zeroconf.h"
10-
# include "BonjourServiceBrowser.h"
11-
# include "BonjourServiceResolver.h"
1210
#endif
1311

1412
#include "Channel.h"
@@ -1033,22 +1031,16 @@ ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoCo
10331031
startDns(si);
10341032
qtwServers->siFavorite->addServerItem(si);
10351033
}
1036-
10371034
#ifdef USE_ZEROCONF
1038-
// Make sure the we got the objects we need, then wire them up
1039-
if (bAllowZeroconf && g.zeroconf->bsbBrowser && g.zeroconf->bsrResolver) {
1040-
connect(g.zeroconf->bsbBrowser.data(), SIGNAL(error(DNSServiceErrorType)), this,
1041-
SLOT(onLanBrowseError(DNSServiceErrorType)));
1042-
connect(g.zeroconf->bsbBrowser.data(), SIGNAL(currentBonjourRecordsChanged(const QList< BonjourRecord > &)),
1043-
this, SLOT(onUpdateLanList(const QList< BonjourRecord > &)));
1044-
connect(g.zeroconf->bsrResolver.data(), SIGNAL(error(BonjourRecord, DNSServiceErrorType)), this,
1045-
SLOT(onLanResolveError(BonjourRecord, DNSServiceErrorType)));
1046-
connect(g.zeroconf->bsrResolver.data(), SIGNAL(bonjourRecordResolved(BonjourRecord, QString, int)), this,
1047-
SLOT(onResolved(BonjourRecord, QString, int)));
1048-
onUpdateLanList(g.zeroconf->bsbBrowser->currentRecords());
1035+
if (bAllowZeroconf && g.zeroconf && g.zeroconf->isOk()) {
1036+
connect(g.zeroconf, &Zeroconf::recordsChanged, this, &ConnectDialog::onUpdateLanList);
1037+
connect(g.zeroconf, &Zeroconf::recordResolved, this, &ConnectDialog::onResolved);
1038+
connect(g.zeroconf, &Zeroconf::resolveError, this, &ConnectDialog::onLanResolveError);
1039+
onUpdateLanList(g.zeroconf->currentRecords());
1040+
1041+
g.zeroconf->startBrowser(QLatin1String("_mumble._tcp"));
10491042
}
10501043
#endif
1051-
10521044
qtPingTick = new QTimer(this);
10531045
connect(qtPingTick, SIGNAL(timeout()), this, SLOT(timeTick()));
10541046

@@ -1082,6 +1074,12 @@ ConnectDialog::ConnectDialog(QWidget *p, bool autoconnect) : QDialog(p), bAutoCo
10821074
}
10831075

10841076
ConnectDialog::~ConnectDialog() {
1077+
#ifdef USE_ZEROCONF
1078+
if (bAllowZeroconf && g.zeroconf && g.zeroconf->isOk()) {
1079+
g.zeroconf->stopBrowser();
1080+
g.zeroconf->cleanupResolvers();
1081+
}
1082+
#endif
10851083
ServerItem::qmIcons.clear();
10861084

10871085
QList< FavoriteServer > ql;
@@ -1356,7 +1354,7 @@ void ConnectDialog::initList() {
13561354
}
13571355

13581356
#ifdef USE_ZEROCONF
1359-
void ConnectDialog::onResolved(BonjourRecord record, QString host, int port) {
1357+
void ConnectDialog::onResolved(const BonjourRecord record, const QString host, const uint16_t port) {
13601358
qlBonjourActive.removeAll(record);
13611359
foreach (ServerItem *si, qlItems) {
13621360
if (si->zeroconfRecord == record) {
@@ -1393,7 +1391,7 @@ void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
13931391
if (!found) {
13941392
ServerItem *si = new ServerItem(record);
13951393
qlItems << si;
1396-
g.zeroconf->bsrResolver->resolveBonjourRecord(record);
1394+
g.zeroconf->startResolver(record);
13971395
startDns(si);
13981396
qtwServers->siLAN->addServerItem(si);
13991397
}
@@ -1406,13 +1404,8 @@ void ConnectDialog::onUpdateLanList(const QList< BonjourRecord > &list) {
14061404
}
14071405
}
14081406

1409-
void ConnectDialog::onLanBrowseError(DNSServiceErrorType err) {
1410-
qWarning() << "Bonjour reported browser error " << err;
1411-
}
1412-
1413-
void ConnectDialog::onLanResolveError(BonjourRecord br, DNSServiceErrorType err) {
1414-
qlBonjourActive.removeAll(br);
1415-
qWarning() << "Bonjour reported resolver error " << err;
1407+
void ConnectDialog::onLanResolveError(const BonjourRecord record) {
1408+
qlBonjourActive.removeAll(record);
14161409
}
14171410
#endif
14181411

@@ -1627,17 +1620,15 @@ void ConnectDialog::startDns(ServerItem *si) {
16271620
foreach (const ServerAddress &addr, si->qlAddresses) { qhPings[addr].insert(si); }
16281621
return;
16291622
}
1630-
16311623
#ifdef USE_ZEROCONF
16321624
if (bAllowZeroconf && si->qsHostname.isEmpty() && !si->zeroconfRecord.serviceName.isEmpty()) {
16331625
if (!qlBonjourActive.contains(si->zeroconfRecord)) {
1634-
g.zeroconf->bsrResolver->resolveBonjourRecord(si->zeroconfRecord);
1626+
g.zeroconf->startResolver(si->zeroconfRecord);
16351627
qlBonjourActive.append(si->zeroconfRecord);
16361628
}
16371629
return;
16381630
}
16391631
#endif
1640-
16411632
if (!qhDNSWait.contains(unresolved)) {
16421633
if (si->itType == ServerItem::PublicType)
16431634
qlDNSLookup.append(unresolved);

src/mumble/ConnectDialog.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,9 @@ public slots:
358358
QList< BonjourRecord > qlBonjourActive;
359359
public slots:
360360
void onUpdateLanList(const QList< BonjourRecord > &);
361-
void onLanBrowseError(DNSServiceErrorType);
362361

363-
void onResolved(BonjourRecord, QString, int);
364-
void onLanResolveError(BonjourRecord, DNSServiceErrorType);
362+
void onResolved(const BonjourRecord, const QString, const uint16_t);
363+
void onLanResolveError(const BonjourRecord);
365364
#endif
366365
private slots:
367366
void on_qleSearchServername_textChanged(const QString &searchServername);

0 commit comments

Comments
 (0)