diff --git a/libnymea-app/connection/discovery/nymeadiscovery.cpp b/libnymea-app/connection/discovery/nymeadiscovery.cpp index 677631b1..32e0740f 100644 --- a/libnymea-app/connection/discovery/nymeadiscovery.cpp +++ b/libnymea-app/connection/discovery/nymeadiscovery.cpp @@ -152,6 +152,7 @@ void NymeaDiscovery::cacheHost(NymeaHost *host) QList connections; Connection *remoteConnection = host->connections()->bestMatch(Connection::BearerTypeCloud); if (remoteConnection) { + qCritical() << "*********** caching" << remoteConnection->url(); connections.append(remoteConnection); } Connection *loopbackConnection = host->connections()->bestMatch(Connection::BearerTypeLoopback); diff --git a/libnymea-app/connection/nymeahost.cpp b/libnymea-app/connection/nymeahost.cpp index 80b6fb26..578b8c71 100644 --- a/libnymea-app/connection/nymeahost.cpp +++ b/libnymea-app/connection/nymeahost.cpp @@ -101,6 +101,21 @@ bool NymeaHost::online() const return m_online; } +void NymeaHost::addTunnelConnection() +{ + for (int i = 0; i < m_connections->rowCount(); i++) { + if (m_connections->get(i)->url().scheme() == "tunnel") { + return; + } + } + QUrl url; + url.setScheme("tunnel"); + url.setHost(m_uuid.toString().remove(QRegExp("[{}]"))); + qCritical() << "Adding tunnel connection" << url << m_uuid; + Connection *connection = new Connection(url, Connection::BearerTypeCloud, true, "foooobaaaar", this); + m_connections->addConnection(connection); +} + void NymeaHost::syncOnlineState() { for (int i = 0; i < m_connections->rowCount(); i++) { @@ -217,7 +232,7 @@ Connection *Connections::bestMatch(Connection::BearerTypes bearerTypes) const { Connection *best = nullptr; foreach (Connection *c, m_connections) { -// qDebug() << "have connection:" << bearerTypes << c->url() << c->bearerType() << bearerTypes.testFlag(c->bearerType()); +// qWarning() << "have connection:" << bearerTypes << c->url() << c->bearerType() << bearerTypes.testFlag(c->bearerType()); if ((bearerTypes & c->bearerType()) == Connection::BearerTypeNone) { continue; } @@ -320,6 +335,9 @@ int Connection::priority() const break; case BearerTypeCloud: prio += 200; + if (m_url.scheme().startsWith("tunnel")) { + prio += 1; + } break; case BearerTypeBluetooth: prio += 100; diff --git a/libnymea-app/connection/nymeahost.h b/libnymea-app/connection/nymeahost.h index 4620d1fe..c02c7b71 100644 --- a/libnymea-app/connection/nymeahost.h +++ b/libnymea-app/connection/nymeahost.h @@ -156,6 +156,8 @@ public: bool online() const; + Q_INVOKABLE void addTunnelConnection(); + signals: void nameChanged(); void versionChanged(); diff --git a/libnymea-app/connection/tunnelproxytransport.cpp b/libnymea-app/connection/tunnelproxytransport.cpp index ba078e92..783f8b6b 100644 --- a/libnymea-app/connection/tunnelproxytransport.cpp +++ b/libnymea-app/connection/tunnelproxytransport.cpp @@ -32,6 +32,8 @@ #include +using namespace remoteproxyclient; + TunnelProxyTransport::TunnelProxyTransport(QObject *parent) : NymeaTransportInterface(parent) { @@ -112,6 +114,11 @@ QSslCertificate TunnelProxyTransport::serverCertificate() const return QSslCertificate(); } +void TunnelProxyTransport::onRemoteConnectionStateChanged(remoteproxyclient::TunnelProxyRemoteConnection::State state) +{ + qCritical() << "FIXME TODO! remoteConnectionStateChanged"; +} + void TunnelProxyTransport::onRemoteConnectedChanged(bool remoteConnected) { qDebug() << "Tunnel proxy remote connection" << (remoteConnected ? "connected" : "disconnected"); diff --git a/libnymea-app/connection/tunnelproxytransport.h b/libnymea-app/connection/tunnelproxytransport.h index 10c2cfcc..6d619936 100644 --- a/libnymea-app/connection/tunnelproxytransport.h +++ b/libnymea-app/connection/tunnelproxytransport.h @@ -44,7 +44,6 @@ public: QStringList supportedSchemes() const override; }; -using namespace remoteproxyclient; class TunnelProxyTransport : public NymeaTransportInterface { @@ -63,13 +62,13 @@ public: QSslCertificate serverCertificate() const override; private slots: - void onRemoteConnectionStateChanged(TunnelProxyRemoteConnection::State state); + void onRemoteConnectionStateChanged(remoteproxyclient::TunnelProxyRemoteConnection::State state); void onRemoteConnectedChanged(bool remoteConnected); void onRemoteConnectionErrorOccurred(QAbstractSocket::SocketError error); private: QUrl m_url; - TunnelProxyRemoteConnection *m_remoteConnection = nullptr; + remoteproxyclient::TunnelProxyRemoteConnection *m_remoteConnection = nullptr; }; diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index 7a76dbc5..497ebaa1 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -37,6 +37,7 @@ #include "connection/websockettransport.h" #include "connection/bluetoothtransport.h" #include "connection/cloudtransport.h" +#include "connection/tunnelproxytransport.h" #include #include @@ -57,10 +58,11 @@ JsonRpcClient::JsonRpcClient(QObject *parent) : m_id(0) { m_connection = new NymeaConnection(this); - m_connection->registerTransport(new TcpSocketTransportFactory()); - m_connection->registerTransport(new WebsocketTransportFactory()); - m_connection->registerTransport(new BluetoothTransportFactoy()); - m_connection->registerTransport(new CloudTransportFactory()); +// m_connection->registerTransport(new TcpSocketTransportFactory()); +// m_connection->registerTransport(new WebsocketTransportFactory()); +// m_connection->registerTransport(new BluetoothTransportFactoy()); +// m_connection->registerTransport(new CloudTransportFactory()); + m_connection->registerTransport(new TunnelProxyTransportFactory()); connect(m_connection, &NymeaConnection::availableBearerTypesChanged, this, &JsonRpcClient::availableBearerTypesChanged); connect(m_connection, &NymeaConnection::connectionStatusChanged, this, &JsonRpcClient::connectionStatusChanged); diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index b59f0607..ab9bfcca 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -312,6 +312,7 @@ Item { onConnectedChanged: { print("json client connected changed", engine.jsonRpcClient.connected, engine.jsonRpcClient.serverUuid) if (engine.jsonRpcClient.connected) { + engine.jsonRpcClient.currentHost.addTunnelConnection(); nymeaDiscovery.cacheHost(engine.jsonRpcClient.currentHost) configuredHost.uuid = engine.jsonRpcClient.serverUuid // tabSettings.lastConnectedHost = engine.jsonRpcClient.serverUuid