diff --git a/libnymea-core/OpenSSL/OpenSSLConnection.cpp b/libnymea-core/cloud/OpenSSL/OpenSSLConnection.cpp similarity index 100% rename from libnymea-core/OpenSSL/OpenSSLConnection.cpp rename to libnymea-core/cloud/OpenSSL/OpenSSLConnection.cpp diff --git a/libnymea-core/OpenSSL/OpenSSLConnection.hpp b/libnymea-core/cloud/OpenSSL/OpenSSLConnection.hpp similarity index 100% rename from libnymea-core/OpenSSL/OpenSSLConnection.hpp rename to libnymea-core/cloud/OpenSSL/OpenSSLConnection.hpp diff --git a/libnymea-core/awsconnector.cpp b/libnymea-core/cloud/awsconnector.cpp similarity index 98% rename from libnymea-core/awsconnector.cpp rename to libnymea-core/cloud/awsconnector.cpp index 0fa1ff8c..90c9c60c 100644 --- a/libnymea-core/awsconnector.cpp +++ b/libnymea-core/cloud/awsconnector.cpp @@ -498,7 +498,7 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam if (jsonDoc.toVariant().toMap().value("status").toInt() == 200) { connector->storeSyncedNameCache(connector->m_clientName); } - } else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && !topic.contains("reply")) { + } else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && !topic.contains("reply") && !topic.contains("proxy")) { static QStringList dupes; QString id = jsonDoc.toVariant().toMap().value("id").toString(); QString type = jsonDoc.toVariant().toMap().value("type").toString(); @@ -512,6 +512,9 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam connector->webRtcHandshakeMessageReceived(topic, jsonDoc.toVariant().toMap()); } else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && topic.contains("reply")) { // silently drop our own things (should not be subscribed to that in the first place) + } else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && topic.contains("proxy")) { + qCDebug(dcAWS) << "Proxy remote connection request received"; + connector->staticMetaObject.invokeMethod(connector, "proxyConnectionRequestReceived", Qt::QueuedConnection); } else if (topic == QString("%1/notify/response").arg(connector->m_clientId)) { int transactionId = jsonDoc.toVariant().toMap().value("id").toInt(); int status = jsonDoc.toVariant().toMap().value("status").toInt(); diff --git a/libnymea-core/awsconnector.h b/libnymea-core/cloud/awsconnector.h similarity index 99% rename from libnymea-core/awsconnector.h rename to libnymea-core/cloud/awsconnector.h index 84ec7149..494ea96e 100644 --- a/libnymea-core/awsconnector.h +++ b/libnymea-core/cloud/awsconnector.h @@ -69,6 +69,8 @@ signals: void pushNotificationSent(int id, int status); void turnCredentialsReceived(const QVariantMap &turnCredentials); + void proxyConnectionRequestReceived(); + private slots: void doConnect(); void onConnected(); diff --git a/libnymea-core/cloudmanager.cpp b/libnymea-core/cloud/cloudmanager.cpp similarity index 94% rename from libnymea-core/cloudmanager.cpp rename to libnymea-core/cloud/cloudmanager.cpp index a1e1fe2d..a3a8a320 100644 --- a/libnymea-core/cloudmanager.cpp +++ b/libnymea-core/cloud/cloudmanager.cpp @@ -23,7 +23,12 @@ #include "janusconnector.h" #include "loggingcategories.h" #include "cloudnotifications.h" +#include "nymeaconfiguration.h" +#include "cloudtransport.h" +#include "libnymea-remoteproxyclient/remoteproxyconnection.h" + +using namespace remoteproxyclient; CloudManager::CloudManager(NetworkManager *networkManager, QObject *parent) : QObject(parent), m_networkManager(networkManager) @@ -41,6 +46,9 @@ CloudManager::CloudManager(NetworkManager *networkManager, QObject *parent) : QO connect(m_awsConnector, &AWSConnector::turnCredentialsReceived, m_janusConnector, &JanusConnector::setTurnCredentials); connect(m_networkManager, &NetworkManager::stateChanged, this, &CloudManager::onlineStateChanged); + + m_transport = new CloudTransport(ServerConfiguration()); + connect(m_awsConnector, &AWSConnector::proxyConnectionRequestReceived, m_transport, &CloudTransport::connectToCloud); } CloudManager::~CloudManager() @@ -141,6 +149,11 @@ CloudNotifications *CloudManager::createNotificationsPlugin() const return notifications; } +CloudTransport *CloudManager::createTransportInterface() const +{ + return m_transport; +} + void CloudManager::connect2aws() { m_awsConnector->connect2AWS(m_serverUrl, diff --git a/libnymea-core/cloudmanager.h b/libnymea-core/cloud/cloudmanager.h similarity index 94% rename from libnymea-core/cloudmanager.h rename to libnymea-core/cloud/cloudmanager.h index 2f56fef8..ed7f9ba3 100644 --- a/libnymea-core/cloudmanager.h +++ b/libnymea-core/cloud/cloudmanager.h @@ -31,7 +31,13 @@ class JanusConnector; class AWSConnector; class CloudNotifications; +namespace remoteproxyclient { +class RemoteProxyConnection; +} +namespace nymeaserver { + +class CloudTransport; class CloudManager : public QObject { Q_OBJECT @@ -53,6 +59,7 @@ public: bool keepAlive(const QString &sessionId); CloudNotifications* createNotificationsPlugin() const; + CloudTransport* createTransportInterface() const; signals: void connectedChanged(bool connected); @@ -84,7 +91,8 @@ private: QString m_clientCertificate; QString m_clientCertificateKey; - CloudNotifications *m_notifications; + CloudTransport *m_transport; }; +} #endif // CLOUDMANAGER_H diff --git a/libnymea-core/cloudnotifications.cpp b/libnymea-core/cloud/cloudnotifications.cpp similarity index 100% rename from libnymea-core/cloudnotifications.cpp rename to libnymea-core/cloud/cloudnotifications.cpp diff --git a/libnymea-core/cloudnotifications.h b/libnymea-core/cloud/cloudnotifications.h similarity index 100% rename from libnymea-core/cloudnotifications.h rename to libnymea-core/cloud/cloudnotifications.h diff --git a/libnymea-core/cloud/cloudtransport.cpp b/libnymea-core/cloud/cloudtransport.cpp new file mode 100644 index 00000000..deb6d054 --- /dev/null +++ b/libnymea-core/cloud/cloudtransport.cpp @@ -0,0 +1,47 @@ +#include "cloudtransport.h" +#include "loggingcategories.h" + +#include "libnymea-remoteproxyclient/remoteproxyconnection.h" + +using namespace remoteproxyclient; + +namespace nymeaserver { + +CloudTransport::CloudTransport(const ServerConfiguration &config, QObject *parent): + TransportInterface(config, parent), + m_remoteProxy(new RemoteProxyConnection(QUuid::createUuid(), "nymea:core", RemoteProxyConnection::ConnectionTypeWebSocket, this)) +{ + +} + +void CloudTransport::sendData(const QUuid &clientId, const QByteArray &data) +{ + qCDebug(dcCloud) << "Should send data" << clientId << data; +} + +void CloudTransport::sendData(const QList &clientIds, const QByteArray &data) +{ + foreach (const QUuid &clientId, clientIds) { + sendData(clientId, data); + } +} + +bool CloudTransport::startServer() +{ + qCDebug(dcCloud) << "Should start cloud server"; + return true; +} + +bool CloudTransport::stopServer() +{ + qCDebug(dcCloud) << "Should stop cloud server"; + return true; +} + +void CloudTransport::connectToCloud() +{ + qCDebug(dcCloud) << "Should connect to cloud"; + m_remoteProxy->connectServer(QHostAddress("127.0.0.1"), 1212); +} + +} diff --git a/libnymea-core/cloud/cloudtransport.h b/libnymea-core/cloud/cloudtransport.h new file mode 100644 index 00000000..547d3697 --- /dev/null +++ b/libnymea-core/cloud/cloudtransport.h @@ -0,0 +1,34 @@ +#ifndef CLOUDTRANSPORT_H +#define CLOUDTRANSPORT_H + +#include +#include "../transportinterface.h" + +namespace remoteproxyclient { + class RemoteProxyConnection; +} +namespace nymeaserver { + +class CloudTransport : public TransportInterface +{ + Q_OBJECT +public: + explicit CloudTransport(const ServerConfiguration &config, QObject *parent = nullptr); + + void sendData(const QUuid &clientId, const QByteArray &data) override; + void sendData(const QList &clientIds, const QByteArray &data) override; + + bool startServer() override; + bool stopServer() override; +signals: + +public slots: + void connectToCloud(); + +private: + remoteproxyclient::RemoteProxyConnection *m_remoteProxy = nullptr; +}; + +} + +#endif // CLOUDTRANSPORT_H diff --git a/libnymea-core/janusconnector.cpp b/libnymea-core/cloud/janusconnector.cpp similarity index 100% rename from libnymea-core/janusconnector.cpp rename to libnymea-core/cloud/janusconnector.cpp diff --git a/libnymea-core/janusconnector.h b/libnymea-core/cloud/janusconnector.h similarity index 100% rename from libnymea-core/janusconnector.h rename to libnymea-core/cloud/janusconnector.h diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 392c48cd..a3ed3223 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -69,11 +69,11 @@ HEADERS += nymeacore.h \ usermanager.h \ tokeninfo.h \ certificategenerator.h \ - awsconnector.h \ - cloudmanager.h \ - cloudnotifications.h \ - OpenSSL/OpenSSLConnection.hpp \ - janusconnector.h \ + cloud/awsconnector.h \ + cloud/cloudmanager.h \ + cloud/cloudnotifications.h \ + cloud/OpenSSL/OpenSSLConnection.hpp \ + cloud/janusconnector.h \ pushbuttondbusservice.h \ hardwaremanagerimplementation.h \ hardware/plugintimermanagerimplementation.h \ @@ -96,7 +96,8 @@ HEADERS += nymeacore.h \ debugserverhandler.h \ tagging/tagsstorage.h \ tagging/tag.h \ - jsonrpc/tagshandler.h + jsonrpc/tagshandler.h \ + cloud/cloudtransport.h SOURCES += nymeacore.cpp \ tcpserver.cpp \ @@ -150,11 +151,11 @@ SOURCES += nymeacore.cpp \ usermanager.cpp \ tokeninfo.cpp \ certificategenerator.cpp \ - awsconnector.cpp \ - cloudmanager.cpp \ - cloudnotifications.cpp \ - OpenSSL/OpenSSLConnection.cpp \ - janusconnector.cpp \ + cloud/awsconnector.cpp \ + cloud/cloudmanager.cpp \ + cloud/cloudnotifications.cpp \ + cloud/OpenSSL/OpenSSLConnection.cpp \ + cloud/janusconnector.cpp \ pushbuttondbusservice.cpp \ hardwaremanagerimplementation.cpp \ hardware/plugintimermanagerimplementation.cpp \ @@ -177,4 +178,5 @@ SOURCES += nymeacore.cpp \ debugserverhandler.cpp \ tagging/tagsstorage.cpp \ tagging/tag.cpp \ - jsonrpc/tagshandler.cpp + jsonrpc/tagshandler.cpp \ + cloud/cloudtransport.cpp diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index ad6a6cae..fd769000 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -114,7 +114,8 @@ #include "devicemanager.h" #include "plugin/device.h" -#include "cloudnotifications.h" +#include "cloud/cloudnotifications.h" +#include "cloud/cloudtransport.h" #include @@ -558,6 +559,9 @@ void NymeaCore::init() { CloudNotifications *cloudNotifications = m_cloudManager->createNotificationsPlugin(); m_deviceManager->registerStaticPlugin(cloudNotifications, cloudNotifications->metaData()); + CloudTransport *cloudTransport = m_cloudManager->createTransportInterface(); + m_serverManager->jsonServer()->registerTransportInterface(cloudTransport, false); + connect(m_configuration, &NymeaConfiguration::localeChanged, this, &NymeaCore::onLocaleChanged); connect(m_configuration, &NymeaConfiguration::cloudEnabledChanged, m_cloudManager, &CloudManager::setEnabled); connect(m_configuration, &NymeaConfiguration::serverNameChanged, m_cloudManager, &CloudManager::setDeviceName); diff --git a/libnymea-core/nymeacore.h b/libnymea-core/nymeacore.h index c3be0d8b..cc503ff8 100644 --- a/libnymea-core/nymeacore.h +++ b/libnymea-core/nymeacore.h @@ -32,7 +32,7 @@ #include "devicemanager.h" #include "ruleengine.h" #include "servermanager.h" -#include "cloudmanager.h" +#include "cloud/cloudmanager.h" #include "time/timemanager.h" #include "hardwaremanagerimplementation.h" diff --git a/server/server.pro b/server/server.pro index 3159616d..618b4bc1 100644 --- a/server/server.pro +++ b/server/server.pro @@ -12,7 +12,7 @@ QT *= sql xml websockets bluetooth dbus network LIBS += -L$$top_builddir/libnymea/ -lnymea \ -L$$top_builddir/libnymea-core -lnymea-core \ - -lssl -lcrypto -laws-iot-sdk-cpp + -lssl -lcrypto -laws-iot-sdk-cpp -lnymea-remoteproxyclient # Server files include(qtservice/qtservice.pri) diff --git a/tests/auto/autotests.pri b/tests/auto/autotests.pri index dfe71ad4..9c27d916 100644 --- a/tests/auto/autotests.pri +++ b/tests/auto/autotests.pri @@ -8,7 +8,7 @@ INCLUDEPATH += $$top_srcdir/libnymea \ LIBS += -L$$top_builddir/libnymea/ -lnymea \ -L$$top_builddir/libnymea-core/ -lnymea-core \ -L$$top_builddir/plugins/mock/ \ - -lssl -lcrypto -laws-iot-sdk-cpp -lavahi-common -lavahi-client + -lssl -lcrypto -laws-iot-sdk-cpp -lavahi-common -lavahi-client -lnymea-remoteproxyclient SOURCES += ../nymeatestbase.cpp \