Update clients for tcp
parent
3eb247e652
commit
6c355b4c43
|
|
@ -113,7 +113,7 @@ int main(int argc, char *argv[])
|
|||
QCommandLineOption nonceOption(QStringList() << "n" << "nonce", "The shared connection unique nonce for this tunnel.", "nonce");
|
||||
parser.addOption(nonceOption);
|
||||
|
||||
QCommandLineOption insecureOption(QStringList() << "i" << "igore-ssl", "Ignore SSL certificate errors.");
|
||||
QCommandLineOption insecureOption(QStringList() << "i" << "ignore-ssl", "Ignore SSL certificate errors.");
|
||||
parser.addOption(insecureOption);
|
||||
|
||||
QCommandLineOption pingPongOption(QStringList() << "p" << "pingpong", "Start a ping pong traffic trough the remote connection.");
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ TunnelProxySocketServer::TunnelProxySocketServer(const QUuid &serverUuid, const
|
|||
m_serverUuid(serverUuid),
|
||||
m_serverName(serverName)
|
||||
{
|
||||
|
||||
setupReconnectTimer();
|
||||
}
|
||||
|
||||
TunnelProxySocketServer::TunnelProxySocketServer(const QUuid &serverUuid, const QString &serverName, ConnectionType connectionType, QObject *parent) :
|
||||
|
|
@ -51,7 +51,7 @@ TunnelProxySocketServer::TunnelProxySocketServer(const QUuid &serverUuid, const
|
|||
m_serverName(serverName),
|
||||
m_connectionType(connectionType)
|
||||
{
|
||||
|
||||
setupReconnectTimer();
|
||||
}
|
||||
|
||||
TunnelProxySocketServer::~TunnelProxySocketServer()
|
||||
|
|
@ -74,6 +74,11 @@ TunnelProxySocketServer::Error TunnelProxySocketServer::serverError() const
|
|||
return m_serverError;
|
||||
}
|
||||
|
||||
TunnelProxySocketServer::State TunnelProxySocketServer::state() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::ignoreSslErrors()
|
||||
{
|
||||
m_connection->ignoreSslErrors();
|
||||
|
|
@ -109,8 +114,13 @@ QString TunnelProxySocketServer::remoteProxyApiVersion() const
|
|||
return m_remoteProxyApiVersion;
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::startServer(const QUrl &serverUrl)
|
||||
bool TunnelProxySocketServer::startServer(const QUrl &serverUrl)
|
||||
{
|
||||
if (!serverUrl.isValid() || serverUrl.isEmpty()) {
|
||||
qCWarning(dcTunnelProxySocketServer()) << "Could not start server. The given remote proxy URL is not valid" << serverUrl.toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_serverUrl = serverUrl;
|
||||
m_error = QAbstractSocket::UnknownSocketError;
|
||||
|
||||
|
|
@ -139,10 +149,16 @@ void TunnelProxySocketServer::startServer(const QUrl &serverUrl)
|
|||
|
||||
qCDebug(dcTunnelProxySocketServer()) << "Connecting to" << m_serverUrl.toString();
|
||||
m_connection->connectServer(m_serverUrl);
|
||||
m_enabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::stopServer()
|
||||
{
|
||||
m_enabled = false;
|
||||
m_reconnectTimer.stop();
|
||||
|
||||
if (m_connection) {
|
||||
qCDebug(dcTunnelProxySocketServer()) << "Disconnecting from" << m_connection->serverUrl().toString();
|
||||
m_connection->disconnectServer();
|
||||
|
|
@ -231,6 +247,7 @@ void TunnelProxySocketServer::onConnectionStateChanged(QAbstractSocket::SocketSt
|
|||
break;
|
||||
case QAbstractSocket::ConnectedState:
|
||||
setState(StateConnected);
|
||||
m_reconnectTimer.stop();
|
||||
break;
|
||||
case QAbstractSocket::ClosingState:
|
||||
setState(StateDiconnecting);
|
||||
|
|
@ -331,6 +348,23 @@ void TunnelProxySocketServer::requestSocketDisconnect(quint16 socketAddress)
|
|||
});
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::setupReconnectTimer()
|
||||
{
|
||||
m_reconnectTimer.setInterval(5000);
|
||||
m_reconnectTimer.setSingleShot(true);
|
||||
connect(&m_reconnectTimer, &QTimer::timeout, this, [this](){
|
||||
if (!m_enabled) {
|
||||
m_reconnectTimer.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_state == StateDisconnected) {
|
||||
qCDebug(dcTunnelProxySocketServer()) << "Trying to reconnect to the remote proxy...";
|
||||
startServer(m_serverUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::setState(State state)
|
||||
{
|
||||
if (m_state == state)
|
||||
|
|
@ -341,6 +375,11 @@ void TunnelProxySocketServer::setState(State state)
|
|||
emit stateChanged(m_state);
|
||||
|
||||
setRunning(m_state == StateRunning);
|
||||
|
||||
if (m_state == StateDisconnected && m_enabled) {
|
||||
qCDebug(dcTunnelProxySocketServer()) << "Starting reconnect timer...";
|
||||
m_reconnectTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
void TunnelProxySocketServer::setRunning(bool running)
|
||||
|
|
@ -394,6 +433,8 @@ void TunnelProxySocketServer::cleanUp()
|
|||
m_remoteProxyServerVersion.clear();
|
||||
m_remoteProxyApiVersion.clear();
|
||||
|
||||
m_enabled = false;
|
||||
|
||||
setState(StateDisconnected);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
#include <QSslError>
|
||||
#include <QLoggingCategory>
|
||||
|
|
@ -87,6 +88,8 @@ public:
|
|||
QAbstractSocket::SocketError error() const;
|
||||
Error serverError() const;
|
||||
|
||||
State state() const;
|
||||
|
||||
void ignoreSslErrors();
|
||||
void ignoreSslErrors(const QList<QSslError> &errors);
|
||||
|
||||
|
|
@ -98,7 +101,7 @@ public:
|
|||
QString remoteProxyApiVersion() const;
|
||||
|
||||
public slots:
|
||||
void startServer(const QUrl &serverUrl);
|
||||
bool startServer(const QUrl &serverUrl);
|
||||
void stopServer();
|
||||
|
||||
signals:
|
||||
|
|
@ -145,6 +148,9 @@ private:
|
|||
Error m_serverError = ErrorNoError;
|
||||
State m_state = StateDisconnected;
|
||||
|
||||
QTimer m_reconnectTimer;
|
||||
bool m_enabled = false;
|
||||
|
||||
ProxyConnection *m_connection = nullptr;
|
||||
JsonRpcClient *m_jsonClient = nullptr;
|
||||
|
||||
|
|
@ -153,6 +159,7 @@ private:
|
|||
QByteArray m_dataBuffer;
|
||||
|
||||
void requestSocketDisconnect(quint16 socketAddress);
|
||||
void setupReconnectTimer();
|
||||
|
||||
void setState(State state);
|
||||
void setRunning(bool running);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
|||
m_remoteConnection = new TunnelProxyRemoteConnection(m_uuid, m_name);
|
||||
|
||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::stateChanged, this, [this](TunnelProxyRemoteConnection::State state){
|
||||
qDebug() << state;
|
||||
switch (state) {
|
||||
case TunnelProxyRemoteConnection::StateRegister:
|
||||
qDebug() << "Connected with" << m_remoteConnection->remoteProxyServer() << m_remoteConnection->remoteProxyServerName() << m_remoteConnection->remoteProxyServerVersion() << m_remoteConnection->remoteProxyApiVersion();
|
||||
|
|
@ -22,7 +23,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
|||
});
|
||||
|
||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::remoteConnectedChanged, this, [](bool remoteConnected){
|
||||
qDebug() << "Remote connection " << (remoteConnected ? "established" : "disconnected");
|
||||
qDebug() << "Remote connection" << (remoteConnected ? "established successfully" : "disconnected");
|
||||
});
|
||||
|
||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::dataReady, this, [](const QByteArray &data){
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ int main(int argc, char *argv[])
|
|||
urlOption.setDefaultValue("ssl://dev-remoteproxy.nymea.io:2213");
|
||||
parser.addOption(urlOption);
|
||||
|
||||
QCommandLineOption insecureOption(QStringList() << "i" << "igore-ssl", "Ignore SSL certificate errors.");
|
||||
QCommandLineOption insecureOption(QStringList() << "i" << "ignore-ssl", "Ignore SSL certificate errors.");
|
||||
parser.addOption(insecureOption);
|
||||
|
||||
QCommandLineOption serverOption(QStringList() << "s" << "server", "Connect as tunnel proxy server connection.");
|
||||
|
|
|
|||
Loading…
Reference in New Issue