diff --git a/client/main.cpp b/client/main.cpp index 539ca06..5586ac5 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -107,6 +107,10 @@ int main(int argc, char *argv[]) QCommandLineOption insecureOption(QStringList() << "i" << "igore-ssl", "Ignore SSL certificate errors."); parser.addOption(insecureOption); + QCommandLineOption pingPongOption(QStringList() << "p" << "pingpong", "Start a ping pong traffic trough the remote connection."); + parser.addOption(pingPongOption); + + QCommandLineOption nameOption(QStringList() << "name", "The name of the client. Default nymea-remoteproxyclient", "name"); nameOption.setDefaultValue("nymea-remoteproxyclient"); parser.addOption(nameOption); @@ -154,6 +158,7 @@ int main(int argc, char *argv[]) ProxyClient client(parser.value(nameOption), uuid); client.setInsecure(parser.isSet(insecureOption)); + client.setPingpong(parser.isSet(pingPongOption)); client.start(serverUrl, parser.value(tokenOption)); return application.exec(); diff --git a/client/proxyclient.cpp b/client/proxyclient.cpp index a02f44c..4ffd656 100644 --- a/client/proxyclient.cpp +++ b/client/proxyclient.cpp @@ -21,6 +21,8 @@ #include "proxyclient.h" +#include + Q_LOGGING_CATEGORY(dcProxyClient, "ProxyClient") ProxyClient::ProxyClient(const QString &name, const QUuid &uuid, QObject *parent) : @@ -33,6 +35,7 @@ ProxyClient::ProxyClient(const QString &name, const QUuid &uuid, QObject *parent connect(m_connection, &RemoteProxyConnection::ready, this, &ProxyClient::onClientReady); connect(m_connection, &RemoteProxyConnection::authenticated, this, &ProxyClient::onAuthenticationFinished); connect(m_connection, &RemoteProxyConnection::remoteConnectionEstablished, this, &ProxyClient::onRemoteConnectionEstablished); + connect(m_connection, &RemoteProxyConnection::dataReady, this, &ProxyClient::onDataReady); connect(m_connection, &RemoteProxyConnection::errorOccured, this, &ProxyClient::onErrorOccured); connect(m_connection, &RemoteProxyConnection::disconnected, this, &ProxyClient::onClientDisconnected); connect(m_connection, &RemoteProxyConnection::sslErrors, this, &ProxyClient::onSslErrors); @@ -43,6 +46,11 @@ void ProxyClient::setInsecure(bool insecure) m_insecure = insecure; } +void ProxyClient::setPingpong(bool enable) +{ + m_pingpong = enable; +} + void ProxyClient::onErrorOccured(RemoteProxyConnection::Error error) { qCWarning(dcProxyClient()) << "Error occured" << error << m_connection->errorString(); @@ -66,6 +74,16 @@ void ProxyClient::onRemoteConnectionEstablished() qCDebug(dcProxyClient()) << "----------------------------------------------------------------------------------"; qCDebug(dcProxyClient()) << "Remote connection established with" << m_connection->tunnelPartnerName() << m_connection->tunnelPartnerUuid(); qCDebug(dcProxyClient()) << "----------------------------------------------------------------------------------"; + if (m_pingpong) sendPing(); +} + +void ProxyClient::onDataReady(const QByteArray &data) +{ + qCDebug(dcProxyClient()) << "<--" << qUtf8Printable(data); + + if (m_pingpong) { + QTimer::singleShot(1000, this, &ProxyClient::sendPing); + } } void ProxyClient::onClientDisconnected() @@ -87,6 +105,13 @@ void ProxyClient::onSslErrors(const QList errors) } } +void ProxyClient::sendPing() +{ + QByteArray data(QString("Ping from " + m_name + "!").toUtf8()); + qCDebug(dcProxyClient()) << "-->" << qUtf8Printable(data); + m_connection->sendData(data); +} + void ProxyClient::start(const QUrl &url, const QString &token) { m_token = token; diff --git a/client/proxyclient.h b/client/proxyclient.h index 41e6907..f2b5160 100644 --- a/client/proxyclient.h +++ b/client/proxyclient.h @@ -38,12 +38,14 @@ public: explicit ProxyClient(const QString &name, const QUuid &uuid, QObject *parent = nullptr); void setInsecure(bool insecure); + void setPingpong(bool enable); private: QString m_name; QUuid m_uuid; QString m_token; bool m_insecure = false; + bool m_pingpong = false; RemoteProxyConnection *m_connection = nullptr; @@ -52,9 +54,12 @@ private slots: void onClientReady(); void onAuthenticationFinished(); void onRemoteConnectionEstablished(); + void onDataReady(const QByteArray &data); void onClientDisconnected(); void onSslErrors(const QList errors); + void sendPing(); + public slots: void start(const QUrl &url, const QString &token); diff --git a/libnymea-remoteproxy/authentication/authenticator.cpp b/libnymea-remoteproxy/authentication/authenticator.cpp index 2cee567..ac997b1 100644 --- a/libnymea-remoteproxy/authentication/authenticator.cpp +++ b/libnymea-remoteproxy/authentication/authenticator.cpp @@ -1,3 +1,24 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2018 Simon Stürz * + * * + * This file is part of nymea-remoteproxy. * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program 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 program. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "proxyclient.h" #include "authenticator.h" #include "authenticationreply.h" diff --git a/libnymea-remoteproxy/engine.cpp b/libnymea-remoteproxy/engine.cpp index 36ef3b6..5f3013c 100644 --- a/libnymea-remoteproxy/engine.cpp +++ b/libnymea-remoteproxy/engine.cpp @@ -129,6 +129,11 @@ void Engine::setDeveloperModeEnabled(bool enabled) m_developerMode = enabled; } +ProxyConfiguration *Engine::configuration() const +{ + return m_configuration; +} + Authenticator *Engine::authenticator() const { return m_authenticator; diff --git a/libnymea-remoteproxy/engine.h b/libnymea-remoteproxy/engine.h index a835b2b..d81d03f 100644 --- a/libnymea-remoteproxy/engine.h +++ b/libnymea-remoteproxy/engine.h @@ -55,6 +55,7 @@ public: void setAuthenticator(Authenticator *authenticator); void setDeveloperModeEnabled(bool enabled); + ProxyConfiguration *configuration() const; Authenticator *authenticator() const; ProxyServer *proxyServer() const; WebSocketServer *webSocketServer() const; diff --git a/libnymea-remoteproxy/monitorserver.cpp b/libnymea-remoteproxy/monitorserver.cpp index a813545..18dc0c8 100644 --- a/libnymea-remoteproxy/monitorserver.cpp +++ b/libnymea-remoteproxy/monitorserver.cpp @@ -19,6 +19,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "engine.h" #include "monitorserver.h" #include "loggingcategories.h" @@ -52,7 +53,10 @@ bool MonitorServer::running() const QVariantMap MonitorServer::createMonitorData() { QVariantMap monitorData; - + monitorData.insert("serverName", Engine::instance()->configuration()->serverName()); + monitorData.insert("serverVersion", SERVER_VERSION_STRING); + monitorData.insert("apiVersion", API_VERSION_STRING); + monitorData.insert("proxyStatistic", Engine::instance()->proxyServer()->currentStatistics()); return monitorData; } diff --git a/libnymea-remoteproxy/proxyserver.cpp b/libnymea-remoteproxy/proxyserver.cpp index 336a1af..b065491 100644 --- a/libnymea-remoteproxy/proxyserver.cpp +++ b/libnymea-remoteproxy/proxyserver.cpp @@ -59,6 +59,14 @@ void ProxyServer::registerTransportInterface(TransportInterface *interface) m_transportInterfaces.append(interface); } +QVariantMap ProxyServer::currentStatistics() +{ + QVariantMap statisticsMap; + statisticsMap.insert("clientCount", m_proxyClients.count()); + statisticsMap.insert("tunnelCount", m_tunnels.count()); + return statisticsMap; +} + void ProxyServer::setRunning(bool running) { if (m_running == running) diff --git a/libnymea-remoteproxy/proxyserver.h b/libnymea-remoteproxy/proxyserver.h index 3762e65..9879d3f 100644 --- a/libnymea-remoteproxy/proxyserver.h +++ b/libnymea-remoteproxy/proxyserver.h @@ -43,6 +43,8 @@ public: bool running() const; void registerTransportInterface(TransportInterface *interface); + QVariantMap currentStatistics(); + private: JsonRpcServer *m_jsonRpcServer = nullptr; QList m_transportInterfaces; diff --git a/libnymea-remoteproxyclient/remoteproxyconnection.cpp b/libnymea-remoteproxyclient/remoteproxyconnection.cpp index c46d32e..58e4f63 100644 --- a/libnymea-remoteproxyclient/remoteproxyconnection.cpp +++ b/libnymea-remoteproxyclient/remoteproxyconnection.cpp @@ -149,22 +149,6 @@ QString RemoteProxyConnection::tunnelPartnerUuid() const return m_tunnelPartnerUuid; } -bool RemoteProxyConnection::sendData(const QByteArray &data) -{ - if (!isConnected()) { - qCWarning(dcRemoteProxyClientConnection()) << "Could not send data. Not connected."; - return false; - } - - if (!isRemoteConnected()) { - qCWarning(dcRemoteProxyClientConnection()) << "Could not send data. The remote client is not connected yet."; - return false; - } - - m_connection->sendData(data); - return true; -} - void RemoteProxyConnection::cleanUp() { if (m_jsonClient) { @@ -381,4 +365,21 @@ void RemoteProxyConnection::disconnectServer() } } +bool RemoteProxyConnection::sendData(const QByteArray &data) +{ + if (!isConnected()) { + qCWarning(dcRemoteProxyClientConnection()) << "Could not send data. Not connected."; + return false; + } + + if (!isRemoteConnected()) { + qCWarning(dcRemoteProxyClientConnection()) << "Could not send data. The remote client is not connected yet."; + return false; + } + + m_connection->sendData(data); + return true; +} + + } diff --git a/libnymea-remoteproxyclient/remoteproxyconnection.h b/libnymea-remoteproxyclient/remoteproxyconnection.h index 1be350d..1c8fc67 100644 --- a/libnymea-remoteproxyclient/remoteproxyconnection.h +++ b/libnymea-remoteproxyclient/remoteproxyconnection.h @@ -97,8 +97,6 @@ public: QString tunnelPartnerName() const; QString tunnelPartnerUuid() const; - bool sendData(const QByteArray &data); - private: ConnectionType m_connectionType = ConnectionTypeWebSocket; QUuid m_clientUuid; @@ -156,6 +154,7 @@ public slots: bool connectServer(const QUrl &url); bool authenticate(const QString &token); void disconnectServer(); + bool sendData(const QByteArray &data); }; diff --git a/server/main.cpp b/server/main.cpp index 90545de..3bc31c9 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/server/remoteproxyserverapplication.cpp b/server/remoteproxyserverapplication.cpp index ea5dde2..a34d5c9 100644 --- a/server/remoteproxyserverapplication.cpp +++ b/server/remoteproxyserverapplication.cpp @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/server/remoteproxyserverapplication.h b/server/remoteproxyserverapplication.h index 7a9d8d5..09493a8 100644 --- a/server/remoteproxyserverapplication.h +++ b/server/remoteproxyserverapplication.h @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/tests/test-offline/nymea-remoteproxy-tests-offline.cpp b/tests/test-offline/nymea-remoteproxy-tests-offline.cpp index 69df61c..c2d1abb 100644 --- a/tests/test-offline/nymea-remoteproxy-tests-offline.cpp +++ b/tests/test-offline/nymea-remoteproxy-tests-offline.cpp @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/tests/test-offline/nymea-remoteproxy-tests-offline.h b/tests/test-offline/nymea-remoteproxy-tests-offline.h index a46b181..96170e7 100644 --- a/tests/test-offline/nymea-remoteproxy-tests-offline.h +++ b/tests/test-offline/nymea-remoteproxy-tests-offline.h @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/tests/testbase/basetest.cpp b/tests/testbase/basetest.cpp index 4dfb1b6..55f4a02 100644 --- a/tests/testbase/basetest.cpp +++ b/tests/testbase/basetest.cpp @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/tests/testbase/basetest.h b/tests/testbase/basetest.h index f97b124..8d104e5 100644 --- a/tests/testbase/basetest.h +++ b/tests/testbase/basetest.h @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/tests/testbase/mockauthenticator.cpp b/tests/testbase/mockauthenticator.cpp index 7e9d6db..c307b56 100644 --- a/tests/testbase/mockauthenticator.cpp +++ b/tests/testbase/mockauthenticator.cpp @@ -2,7 +2,7 @@ * * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh-cloudproxy. * + * This file is part of nymea-remoteproxy. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by *