From 5f93345d1fe2e25c0aa5a986047397d59accdc1a Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Mon, 3 Jun 2024 00:24:29 +0200 Subject: [PATCH] Improve network debugging messages to help with Conan PR --- libraries/networking/src/LimitedNodeList.cpp | 20 ++++++++++++----- libraries/networking/src/LimitedNodeList.h | 3 ++- libraries/networking/src/SockAddr.cpp | 9 +++++--- libraries/networking/src/SocketType.h | 4 ++++ .../networking/src/udt/NetworkSocket.cpp | 22 +++++++++---------- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 33b2fcad78..d182e7ea94 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -41,7 +41,7 @@ #if defined(Q_OS_WIN) #include -#else +#else #include #endif @@ -501,7 +501,7 @@ qint64 LimitedNodeList::sendUnreliableUnorderedPacketList(NLPacketList& packetLi } return bytesSent; } else { - qCDebug(networking) << "LimitedNodeList::sendUnreliableUnorderedPacketList called without active socket for node" + qCDebug(networking) << "LimitedNodeList::sendUnreliableUnorderedPacketList called without active socket for node" << destinationNode << " - not sending."; return ERROR_SENDING_PACKET_BYTES; } @@ -1143,7 +1143,7 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() { if (_stunSockAddr.getAddress().isNull()) { // if we fail to lookup the socket then timeout the STUN address lookup - connect(&_stunSockAddr, &SockAddr::lookupFailed, this, &LimitedNodeList::possiblyTimeoutSTUNAddressLookup); + connect(&_stunSockAddr, &SockAddr::lookupFailed, this, &LimitedNodeList::STUNAddressLookupFailed); // immediately send a STUN request once we know the socket connect(&_stunSockAddr, &SockAddr::lookupCompleted, this, &LimitedNodeList::sendSTUNRequest); @@ -1157,7 +1157,7 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() { QTimer* lookupTimeoutTimer = new QTimer { this }; lookupTimeoutTimer->setSingleShot(true); - connect(lookupTimeoutTimer, &QTimer::timeout, this, &LimitedNodeList::possiblyTimeoutSTUNAddressLookup); + connect(lookupTimeoutTimer, &QTimer::timeout, this, &LimitedNodeList::STUNAddressLookupTimeout); // delete the lookup timeout timer once it has fired connect(lookupTimeoutTimer, &QTimer::timeout, lookupTimeoutTimer, &QTimer::deleteLater); @@ -1172,10 +1172,18 @@ void LimitedNodeList::startSTUNPublicSocketUpdate() { } } -void LimitedNodeList::possiblyTimeoutSTUNAddressLookup() { +void LimitedNodeList::STUNAddressLookupFailed() { + if (_stunSockAddr.getAddress().isNull()) { + // got a lookup failure + qCCritical(networking) << "PAGE: Failed to lookup address of STUN server" << STUN_SERVER_HOSTNAME; + stopInitialSTUNUpdate(false); + } +} + +void LimitedNodeList::STUNAddressLookupTimeout() { if (_stunSockAddr.getAddress().isNull()) { // our stun address is still NULL, but we've been waiting for long enough - time to force a fail - qCCritical(networking) << "PAGE: Failed to lookup address of STUN server" << STUN_SERVER_HOSTNAME; + qCCritical(networking) << "PAGE: Address lookup of STUN server" << STUN_SERVER_HOSTNAME << "timed out"; stopInitialSTUNUpdate(false); } } diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 103f7e0755..cdb742a3c3 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -483,7 +483,8 @@ protected: private slots: void flagTimeForConnectionStep(ConnectionStep connectionStep, quint64 timestamp); - void possiblyTimeoutSTUNAddressLookup(); + void STUNAddressLookupTimeout(); + void STUNAddressLookupFailed(); void addSTUNHandlerToUnfiltered(); // called once STUN socket known private: diff --git a/libraries/networking/src/SockAddr.cpp b/libraries/networking/src/SockAddr.cpp index 29fbde3934..1f049d14c7 100644 --- a/libraries/networking/src/SockAddr.cpp +++ b/libraries/networking/src/SockAddr.cpp @@ -67,12 +67,13 @@ SockAddr::SockAddr(SocketType socketType, const QString& hostname, quint16 hostO if (_address.protocol() != QAbstractSocket::IPv4Protocol) { // lookup the IP by the hostname if (shouldBlockForLookup) { - qCDebug(networking) << "Synchronously looking up IP address for hostname" << hostname; + qCDebug(networking) << "Synchronously looking up IP address for hostname" << hostname << "for" << socketType << "socket on port" << hostOrderPort; QHostInfo result = QHostInfo::fromName(hostname); handleLookupResult(result); } else { - int lookupID = QHostInfo::lookupHost(hostname, this, SLOT(handleLookupResult(QHostInfo))); - qCDebug(networking) << "Asynchronously looking up IP address for hostname" << hostname << "- lookup ID is" << lookupID; + qCDebug(networking) << "Asynchronously looking up IP address for hostname" << hostname << "for" << socketType << "socket on port" << hostOrderPort; + int lookupID = QHostInfo::lookupHost(hostname, this, &SockAddr::handleLookupResult); + qCDebug(networking) << "Lookup ID for " << hostname << "is" << lookupID; } } } @@ -95,6 +96,8 @@ bool SockAddr::operator==(const SockAddr& rhsSockAddr) const { } void SockAddr::handleLookupResult(const QHostInfo& hostInfo) { + qCDebug(networking) << "handleLookupResult for" << hostInfo.lookupId(); + if (hostInfo.error() != QHostInfo::NoError) { qCDebug(networking) << "Lookup failed for" << hostInfo.lookupId() << ":" << hostInfo.errorString(); emit lookupFailed(); diff --git a/libraries/networking/src/SocketType.h b/libraries/networking/src/SocketType.h index 399940654d..33da7c4ea0 100644 --- a/libraries/networking/src/SocketType.h +++ b/libraries/networking/src/SocketType.h @@ -36,6 +36,10 @@ public: } }; +inline QDebug operator<<(QDebug debug, SocketType type) { + debug << SocketTypeToString::socketTypeToString(type); + return debug; +} /// @} #endif // overte_SocketType_h diff --git a/libraries/networking/src/udt/NetworkSocket.cpp b/libraries/networking/src/udt/NetworkSocket.cpp index 179abe9f78..298455e33c 100644 --- a/libraries/networking/src/udt/NetworkSocket.cpp +++ b/libraries/networking/src/udt/NetworkSocket.cpp @@ -45,7 +45,7 @@ void NetworkSocket::setSocketOption(SocketType socketType, QAbstractSocket::Sock break; #endif default: - qCCritical(networking) << "Socket type not specified in setSocketOption()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in setSocketOption()"; } } @@ -58,7 +58,7 @@ QVariant NetworkSocket::socketOption(SocketType socketType, QAbstractSocket::Soc return _webrtcSocket.socketOption(option); #endif default: - qCCritical(networking) << "Socket type not specified in socketOption()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in socketOption()"; return ""; } } @@ -75,7 +75,7 @@ void NetworkSocket::bind(SocketType socketType, const QHostAddress& address, qui break; #endif default: - qCCritical(networking) << "Socket type not specified in bind()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in bind()"; } } @@ -90,7 +90,7 @@ void NetworkSocket::abort(SocketType socketType) { break; #endif default: - qCCritical(networking) << "Socket type not specified in abort()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in abort()"; } } @@ -104,7 +104,7 @@ quint16 NetworkSocket::localPort(SocketType socketType) const { return _webrtcSocket.localPort(); #endif default: - qCCritical(networking) << "Socket type not specified in localPort()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in localPort()"; return 0; } } @@ -119,7 +119,7 @@ qintptr NetworkSocket::socketDescriptor(SocketType socketType) const { return 0; #endif default: - qCCritical(networking) << "Socket type not specified in socketDescriptor()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in socketDescriptor()"; return 0; } } @@ -136,7 +136,7 @@ qint64 NetworkSocket::writeDatagram(const QByteArray& datagram, const SockAddr& return _webrtcSocket.writeDatagram(datagram, sockAddr); #endif default: - qCCritical(networking) << "Socket type not specified in writeDatagram() address"; + qCCritical(networking) << "Socket type" << sockAddr.getType() << "not recognized in writeDatagram() address"; return 0; } } @@ -150,7 +150,7 @@ qint64 NetworkSocket::bytesToWrite(SocketType socketType, const SockAddr& addres return _webrtcSocket.bytesToWrite(address); #endif default: - qCCritical(networking) << "Socket type not specified in bytesToWrite()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in bytesToWrite()"; return 0; } } @@ -232,7 +232,7 @@ QAbstractSocket::SocketState NetworkSocket::state(SocketType socketType) const { return _webrtcSocket.state(); #endif default: - qCCritical(networking) << "Socket type not specified in state()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in state()"; return QAbstractSocket::SocketState::UnconnectedState; } } @@ -247,7 +247,7 @@ QAbstractSocket::SocketError NetworkSocket::error(SocketType socketType) const { return _webrtcSocket.error(); #endif default: - qCCritical(networking) << "Socket type not specified in error()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in error()"; return QAbstractSocket::SocketError::UnknownSocketError; } } @@ -261,7 +261,7 @@ QString NetworkSocket::errorString(SocketType socketType) const { return _webrtcSocket.errorString(); #endif default: - qCCritical(networking) << "Socket type not specified in errorString()"; + qCCritical(networking) << "Socket type" << socketType << "not recognized in errorString()"; return ""; } }