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:
parent
a50607939d
commit
26b0ec8b98
7 changed files with 21 additions and 11 deletions
|
@ -22,10 +22,11 @@
|
|||
#include "kdeconnectconfig.h"
|
||||
#include "linkprovider.h"
|
||||
|
||||
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
|
||||
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource)
|
||||
: QObject(parent)
|
||||
, mPrivateKey(KdeConnectConfig::instance()->privateKey())
|
||||
, mDeviceId(deviceId)
|
||||
, mConnectionSource(connectionSource)
|
||||
, mLinkProvider(parent)
|
||||
{
|
||||
Q_ASSERT(!deviceId.isEmpty());
|
||||
|
|
|
@ -35,7 +35,9 @@ class DeviceLink
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DeviceLink(const QString& deviceId, LinkProvider* parent);
|
||||
enum ConnectionStarted : bool { Locally, Remotely };
|
||||
|
||||
DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
|
||||
virtual ~DeviceLink() { };
|
||||
|
||||
const QString& deviceId() { return mDeviceId; }
|
||||
|
@ -44,6 +46,10 @@ public:
|
|||
virtual bool sendPackage(NetworkPackage& np) = 0;
|
||||
virtual bool sendPackageEncrypted(QCA::PublicKey& publicKey, NetworkPackage& np) = 0;
|
||||
|
||||
ConnectionStarted connectionSource() const {
|
||||
return mConnectionSource;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void receivedPackage(const NetworkPackage& np);
|
||||
|
||||
|
@ -52,6 +58,7 @@ protected:
|
|||
|
||||
private:
|
||||
const QString mDeviceId;
|
||||
const ConnectionStarted mConnectionSource;
|
||||
LinkProvider* mLinkProvider;
|
||||
|
||||
};
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#include "downloadjob.h"
|
||||
#include "socketlinereader.h"
|
||||
|
||||
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket)
|
||||
: DeviceLink(deviceId, parent)
|
||||
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QTcpSocket* socket, ConnectionStarted connectionSource)
|
||||
: DeviceLink(deviceId, parent, connectionSource)
|
||||
, mSocketLineReader(new SocketLineReader(socket))
|
||||
{
|
||||
connect(mSocketLineReader, SIGNAL(readyRead()),
|
||||
|
|
|
@ -35,7 +35,7 @@ class LanDeviceLink
|
|||
Q_OBJECT
|
||||
|
||||
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 sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np) override;
|
||||
|
|
|
@ -106,7 +106,7 @@ void LanLinkProvider::onNetworkChange()
|
|||
|
||||
//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().
|
||||
void LanLinkProvider::newUdpConnection()
|
||||
void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
|
||||
{
|
||||
while (mUdpServer->hasPendingDatagrams()) {
|
||||
QByteArray datagram;
|
||||
|
@ -174,8 +174,8 @@ void LanLinkProvider::connected()
|
|||
NetworkPackage* receivedPackage = receivedIdentityPackages[socket].np;
|
||||
const QString& deviceId = receivedPackage->get<QString>("deviceId");
|
||||
//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::createIdentityPackage(&np2);
|
||||
|
@ -262,7 +262,7 @@ void LanLinkProvider::dataReceived()
|
|||
socket, SLOT(deleteLater()));
|
||||
|
||||
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*)),
|
||||
this, SLOT(deviceLinkDestroyed(QObject*)));
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "loopbacklinkprovider.h"
|
||||
|
||||
LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
|
||||
: DeviceLink(deviceId, provider)
|
||||
: DeviceLink(deviceId, provider, Remotely)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -163,8 +163,10 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
|
|||
Device* device = new Device(this, identityPackage, dl);
|
||||
//qCDebug(KDECONNECT_CORE) << "It is a new device";
|
||||
|
||||
if (d->discoveryMode && !device->isPaired()) {
|
||||
device->deleteLater();
|
||||
//we discard the connections that we created but it's not paired.
|
||||
//we keep the remotely initiated ones, since the remotes require them
|
||||
if (!isDiscoveringDevices() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
|
||||
dl->deleteLater();
|
||||
} else {
|
||||
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
|
||||
connect(device, SIGNAL(pairingChanged(bool)), this, SLOT(onDeviceStatusChanged()));
|
||||
|
|
Loading…
Reference in a new issue