Files
amnezia-client/client/protocols/vpnprotocol.h
T

101 lines
2.3 KiB
C++
Raw Normal View History

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;
2023-05-14 21:11:19 +08:00
//todo change name
namespace Vpn
{
Q_NAMESPACE
enum ConnectionState {
Unknown,
Disconnected,
Preparing,
Connecting,
Connected,
Disconnecting,
Reconnecting,
Error
};
Q_ENUM_NS(ConnectionState)
static void declareQmlVpnConnectionStateEnum() {
qmlRegisterUncreatableMetaObject(
Vpn::staticMetaObject,
"ConnectionState",
1, 0,
"ConnectionState",
"Error: only enums"
);
}
}
2020-12-26 15:03:51 +03:00
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
2023-05-14 21:11:19 +08:00
static QString textConnectionState(Vpn::ConnectionState 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;
2023-05-14 21:11:19 +08:00
Vpn::ConnectionState 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);
2023-05-14 21:11:19 +08:00
void connectionStateChanged(Vpn::ConnectionState 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-11-26 17:43:02 +03:00
public slots:
virtual void onTimeout(); // todo: remove?
void setBytesChanged(quint64 receivedBytes, quint64 sentBytes);
2023-05-14 21:11:19 +08:00
void setConnectionState(Vpn::ConnectionState state);
2020-12-26 15:03:51 +03:00
protected:
void startTimeoutTimer();
void stopTimeoutTimer();
2023-05-14 21:11:19 +08:00
Vpn::ConnectionState m_connectionState;
2021-11-30 21:51:06 +03:00
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