2020-12-26 15:03:51 +03:00
|
|
|
#ifndef VPNCONNECTION_H
|
|
|
|
|
#define VPNCONNECTION_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2025-12-02 11:46:24 +07:00
|
|
|
#include <QMetaObject>
|
2020-12-26 15:03:51 +03:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QScopedPointer>
|
2021-02-02 01:47:40 +03:00
|
|
|
#include <QRemoteObjectNode>
|
2023-08-08 19:02:41 -07:00
|
|
|
#include <QTimer>
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
#include "core/protocols/vpnProtocol.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"
|
2022-12-12 14:41:54 +01:00
|
|
|
|
2022-02-22 02:08:57 +03:00
|
|
|
#ifdef AMNEZIA_DESKTOP
|
2026-04-30 14:53:03 +08:00
|
|
|
#include "core/utils/ipcClient.h"
|
2022-02-22 02:08:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
2023-03-15 16:46:59 +03:00
|
|
|
#ifdef Q_OS_ANDROID
|
2026-04-30 14:53:03 +08:00
|
|
|
#include "core/protocols/androidVpnProtocol.h"
|
2023-03-15 16:46:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
using namespace amnezia;
|
2020-12-26 15:03:51 +03:00
|
|
|
|
|
|
|
|
class VpnConnection : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2026-04-30 14:53:03 +08:00
|
|
|
explicit VpnConnection(SecureServersRepository* serversRepository, SecureAppSettingsRepository* appSettingsRepository, QObject* parent = nullptr);
|
2021-02-18 15:00:41 +03:00
|
|
|
~VpnConnection() override;
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-01-09 19:55:16 +03:00
|
|
|
static QString bytesPerSecToText(quint64 bytes);
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
ErrorCode lastError() const;
|
2026-04-30 14:53:03 +08:00
|
|
|
Vpn::ConnectionState connectionState() const;
|
2021-02-18 15:00:41 +03:00
|
|
|
|
|
|
|
|
QSharedPointer<VpnProtocol> vpnProtocol() const;
|
|
|
|
|
|
2021-06-12 11:59:36 +03:00
|
|
|
const QString &remoteAddress() const;
|
2026-04-30 14:53:03 +08:00
|
|
|
void addSitesRoutes(const QString &gw, amnezia::RouteMode mode);
|
2021-06-12 11:59:36 +03:00
|
|
|
|
2023-03-15 16:46:59 +03:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
|
void restoreConnection();
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-10-26 12:59:20 +03:00
|
|
|
public slots:
|
2026-04-30 14:53:03 +08:00
|
|
|
void setRepositories(SecureServersRepository* serversRepository, SecureAppSettingsRepository* appSettingsRepository);
|
2026-05-15 12:33:36 +08:00
|
|
|
void connectToVpn(const QString &serverId, DockerContainer container, const QJsonObject &vpnConfiguration);
|
2026-02-19 13:21:49 +01:00
|
|
|
void reconnectToVpn();
|
2021-10-26 12:59:20 +03:00
|
|
|
void disconnectFromVpn();
|
|
|
|
|
|
2025-05-02 23:54:36 -07:00
|
|
|
void onKillSwitchModeChanged(bool enabled);
|
2025-11-30 18:49:16 -08:00
|
|
|
void disconnectSlots();
|
2023-08-08 16:41:00 -07:00
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
void setConnectionState(Vpn::ConnectionState state);
|
|
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
signals:
|
|
|
|
|
void bytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
2023-05-14 21:11:19 +08:00
|
|
|
void connectionStateChanged(Vpn::ConnectionState state);
|
2021-01-08 16:51:58 +03:00
|
|
|
void vpnProtocolError(amnezia::ErrorCode error);
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
void serviceIsNotReady();
|
|
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
protected slots:
|
|
|
|
|
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
2023-05-14 21:11:19 +08:00
|
|
|
void onConnectionStateChanged(Vpn::ConnectionState state);
|
2022-12-12 14:41:54 +01:00
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
protected:
|
2021-02-18 15:00:41 +03:00
|
|
|
QSharedPointer<VpnProtocol> m_vpnProtocol;
|
2021-01-26 15:01:15 +03:00
|
|
|
|
|
|
|
|
private:
|
2026-04-30 14:53:03 +08:00
|
|
|
SecureServersRepository* m_serversRepository;
|
|
|
|
|
SecureAppSettingsRepository* m_appSettingsRepository;
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
QJsonObject m_vpnConfiguration;
|
2021-06-01 18:18:09 +03:00
|
|
|
QJsonObject m_routeMode;
|
2021-06-12 11:59:36 +03:00
|
|
|
QString m_remoteAddress;
|
2023-08-08 19:02:41 -07:00
|
|
|
|
|
|
|
|
// Only for iOS for now, check counters
|
|
|
|
|
QTimer m_checkTimer;
|
2021-02-02 01:47:40 +03:00
|
|
|
|
2023-03-15 16:46:59 +03:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
|
AndroidVpnProtocol* androidVpnProtocol = nullptr;
|
|
|
|
|
|
2023-12-04 18:23:08 +03:00
|
|
|
AndroidVpnProtocol* createDefaultAndroidVpnProtocol();
|
2023-03-15 16:46:59 +03:00
|
|
|
void createAndroidConnections();
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-02-19 13:21:49 +01:00
|
|
|
Vpn::ConnectionState m_connectionState;
|
|
|
|
|
|
2023-03-15 16:46:59 +03:00
|
|
|
void createProtocolConnections();
|
2023-10-13 15:45:06 +05:00
|
|
|
|
|
|
|
|
void appendSplitTunnelingConfig();
|
2024-04-25 20:01:00 +07:00
|
|
|
void appendKillSwitchConfig();
|
2020-12-26 15:03:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // VPNCONNECTION_H
|