Determine which IP address to use for sshfs

Summary:
There is currently an issue where the device doesn't send the correct IP address for sshfs when a VPN is present.

Instead of asking the device to find and send its address, we can store it from when the device link is created then reuse it.

Test Plan:
All unit tests pass.

In these different situations:
  - without a VPN
  - with a VPN running
  - with a VPN started then stopped (the tun interface might still be there)
Try to remotely browse the device. It should work in all cases.

Reviewers: #kde_connect, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: albertvaka, apol, nicolasfella, sredman

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D6730
This commit is contained in:
Jean Vincent 2017-07-22 11:13:21 +02:00 committed by Albert Vaca
parent c864267f04
commit 25b86c6c7f
5 changed files with 29 additions and 1 deletions

View file

@ -56,6 +56,9 @@ void LanDeviceLink::reset(QSslSocket* socket, ConnectionStarted connectionSource
mConnectionSource = connectionSource;
QHostAddress addr = socket->peerAddress();
mHostAddress = (addr.protocol() == QAbstractSocket::IPv6Protocol) ? QHostAddress(addr.toIPv4Address()) : addr;
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), QStringLiteral("certificate"));
DeviceLink::setPairStatus(certString.isEmpty()? PairStatus::NotPaired : PairStatus::Paired);
}

View file

@ -54,12 +54,15 @@ public:
bool linkShouldBeKeptAlive() override;
QHostAddress hostAddress() const { return mHostAddress; }
private Q_SLOTS:
void dataReceived();
private:
SocketLineReader* mSocketLineReader;
ConnectionStarted mConnectionSource;
QHostAddress mHostAddress;
};
#endif

View file

@ -35,6 +35,7 @@
#include "kdeconnectplugin.h"
#include "pluginloader.h"
#include "backends/devicelink.h"
#include "backends/lan/landevicelink.h"
#include "backends/linkprovider.h"
#include "networkpackage.h"
#include "kdeconnectconfig.h"
@ -380,6 +381,17 @@ void Device::cleanUnneededLinks() {
}
}
QHostAddress Device::getLocalIpAddress() const
{
for (DeviceLink* dl : m_deviceLinks) {
LanDeviceLink* ldl = dynamic_cast<LanDeviceLink*>(dl);
if (ldl) {
return ldl->hostAddress();
}
}
return QHostAddress::Null;
}
Device::DeviceType Device::str2type(const QString &deviceType) {
if (deviceType == QLatin1String("desktop")) return Desktop;
if (deviceType == QLatin1String("laptop")) return Laptop;

View file

@ -25,6 +25,7 @@
#include <QString>
#include <QVector>
#include <QSet>
#include <QHostAddress>
#include "networkpackage.h"
#include "backends/devicelink.h"
@ -103,6 +104,8 @@ public:
int protocolVersion() { return m_protocolVersion; }
QStringList supportedPlugins() const { return m_supportedPlugins.toList(); }
QHostAddress getLocalIpAddress() const;
public Q_SLOTS:
///sends a @p np package to the device
///virtual for testing purposes.

View file

@ -113,10 +113,17 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
if (np.has(QStringLiteral("multiPaths"))) path = '/';
else path = np.get<QString>(QStringLiteral("path"));
QHostAddress addr = m_sftp->device()->getLocalIpAddress();
if (addr == QHostAddress::Null) {
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Device doesn't have a LanDeviceLink, unable to get IP address";
return;
}
QString ip = addr.toString();
const QStringList arguments = QStringList()
<< QStringLiteral("%1@%2:%3").arg(
np.get<QString>(QStringLiteral("user")),
np.get<QString>(QStringLiteral("ip")),
ip,
path)
<< m_mountPoint
<< QStringLiteral("-p") << np.get<QString>(QStringLiteral("port"))