Make sure we don't disconnect from discovering remotes

Otherwise it's hard to let other devices connect to us, without having both
devices in discoverability mode.

Reviewed by Albert Vaca
This commit is contained in:
Aleix Pol 2015-09-09 12:30:39 +02:00
parent a50607939d
commit 26b0ec8b98
7 changed files with 21 additions and 11 deletions

View file

@ -22,10 +22,11 @@
#include "kdeconnectconfig.h" #include "kdeconnectconfig.h"
#include "linkprovider.h" #include "linkprovider.h"
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent) DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource)
: QObject(parent) : QObject(parent)
, mPrivateKey(KdeConnectConfig::instance()->privateKey()) , mPrivateKey(KdeConnectConfig::instance()->privateKey())
, mDeviceId(deviceId) , mDeviceId(deviceId)
, mConnectionSource(connectionSource)
, mLinkProvider(parent) , mLinkProvider(parent)
{ {
Q_ASSERT(!deviceId.isEmpty()); Q_ASSERT(!deviceId.isEmpty());

View file

@ -35,7 +35,9 @@ class DeviceLink
Q_OBJECT Q_OBJECT
public: public:
DeviceLink(const QString& deviceId, LinkProvider* parent); enum ConnectionStarted : bool { Locally, Remotely };
DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
virtual ~DeviceLink() { }; virtual ~DeviceLink() { };
const QString& deviceId() { return mDeviceId; } const QString& deviceId() { return mDeviceId; }
@ -44,6 +46,10 @@ public:
virtual bool sendPackage(NetworkPackage& np) = 0; virtual bool sendPackage(NetworkPackage& np) = 0;
virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) = 0; virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) = 0;
ConnectionStarted connectionSource() const {
return mConnectionSource;
}
Q_SIGNALS: Q_SIGNALS:
void receivedPackage(const NetworkPackage& np); void receivedPackage(const NetworkPackage& np);
@ -52,6 +58,7 @@ protected:
private: private:
const QString mDeviceId; const QString mDeviceId;
const ConnectionStarted mConnectionSource;
LinkProvider* mLinkProvider; LinkProvider* mLinkProvider;
}; };

View file

@ -31,8 +31,8 @@
#include "downloadjob.h" #include "downloadjob.h"
#include "socketlinereader.h" #include "socketlinereader.h"
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket) LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket, ConnectionStarted connectionSource)
: DeviceLink(deviceId, parent) : DeviceLink(deviceId, parent, connectionSource)
, mSocketLineReader(new SocketLineReader(socket)) , mSocketLineReader(new SocketLineReader(socket))
{ {
connect(mSocketLineReader, SIGNAL(readyRead()), connect(mSocketLineReader, SIGNAL(readyRead()),

View file

@ -35,7 +35,7 @@ class LanDeviceLink
Q_OBJECT Q_OBJECT
public: public:
LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket); LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket, ConnectionStarted connectionSource);
bool sendPackage(NetworkPackage& np) override; bool sendPackage(NetworkPackage& np) override;
bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np) override; bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np) override;

View file

@ -106,7 +106,7 @@ void LanLinkProvider::onNetworkChange()
//I'm the existing device, a new device is kindly introducing itself. //I'm the existing device, a new device is kindly introducing itself.
//I will create a TcpSocket and try to connect. This can result in either connected() or connectError(). //I will create a TcpSocket and try to connect. This can result in either connected() or connectError().
void LanLinkProvider::newUdpConnection() void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
{ {
while (mUdpServer->hasPendingDatagrams()) { while (mUdpServer->hasPendingDatagrams()) {
QByteArray datagram; QByteArray datagram;
@ -174,8 +174,8 @@ void LanLinkProvider::connected()
NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np; NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np;
const QString& deviceId = receivedPackage->get<QString>("deviceId"); const QString& deviceId = receivedPackage->get<QString>("deviceId");
//qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable(); //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Remotely);
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket);
NetworkPackage np2(""); NetworkPackage np2("");
NetworkPackage::createIdentityPackage(&np2); NetworkPackage::createIdentityPackage(&np2);
@ -262,7 +262,7 @@ void LanLinkProvider::dataReceived()
socket, SLOT(deleteLater())); socket, SLOT(deleteLater()));
const QString& deviceId = np.get<QString>("deviceId"); const QString& deviceId = np.get<QString>("deviceId");
LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket); LanDeviceLink* deviceLink = new LanDeviceLink(deviceId, this, socket, DeviceLink::Locally);
connect(deviceLink, SIGNAL(destroyed(QObject*)), connect(deviceLink, SIGNAL(destroyed(QObject*)),
this, SLOT(deviceLinkDestroyed(QObject*))); this, SLOT(deviceLinkDestroyed(QObject*)));

View file

@ -23,7 +23,7 @@
#include "loopbacklinkprovider.h" #include "loopbacklinkprovider.h"
LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider) LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
: DeviceLink(deviceId, provider) : DeviceLink(deviceId, provider, Remotely)
{ {
} }

View file

@ -163,8 +163,10 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
Device* device = new Device(this, identityPackage, dl); Device* device = new Device(this, identityPackage, dl);
//qCDebug(KDECONNECT_CORE) << "It is a new device"; //qCDebug(KDECONNECT_CORE) << "It is a new device";
if (d->discoveryMode && !device->isPaired()) { //we discard the connections that we created but it's not paired.
device->deleteLater(); //we keep the remotely initiated ones, since the remotes require them
if (!isDiscoveringDevices() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
dl->deleteLater();
} else { } else {
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged())); connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged())); connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));