diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 7d2f085d6f..d92db8a5d4 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -1225,8 +1225,8 @@ void LimitedNodeList::connectedForLocalSocketTest() { auto localHostAddress = localIPTestSocket->localAddress(); if (localHostAddress.protocol() == QAbstractSocket::IPv4Protocol) { - _hasTCPCheckedLocalSocket = true; setLocalSocket(HifiSockAddr { localHostAddress, _nodeSocket.localPort() }); + _hasTCPCheckedLocalSocket = true; } localIPTestSocket->deleteLater(); @@ -1244,7 +1244,7 @@ void LimitedNodeList::errorTestingLocalSocket() { setLocalSocket(HifiSockAddr { getGuessedLocalAddress(), _nodeSocket.localPort() }); } - localIPTestSocket->deleteLater();; + localIPTestSocket->deleteLater(); } } diff --git a/libraries/networking/src/NetworkPeer.cpp b/libraries/networking/src/NetworkPeer.cpp index a48922726e..b7807bc62d 100644 --- a/libraries/networking/src/NetworkPeer.cpp +++ b/libraries/networking/src/NetworkPeer.cpp @@ -140,7 +140,7 @@ void NetworkPeer::activatePublicSocket() { void NetworkPeer::activateSymmetricSocket() { if (_activeSocket != &_symmetricSocket) { - qCDebug(networking) << "Activating symmetric socket for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid); + qCDebug(networking) << "Activating symmetric socket (" << _symmetricSocket << ") for network peer with ID" << uuidStringWithoutCurlyBraces(_uuid); setActiveSocket(&_symmetricSocket); } } diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index c25075171b..4c01517346 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -263,7 +263,7 @@ Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr, bool fi if (filterCreate && _connectionCreationFilterOperator && !_connectionCreationFilterOperator(sockAddr)) { // the connection creation filter did not allow us to create a new connection #ifdef UDT_CONNECTION_DEBUG - qCDebug(networking) << "Socket::findOrCreateConnection refusing to create connection for" << sockAddr + qCDebug(networking) << "Socket::findOrCreateConnection refusing to create Connection class for" << sockAddr << "due to connection creation filter"; #endif // UDT_CONNECTION_DEBUG return nullptr; @@ -279,7 +279,7 @@ Connection* Socket::findOrCreateConnection(const HifiSockAddr& sockAddr, bool fi QObject::connect(connection.get(), &Connection::receiverHandshakeRequestComplete, this, &Socket::clientHandshakeRequestComplete); - qCDebug(networking) << "Creating new connection to" << sockAddr; + qCDebug(networking) << "Creating new Connection class for" << sockAddr; it = _connectionsHash.insert(it, std::make_pair(sockAddr, std::move(connection))); } diff --git a/libraries/shared/src/shared/FileLogger.cpp b/libraries/shared/src/shared/FileLogger.cpp index b64d08c0d8..2ccc247af3 100644 --- a/libraries/shared/src/shared/FileLogger.cpp +++ b/libraries/shared/src/shared/FileLogger.cpp @@ -56,7 +56,6 @@ static FilePersistThread* _persistThreadInstance; QString getLogRollerFilename() { QString result = FileUtils::standardPath(LOGS_DIRECTORY); - QHostAddress clientAddress = getGuessedLocalAddress(); QDateTime now = QDateTime::currentDateTime(); QString fileSessionID; diff --git a/libraries/shared/src/shared/NetworkUtils.cpp b/libraries/shared/src/shared/NetworkUtils.cpp index 50356d30fc..705eac39c9 100644 --- a/libraries/shared/src/shared/NetworkUtils.cpp +++ b/libraries/shared/src/shared/NetworkUtils.cpp @@ -9,9 +9,19 @@ #include "NetworkUtils.h" #include +namespace { + const QString LINK_LOCAL_SUBNET {"169.254."}; + + // Is address local-subnet valid only (rfc 3927): + bool isLinkLocalAddress(const QHostAddress& ip4Addr) { + return ip4Addr.toString().startsWith(LINK_LOCAL_SUBNET); + } +} + QHostAddress getGuessedLocalAddress() { QHostAddress localAddress; + QHostAddress linkLocalAddress; foreach(const QNetworkInterface &networkInterface, QNetworkInterface::allInterfaces()) { if (networkInterface.flags() & QNetworkInterface::IsUp @@ -20,12 +30,16 @@ QHostAddress getGuessedLocalAddress() { // we've decided that this is the active NIC // enumerate it's addresses to grab the IPv4 address foreach(const QNetworkAddressEntry &entry, networkInterface.addressEntries()) { + const auto& addressCandidate = entry.ip(); // make sure it's an IPv4 address that isn't the loopback - if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.ip().isLoopback()) { - - // set our localAddress and break out - localAddress = entry.ip(); - break; + if (addressCandidate.protocol() == QAbstractSocket::IPv4Protocol && !addressCandidate.isLoopback()) { + if (isLinkLocalAddress(addressCandidate)) { + linkLocalAddress = addressCandidate; // Last resort + } else { + // set our localAddress and break out + localAddress = addressCandidate; + break; + } } } } @@ -36,7 +50,5 @@ QHostAddress getGuessedLocalAddress() { } // return the looked up local address - return localAddress; + return localAddress.isNull() ? linkLocalAddress : localAddress; } - -