Add tunnel proxy statistics and fix typo

This commit is contained in:
Simon Stürz 2021-08-16 07:41:54 +02:00
parent 7161cfe795
commit 23462e194e
26 changed files with 81 additions and 46 deletions

View File

@ -42,7 +42,7 @@ ProxyClient::ProxyClient(const QString &name, const QUuid &uuid, RemoteProxyConn
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::errorOccurred, this, &ProxyClient::onErrorOccurred);
connect(m_connection, &RemoteProxyConnection::disconnected, this, &ProxyClient::onClientDisconnected);
connect(m_connection, &RemoteProxyConnection::sslErrors, this, &ProxyClient::onSslErrors);
}
@ -57,9 +57,9 @@ void ProxyClient::setPingpong(bool enable)
m_pingpong = enable;
}
void ProxyClient::onErrorOccured(QAbstractSocket::SocketError error)
void ProxyClient::onErrorOccurred(QAbstractSocket::SocketError error)
{
qCWarning(dcProxyClient()) << "Error occured" << error;
qCWarning(dcProxyClient()) << "Error occurred" << error;
exit(-1);
}
@ -100,10 +100,10 @@ void ProxyClient::onClientDisconnected()
void ProxyClient::onSslErrors(const QList<QSslError> errors)
{
if (m_insecure) {
qCDebug(dcProxyClient()) << "SSL errors occured. Ignoring because explicit specified.";
qCDebug(dcProxyClient()) << "SSL errors occurred. Ignoring because explicit specified.";
m_connection->ignoreSslErrors();
} else {
qCWarning(dcProxyClient()) << "SSL errors occured:";
qCWarning(dcProxyClient()) << "SSL errors occurred:";
foreach (const QSslError &sslError, errors) {
qCWarning(dcProxyClient()) << " --> " << sslError.errorString();
}

View File

@ -57,7 +57,7 @@ private:
RemoteProxyConnection *m_connection = nullptr;
private slots:
void onErrorOccured(QAbstractSocket::SocketError error);
void onErrorOccurred(QAbstractSocket::SocketError error);
void onClientReady();
void onAuthenticationFinished();
void onRemoteConnectionEstablished();

View File

@ -256,6 +256,7 @@ QVariantMap Engine::createServerStatistic()
monitorData.insert("serverVersion", SERVER_VERSION_STRING);
monitorData.insert("apiVersion", API_VERSION_STRING);
monitorData.insert("proxyStatistic", proxyServer()->currentStatistics());
monitorData.insert("tunnelProxyStatistic", tunnelProxyServer()->currentStatistics());
return monitorData;
}

View File

@ -95,7 +95,7 @@ void AuthenticationHandler::onAuthenticationFinished()
JsonReply *jsonReply = m_runningAuthentications.take(authenticationReply);
if (authenticationReply->error() != Authenticator::AuthenticationErrorNoError) {
qCWarning(dcJsonRpc()) << "Authentication error occured" << authenticationReply->error();
qCWarning(dcJsonRpc()) << "Authentication error occurred" << authenticationReply->error();
jsonReply->setSuccess(false);
} else {
// Successfully authenticated

View File

@ -39,9 +39,9 @@ Q_LOGGING_CATEGORY(dcWebSocketServerTraffic, "WebSocketServerTraffic")
Q_LOGGING_CATEGORY(dcAuthentication, "Authentication")
Q_LOGGING_CATEGORY(dcAuthenticationProcess, "AuthenticationProcess")
Q_LOGGING_CATEGORY(dcProxyServer, "ProxyServer")
Q_LOGGING_CATEGORY(dcProxyServerTraffic, "ProxyServerTraffic")
Q_LOGGING_CATEGORY(dcTunnelProxyServer, "TunnelProxyServer")
Q_LOGGING_CATEGORY(dcTunnelProxyServerTraffic, "TunnelProxyServerTraffic")
Q_LOGGING_CATEGORY(dcProxyServerTraffic, "ProxyServerTraffic")
Q_LOGGING_CATEGORY(dcMonitorServer, "MonitorServer")
Q_LOGGING_CATEGORY(dcAwsCredentialsProvider, "AwsCredentialsProvider")
Q_LOGGING_CATEGORY(dcAwsCredentialsProviderTraffic, "AwsCredentialsProviderTraffic")

View File

@ -37,7 +37,7 @@ ProxyClient::ProxyClient(TransportInterface *interface, const QUuid &clientId, c
TransportClient(interface, clientId, address, parent)
{
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &ProxyClient::timeoutOccured);
connect(m_timer, &QTimer::timeout, this, &ProxyClient::timeoutOccurred);
m_timer->setSingleShot(true);
resetTimer();
}

View File

@ -90,7 +90,7 @@ private:
signals:
void authenticated();
void tunnelConnected();
void timeoutOccured();
void timeoutOccurred();
};

View File

@ -216,7 +216,7 @@ void ProxyServer::onClientConnected(const QUuid &clientId, const QHostAddress &a
ProxyClient *proxyClient = new ProxyClient(interface, clientId, address, this);
connect(proxyClient, &ProxyClient::authenticated, this, &ProxyServer::onProxyClientAuthenticated);
connect(proxyClient, &ProxyClient::timeoutOccured, this, &ProxyServer::onProxyClientTimeoutOccured);
connect(proxyClient, &ProxyClient::timeoutOccurred, this, &ProxyServer::onProxyClientTimeoutOccurred);
m_totalClientCount += 1;
saveStatistics();
@ -375,10 +375,10 @@ void ProxyServer::onProxyClientAuthenticated()
}
}
void ProxyServer::onProxyClientTimeoutOccured()
void ProxyServer::onProxyClientTimeoutOccurred()
{
ProxyClient *proxyClient = static_cast<ProxyClient *>(sender());
qCDebug(dcProxyServer()) << "Timeout occured for" << proxyClient;
qCDebug(dcProxyServer()) << "Timeout occurred for" << proxyClient;
switch (proxyClient->timerWaitState()) {
case ProxyClient::TimerWaitStateInactive:
proxyClient->killConnection("Proxy timeout occuret. The socket was inactive.");

View File

@ -83,7 +83,6 @@ private:
void loadStatistics();
void saveStatistics();
// Helper methods
ProxyClient *getRemoteClient(ProxyClient *proxyClient);
void establishTunnel(ProxyClient *firstClient, ProxyClient *secondClient);
@ -97,7 +96,7 @@ private slots:
void onClientDataAvailable(const QUuid &clientId, const QByteArray &data);
void onProxyClientAuthenticated();
void onProxyClientTimeoutOccured();
void onProxyClientTimeoutOccurred();
public slots:
void startServer();

View File

@ -200,7 +200,7 @@ void SslServer::onSocketReadyRead()
void SslServer::onSocketError(QAbstractSocket::SocketError error)
{
qCWarning(dcTcpSocketServer()) << "Socket error occured" << error;
qCWarning(dcTcpSocketServer()) << "Socket error occurred" << error;
}
}

View File

@ -197,6 +197,39 @@ TunnelProxyServer::TunnelProxyError TunnelProxyServer::disconnectClient(const QU
return TunnelProxyServer::TunnelProxyErrorNoError;
}
QVariantMap TunnelProxyServer::currentStatistics()
{
QVariantMap statisticsMap;
statisticsMap.insert("totalClientCount", m_proxyClients.count());
statisticsMap.insert("serverConnectionsCount", m_tunnelProxyServerConnections.count());
statisticsMap.insert("clientConnectionsCount", m_tunnelProxyClientConnections.count());
QVariantList tunnelConnections;
foreach (TunnelProxyServerConnection *serverConnection, m_tunnelProxyServerConnections) {
QVariantMap serverMap;
serverMap.insert("id", serverConnection->transportClient()->clientId().toString());
serverMap.insert("address", serverConnection->transportClient()->peerAddress().toString());
serverMap.insert("timestamp", serverConnection->transportClient()->creationTime());
serverMap.insert("name", serverConnection->transportClient()->name());
serverMap.insert("serverUuid", serverConnection->transportClient()->uuid());
QVariantList clientList;
foreach (TunnelProxyClientConnection *clientConnection, serverConnection->clientConnections()) {
QVariantMap clientMap;
clientMap.insert("id", clientConnection->transportClient()->clientId().toString());
clientMap.insert("address", clientConnection->transportClient()->peerAddress().toString());
clientMap.insert("timestamp", clientConnection->transportClient()->creationTime());
clientMap.insert("name", clientConnection->transportClient()->name());
clientMap.insert("clientUuid", clientConnection->transportClient()->uuid());
clientList.append(clientMap);
}
serverMap.insert("clientConnections", clientList);
}
statisticsMap.insert("tunnelConnections", tunnelConnections);
return statisticsMap;
}
void TunnelProxyServer::startServer()
{
qCDebug(dcTunnelProxyServer()) << "Starting tunnel proxy...";

View File

@ -67,6 +67,8 @@ public:
TunnelProxyServer::TunnelProxyError registerClient(const QUuid &clientId, const QUuid &clientUuid, const QString &clientName, const QUuid &serverUuid);
TunnelProxyServer::TunnelProxyError disconnectClient(const QUuid &clientId, quint16 socketAddress);
QVariantMap currentStatistics();
public slots:
void startServer();
void stopServer();

View File

@ -65,7 +65,7 @@ signals:
void dataReceived(const QByteArray &data);
void stateChanged(QAbstractSocket::SocketState state);
void errorOccured(QAbstractSocket::SocketError error);
void errorOccurred(QAbstractSocket::SocketError error);
void sslErrors(const QList<QSslError> &errors);

View File

@ -192,8 +192,8 @@ void RemoteProxyConnection::setError(QAbstractSocket::SocketError error)
return;
m_error = error;
qCDebug(dcRemoteProxyClientConnection()) << "Error occured" << m_error;
emit errorOccured(m_error);
qCDebug(dcRemoteProxyClientConnection()) << "Error occurred" << m_error;
emit errorOccurred(m_error);
}
void RemoteProxyConnection::onConnectionChanged(bool isConnected)
@ -337,7 +337,7 @@ bool RemoteProxyConnection::connectServer(const QUrl &url)
connect(m_connection, &ProxyConnection::connectedChanged, this, &RemoteProxyConnection::onConnectionChanged);
connect(m_connection, &ProxyConnection::dataReceived, this, &RemoteProxyConnection::onConnectionDataAvailable);
connect(m_connection, &ProxyConnection::errorOccured, this, &RemoteProxyConnection::onConnectionSocketError);
connect(m_connection, &ProxyConnection::errorOccurred, this, &RemoteProxyConnection::onConnectionSocketError);
connect(m_connection, &ProxyConnection::stateChanged, this, &RemoteProxyConnection::onConnectionStateChanged);
connect(m_connection, &ProxyConnection::sslErrors, this, &RemoteProxyConnection::sslErrors);

View File

@ -133,7 +133,7 @@ signals:
void disconnected();
void stateChanged(RemoteProxyConnection::State state);
void errorOccured(QAbstractSocket::SocketError error);
void errorOccurred(QAbstractSocket::SocketError error);
void sslErrors(const QList<QSslError> &errors);
void dataReady(const QByteArray &data);

View File

@ -88,8 +88,8 @@ void TcpSocketConnection::onEncrypted()
void TcpSocketConnection::onError(QAbstractSocket::SocketError error)
{
qCWarning(dcRemoteProxyClientTcpSocket()) << "Socket error occured" << error << m_tcpSocket->errorString();
emit errorOccured(error);
qCWarning(dcRemoteProxyClientTcpSocket()) << "Socket error occurred" << error << m_tcpSocket->errorString();
emit errorOccurred(error);
}
void TcpSocketConnection::onStateChanged(QAbstractSocket::SocketState state)

View File

@ -123,7 +123,7 @@ bool TunnelProxyRemoteConnection::connectServer(const QUrl &url, const QUuid &se
connect(m_connection, &ProxyConnection::connectedChanged, this, &TunnelProxyRemoteConnection::onConnectionChanged);
connect(m_connection, &ProxyConnection::dataReceived, this, &TunnelProxyRemoteConnection::onConnectionDataAvailable);
connect(m_connection, &ProxyConnection::errorOccured, this, &TunnelProxyRemoteConnection::onConnectionSocketError);
connect(m_connection, &ProxyConnection::errorOccurred, this, &TunnelProxyRemoteConnection::onConnectionSocketError);
connect(m_connection, &ProxyConnection::stateChanged, this, &TunnelProxyRemoteConnection::onConnectionStateChanged);
connect(m_connection, &ProxyConnection::sslErrors, this, &TunnelProxyRemoteConnection::sslErrors);
@ -287,8 +287,8 @@ void TunnelProxyRemoteConnection::setError(QAbstractSocket::SocketError error)
return;
m_error = error;
qCWarning(dcTunnelProxyRemoteConnection()) << "Error occured" << m_error;
emit errorOccured(m_error);
qCWarning(dcTunnelProxyRemoteConnection()) << "Error occurred" << m_error;
emit errorOccurred(m_error);
}
void TunnelProxyRemoteConnection::cleanUp()

View File

@ -90,7 +90,7 @@ public slots:
signals:
void stateChanged(TunnelProxyRemoteConnection::State state);
void errorOccured(QAbstractSocket::SocketError error);
void errorOccurred(QAbstractSocket::SocketError error);
void sslErrors(const QList<QSslError> &errors);
void remoteConnectedChanged(bool remoteConnected);

View File

@ -139,7 +139,7 @@ bool TunnelProxySocketServer::startServer(const QUrl &serverUrl)
connect(m_connection, &ProxyConnection::connectedChanged, this, &TunnelProxySocketServer::onConnectionChanged);
connect(m_connection, &ProxyConnection::dataReceived, this, &TunnelProxySocketServer::onConnectionDataAvailable);
connect(m_connection, &ProxyConnection::errorOccured, this, &TunnelProxySocketServer::onConnectionSocketError);
connect(m_connection, &ProxyConnection::errorOccurred, this, &TunnelProxySocketServer::onConnectionSocketError);
connect(m_connection, &ProxyConnection::stateChanged, this, &TunnelProxySocketServer::onConnectionStateChanged);
connect(m_connection, &ProxyConnection::sslErrors, this, &TunnelProxySocketServer::sslErrors);
@ -398,8 +398,8 @@ void TunnelProxySocketServer::setError(QAbstractSocket::SocketError error)
return;
m_error = error;
qCDebug(dcTunnelProxySocketServer()) << "Error occured" << m_error;
emit errorOccured(m_error);
qCDebug(dcTunnelProxySocketServer()) << "Error occurred" << m_error;
emit errorOccurred(m_error);
}
void TunnelProxySocketServer::setServerError(Error error)
@ -407,9 +407,9 @@ void TunnelProxySocketServer::setServerError(Error error)
if (m_serverError == error)
return;
qCDebug(dcTunnelProxySocketServer()) << "Server error occured" << error;
qCDebug(dcTunnelProxySocketServer()) << "Server error occurred" << error;
m_serverError = error;
emit serverErrorOccured(m_serverError);
emit serverErrorOccurred(m_serverError);
}
void TunnelProxySocketServer::cleanUp()

View File

@ -106,8 +106,8 @@ public slots:
signals:
void stateChanged(TunnelProxySocketServer::State state);
void errorOccured(QAbstractSocket::SocketError error);
void serverErrorOccured(Error error);
void errorOccurred(QAbstractSocket::SocketError error);
void serverErrorOccurred(Error error);
void sslErrors(const QList<QSslError> &errors);
void runningChanged(bool running);

View File

@ -72,8 +72,8 @@ void WebSocketConnection::onDisconnected()
void WebSocketConnection::onError(QAbstractSocket::SocketError error)
{
qCDebug(dcRemoteProxyClientWebSocket()) << "Socket error occured" << error << m_webSocket->errorString();
emit errorOccured(error);
qCDebug(dcRemoteProxyClientWebSocket()) << "Socket error occurred" << error << m_webSocket->errorString();
emit errorOccurred(error);
}
void WebSocketConnection::onStateChanged(QAbstractSocket::SocketState state)

View File

@ -38,7 +38,7 @@ MonitorClient::MonitorClient(const QString &serverName, QObject *parent) :
connect(m_socket, &QLocalSocket::connected, this, &MonitorClient::onConnected);
connect(m_socket, &QLocalSocket::disconnected, this, &MonitorClient::onDisconnected);
connect(m_socket, &QLocalSocket::readyRead, this, &MonitorClient::onReadyRead);
connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onErrorOccured(QLocalSocket::LocalSocketError)));
connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onErrorOccurred(QLocalSocket::LocalSocketError)));
}
void MonitorClient::onConnected()
@ -71,10 +71,10 @@ void MonitorClient::onReadyRead()
emit dataReady(dataMap);
}
void MonitorClient::onErrorOccured(QLocalSocket::LocalSocketError socketError)
void MonitorClient::onErrorOccurred(QLocalSocket::LocalSocketError socketError)
{
Q_UNUSED(socketError)
qWarning() << "Local socket error occured" << m_socket->errorString();
qWarning() << "Local socket error occurred" << m_socket->errorString();
}
void MonitorClient::connectMonitor()

View File

@ -52,7 +52,7 @@ private slots:
void onConnected();
void onDisconnected();
void onReadyRead();
void onErrorOccured(QLocalSocket::LocalSocketError socketError);
void onErrorOccurred(QLocalSocket::LocalSocketError socketError);
public slots:
void connectMonitor();

View File

@ -1086,7 +1086,7 @@ void RemoteProxyTestsProxy::sslConfigurations()
// Connect to the server (insecure disabled)
RemoteProxyConnection *connector = new RemoteProxyConnection(QUuid::createUuid(), "Test client one", this);
QSignalSpy spyError(connector, &RemoteProxyConnection::errorOccured);
QSignalSpy spyError(connector, &RemoteProxyConnection::errorOccurred);
QVERIFY(connector->connectServer(m_serverUrlProxyWebSocket));
spyError.wait();
QVERIFY(spyError.count() == 1);
@ -1213,7 +1213,7 @@ void RemoteProxyTestsProxy::authenticationReplyConnection()
connectionReadySpy.wait();
QVERIFY(connectionReadySpy.count() == 1);
QSignalSpy connectionErrorSpy(connection, &RemoteProxyConnection::errorOccured);
QSignalSpy connectionErrorSpy(connection, &RemoteProxyConnection::errorOccurred);
connection->authenticate("blub");
connectionErrorSpy.wait();
QVERIFY(connectionErrorSpy.count() == 1);

View File

@ -30,15 +30,15 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
qDebug() << "Data received" << data;
});
connect(m_remoteConnection, &TunnelProxyRemoteConnection::errorOccured, this, [](QAbstractSocket::SocketError error){
qWarning() << "Socket error occured" << error;
connect(m_remoteConnection, &TunnelProxyRemoteConnection::errorOccurred, this, [](QAbstractSocket::SocketError error){
qWarning() << "Socket error occurred" << error;
});
connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [=](const QList<QSslError> &errors){
if (m_insecure) {
m_remoteConnection->ignoreSslErrors(errors);
} else {
qWarning() << "SSL errors occured:";
qWarning() << "SSL errors occurred:";
foreach (const QSslError &sslError, errors) {
qWarning() << " --> " << sslError.errorString();
}

View File

@ -29,7 +29,7 @@ ServerConnection::ServerConnection(const QUrl &serverUrl, const QString &name, c
if (m_insecure) {
m_socketServer->ignoreSslErrors(errors);
} else {
qWarning() << "SSL errors occured:";
qWarning() << "SSL errors occurred:";
foreach (const QSslError &sslError, errors) {
qWarning() << " --> " << sslError.errorString();
}