mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-17 08:16:06 +03:00
* refactor: remove serverConfig struct * refactor: add warnings for api v1 configs * refactor: moved the server type definition to a separate namespace * refactor: simplified gateway stacks * fix: fixed server description * fix: fixed postAsync reply usage * fix: fixed validateConfig call * fix: fixed server name in notifications * fix: fixed initPrepareConfigHandler for lagacy configs
82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
#ifndef CONNECTIONCONTROLLER_H
|
|
#define CONNECTIONCONTROLLER_H
|
|
|
|
#include <QObject>
|
|
#include <QJsonObject>
|
|
#include <QPair>
|
|
#include <memory>
|
|
|
|
#include "core/utils/containerEnum.h"
|
|
#include "core/utils/containers/containerUtils.h"
|
|
#include "core/utils/protocolEnum.h"
|
|
#include "core/utils/errorCodes.h"
|
|
#include "core/utils/routeModes.h"
|
|
#include "core/utils/commonStructs.h"
|
|
#include "core/repositories/secureServersRepository.h"
|
|
#include "core/repositories/secureAppSettingsRepository.h"
|
|
#include "core/protocols/vpnProtocol.h"
|
|
#include "vpnConnection.h"
|
|
|
|
using namespace amnezia;
|
|
|
|
class ConnectionController : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ConnectionController(SecureServersRepository* serversRepository,
|
|
SecureAppSettingsRepository* appSettingsRepository,
|
|
VpnConnection* vpnConnection,
|
|
QObject* parent = nullptr);
|
|
~ConnectionController() = default;
|
|
|
|
ErrorCode prepareConnection(const QString &serverId,
|
|
QJsonObject& vpnConfiguration,
|
|
DockerContainer& container);
|
|
|
|
ErrorCode openConnection(const QString &serverId);
|
|
|
|
void closeConnection();
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
void restoreConnection();
|
|
#endif
|
|
|
|
void onKillSwitchModeChanged(bool enabled);
|
|
|
|
ErrorCode lastConnectionError() const;
|
|
|
|
bool isConnected() const;
|
|
void setConnectionState(Vpn::ConnectionState state);
|
|
|
|
QJsonObject createConnectionConfiguration(const QPair<QString, QString> &dns,
|
|
bool isApiConfig,
|
|
const QString &hostName,
|
|
const QString &description,
|
|
int configVersion,
|
|
const ContainerConfig &containerConfig,
|
|
DockerContainer container);
|
|
|
|
bool isServiceReady() const;
|
|
|
|
bool isContainerSupported(DockerContainer container) const;
|
|
|
|
signals:
|
|
void connectionStateChanged(Vpn::ConnectionState state);
|
|
void openConnectionRequested(const QString &serverId, DockerContainer container, const QJsonObject &vpnConfiguration);
|
|
void closeConnectionRequested();
|
|
void setConnectionStateRequested(Vpn::ConnectionState state);
|
|
void killSwitchModeChangedRequested(bool enabled);
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
void restoreConnectionRequested();
|
|
#endif
|
|
|
|
private:
|
|
SecureServersRepository* m_serversRepository;
|
|
SecureAppSettingsRepository* m_appSettingsRepository;
|
|
VpnConnection* m_vpnConnection;
|
|
};
|
|
|
|
#endif
|