2020-12-26 15:03:51 +03:00
|
|
|
#ifndef VPNPROTOCOL_H
|
|
|
|
|
#define VPNPROTOCOL_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
2021-02-18 15:00:41 +03:00
|
|
|
#include <QJsonObject>
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
#include "core/defs.h"
|
2021-10-04 19:07:49 +03:00
|
|
|
#include "containers/containers_defs.h"
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
using namespace amnezia;
|
|
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
|
|
class VpnProtocol : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2021-02-18 15:00:41 +03:00
|
|
|
explicit VpnProtocol(const QJsonObject& configuration, QObject* parent = nullptr);
|
2021-01-06 17:12:24 +03:00
|
|
|
virtual ~VpnProtocol() override = default;
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-11-30 16:56:24 +04:00
|
|
|
enum VpnConnectionState {Unknown, Disconnected, Preparing, Connecting, Connected, Disconnecting, Reconnecting, Error};
|
|
|
|
|
Q_ENUM(VpnConnectionState)
|
2020-12-26 23:17:20 +03:00
|
|
|
|
2021-11-30 16:56:24 +04:00
|
|
|
static QString textConnectionState(VpnConnectionState connectionState);
|
2020-12-26 23:17:20 +03:00
|
|
|
|
2021-10-04 19:07:49 +03:00
|
|
|
virtual ErrorCode prepare() { return ErrorCode::NoError; }
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
virtual bool isConnected() const;
|
|
|
|
|
virtual bool isDisconnected() const;
|
2021-01-06 17:12:24 +03:00
|
|
|
virtual ErrorCode start() = 0;
|
2020-12-26 15:03:51 +03:00
|
|
|
virtual void stop() = 0;
|
|
|
|
|
|
2021-11-30 16:56:24 +04:00
|
|
|
VpnConnectionState connectionState() const;
|
2021-01-06 17:12:24 +03:00
|
|
|
ErrorCode lastError() const;
|
2020-12-26 23:17:20 +03:00
|
|
|
QString textConnectionState() const;
|
2021-01-06 17:12:24 +03:00
|
|
|
void setLastError(ErrorCode lastError);
|
2020-12-26 23:17:20 +03:00
|
|
|
|
2021-01-26 15:01:15 +03:00
|
|
|
QString routeGateway() const;
|
|
|
|
|
QString vpnGateway() const;
|
|
|
|
|
|
2021-10-04 19:07:49 +03:00
|
|
|
static VpnProtocol* factory(amnezia::DockerContainer container, const QJsonObject &configuration);
|
|
|
|
|
|
2020-12-26 15:03:51 +03:00
|
|
|
signals:
|
|
|
|
|
void bytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
2021-11-30 16:56:24 +04:00
|
|
|
void connectionStateChanged(VpnProtocol::VpnConnectionState state);
|
2020-12-26 15:03:51 +03:00
|
|
|
void timeoutTimerEvent();
|
2021-01-08 16:51:58 +03:00
|
|
|
void protocolError(amnezia::ErrorCode e);
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-09-30 15:56:48 +03:00
|
|
|
// This signal is emitted when the controller is initialized. Note that the
|
|
|
|
|
// VPN tunnel can be already active. In this case, "connected" should be set
|
|
|
|
|
// to true and the "connectionDate" should be set to the activation date if
|
|
|
|
|
// known.
|
|
|
|
|
// If "status" is set to false, the backend service is considered unavailable.
|
|
|
|
|
void initialized(bool status, bool connected,
|
|
|
|
|
const QDateTime& connectionDate);
|
2020-12-26 15:03:51 +03:00
|
|
|
protected slots:
|
|
|
|
|
virtual void onTimeout();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void startTimeoutTimer();
|
|
|
|
|
void stopTimeoutTimer();
|
|
|
|
|
|
|
|
|
|
virtual void setBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
2021-11-30 16:56:24 +04:00
|
|
|
virtual void setConnectionState(VpnProtocol::VpnConnectionState state);
|
2020-12-26 15:03:51 +03:00
|
|
|
|
2021-11-30 16:56:24 +04:00
|
|
|
VpnConnectionState m_connectionState;
|
2021-01-26 15:01:15 +03:00
|
|
|
QString m_routeGateway;
|
2021-06-03 20:27:46 +03:00
|
|
|
QString m_vpnLocalAddress;
|
2021-01-26 15:01:15 +03:00
|
|
|
QString m_vpnGateway;
|
2020-12-26 23:17:20 +03:00
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
QJsonObject m_rawConfig;
|
|
|
|
|
|
2020-12-26 23:17:20 +03:00
|
|
|
private:
|
2020-12-26 15:03:51 +03:00
|
|
|
QTimer* m_timeoutTimer;
|
2021-01-06 17:12:24 +03:00
|
|
|
ErrorCode m_lastError;
|
2020-12-26 23:17:20 +03:00
|
|
|
quint64 m_receivedBytes;
|
|
|
|
|
quint64 m_sentBytes;
|
2020-12-26 15:03:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // VPNPROTOCOL_H
|