Add tunnel proxy transport basic structure and prepare connecting

pull/642/head
Simon Stürz 2021-08-16 12:28:54 +02:00 committed by Michael Zanetti
parent aeaaf38287
commit 64f9ff490d
5 changed files with 213 additions and 2 deletions

View File

@ -66,7 +66,7 @@ CloudTransport::CloudTransport(AWSClient *awsClient, QObject *parent):
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::dataReady, this, [this](const QByteArray &data) {
emit dataReady(data);
});
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::errorOccured, this, [] (QAbstractSocket::SocketError error) {
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::errorOccurred, this, [] (QAbstractSocket::SocketError error) {
qDebug() << "Remote proxy Error:" << error;
// emit NymeaTransportInterface::error(QAbstractSocket::ConnectionRefusedError);
});

View File

@ -0,0 +1,133 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, GNU version 3. This project is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "tunnelproxytransport.h"
#include <QCoreApplication>
TunnelProxyTransport::TunnelProxyTransport(QObject *parent) :
NymeaTransportInterface(parent)
{
m_remoteConnection = new TunnelProxyRemoteConnection(QUuid::createUuid(), qApp->applicationName(), this);
QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::stateChanged, this, &TunnelProxyTransport::onRemoteConnectionStateChanged);
QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::remoteConnectedChanged, this, &TunnelProxyTransport::onRemoteConnectedChanged);
QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::dataReady, this, &TunnelProxyTransport::dataReady);
QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::errorOccurred, this, &TunnelProxyTransport::onRemoteConnectionErrorOccurred);
QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [=](const QList<QSslError> &errors){
qWarning() << "Remote tunnel proxy server SSL errors occurred:";
foreach (const QSslError &sslError, errors) {
qWarning() << " --> " << sslError.errorString();
}
});
}
bool TunnelProxyTransport::connect(const QUrl &url)
{
m_url = url;
// FIXME: get nymea uuid from URL somehow...
//QUrl("ssl://dev-remoteproxy.nymea.io:2213");
//m_remoteConnection->connectServer()
return false;
}
QUrl TunnelProxyTransport::url() const
{
return m_url;
}
NymeaTransportInterface::ConnectionState TunnelProxyTransport::connectionState() const
{
switch (m_remoteConnection->state()) {
case TunnelProxyRemoteConnection::StateRemoteConnected:
return NymeaTransportInterface::ConnectionStateConnected;
case TunnelProxyRemoteConnection::StateConnecting:
case TunnelProxyRemoteConnection::StateHostLookup:
case TunnelProxyRemoteConnection::StateConnected:
case TunnelProxyRemoteConnection::StateInitializing:
case TunnelProxyRemoteConnection::StateRegister:
return NymeaTransportInterface::ConnectionStateConnecting;
case TunnelProxyRemoteConnection::StateDiconnecting:
case TunnelProxyRemoteConnection::StateDisconnected:
return NymeaTransportInterface::ConnectionStateDisconnected;
}
}
void TunnelProxyTransport::disconnect()
{
m_remoteConnection->disconnectServer();
}
void TunnelProxyTransport::sendData(const QByteArray &data)
{
m_remoteConnection->sendData(data);
}
void TunnelProxyTransport::ignoreSslErrors(const QList<QSslError> &errors)
{
// FIXME: once the tunnel connection implements SSL connection trought the tunnel proxy, we need to implement this
Q_UNUSED(errors)
}
bool TunnelProxyTransport::isEncrypted() const
{
return false;
}
QSslCertificate TunnelProxyTransport::serverCertificate() const
{
// FIXME: once the tunnel connection implements SSL connection trought the tunnel proxy, we need to implement this
return QSslCertificate();
}
void TunnelProxyTransport::onRemoteConnectedChanged(bool remoteConnected)
{
qDebug() << "Tunnel proxy remote connection" << (remoteConnected ? "connected" : "disconnected");
}
void TunnelProxyTransport::onRemoteConnectionErrorOccurred(QAbstractSocket::SocketError error)
{
qWarning() << "Tunnel proxy socket error occurred" << error;
}
NymeaTransportInterface *TunnelProxyTransportFactory::createTransport(QObject *parent) const
{
return new TunnelProxyTransport(parent);
}
QStringList TunnelProxyTransportFactory::supportedSchemes() const
{
return { "tunnel" };
}

View File

@ -0,0 +1,76 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
* This project including source code and documentation is protected by
* copyright law, and remains the property of nymea GmbH. All rights, including
* reproduction, publication, editing and translation, are reserved. The use of
* this project is subject to the terms of a license agreement to be concluded
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
* under https://nymea.io/license
*
* GNU General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, GNU version 3. This project is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this project. If not, see <https://www.gnu.org/licenses/>.
*
* For any further details and any questions please contact us under
* contact@nymea.io or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef TUNNELPROXYTRANSPORT_H
#define TUNNELPROXYTRANSPORT_H
#include <QUrl>
#include <QObject>
#include "nymeatransportinterface.h"
#include "tunnelproxy/tunnelproxyremoteconnection.h"
class TunnelProxyTransportFactory: public NymeaTransportInterfaceFactory
{
public:
NymeaTransportInterface* createTransport(QObject *parent = nullptr) const override;
QStringList supportedSchemes() const override;
};
using namespace remoteproxyclient;
class TunnelProxyTransport : public NymeaTransportInterface
{
Q_OBJECT
public:
explicit TunnelProxyTransport(QObject *parent = nullptr);
bool connect(const QUrl &url) override;
QUrl url() const override;
ConnectionState connectionState() const override;
void disconnect() override;
void sendData(const QByteArray &data) override;
void ignoreSslErrors(const QList<QSslError> &errors) override;
bool isEncrypted() const override;
QSslCertificate serverCertificate() const override;
private slots:
void onRemoteConnectionStateChanged(TunnelProxyRemoteConnection::State state);
void onRemoteConnectedChanged(bool remoteConnected);
void onRemoteConnectionErrorOccurred(QAbstractSocket::SocketError error);
private:
QUrl m_url;
TunnelProxyRemoteConnection *m_remoteConnection = nullptr;
};
#endif // TUNNELPROXYTRANSPORT_H

View File

@ -25,6 +25,7 @@ SOURCES += \
$$PWD/energy/energymanager.cpp \
$$PWD/energy/powerbalancelogs.cpp \
$$PWD/energy/thingpowerlogs.cpp \
$$PWD/connection/tunnelproxytransport.cpp \
$$PWD/models/scriptsproxymodel.cpp \
$$PWD/tagwatcher.cpp \
$$PWD/zigbee/zigbeenode.cpp \
@ -185,6 +186,7 @@ HEADERS += \
$$PWD/energy/energymanager.h \
$$PWD/energy/powerbalancelogs.h \
$$PWD/energy/thingpowerlogs.h \
$$PWD/connection/tunnelproxytransport.h \
$$PWD/models/scriptsproxymodel.h \
$$PWD/tagwatcher.h \
$$PWD/zigbee/zigbeenode.h \

@ -1 +1 @@
Subproject commit 9c7075192b2b799feb302b48618eb4ef4d942172
Subproject commit 99bf634990dcd2231e6a265581a35aeffaf30037