From eb609da9a40962d754a1b0eb99925f7acd700799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 14 Feb 2023 15:05:51 +0100 Subject: [PATCH] Tell the server if a client has been disconnected without notice --- libnymea-remoteproxy/server/jsonrpcserver.cpp | 19 ++++++++++--------- .../tunnelproxy/tunnelproxyserver.cpp | 7 +++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libnymea-remoteproxy/server/jsonrpcserver.cpp b/libnymea-remoteproxy/server/jsonrpcserver.cpp index 074f3cb..72e63cd 100644 --- a/libnymea-remoteproxy/server/jsonrpcserver.cpp +++ b/libnymea-remoteproxy/server/jsonrpcserver.cpp @@ -244,7 +244,7 @@ void JsonRpcServer::processDataPacket(TransportClient *transportClient, const QB } JsonReply *reply; - QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params), Q_ARG(TransportClient *, transportClient)); + QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params), Q_ARG(TransportClient*, transportClient)); if (reply->type() == JsonReply::TypeAsync) { m_asyncReplies.insert(reply, transportClient); reply->setClientId(transportClient->clientId()); @@ -297,24 +297,25 @@ void JsonRpcServer::asyncReplyFinished() qCWarning(dcJsonRpc()) << "Return value validation failed. This should never happen. Please check the source code."; } - sendResponse(transportClient, reply->commandId(), reply->data()); - if (!reply->success()) { // Disconnect this client since the request was not successfully transportClient->killConnectionAfterResponse("API call was not successfully."); } - - // If the server decided to kill the connection after the response, do it now - if (transportClient->killConnectionRequested()) { - transportClient->killConnection(transportClient->killConnectionReason()); - } + sendResponse(transportClient, reply->commandId(), reply->data()); } else { qCWarning(dcJsonRpc()) << "The reply timeouted."; + transportClient->killConnectionAfterResponse("API call timeouted."); sendErrorResponse(transportClient, reply->commandId(), "Command timed out"); // Disconnect this client since he requested something that created a timeout - transportClient->killConnection("API call timeouted."); + + } + + + // If the server decided to kill the connection after the response, do it now + if (transportClient->killConnectionRequested()) { + transportClient->killConnection(transportClient->killConnectionReason()); } } diff --git a/libnymea-remoteproxy/tunnelproxy/tunnelproxyserver.cpp b/libnymea-remoteproxy/tunnelproxy/tunnelproxyserver.cpp index fbb85c5..07b2a44 100644 --- a/libnymea-remoteproxy/tunnelproxy/tunnelproxyserver.cpp +++ b/libnymea-remoteproxy/tunnelproxy/tunnelproxyserver.cpp @@ -392,8 +392,11 @@ void TunnelProxyServer::onClientDataAvailable(const QUuid &clientId, const QByte TunnelProxyClientConnection *clientConnection = serverConnection->getClientConnection(frame.socketAddress); if (!clientConnection) { qCWarning(dcTunnelProxyServer()) << "The server connection wants to send data to a client connection which has not been registered to the server."; - // FIXME: tell the server this client does not exist - return; + qCWarning(dcTunnelProxyServer()) << "Notifying the server that there is no longer any socket connected with address" << frame.socketAddress; + QVariantMap params; + params.insert("socketAddress", frame.socketAddress); + m_jsonRpcServer->sendNotification("TunnelProxy", "ClientDisconnected", params, serverConnection->transportClient()); + continue; } qCDebug(dcTunnelProxyServerTraffic()) << "--> Tunnel data from server socket" << frame.socketAddress << "to" << clientConnection << "\n" << frame.data;