mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
80 lines
2.5 KiB
C++
80 lines
2.5 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(int serverIndex,
|
|
QJsonObject& vpnConfiguration,
|
|
DockerContainer& container);
|
|
|
|
ErrorCode openConnection(int serverIndex);
|
|
|
|
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,
|
|
const ServerConfig &serverConfig,
|
|
const ContainerConfig &containerConfig,
|
|
DockerContainer container);
|
|
|
|
bool isServiceReady() const;
|
|
|
|
bool isContainerSupported(DockerContainer container) const;
|
|
|
|
signals:
|
|
void connectionStateChanged(Vpn::ConnectionState state);
|
|
void openConnectionRequested(int serverIndex, DockerContainer container, const QJsonObject &vpnConfiguration);
|
|
void switchConnectionRequested(int serverIndex, 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
|