diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index a0df4dc0..67a21bba 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -38,7 +38,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr const std::function)> &cbReadStdOut, const std::function)> &cbReadStdErr) { - SshConnection *client = connectToHost(sshParams(credentials)); + QSharedPointer client = connectToHost(sshParams(credentials)); if (client->state() == SshConnection::State::Connecting) { qDebug() << "ServerController::runScript aborted, connectToHost in progress"; return ErrorCode::SshTimeoutError; @@ -229,7 +229,7 @@ QByteArray ServerController::getTextFileFromContainer(DockerContainer container, qDebug().noquote() << "Copy file from container\n" << script; - SshConnection *client = connectToHost(sshParams(credentials)); + QSharedPointer client = connectToHost(sshParams(credentials)); if (client->state() != SshConnection::State::Connected) { if (errorCode) *errorCode = fromSshConnectionErrorCode(client->errorState()); return {}; @@ -288,7 +288,7 @@ ErrorCode ServerController::checkOpenVpnServer(DockerContainer container, const ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credentials, const QByteArray &data, const QString &remotePath, QSsh::SftpOverwriteMode overwriteMode) { - SshConnection *client = connectToHost(sshParams(credentials)); + QSharedPointer client = connectToHost(sshParams(credentials)); if (client->state() != SshConnection::State::Connected) { return fromSshConnectionErrorCode(client->errorState()); } @@ -780,23 +780,23 @@ QString ServerController::checkSshConnection(const ServerCredentials &credential return stdOut; } -SshConnection *ServerController::connectToHost(const SshConnectionParameters &sshParams) +QSharedPointer ServerController::connectToHost(const SshConnectionParameters &sshParams) { - SshConnection *client = acquireConnection(sshParams); - if (!client) return nullptr; + QSharedPointer client(new SshConnection(sshParams)); + if (!client.get()) return nullptr; QEventLoop waitssh; - QObject::connect(client, &SshConnection::connected, &waitssh, [&]() { + QObject::connect(client.get(), &SshConnection::connected, &waitssh, [&]() { qDebug() << "Server connected by ssh"; waitssh.quit(); }); - QObject::connect(client, &SshConnection::disconnected, &waitssh, [&]() { + QObject::connect(client.get(), &SshConnection::disconnected, &waitssh, [&]() { qDebug() << "Server disconnected by ssh"; waitssh.quit(); }); - QObject::connect(client, &SshConnection::error, &waitssh, [&](QSsh::SshError error) { + QObject::connect(client.get(), &SshConnection::error, &waitssh, [&](QSsh::SshError error) { qCritical() << "Ssh error:" << error << client->errorString(); waitssh.quit(); }); @@ -839,12 +839,6 @@ void ServerController::setCancelInstallation(const bool cancel) m_cancelInstallation = cancel; } -void ServerController::disconnectFromHost(const ServerCredentials &credentials) -{ - SshConnection *client = acquireConnection(sshParams(credentials)); - if (client) client->disconnectFromHost(); -} - ErrorCode ServerController::setupServerFirewall(const ServerCredentials &credentials) { return runScript(credentials, diff --git a/client/core/servercontroller.h b/client/core/servercontroller.h index 94ab4efc..68d47417 100644 --- a/client/core/servercontroller.h +++ b/client/core/servercontroller.h @@ -31,7 +31,6 @@ public: ErrorCode fromSshProcessExitStatus(int exitStatus); QSsh::SshConnectionParameters sshParams(const ServerCredentials &credentials); - void disconnectFromHost(const ServerCredentials &credentials); ErrorCode removeAllContainers(const ServerCredentials &credentials); ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container); @@ -72,7 +71,7 @@ public: Vars genVarsForScript(const ServerCredentials &credentials, DockerContainer container = DockerContainer::None, const QJsonObject &config = QJsonObject()); QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr); - QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams); + QSharedPointer connectToHost(const QSsh::SshConnectionParameters &sshParams); void setCancelInstallation(const bool cancel); ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap &installedContainers); diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp index 0b02241c..187af9ee 100644 --- a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp @@ -45,7 +45,6 @@ void AdvancedServerSettingsLogic::onPushButtonClearServerClicked() } ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); - m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); if (e) { emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" + tr("Error message: ") + errorString(e) + "\n" + diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index cdfd1833..3dbd7b86 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -342,8 +342,6 @@ void UiLogic::installServer(QPair &container) errorCode = pageLogic()->doInstallAction(installAction, pageFunc, progressBarFunc, noButton, waitInfoFunc, busyInfoFunc, cancelButtonFunc); - m_serverController->disconnectFromHost(m_installCredentials); - if (errorCode == ErrorCode::NoError) { if (!isServerCreated) { QJsonObject server; @@ -534,7 +532,6 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool & QMap installedContainers; ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers); - m_serverController->disconnectFromHost(credentials); if (errorCode != ErrorCode::NoError) { return errorCode; } diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 6d8aa493..21643ae5 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -372,8 +372,6 @@ void VpnConnection::connectToVpn(int serverIndex, createProtocolConnections(); - m_serverController->disconnectFromHost(credentials); - e = m_vpnProtocol.data()->start(); if (e) emit VpnProtocol::Error; }