Revert "Remove a bunch of debug logs"

This reverts commit 872e75b6fa.
This commit is contained in:
Albert Vaca Cintora 2023-08-11 15:10:59 +02:00
parent 0fd5d41fbe
commit 4b6cfaaf6c
2 changed files with 31 additions and 4 deletions

View file

@ -230,6 +230,7 @@ void LanLinkProvider::sendUdpIdentityPacket(QUdpSocket &socket, const QList<QHos
for (auto &address : addresses) {
qint64 bytes = socket.writeDatagram(payload, address, m_udpBroadcastPort);
qWarning() << "Send UDP identity packet to" << address;
if (bytes == -1 && socket.error() == QAbstractSocket::DatagramTooLargeError) {
// On macOS and FreeBSD, UDP broadcasts larger than MTU get dropped. See:
// https://opensource.apple.com/source/xnu/xnu-3789.1.32/bsd/netinet/ip_output.c.auto.html#:~:text=/*%20don%27t%20allow%20broadcast%20messages%20to%20be%20fragmented%20*/
@ -255,6 +256,8 @@ void LanLinkProvider::udpBroadcastReceived()
m_udpSocket.readDatagram(datagram.data(), datagram.size(), &sender);
qWarning() << "Received UDP identity packet";
if (sender.isLoopback() && !m_testMode)
continue;

View file

@ -107,6 +107,7 @@ static int query_callback(int sock, const struct sockaddr* from, size_t addrlen,
if (discoveredService->address == QHostAddress::Null) {
discoveredService->address = QHostAddress(from); // In case we don't receive a A record, use from as address
}
qWarning() << "Got a PTR for addres" << discoveredService->address;
} break;
case MDNS_RECORDTYPE_SRV: {
static char nameBuffer[256];
@ -239,7 +240,7 @@ void Discoverer::sendQuery(const QString &serviceType)
qCDebug(KDECONNECT_CORE) << "Sending mDNS query via socket" << socket;
int ret = mdns_multiquery_send(socket, &query, 1, buffer, sizeof(buffer), 0);
if (ret < 0) {
qCWarning(KDECONNECT_CORE) << "Failed to send mDNS query:" << strerror(errno);
qWarning() << "Failed to send mDNS query:" << strerror(errno);
}
}
}
@ -278,7 +279,7 @@ static QHostAddress findBestAddressMatchV4(const QVector<QHostAddress> &hostAddr
return hostAddresses[0];
}
// qDebug() << "I have more than one IP address:" << hostAddresses << "- Finding best match for source IP:" << otherIp;
qWarning() << "I have more than one IP address:" << hostAddresses << "- Finding best match for source IP:" << otherIp;
QHostAddress matchingIp = hostAddresses[0];
int matchingBits = -1;
@ -294,7 +295,7 @@ static QHostAddress findBestAddressMatchV4(const QVector<QHostAddress> &hostAddr
}
}
// qDebug() << "Found match:" << matchingIp;
qWarning() << "Found match:" << matchingIp;
return matchingIp;
}
@ -372,12 +373,17 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
int ret = 0;
if (name == dnsSdName) {
qWarning() << "Someone queried all services for" << recordTypeToStr(record_type);
if ((record_type == MDNS_RECORDTYPE_PTR) || (record_type == MDNS_RECORDTYPE_ANY)) {
// The PTR query was for the DNS-SD domain, send answer with a PTR record for the service name we advertise.
mdns_record_t answer = createMdnsRecord(self, MDNS_RECORDTYPE_PTR);
// Send the answer, unicast or multicast depending on flag in query
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
printf(" --> answer %.*s (%s)\n", MDNS_STRING_FORMAT(answer.data.ptr.name), (unicast ? "unicast" : "multicast"));
if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length,
@ -387,6 +393,7 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
}
}
} else if (name == self.serviceType) {
qWarning() << "Someone queried my service type for" << recordTypeToStr(record_type);
if ((record_type == MDNS_RECORDTYPE_PTR) || (record_type == MDNS_RECORDTYPE_ANY)) {
// The PTR query was for our service, answer a PTR record reverse mapping the queried service name
// to our service instance name and add additional records containing the SRV record mapping the
@ -407,7 +414,10 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
additional.append(createMdnsRecord(self, MDNS_RECORDTYPE_TXT, nullptr, txtIterator));
}
// Send the answer, unicast or multicast depending on flag in query
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
printf(" --> answer %.*s (%s)\n", MDNS_STRING_FORMAT(answer.data.ptr.name), (unicast ? "unicast" : "multicast"));
if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length,
@ -418,6 +428,7 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
}
}
} else if (name == self.serviceInstance) {
qWarning() << "Someone queried my service instance" << recordTypeToStr(record_type);
if ((record_type == MDNS_RECORDTYPE_SRV) || (record_type == MDNS_RECORDTYPE_ANY)) {
// The SRV query was for our service instance, answer a SRV record mapping the service
// instance name to our qualified hostname (typically "<hostname>.local.") and port, as
@ -437,7 +448,10 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
additional.append(createMdnsRecord(self, MDNS_RECORDTYPE_TXT, nullptr, txtIterator));
}
// Send the answer, unicast or multicast depending on flag in query
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
printf(" --> answer %.*s port %d (%s)\n", MDNS_STRING_FORMAT(answer.data.srv.name), answer.data.srv.port, (unicast ? "unicast" : "multicast"));
if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length,
@ -448,6 +462,7 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
}
}
} else if (name == self.hostname) {
qWarning() << "Someone queried my host for" << recordTypeToStr(record_type);
if (((record_type == MDNS_RECORDTYPE_A) || (record_type == MDNS_RECORDTYPE_ANY)) && !self.addressesV4.empty()) {
// The A query was for our qualified hostname and we have an IPv4 address, answer with an A
// record mapping the hostname to an IPv4 address, as well as an AAAA record and TXT records
@ -463,7 +478,10 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
additional.append(createMdnsRecord(self, MDNS_RECORDTYPE_TXT, nullptr, txtIterator));
}
// Send the answer, unicast or multicast depending on flag in query
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
printf(" --> answer %.*s IPv4 (%s)\n", MDNS_STRING_FORMAT(answer.name), (unicast ? "unicast" : "multicast"));
if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length,
@ -487,7 +505,10 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
additional.append(createMdnsRecord(self, MDNS_RECORDTYPE_TXT, nullptr, txtIterator));
}
// Send the answer, unicast or multicast depending on flag in query
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
printf(" --> answer %.*s IPv6 (%s)\n", MDNS_STRING_FORMAT(answer.name), (unicast ? "unicast" : "multicast"));
if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length,
@ -572,6 +593,7 @@ Announcer::Announcer(const QString &instanceName, const QString &serviceType, ui
void Announcer::detectHostAddresses()
{
qWarning() << "detectHostAddresses";
self.addressesV4.clear();
self.addressesV6.clear();
for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) {
@ -582,8 +604,10 @@ void Announcer::detectHostAddresses()
for (const QNetworkAddressEntry &ifaceAddress : iface.addressEntries()) {
QHostAddress sourceAddress = ifaceAddress.ip();
if (sourceAddress.protocol() == QAbstractSocket::IPv4Protocol && sourceAddress != QHostAddress::LocalHost) {
qWarning() << "Found ipv4" << sourceAddress;
self.addressesV4.append(sourceAddress);
} else if (sourceAddress.protocol() == QAbstractSocket::IPv6Protocol && sourceAddress != QHostAddress::LocalHostIPv6) {
qWarning() << "Found ipv6" << sourceAddress;
self.addressesV6.append(sourceAddress);
}
}
@ -594,7 +618,7 @@ void Announcer::startAnnouncing()
{
int num_sockets = listenForQueries();
if (num_sockets <= 0) {
qCWarning(KDECONNECT_CORE) << "Failed to open any MDNS client sockets";
qWarning() << "Failed to open any client sockets";
return;
}
sendMulticastAnnounce(false);