diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index a1aef9878..d548535e2 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -37,12 +37,10 @@ static const int MAX_UNPAIRED_CONNECTIONS = 42; static const int MAX_REMEMBERED_IDENTITY_PACKETS = 42; -LanLinkProvider::LanLinkProvider(bool testMode, quint16 udpBroadcastPort, quint16 udpListenPort) +LanLinkProvider::LanLinkProvider(bool testMode) : m_server(new Server(this)) , m_udpSocket(this) , m_tcpPort(0) - , m_udpBroadcastPort(udpBroadcastPort) - , m_udpListenPort(udpListenPort) , m_testMode(testMode) , m_combineBroadcastsTimer(this) , m_mdnsDiscovery(this) @@ -83,12 +81,12 @@ void LanLinkProvider::onStart() { const QHostAddress bindAddress = m_testMode ? QHostAddress::LocalHost : QHostAddress::Any; - bool success = m_udpSocket.bind(bindAddress, m_udpListenPort, QUdpSocket::ShareAddress); + bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress); if (!success) { QAbstractSocket::SocketError sockErr = m_udpSocket.error(); // Refer to https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum to decode socket error number QString errorMessage = QString::fromLatin1(QMetaEnum::fromType().valueToKey(sockErr)); - qCritical(KDECONNECT_CORE) << QLatin1String("Failed to bind UDP socket on port") << m_udpListenPort << QLatin1String("with error") << errorMessage; + qCritical(KDECONNECT_CORE) << QLatin1String("Failed to bind UDP socket on port") << UDP_PORT << QLatin1String("with error") << errorMessage; } Q_ASSERT(success); @@ -211,7 +209,7 @@ void LanLinkProvider::sendUdpIdentityPacket(QUdpSocket &socket, const QListerrorString(); NetworkPacket np = KdeConnectConfig::instance().deviceInfo().toIdentityPacket(); np.set(QStringLiteral("tcpPort"), m_tcpPort); - m_udpSocket.writeDatagram(np.serialize(), m_receivedIdentityPackets[socket].sender, m_udpBroadcastPort); + m_udpSocket.writeDatagram(np.serialize(), m_receivedIdentityPackets[socket].sender, UDP_PORT); // The socket we created didn't work, and we didn't manage // to create a LanDeviceLink from it, deleting everything. @@ -358,7 +356,7 @@ void LanLinkProvider::tcpSocketConnected() // The socket doesn't seem to work, so we can't create the connection. qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)"; - m_udpSocket.writeDatagram(np2.serialize(), m_receivedIdentityPackets[socket].sender, m_udpBroadcastPort); + m_udpSocket.writeDatagram(np2.serialize(), m_receivedIdentityPackets[socket].sender, UDP_PORT); // Cleanup the network packet now. The socket should be deleted via the disconnected() signal. // We don't do this on success, because it is done later in the encrypted() slot. diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 8089146b0..c16f1959c 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -27,10 +27,8 @@ class KDECONNECTCORE_EXPORT LanLinkProvider : public LinkProvider public: /** * @param testMode Some special overrides needed while testing - * @param udpBroadcastPort Port which should be used for *sending* identity packets - * @param udpListenPort Port which should be used for *receiving* identity packets */ - LanLinkProvider(bool testMode = false, quint16 udpBroadcastPort = UDP_PORT, quint16 udpListenPort = UDP_PORT); + LanLinkProvider(bool testMode = false); ~LanLinkProvider() override; QString name() override @@ -77,9 +75,6 @@ private: QUdpSocket m_udpSocket; quint16 m_tcpPort; - quint16 m_udpBroadcastPort; - quint16 m_udpListenPort; - QMap m_links; struct PendingConnect {