Changeset View
Changeset View
Standalone View
Standalone View
core/backends/lan/lanlinkprovider.cpp
Context not available. | |||||
45 | #define MIN_VERSION_WITH_SSL_SUPPORT 6 | 45 | #define MIN_VERSION_WITH_SSL_SUPPORT 6 | ||
---|---|---|---|---|---|
46 | 46 | | |||
47 | LanLinkProvider::LanLinkProvider(bool testMode) | 47 | LanLinkProvider::LanLinkProvider(bool testMode) | ||
48 | : mTestMode(testMode) | 48 | : m_testMode(testMode) | ||
49 | { | 49 | { | ||
50 | mTcpPort = 0; | 50 | m_tcpPort = 0; | ||
51 | 51 | | |||
52 | combineBroadcastsTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough | 52 | m_combineBroadcastsTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough | ||
53 | combineBroadcastsTimer.setSingleShot(true); | 53 | m_combineBroadcastsTimer.setSingleShot(true); | ||
54 | connect(&combineBroadcastsTimer, &QTimer::timeout, this, &LanLinkProvider::broadcastToNetwork); | 54 | connect(&m_combineBroadcastsTimer, &QTimer::timeout, this, &LanLinkProvider::broadcastToNetwork); | ||
55 | 55 | | |||
56 | connect(&mUdpSocket, &QIODevice::readyRead, this, &LanLinkProvider::newUdpConnection); | 56 | connect(&m_udpSocket, &QIODevice::readyRead, this, &LanLinkProvider::newUdpConnection); | ||
57 | 57 | | |||
58 | mServer = new Server(this); | 58 | m_server = new Server(this); | ||
59 | mServer->setProxy(QNetworkProxy::NoProxy); | 59 | m_server->setProxy(QNetworkProxy::NoProxy); | ||
60 | connect(mServer,&QTcpServer::newConnection,this, &LanLinkProvider::newConnection); | 60 | connect(m_server,&QTcpServer::newConnection,this, &LanLinkProvider::newConnection); | ||
61 | 61 | | |||
62 | mUdpSocket.setProxy(QNetworkProxy::NoProxy); | 62 | m_udpSocket.setProxy(QNetworkProxy::NoProxy); | ||
63 | 63 | | |||
64 | //Detect when a network interface changes status, so we announce ourelves in the new network | 64 | //Detect when a network interface changes status, so we announce ourelves in the new network | ||
65 | QNetworkConfigurationManager* networkManager = new QNetworkConfigurationManager(this); | 65 | QNetworkConfigurationManager* networkManager = new QNetworkConfigurationManager(this); | ||
Context not available. | |||||
67 | 67 | | |||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration &config) | 70 | void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration& config) | ||
71 | { | 71 | { | ||
72 | if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) { | 72 | if (m_lastConfig != config && config.state() == QNetworkConfiguration::Active) { | ||
73 | m_lastConfig = config; | 73 | m_lastConfig = config; | ||
Context not available. | |||||
81 | 81 | | |||
82 | void LanLinkProvider::onStart() | 82 | void LanLinkProvider::onStart() | ||
83 | { | 83 | { | ||
84 | const QHostAddress bindAddress = mTestMode? QHostAddress::LocalHost : QHostAddress::Any; | 84 | const QHostAddress bindAddress = m_testMode? QHostAddress::LocalHost : QHostAddress::Any; | ||
85 | 85 | | |||
86 | bool success = mUdpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress); | 86 | bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress); | ||
87 | Q_ASSERT(success); | 87 | Q_ASSERT(success); | ||
88 | 88 | | |||
89 | qCDebug(KDECONNECT_CORE) << "onStart"; | 89 | qCDebug(KDECONNECT_CORE) << "onStart"; | ||
90 | 90 | | |||
91 | mTcpPort = MIN_TCP_PORT; | 91 | m_tcpPort = MIN_TCP_PORT; | ||
92 | while (!mServer->listen(bindAddress, mTcpPort)) { | 92 | while (!m_server->listen(bindAddress, m_tcpPort)) { | ||
93 | mTcpPort++; | 93 | m_tcpPort++; | ||
94 | if (mTcpPort > MAX_TCP_PORT) { //No ports available? | 94 | if (m_tcpPort > MAX_TCP_PORT) { //No ports available? | ||
95 | qCritical(KDECONNECT_CORE) << "Error opening a port in range" << MIN_TCP_PORT << "-" << MAX_TCP_PORT; | 95 | qCritical(KDECONNECT_CORE) << "Error opening a port in range" << MIN_TCP_PORT << "-" << MAX_TCP_PORT; | ||
96 | mTcpPort = 0; | 96 | m_tcpPort = 0; | ||
97 | return; | 97 | return; | ||
98 | } | 98 | } | ||
99 | } | 99 | } | ||
Context not available. | |||||
104 | void LanLinkProvider::onStop() | 104 | void LanLinkProvider::onStop() | ||
105 | { | 105 | { | ||
106 | qCDebug(KDECONNECT_CORE) << "onStop"; | 106 | qCDebug(KDECONNECT_CORE) << "onStop"; | ||
107 | mUdpSocket.close(); | 107 | m_udpSocket.close(); | ||
108 | mServer->close(); | 108 | m_server->close(); | ||
109 | } | 109 | } | ||
110 | 110 | | |||
111 | void LanLinkProvider::onNetworkChange() | 111 | void LanLinkProvider::onNetworkChange() | ||
112 | { | 112 | { | ||
113 | if (combineBroadcastsTimer.isActive()) { | 113 | if (m_combineBroadcastsTimer.isActive()) { | ||
114 | qCDebug(KDECONNECT_CORE()) << "Preventing duplicate broadcasts"; | 114 | qCDebug(KDECONNECT_CORE()) << "Preventing duplicate broadcasts"; | ||
115 | return; | 115 | return; | ||
116 | } | 116 | } | ||
117 | combineBroadcastsTimer.start(); | 117 | m_combineBroadcastsTimer.start(); | ||
118 | } | 118 | } | ||
119 | 119 | | |||
120 | //I'm in a new network, let's be polite and introduce myself | 120 | //I'm in a new network, let's be polite and introduce myself | ||
121 | void LanLinkProvider::broadcastToNetwork() | 121 | void LanLinkProvider::broadcastToNetwork() | ||
122 | { | 122 | { | ||
123 | 123 | | |||
124 | if (!mServer->isListening()) { | 124 | if (!m_server->isListening()) { | ||
125 | //Not started | 125 | //Not started | ||
126 | return; | 126 | return; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | Q_ASSERT(mTcpPort != 0); | 129 | Q_ASSERT(m_tcpPort != 0); | ||
130 | 130 | | |||
131 | qCDebug(KDECONNECT_CORE()) << "Broadcasting identity packet"; | 131 | qCDebug(KDECONNECT_CORE()) << "Broadcasting identity packet"; | ||
132 | 132 | | |||
133 | QHostAddress destAddress = mTestMode? QHostAddress::LocalHost : QHostAddress(QStringLiteral("255.255.255.255")); | 133 | QHostAddress destAddress = m_testMode? QHostAddress::LocalHost : QHostAddress(QStringLiteral("255.255.255.255")); | ||
134 | 134 | | |||
135 | NetworkPackage np(QLatin1String("")); | 135 | NetworkPackage np(QLatin1String("")); | ||
136 | NetworkPackage::createIdentityPackage(&np); | 136 | NetworkPackage::createIdentityPackage(&np); | ||
137 | np.set(QStringLiteral("tcpPort"), mTcpPort); | 137 | np.set(QStringLiteral("tcpPort"), m_tcpPort); | ||
138 | 138 | | |||
139 | #ifdef Q_OS_WIN | 139 | #ifdef Q_OS_WIN | ||
140 | //On Windows we need to broadcast from every local IP address to reach all networks | 140 | //On Windows we need to broadcast from every local IP address to reach all networks | ||
141 | QUdpSocket sendSocket; | 141 | QUdpSocket sendSocket; | ||
142 | sendSocket.setProxy(QNetworkProxy::NoProxy); | 142 | sendSocket.setProxy(QNetworkProxy::NoProxy); | ||
143 | for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) { | 143 | for (const QNetworkInterface& iface : QNetworkInterface::allInterfaces()) { | ||
144 | if ( (iface.flags() & QNetworkInterface::IsUp) | 144 | if ( (iface.flags() & QNetworkInterface::IsUp) | ||
145 | && (iface.flags() & QNetworkInterface::IsRunning) | 145 | && (iface.flags() & QNetworkInterface::IsRunning) | ||
146 | && (iface.flags() & QNetworkInterface::CanBroadcast)) { | 146 | && (iface.flags() & QNetworkInterface::CanBroadcast)) { | ||
147 | for (const QNetworkAddressEntry &ifaceAddress : iface.addressEntries()) { | 147 | for (const QNetworkAddressEntry& ifaceAddress : iface.addressEntries()) { | ||
148 | QHostAddress sourceAddress = ifaceAddress.ip(); | 148 | QHostAddress sourceAddress = ifaceAddress.ip(); | ||
149 | if (sourceAddress.protocol() == QAbstractSocket::IPv4Protocol && sourceAddress != QHostAddress::LocalHost) { | 149 | if (sourceAddress.protocol() == QAbstractSocket::IPv4Protocol && sourceAddress != QHostAddress::LocalHost) { | ||
150 | qCDebug(KDECONNECT_CORE()) << "Broadcasting as" << sourceAddress; | 150 | qCDebug(KDECONNECT_CORE()) << "Broadcasting as" << sourceAddress; | ||
Context not available. | |||||
156 | } | 156 | } | ||
157 | } | 157 | } | ||
158 | #else | 158 | #else | ||
159 | mUdpSocket.writeDatagram(np.serialize(), destAddress, UDP_PORT); | 159 | m_udpSocket.writeDatagram(np.serialize(), destAddress, UDP_PORT); | ||
160 | #endif | 160 | #endif | ||
161 | 161 | | |||
162 | } | 162 | } | ||
Context not available. | |||||
165 | //I will create a TcpSocket and try to connect. This can result in either connected() or connectError(). | 165 | //I will create a TcpSocket and try to connect. This can result in either connected() or connectError(). | ||
166 | void LanLinkProvider::newUdpConnection() //udpBroadcastReceived | 166 | void LanLinkProvider::newUdpConnection() //udpBroadcastReceived | ||
167 | { | 167 | { | ||
168 | while (mUdpSocket.hasPendingDatagrams()) { | 168 | while (m_udpSocket.hasPendingDatagrams()) { | ||
169 | 169 | | |||
170 | QByteArray datagram; | 170 | QByteArray datagram; | ||
171 | datagram.resize(mUdpSocket.pendingDatagramSize()); | 171 | datagram.resize(m_udpSocket.pendingDatagramSize()); | ||
172 | QHostAddress sender; | 172 | QHostAddress sender; | ||
173 | 173 | | |||
174 | mUdpSocket.readDatagram(datagram.data(), datagram.size(), &sender); | 174 | m_udpSocket.readDatagram(datagram.data(), datagram.size(), &sender); | ||
175 | 175 | | |||
176 | if (sender.isLoopback() && !mTestMode) | 176 | if (sender.isLoopback() && !m_testMode) | ||
177 | continue; | 177 | continue; | ||
178 | 178 | | |||
179 | NetworkPackage* receivedPackage = new NetworkPackage(QLatin1String("")); | 179 | NetworkPackage* receivedPackage = new NetworkPackage(QLatin1String("")); | ||
Context not available. | |||||
200 | 200 | | |||
201 | QSslSocket* socket = new QSslSocket(this); | 201 | QSslSocket* socket = new QSslSocket(this); | ||
202 | socket->setProxy(QNetworkProxy::NoProxy); | 202 | socket->setProxy(QNetworkProxy::NoProxy); | ||
203 | receivedIdentityPackages[socket].np = receivedPackage; | 203 | m_receivedIdentityPackages[socket].np = receivedPackage; | ||
204 | receivedIdentityPackages[socket].sender = sender; | 204 | m_receivedIdentityPackages[socket].sender = sender; | ||
205 | connect(socket, &QAbstractSocket::connected, this, &LanLinkProvider::connected); | 205 | connect(socket, &QAbstractSocket::connected, this, &LanLinkProvider::connected); | ||
206 | connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError())); | 206 | connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError())); | ||
207 | socket->connectToHost(sender, tcpPort); | 207 | socket->connectToHost(sender, tcpPort); | ||
Context not available. | |||||
218 | qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)" << socket->errorString(); | 218 | qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)" << socket->errorString(); | ||
219 | NetworkPackage np(QLatin1String("")); | 219 | NetworkPackage np(QLatin1String("")); | ||
220 | NetworkPackage::createIdentityPackage(&np); | 220 | NetworkPackage::createIdentityPackage(&np); | ||
221 | np.set(QStringLiteral("tcpPort"), mTcpPort); | 221 | np.set(QStringLiteral("tcpPort"), m_tcpPort); | ||
222 | mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, UDP_PORT); | 222 | m_udpSocket.writeDatagram(np.serialize(), m_receivedIdentityPackages[socket].sender, UDP_PORT); | ||
223 | 223 | | |||
224 | //The socket we created didn't work, and we didn't manage | 224 | //The socket we created didn't work, and we didn't manage | ||
225 | //to create a LanDeviceLink from it, deleting everything. | 225 | //to create a LanDeviceLink from it, deleting everything. | ||
226 | delete receivedIdentityPackages.take(socket).np; | 226 | delete m_receivedIdentityPackages.take(socket).np; | ||
227 | delete socket; | 227 | delete socket; | ||
228 | } | 228 | } | ||
229 | 229 | | |||
Context not available. | |||||
241 | // If socket disconnects due to any reason after connection, link on ssl faliure | 241 | // If socket disconnects due to any reason after connection, link on ssl faliure | ||
242 | connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); | 242 | connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); | ||
243 | 243 | | |||
244 | NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np; | 244 | NetworkPackage* receivedPackage = m_receivedIdentityPackages[socket].np; | ||
245 | const QString& deviceId = receivedPackage->get<QString>(QStringLiteral("deviceId")); | 245 | const QString& deviceId = receivedPackage->get<QString>(QStringLiteral("deviceId")); | ||
246 | //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable(); | 246 | //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable(); | ||
247 | 247 | | |||
Context not available. | |||||
281 | //I think this will never happen, but if it happens the deviceLink | 281 | //I think this will never happen, but if it happens the deviceLink | ||
282 | //(or the socket that is now inside it) might not be valid. Delete them. | 282 | //(or the socket that is now inside it) might not be valid. Delete them. | ||
283 | qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)"; | 283 | qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)"; | ||
284 | mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, UDP_PORT); | 284 | m_udpSocket.writeDatagram(np2.serialize(), m_receivedIdentityPackages[socket].sender, UDP_PORT); | ||
285 | } | 285 | } | ||
286 | 286 | | |||
287 | delete receivedIdentityPackages.take(socket).np; | 287 | delete m_receivedIdentityPackages.take(socket).np; | ||
288 | //We don't delete the socket because now it's owned by the LanDeviceLink | 288 | //We don't delete the socket because now it's owned by the LanDeviceLink | ||
289 | } | 289 | } | ||
290 | 290 | | |||
Context not available. | |||||
300 | Q_ASSERT(socket->mode() != QSslSocket::UnencryptedMode); | 300 | Q_ASSERT(socket->mode() != QSslSocket::UnencryptedMode); | ||
301 | LanDeviceLink::ConnectionStarted connectionOrigin = (socket->mode() == QSslSocket::SslClientMode)? LanDeviceLink::Locally : LanDeviceLink::Remotely; | 301 | LanDeviceLink::ConnectionStarted connectionOrigin = (socket->mode() == QSslSocket::SslClientMode)? LanDeviceLink::Locally : LanDeviceLink::Remotely; | ||
302 | 302 | | |||
303 | NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np; | 303 | NetworkPackage* receivedPackage = m_receivedIdentityPackages[socket].np; | ||
304 | const QString& deviceId = receivedPackage->get<QString>(QStringLiteral("deviceId")); | 304 | const QString& deviceId = receivedPackage->get<QString>(QStringLiteral("deviceId")); | ||
305 | 305 | | |||
306 | addLink(deviceId, socket, receivedPackage, connectionOrigin); | 306 | addLink(deviceId, socket, receivedPackage, connectionOrigin); | ||
307 | 307 | | |||
308 | // Copied from connected slot, now delete received package | 308 | // Copied from connected slot, now delete received package | ||
309 | delete receivedIdentityPackages.take(socket).np; | 309 | delete m_receivedIdentityPackages.take(socket).np; | ||
310 | } | 310 | } | ||
311 | 311 | | |||
312 | void LanLinkProvider::sslErrors(const QList<QSslError>& errors) | 312 | void LanLinkProvider::sslErrors(const QList<QSslError>& errors) | ||
Context not available. | |||||
318 | disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); | 318 | disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); | ||
319 | 319 | | |||
320 | qCDebug(KDECONNECT_CORE) << "Failing due to " << errors; | 320 | qCDebug(KDECONNECT_CORE) << "Failing due to " << errors; | ||
321 | Device *device = Daemon::instance()->getDevice(socket->peerVerifyName()); | 321 | Device* device = Daemon::instance()->getDevice(socket->peerVerifyName()); | ||
322 | if (device) { | 322 | if (device) { | ||
323 | device->unpair(); | 323 | device->unpair(); | ||
324 | } | 324 | } | ||
325 | 325 | | |||
326 | delete receivedIdentityPackages.take(socket).np; | 326 | delete m_receivedIdentityPackages.take(socket).np; | ||
327 | // Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually | 327 | // Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually | ||
328 | } | 328 | } | ||
329 | 329 | | |||
Context not available. | |||||
332 | { | 332 | { | ||
333 | //qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection"; | 333 | //qCDebug(KDECONNECT_CORE) << "LanLinkProvider newConnection"; | ||
334 | 334 | | |||
335 | while (mServer->hasPendingConnections()) { | 335 | while (m_server->hasPendingConnections()) { | ||
336 | QSslSocket* socket = mServer->nextPendingConnection(); | 336 | QSslSocket* socket = m_server->nextPendingConnection(); | ||
337 | configureSocket(socket); | 337 | configureSocket(socket); | ||
338 | //This socket is still managed by us (and child of the QTcpServer), if | 338 | //This socket is still managed by us (and child of the QTcpServer), if | ||
339 | //it disconnects before we manage to pass it to a LanDeviceLink, it's | 339 | //it disconnects before we manage to pass it to a LanDeviceLink, it's | ||
Context not available. | |||||
370 | } | 370 | } | ||
371 | 371 | | |||
372 | // Needed in "encrypted" if ssl is used, similar to "connected" | 372 | // Needed in "encrypted" if ssl is used, similar to "connected" | ||
373 | receivedIdentityPackages[socket].np = np; | 373 | m_receivedIdentityPackages[socket].np = np; | ||
374 | 374 | | |||
375 | const QString& deviceId = np->get<QString>(QStringLiteral("deviceId")); | 375 | const QString& deviceId = np->get<QString>(QStringLiteral("deviceId")); | ||
376 | //qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)"; | 376 | //qCDebug(KDECONNECT_CORE) << "Handshaking done (i'm the new device)"; | ||
Context not available. | |||||
396 | } else { | 396 | } else { | ||
397 | qWarning() << np->get<QString>(QStringLiteral("deviceName")) << "uses an old protocol version, this won't work"; | 397 | qWarning() << np->get<QString>(QStringLiteral("deviceName")) << "uses an old protocol version, this won't work"; | ||
398 | //addLink(deviceId, socket, np, LanDeviceLink::Locally); | 398 | //addLink(deviceId, socket, np, LanDeviceLink::Locally); | ||
399 | delete receivedIdentityPackages.take(socket).np; | 399 | delete m_receivedIdentityPackages.take(socket).np; | ||
400 | } | 400 | } | ||
401 | } | 401 | } | ||
402 | 402 | | |||
Context not available. | |||||
404 | { | 404 | { | ||
405 | const QString id = destroyedDeviceLink->property("deviceId").toString(); | 405 | const QString id = destroyedDeviceLink->property("deviceId").toString(); | ||
406 | //qCDebug(KDECONNECT_CORE) << "deviceLinkDestroyed" << id; | 406 | //qCDebug(KDECONNECT_CORE) << "deviceLinkDestroyed" << id; | ||
407 | Q_ASSERT(mLinks.key(static_cast<LanDeviceLink*>(destroyedDeviceLink)) == id); | 407 | Q_ASSERT(m_links.key(static_cast<LanDeviceLink*>(destroyedDeviceLink)) == id); | ||
408 | QMap< QString, LanDeviceLink* >::iterator linkIterator = mLinks.find(id); | 408 | QMap< QString, LanDeviceLink* >::iterator linkIterator = m_links.find(id); | ||
409 | if (linkIterator != mLinks.end()) { | 409 | if (linkIterator != m_links.end()) { | ||
410 | Q_ASSERT(linkIterator.value() == destroyedDeviceLink); | 410 | Q_ASSERT(linkIterator.value() == destroyedDeviceLink); | ||
411 | mLinks.erase(linkIterator); | 411 | m_links.erase(linkIterator); | ||
412 | mPairingHandlers.take(id)->deleteLater(); | 412 | m_pairingHandlers.take(id)->deleteLater(); | ||
413 | } | 413 | } | ||
414 | 414 | | |||
415 | } | 415 | } | ||
Context not available. | |||||
447 | //Usually SSL errors are only bad for trusted devices. Uncomment this section to log errors in any case, for debugging. | 447 | //Usually SSL errors are only bad for trusted devices. Uncomment this section to log errors in any case, for debugging. | ||
448 | //QObject::connect(socket, static_cast<void (QSslSocket::*)(const QList<QSslError>&)>(&QSslSocket::sslErrors), [](const QList<QSslError>& errors) | 448 | //QObject::connect(socket, static_cast<void (QSslSocket::*)(const QList<QSslError>&)>(&QSslSocket::sslErrors), [](const QList<QSslError>& errors) | ||
449 | //{ | 449 | //{ | ||
450 | // Q_FOREACH (const QSslError &error, errors) { | 450 | // Q_FOREACH (const QSslError& error, errors) { | ||
451 | // qCDebug(KDECONNECT_CORE) << "SSL Error:" << error.errorString(); | 451 | // qCDebug(KDECONNECT_CORE) << "SSL Error:" << error.errorString(); | ||
452 | // } | 452 | // } | ||
453 | //}); | 453 | //}); | ||
Context not available. | |||||
486 | 486 | | |||
487 | LanDeviceLink* deviceLink; | 487 | LanDeviceLink* deviceLink; | ||
488 | //Do we have a link for this device already? | 488 | //Do we have a link for this device already? | ||
489 | QMap< QString, LanDeviceLink* >::iterator linkIterator = mLinks.find(deviceId); | 489 | QMap< QString, LanDeviceLink* >::iterator linkIterator = m_links.find(deviceId); | ||
490 | if (linkIterator != mLinks.end()) { | 490 | if (linkIterator != m_links.end()) { | ||
491 | //qCDebug(KDECONNECT_CORE) << "Reusing link to" << deviceId; | 491 | //qCDebug(KDECONNECT_CORE) << "Reusing link to" << deviceId; | ||
492 | deviceLink = linkIterator.value(); | 492 | deviceLink = linkIterator.value(); | ||
493 | deviceLink->reset(socket, connectionOrigin); | 493 | deviceLink->reset(socket, connectionOrigin); | ||
494 | } else { | 494 | } else { | ||
495 | deviceLink = new LanDeviceLink(deviceId, this, socket, connectionOrigin); | 495 | deviceLink = new LanDeviceLink(deviceId, this, socket, connectionOrigin); | ||
496 | connect(deviceLink, &QObject::destroyed, this, &LanLinkProvider::deviceLinkDestroyed); | 496 | connect(deviceLink, &QObject::destroyed, this, &LanLinkProvider::deviceLinkDestroyed); | ||
497 | mLinks[deviceId] = deviceLink; | 497 | m_links[deviceId] = deviceLink; | ||
498 | if (mPairingHandlers.contains(deviceId)) { | 498 | if (m_pairingHandlers.contains(deviceId)) { | ||
499 | //We shouldn't have a pairinghandler if we didn't have a link. | 499 | //We shouldn't have a pairinghandler if we didn't have a link. | ||
500 | //Crash if debug, recover if release (by setting the new devicelink to the old pairinghandler) | 500 | //Crash if debug, recover if release (by setting the new devicelink to the old pairinghandler) | ||
501 | Q_ASSERT(mPairingHandlers.contains(deviceId)); | 501 | Q_ASSERT(m_pairingHandlers.contains(deviceId)); | ||
502 | mPairingHandlers[deviceId]->setDeviceLink(deviceLink); | 502 | m_pairingHandlers[deviceId]->setDeviceLink(deviceLink); | ||
503 | } | 503 | } | ||
504 | Q_EMIT onConnectionReceived(*receivedPackage, deviceLink); | 504 | Q_EMIT onConnectionReceived(*receivedPackage, deviceLink); | ||
505 | } | 505 | } | ||
Context not available. | |||||
508 | 508 | | |||
509 | LanPairingHandler* LanLinkProvider::createPairingHandler(DeviceLink* link) | 509 | LanPairingHandler* LanLinkProvider::createPairingHandler(DeviceLink* link) | ||
510 | { | 510 | { | ||
511 | LanPairingHandler* ph = mPairingHandlers.value(link->deviceId()); | 511 | LanPairingHandler* ph = m_pairingHandlers.value(link->deviceId()); | ||
512 | if (!ph) { | 512 | if (!ph) { | ||
513 | ph = new LanPairingHandler(link); | 513 | ph = new LanPairingHandler(link); | ||
514 | qCDebug(KDECONNECT_CORE) << "creating pairing handler for" << link->deviceId(); | 514 | qCDebug(KDECONNECT_CORE) << "creating pairing handler for" << link->deviceId(); | ||
515 | connect (ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError); | 515 | connect (ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError); | ||
516 | mPairingHandlers[link->deviceId()] = ph; | 516 | m_pairingHandlers[link->deviceId()] = ph; | ||
517 | } | 517 | } | ||
518 | return ph; | 518 | return ph; | ||
519 | } | 519 | } | ||
520 | 520 | | |||
521 | void LanLinkProvider::userRequestsPair(const QString& deviceId) | 521 | void LanLinkProvider::userRequestsPair(const QString& deviceId) | ||
522 | { | 522 | { | ||
523 | LanPairingHandler* ph = createPairingHandler(mLinks.value(deviceId)); | 523 | LanPairingHandler* ph = createPairingHandler(m_links.value(deviceId)); | ||
524 | ph->requestPairing(); | 524 | ph->requestPairing(); | ||
525 | } | 525 | } | ||
526 | 526 | | |||
527 | void LanLinkProvider::userRequestsUnpair(const QString& deviceId) | 527 | void LanLinkProvider::userRequestsUnpair(const QString& deviceId) | ||
528 | { | 528 | { | ||
529 | LanPairingHandler* ph = createPairingHandler(mLinks.value(deviceId)); | 529 | LanPairingHandler* ph = createPairingHandler(m_links.value(deviceId)); | ||
530 | ph->unpair(); | 530 | ph->unpair(); | ||
531 | } | 531 | } | ||
532 | 532 | | |||
Context not available. |