Tell the server if a client has been disconnected without notice

cleanup-proxy-code
Simon Stürz 2023-02-14 15:05:51 +01:00
parent 19e85d509e
commit eb609da9a4
2 changed files with 15 additions and 11 deletions

View File

@ -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());
}
}

View File

@ -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;