1.更新MDNS广播的服务类型命名规范,防止出现多设备打开找不到MDNS的广播的问题 2.更新区分前后板的TAG

This commit is contained in:
2024-09-02 10:22:41 +08:00
parent e0c1e37191
commit 09c5843358
22 changed files with 501 additions and 304 deletions

View File

@@ -27,6 +27,8 @@
#include <QtCore/qglobal.h>
#define BUILD_SHARED_LIBS
#define QMDNSENGINE_LIBRARY
#if defined(BUILD_SHARED_LIBS)
# if defined(QMDNSENGINE_LIBRARY)
# define QMDNSENGINE_EXPORT Q_DECL_EXPORT

View File

@@ -339,7 +339,10 @@ void toPacket(const Message &message, QByteArray &packet)
{
quint16 offset = 0;
quint16 flags = (message.isResponse() ? 0x8400 : 0) |
(message.isTruncated() ? 0x200 : 0);
(message.isTruncated() ? 0x200 : 0);
qDebug() << "Flags set in toPacket:" << QString::number(flags, 16);
writeInteger<quint16>(packet, offset, message.transactionId());
writeInteger<quint16>(packet, offset, flags);
writeInteger<quint16>(packet, offset, message.queries().length());

View File

@@ -71,7 +71,6 @@ void ProberPrivate::assertRecord()
message.addQuery(query);
message.addRecord(proposedRecord);
server->sendMessageToAll(message);
// Wait two seconds to confirm it is unique
timer.stop();
timer.start(2 * 1000);
@@ -80,14 +79,15 @@ void ProberPrivate::assertRecord()
void ProberPrivate::onMessageReceived(const Message &message)
{
// If the response matches the proposed record, increment the suffix and
// try with the new name
if (confirmed || !message.isResponse()) {
// try with the new name
//if (confirmed || !message.isResponse()) {
if (confirmed) {
return;
}
const auto records = message.records();
for (const Record &record : records) {
if (record.name() == proposedRecord.name() && record.type() == proposedRecord.type()) {
qDebug() << "Conflict detected for name:" << proposedRecord.name() << "with type:" << record.type();
++suffix;
assertRecord();
}

View File

@@ -79,8 +79,8 @@ void ProviderPrivate::confirm()
delete prober;
}
prober = new Prober(server, srvProposed, this);
connect(prober, &Prober::nameConfirmed, [this](const QByteArray &name) {
connect(prober, &Prober::nameConfirmed, [this](const QByteArray &name) {
// If existing records were confirmed, indicate that they are no
// longer valid
if (confirmed) {
@@ -128,7 +128,7 @@ void ProviderPrivate::onMessageReceived(const Message &message)
if (!confirmed || message.isResponse()) {
return;
}
//qDebug() << "Failed to start server. Error:" << server->errorString();
bool sendBrowsePtr = false;
bool sendPtr = false;
bool sendSrv = false;
@@ -227,13 +227,16 @@ void Provider::update(const Service &service)
return;
}
bool registered = d->hostname->isRegistered();
//qDebug() << "Hostname registered:" << registered;
if(registered) {
// 不确认服务名称,直接进行广播
d->publish();
//if (d->hostname->isRegistered()) {
if (!d->confirmed || fqName != d->srvRecord.name()) {
/*if (!d->confirmed || fqName != d->srvRecord.name()) {
qDebug() << "confirm()";
d->confirm();
} else {
qDebug() << "publish()";
d->publish();
}
}*/
}
}

View File

@@ -129,8 +129,6 @@ void Server::sendMessageToAll(const Message &message)
{
QByteArray packet;
toPacket(message, packet);
//qDebug() << "MdnsMsg :" << packet.toHex();
qDebug() << "MdnsPort:" << MdnsPort;
qint64 sentBytes = d->ipv4Socket.writeDatagram(packet, MdnsIpv4Address, MdnsPort);
qDebug() << "ipv4Socket sentBytes:" << sentBytes;
sentBytes = d->ipv6Socket.writeDatagram(packet, MdnsIpv6Address, MdnsPort);