[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:29:32 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=aa4150f

The following commit has been merged in the master branch:
commit aa4150f0c9eb96a9023342b47d533e8cef3eed9f
Author: Albert Vaca <albertvaka at gmail.com>
Date:   Sun Jan 10 07:12:13 2016 -0800

    Moved ConnectionStarted from DeviceLink to LanDeviceLink
---
 core/backends/devicelink.cpp                  |  3 +--
 core/backends/devicelink.h                    | 10 ++++------
 core/backends/lan/landevicelink.cpp           | 11 ++++++++---
 core/backends/lan/landevicelink.h             |  5 +++++
 core/backends/lan/lanlinkprovider.cpp         |  8 ++++----
 core/backends/lan/lanlinkprovider.h           |  2 +-
 core/backends/loopback/loopbackdevicelink.cpp |  4 ++--
 core/daemon.cpp                               | 10 +++++++---
 core/device.cpp                               | 28 ++++++++++++++-------------
 core/device.h                                 |  2 +-
 tests/devicetest.cpp                          |  5 +++--
 11 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/core/backends/devicelink.cpp b/core/backends/devicelink.cpp
index d063019..569f0b9 100644
--- a/core/backends/devicelink.cpp
+++ b/core/backends/devicelink.cpp
@@ -22,11 +22,10 @@
 #include "kdeconnectconfig.h"
 #include "linkprovider.h"
 
-DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource)
+DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
     : QObject(parent)
     , mPrivateKey(KdeConnectConfig::instance()->privateKey())
     , mDeviceId(deviceId)
-    , mConnectionSource(connectionSource)
     , mLinkProvider(parent)
     , mPairStatus(NotPaired)
 {
diff --git a/core/backends/devicelink.h b/core/backends/devicelink.h
index a5cc3ff..fd3fc5d 100644
--- a/core/backends/devicelink.h
+++ b/core/backends/devicelink.h
@@ -38,9 +38,8 @@ class DeviceLink
 
 public:
     enum PairStatus : bool { NotPaired, Paired };
-    enum ConnectionStarted : bool { Locally, Remotely };
 
-    DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
+    DeviceLink(const QString& deviceId, LinkProvider* parent);
     virtual ~DeviceLink() { };
 
     virtual QString name() = 0;
@@ -54,12 +53,12 @@ public:
     virtual void userRequestsPair() = 0;
     virtual void userRequestsUnpair() = 0;
 
-    ConnectionStarted connectionSource() const { return mConnectionSource; } //TODO: Move this down to landevicelink and create an abstraction like "bool keepConnectionOpen()" here.
-    void setConnectionSource(ConnectionStarted source) { mConnectionSource = source; }
-
     PairStatus pairStatus() const { return mPairStatus; }
     virtual void setPairStatus(PairStatus status);
 
+    //The daemon will periodically destroy unpaired links if this returns false
+    virtual bool linkShouldBeKeptAlive() { return false; }
+
 Q_SIGNALS:
     void receivedPackage(const NetworkPackage& np);
     void pairStatusChanged(DeviceLink::PairStatus status);
@@ -70,7 +69,6 @@ protected:
 
 private:
     const QString mDeviceId;
-    ConnectionStarted mConnectionSource;
     LinkProvider* mLinkProvider;
     PairStatus mPairStatus;
 
diff --git a/core/backends/lan/landevicelink.cpp b/core/backends/lan/landevicelink.cpp
index 4fdb5b3..a0542f3 100644
--- a/core/backends/lan/landevicelink.cpp
+++ b/core/backends/lan/landevicelink.cpp
@@ -30,13 +30,13 @@
 #include "lanlinkprovider.h"
 
 LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
-    : DeviceLink(deviceId, parent, connectionSource)
+    : DeviceLink(deviceId, parent)
     , mSocketLineReader(nullptr)
 {
     reset(socket, connectionSource);
 }
 
-void LanDeviceLink::reset(QSslSocket* socket, DeviceLink::ConnectionStarted connectionSource)
+void LanDeviceLink::reset(QSslSocket* socket, ConnectionStarted connectionSource)
 {
     if (mSocketLineReader) {
         delete mSocketLineReader;
@@ -53,7 +53,7 @@ void LanDeviceLink::reset(QSslSocket* socket, DeviceLink::ConnectionStarted conn
     //destroyed as well
     socket->setParent(this);
 
-    setConnectionSource(connectionSource);
+    mConnectionSource = connectionSource;
 
     QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), "certificate");
     DeviceLink::setPairStatus(certString.isEmpty()? PairStatus::NotPaired : PairStatus::Paired);
@@ -148,3 +148,8 @@ void LanDeviceLink::setPairStatus(PairStatus status)
     }
 }
 
+bool LanDeviceLink::linkShouldBeKeptAlive() {
+    //We keep the remotely initiated connections, since the remotes require them if they want to request
+    //pairing to us, or connections that are already paired. TODO: Keep connections in the process of pairing
+    return (mConnectionSource == ConnectionStarted::Remotely || pairStatus() == Paired);
+}
diff --git a/core/backends/lan/landevicelink.h b/core/backends/lan/landevicelink.h
index 28978c0..1450aed 100644
--- a/core/backends/lan/landevicelink.h
+++ b/core/backends/lan/landevicelink.h
@@ -37,6 +37,8 @@ class LanDeviceLink
     Q_OBJECT
 
 public:
+    enum ConnectionStarted : bool { Locally, Remotely };
+
     LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource);
     void reset(QSslSocket* socket, ConnectionStarted connectionSource);
 
@@ -49,11 +51,14 @@ public:
 
     virtual void setPairStatus(PairStatus status) override;
 
+    virtual bool linkShouldBeKeptAlive() override;
+
 private Q_SLOTS:
     void dataReceived();
 
 private:
     SocketLineReader* mSocketLineReader;
+    ConnectionStarted mConnectionSource;
 };
 
 #endif
diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp
index 561fb7d..e513e07 100644
--- a/core/backends/lan/lanlinkprovider.cpp
+++ b/core/backends/lan/lanlinkprovider.cpp
@@ -235,7 +235,7 @@ void LanLinkProvider::connected()
             return; // Return statement prevents from deleting received package, needed in slot "encrypted"
         } else {
             qWarning() << "Incompatible protocol version, this won't work";
-            addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
+            addLink(deviceId, socket, receivedPackage, LanDeviceLink::Remotely);
         }
 
     } else {
@@ -264,7 +264,7 @@ void LanLinkProvider::encrypted()
     const QString& deviceId = receivedPackage->get<QString>("deviceId");
     //qCDebug(KDECONNECT_CORE) << "Connected" << socket->isWritable();
 
-    addLink(deviceId, socket, receivedPackage, DeviceLink::Remotely);
+    addLink(deviceId, socket, receivedPackage, LanDeviceLink::Remotely);
 
     // Copied from connected slot, now delete received package
     delete receivedPackage;
@@ -378,7 +378,7 @@ void LanLinkProvider::dataReceived()
         socket->startClientEncryption();
         return;
     } else {
-        addLink(deviceId, socket, np, DeviceLink::Locally);
+        addLink(deviceId, socket, np, LanDeviceLink::Locally);
     }
 
     delete np;
@@ -431,7 +431,7 @@ void LanLinkProvider::configureSocket(QSslSocket* socket)
 
 }
 
-void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, DeviceLink::ConnectionStarted connectionOrigin)
+void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, LanDeviceLink::ConnectionStarted connectionOrigin)
 {
     // Socket disconnection will now be handled by LanDeviceLink
     disconnect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h
index 42bcb68..fbb37a1 100644
--- a/core/backends/lan/lanlinkprovider.h
+++ b/core/backends/lan/lanlinkprovider.h
@@ -67,7 +67,7 @@ private:
     LanPairingHandler* createPairingHandler(DeviceLink* link);
 
     void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
-    void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, DeviceLink::ConnectionStarted connectionOrigin);
+    void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, LanDeviceLink::ConnectionStarted connectionOrigin);
 
     Server* mServer;
     QUdpSocket* mUdpServer;
diff --git a/core/backends/loopback/loopbackdevicelink.cpp b/core/backends/loopback/loopbackdevicelink.cpp
index e897017..ae4e8af 100644
--- a/core/backends/loopback/loopbackdevicelink.cpp
+++ b/core/backends/loopback/loopbackdevicelink.cpp
@@ -24,14 +24,14 @@
 #include "loopbackpairinghandler.h"
 
 LoopbackDeviceLink::LoopbackDeviceLink(const QString& deviceId, LoopbackLinkProvider* provider)
-    : DeviceLink(deviceId, provider, Remotely)
+    : DeviceLink(deviceId, provider)
 {
 
 }
 
 QString LoopbackDeviceLink::name()
 {
-    return "LoopbackLink"; // Should be similar to android
+    return "LoopbackLink";
 }
 
 bool LoopbackDeviceLink::sendPackage(NetworkPackage& input)
diff --git a/core/daemon.cpp b/core/daemon.cpp
index 7e36e6d..9d4bb43 100644
--- a/core/daemon.cpp
+++ b/core/daemon.cpp
@@ -123,7 +123,12 @@ void Daemon::removeDevice(Device* device)
 void Daemon::cleanDevices()
 {
     Q_FOREACH(Device* device, d->mDevices) {
-        if (!device->isTrusted() && device->connectionSource() == DeviceLink::ConnectionStarted::Remotely) {
+        if (device->isTrusted()) {
+            continue;
+        }
+        device->cleanUnneededLinks();
+        //If there are no links remaining
+        if (!device->isReachable()) {
             removeDevice(device);
         }
     }
@@ -178,8 +183,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
         Device* device = new Device(this, identityPackage, dl);
 
         //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->isTrusted() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
+        if (!isDiscoveringDevices() && !device->isTrusted() && !dl->linkShouldBeKeptAlive()) {
             device->deleteLater();
         } else {
             connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
diff --git a/core/device.cpp b/core/device.cpp
index 3bb7c66..c335398 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -345,18 +345,6 @@ bool Device::isTrusted() const
     return KdeConnectConfig::instance()->trustedDevices().contains(id());
 }
 
-DeviceLink::ConnectionStarted Device::connectionSource() const
-{
-    DeviceLink::ConnectionStarted ret = DeviceLink::Remotely;
-    Q_FOREACH(DeviceLink* link, m_deviceLinks) {
-        if(link->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
-            ret = DeviceLink::ConnectionStarted::Locally;
-            break;
-        }
-    }
-    return ret;
-}
-
 QStringList Device::availableLinks() const
 {
     QStringList sl;
@@ -366,6 +354,21 @@ QStringList Device::availableLinks() const
     return sl;
 }
 
+void Device::cleanUnneededLinks() {
+    if (isTrusted()) {
+        return;
+    }
+    for(int i = 0; i < m_deviceLinks.size(); ) {
+        DeviceLink* dl = m_deviceLinks[i];
+        if (!dl->linkShouldBeKeptAlive()) {
+            dl->deleteLater();
+            m_deviceLinks.remove(i);
+        } else {
+            i++;
+        }
+    }
+}
+
 Device::DeviceType Device::str2type(const QString &deviceType) {
     if (deviceType == "desktop") return Desktop;
     if (deviceType == "laptop") return Laptop;
@@ -439,7 +442,6 @@ bool Device::isPluginEnabled(const QString& pluginName) const
                                             : PluginLoader::instance()->getPluginInfo(pluginName).isEnabledByDefault());
 }
 
-//HACK
 QString Device::encryptionInfo() const
 {
     QString result;
diff --git a/core/device.h b/core/device.h
index 8f550d6..a889c6c 100644
--- a/core/device.h
+++ b/core/device.h
@@ -107,7 +107,7 @@ public:
     void setPluginEnabled(const QString& pluginName, bool enabled);
     bool isPluginEnabled(const QString& pluginName) const;
 
-    DeviceLink::ConnectionStarted connectionSource() const;
+    void cleanUnneededLinks();
 
 public Q_SLOTS:
     ///sends a @p np package to the device
diff --git a/tests/devicetest.cpp b/tests/devicetest.cpp
index 87fd50c..03785e3 100644
--- a/tests/devicetest.cpp
+++ b/tests/devicetest.cpp
@@ -75,7 +75,7 @@ void DeviceTest::testPairedDevice()
     // Add link
     LanLinkProvider linkProvider;
     QSslSocket socket;
-    LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, DeviceLink::Locally);
+    LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally);
     device.addLink(*identityPackage, link);
 
     QCOMPARE(device.isReachable(), true);
@@ -96,7 +96,7 @@ void DeviceTest::testUnpairedDevice()
 {
     LanLinkProvider linkProvider;
     QSslSocket socket;
-    LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, DeviceLink::Locally);
+    LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally);
 
     Device device(this, *identityPackage, link);
 
@@ -120,6 +120,7 @@ void DeviceTest::cleanupTestCase()
 {
     delete identityPackage;
 }
+
 QTEST_GUILESS_MAIN(DeviceTest)
 
 #include "devicetest.moc"

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list