Make TCP default connection for clients

This commit is contained in:
Simon Stürz 2022-03-09 17:33:57 +01:00
parent 816111ddc7
commit 1c57db04f3
30 changed files with 50 additions and 52 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -115,11 +115,9 @@ void ProxyClient::resetTimer()
{
switch (m_timerWaitState) {
case TimerWaitStateInactive:
m_timer->stop();
m_timer->start(Engine::instance()->configuration()->inactiveTimeout());
break;
case TimerWaitStateAlone:
m_timer->stop();
m_timer->start(Engine::instance()->configuration()->aloneTimeout());
break;
}
@ -137,7 +135,7 @@ QList<QByteArray> ProxyClient::processData(const QByteArray &data)
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{");
}
if (m_dataBuffer.trimmed().endsWith("}")) {
if (m_dataBuffer.endsWith("}\n") || m_dataBuffer.endsWith("}")) {
packets.append(m_dataBuffer);
m_dataBuffer.clear();
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -381,10 +381,10 @@ void ProxyServer::onProxyClientTimeoutOccurred()
qCDebug(dcProxyServer()) << "Timeout occurred for" << proxyClient;
switch (proxyClient->timerWaitState()) {
case ProxyClient::TimerWaitStateInactive:
proxyClient->killConnection("Proxy timeout occuret. The socket was inactive.");
proxyClient->killConnection("Proxy timeout occurred. The socket was inactive.");
break;
case ProxyClient::TimerWaitStateAlone:
proxyClient->killConnection("Proxy timeout occuret. The tunnel partner did not show up.");
proxyClient->killConnection("Proxy timeout occurred. The tunnel partner did not show up.");
break;
}
}

View File

@ -81,7 +81,7 @@ private:
bool m_sslEnabled;
QSslConfiguration m_sslConfiguration;
QHash<QUuid, QTcpSocket *> m_clientList;
QHash<QUuid, QTcpSocket *> m_clientList;
SslServer *m_server = nullptr;

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -86,7 +86,7 @@ void WebSocketServer::onClientConnected()
// Got a new client connected
QWebSocket *client = m_server->nextPendingConnection();
if (!client) {
qCWarning(dcWebSocketServer()) << "Next pending connection dissapeared. Doing nothing.";
qCWarning(dcWebSocketServer()) << "Next pending connection disappeared. Doing nothing.";
return;
}
@ -147,7 +147,7 @@ void WebSocketServer::onClientError(QAbstractSocket::SocketError error)
QWebSocket *client = static_cast<QWebSocket *>(sender());
qCWarning(dcWebSocketServer()) << "Client error occurred:" << client << client->peerAddress().toString() << error << client->errorString() << "Closing the socket.";
// Note: on any error which can occure, make sure the socket will be closed in any case
// Note: on any error which can occurre, make sure the socket will be closed in any case
client->close();
}
@ -199,7 +199,7 @@ bool WebSocketServer::stopServer()
if (!m_server)
return true;
qCDebug(dcWebSocketServer()) << "Stop server" << m_server->serverName() << serverUrl().toString();
qCDebug(dcWebSocketServer()) << "Stopping server" << m_server->serverName() << serverUrl().toString();
m_server->close();
delete m_server;
m_server = nullptr;

View File

@ -60,7 +60,7 @@ QList<QByteArray> TunnelProxyClient::processData(const QByteArray &data)
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{");
}
if (m_dataBuffer.trimmed().endsWith("}")) {
if (m_dataBuffer.endsWith("}\n") || m_dataBuffer.endsWith("}")) {
packets.append(m_dataBuffer);
m_dataBuffer.clear();
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -200,7 +200,7 @@ void JsonRpcClient::processData(const QByteArray &data)
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{");
}
if (m_dataBuffer.trimmed().endsWith("}")) {
if (m_dataBuffer.endsWith("}\n") || m_dataBuffer.endsWith("}")) {
processDataPacket(m_dataBuffer);
m_dataBuffer.clear();
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -129,14 +129,14 @@ void RemoteProxyTestsProxy::monitorServer()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -598,14 +598,14 @@ void RemoteProxyTestsProxy::authenticateNonce()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -720,7 +720,7 @@ void RemoteProxyTestsProxy::clientConnectionWebSocket()
m_mockAuthenticator->setExpectedAuthenticationError();
// Connect to the server using WebSocket (insecure disabled)
RemoteProxyConnection *connection = new RemoteProxyConnection(QUuid::createUuid(), "Test client one", this);
RemoteProxyConnection *connection = new RemoteProxyConnection(QUuid::createUuid(), "Test client one", RemoteProxyConnection::ConnectionTypeWebSocket, this);
connect(connection, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError);
// Connect to server (insecue enabled for testing)
@ -837,14 +837,14 @@ void RemoteProxyTestsProxy::remoteConnection()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -956,14 +956,14 @@ void RemoteProxyTestsProxy::trippleConnection()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -996,7 +996,7 @@ void RemoteProxyTestsProxy::trippleConnection()
// Connect three
QSignalSpy connectionThreeReadySpy(connectionThree, &RemoteProxyConnection::ready);
QSignalSpy connectionThreeDisconnectedSpy(connectionThree, &RemoteProxyConnection::disconnected);
QVERIFY(connectionThree->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionThree->connectServer(m_serverUrlProxyTcp));
connectionThreeReadySpy.wait();
QVERIFY(connectionThreeReadySpy.count() == 1);
QVERIFY(connectionThree->isConnected());
@ -1041,14 +1041,14 @@ void RemoteProxyTestsProxy::duplicateUuid()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -1088,7 +1088,7 @@ void RemoteProxyTestsProxy::sslConfigurations()
// Connect to the server (insecure disabled)
RemoteProxyConnection *connector = new RemoteProxyConnection(QUuid::createUuid(), "Test client one", this);
QSignalSpy spyError(connector, &RemoteProxyConnection::errorOccurred);
QVERIFY(connector->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connector->connectServer(m_serverUrlProxyTcp));
spyError.wait();
QVERIFY(spyError.count() == 1);
qDebug() << connector->error();
@ -1098,7 +1098,7 @@ void RemoteProxyTestsProxy::sslConfigurations()
// Connect to server (insecue enabled)
QSignalSpy spyConnected(connector, &RemoteProxyConnection::connected);
connect(connector, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError);
connector->connectServer(m_serverUrlProxyWebSocket);
connector->connectServer(m_serverUrlProxyTcp);
spyConnected.wait();
QVERIFY(connector->isConnected());
@ -1153,7 +1153,7 @@ void RemoteProxyTestsProxy::inactiveTimeout()
// Connect one
QSignalSpy connectionReadySpy(connection, &RemoteProxyConnection::ready);
QSignalSpy connectionDisconnectedSpy(connection, &RemoteProxyConnection::disconnected);
QVERIFY(connection->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connection->connectServer(m_serverUrlProxyTcp));
connectionReadySpy.wait();
QVERIFY(connectionReadySpy.count() == 1);
@ -1210,7 +1210,7 @@ void RemoteProxyTestsProxy::authenticationReplyConnection()
// Connect one
QSignalSpy connectionReadySpy(connection, &RemoteProxyConnection::ready);
QVERIFY(connection->connectServer(m_serverUrlProxyWebSocket));
QVERIFY(connection->connectServer(m_serverUrlProxyTcp));
connectionReadySpy.wait();
QVERIFY(connectionReadySpy.count() == 1);

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Copyright 2013 - 2022, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.

View File

@ -326,7 +326,7 @@ bool BaseTest::createRemoteConnection(const QString &token, const QString &nonce
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
if (!connectionOne->connectServer(m_serverUrlProxyWebSocket)) {
if (!connectionOne->connectServer(m_serverUrlProxyTcp)) {
qWarning() << "Could not connect client one";
return false;
}
@ -344,7 +344,7 @@ bool BaseTest::createRemoteConnection(const QString &token, const QString &nonce
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
if (!connectionTwo->connectServer(m_serverUrlProxyWebSocket)) {
if (!connectionTwo->connectServer(m_serverUrlProxyTcp)) {
qWarning() << "Could not connect client two";
return false;
}