parent
a1a6185fd6
commit
5510ff7dce
4 changed files with 35 additions and 50 deletions
|
@ -15,7 +15,7 @@ public:
|
||||||
explicit IOSVpnProtocol(amnezia::Proto proto, const QJsonObject& configuration, QObject* parent = nullptr);
|
explicit IOSVpnProtocol(amnezia::Proto proto, const QJsonObject& configuration, QObject* parent = nullptr);
|
||||||
static IOSVpnProtocol* instance();
|
static IOSVpnProtocol* instance();
|
||||||
|
|
||||||
virtual ~IOSVpnProtocol() override = default;
|
virtual ~IOSVpnProtocol() override;
|
||||||
|
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,12 @@ IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QO
|
||||||
connect(this, &IOSVpnProtocol::newTransmittedDataCount, this, &IOSVpnProtocol::setBytesChanged);
|
connect(this, &IOSVpnProtocol::newTransmittedDataCount, this, &IOSVpnProtocol::setBytesChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IOSVpnProtocol::~IOSVpnProtocol()
|
||||||
|
{
|
||||||
|
qDebug() << "IOSVpnProtocol::~IOSVpnProtocol()";
|
||||||
|
IOSVpnProtocol::stop();
|
||||||
|
}
|
||||||
|
|
||||||
IOSVpnProtocol* IOSVpnProtocol::instance() {
|
IOSVpnProtocol* IOSVpnProtocol::instance() {
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
@ -158,9 +164,12 @@ void IOSVpnProtocol::checkStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_checkingStatus = true;
|
m_checkingStatus = true;
|
||||||
|
|
||||||
|
QPointer<IOSVpnProtocol> weakSelf = this;
|
||||||
|
|
||||||
[m_controller checkStatusWithCallback:^(NSString* serverIpv4Gateway, NSString* deviceIpv4Address,
|
[m_controller checkStatusWithCallback:^(NSString* serverIpv4Gateway, NSString* deviceIpv4Address,
|
||||||
NSString* configString) {
|
NSString* configString) {
|
||||||
|
if (!weakSelf) return;
|
||||||
QString config = QString::fromNSString(configString);
|
QString config = QString::fromNSString(configString);
|
||||||
|
|
||||||
m_checkingStatus = false;
|
m_checkingStatus = false;
|
||||||
|
@ -185,7 +194,7 @@ void IOSVpnProtocol::checkStatus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit newTransmittedDataCount(rxBytes, txBytes);
|
emit weakSelf->newTransmittedDataCount(rxBytes, txBytes);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
VpnConnection::VpnConnection(std::shared_ptr<Settings> settings,
|
VpnConnection::VpnConnection(std::shared_ptr<Settings> settings,
|
||||||
std::shared_ptr<VpnConfigurator> configurator, QObject* parent) : QObject(parent),
|
std::shared_ptr<VpnConfigurator> configurator, QObject* parent) : QObject(parent),
|
||||||
m_settings(settings),
|
m_settings(settings),
|
||||||
m_configurator(configurator),
|
m_configurator(configurator)
|
||||||
m_isIOSConnected(false)
|
|
||||||
{
|
{
|
||||||
|
m_checkTimer.setInterval(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
VpnConnection::~VpnConnection()
|
VpnConnection::~VpnConnection()
|
||||||
|
@ -96,31 +96,16 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState sta
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
if (state == VpnProtocol::Connected){
|
if (state == VpnProtocol::Connected) {
|
||||||
m_isIOSConnected = true;
|
m_checkTimer.start();
|
||||||
checkIOSStatus();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_isIOSConnected = false;
|
m_checkTimer.stop();
|
||||||
// m_receivedBytes = 0;
|
|
||||||
// m_sentBytes = 0;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
emit connectionStateChanged(state);
|
emit connectionStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
void VpnConnection::checkIOSStatus()
|
|
||||||
{
|
|
||||||
QTimer::singleShot(1000, [this]() {
|
|
||||||
if(m_isIOSConnected){
|
|
||||||
iosVpnProtocol->checkStatus();
|
|
||||||
checkIOSStatus();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const QString &VpnConnection::remoteAddress() const
|
const QString &VpnConnection::remoteAddress() const
|
||||||
{
|
{
|
||||||
return m_remoteAddress;
|
return m_remoteAddress;
|
||||||
|
@ -236,7 +221,6 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
||||||
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig, Proto proto,
|
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &containerConfig, Proto proto,
|
||||||
ErrorCode *errorCode)
|
ErrorCode *errorCode)
|
||||||
{
|
{
|
||||||
ErrorCode e = ErrorCode::NoError;
|
|
||||||
QMap<Proto, QString> lastVpnConfig = getLastVpnConfig(containerConfig);
|
QMap<Proto, QString> lastVpnConfig = getLastVpnConfig(containerConfig);
|
||||||
|
|
||||||
QString configData;
|
QString configData;
|
||||||
|
@ -246,19 +230,16 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
configData = m_configurator->genVpnProtocolConfig(credentials,
|
configData = m_configurator->genVpnProtocolConfig(credentials,
|
||||||
container, containerConfig, proto, &e);
|
container, containerConfig, proto, errorCode);
|
||||||
|
|
||||||
|
if (errorCode && *errorCode) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
QString configDataBeforeLocalProcessing = configData;
|
QString configDataBeforeLocalProcessing = configData;
|
||||||
|
|
||||||
configData = m_configurator->processConfigWithLocalSettings(serverIndex, container, proto, configData);
|
configData = m_configurator->processConfigWithLocalSettings(serverIndex, container, proto, configData);
|
||||||
|
|
||||||
|
|
||||||
if (errorCode && e) {
|
|
||||||
*errorCode = e;
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (serverIndex >= 0) {
|
if (serverIndex >= 0) {
|
||||||
qDebug() << "VpnConnection::createVpnConfiguration: saving config for server #" << serverIndex << container << proto;
|
qDebug() << "VpnConnection::createVpnConfiguration: saving config for server #" << serverIndex << container << proto;
|
||||||
QJsonObject protoObject = m_settings->protocolConfig(serverIndex, container, proto);
|
QJsonObject protoObject = m_settings->protocolConfig(serverIndex, container, proto);
|
||||||
|
@ -267,7 +248,6 @@ QString VpnConnection::createVpnConfigurationForProto(int serverIndex,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCode) *errorCode = e;
|
|
||||||
return configData;
|
return configData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,18 +255,15 @@ QJsonObject VpnConnection::createVpnConfiguration(int serverIndex,
|
||||||
const ServerCredentials &credentials, DockerContainer container,
|
const ServerCredentials &credentials, DockerContainer container,
|
||||||
const QJsonObject &containerConfig, ErrorCode *errorCode)
|
const QJsonObject &containerConfig, ErrorCode *errorCode)
|
||||||
{
|
{
|
||||||
ErrorCode e = ErrorCode::NoError;
|
|
||||||
QJsonObject vpnConfiguration;
|
QJsonObject vpnConfiguration;
|
||||||
|
|
||||||
|
|
||||||
for (ProtocolEnumNS::Proto proto : ContainerProps::protocolsForContainer(container)) {
|
for (ProtocolEnumNS::Proto proto : ContainerProps::protocolsForContainer(container)) {
|
||||||
QJsonObject vpnConfigData = QJsonDocument::fromJson(
|
QJsonObject vpnConfigData = QJsonDocument::fromJson(
|
||||||
createVpnConfigurationForProto(
|
createVpnConfigurationForProto(
|
||||||
serverIndex, credentials, container, containerConfig, proto, &e).toUtf8()).
|
serverIndex, credentials, container, containerConfig, proto, errorCode).toUtf8()).
|
||||||
object();
|
object();
|
||||||
|
|
||||||
if (e) {
|
if (errorCode && *errorCode) {
|
||||||
if (errorCode) *errorCode = e;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +313,7 @@ void VpnConnection::connectToVpn(int serverIndex,
|
||||||
|
|
||||||
ErrorCode e = ErrorCode::NoError;
|
ErrorCode e = ErrorCode::NoError;
|
||||||
|
|
||||||
m_vpnConfiguration = createVpnConfiguration(serverIndex, credentials, container, containerConfig);
|
m_vpnConfiguration = createVpnConfiguration(serverIndex, credentials, container, containerConfig, &e);
|
||||||
if (e) {
|
if (e) {
|
||||||
emit connectionStateChanged(VpnProtocol::Error);
|
emit connectionStateChanged(VpnProtocol::Error);
|
||||||
return;
|
return;
|
||||||
|
@ -356,16 +333,18 @@ void VpnConnection::connectToVpn(int serverIndex,
|
||||||
m_vpnProtocol.reset(androidVpnProtocol);
|
m_vpnProtocol.reset(androidVpnProtocol);
|
||||||
#elif defined Q_OS_IOS
|
#elif defined Q_OS_IOS
|
||||||
Proto proto = ContainerProps::defaultProtocol(container);
|
Proto proto = ContainerProps::defaultProtocol(container);
|
||||||
//if (iosVpnProtocol==NULL) {
|
auto iosVpnProtocol = new IOSVpnProtocol(proto, m_vpnConfiguration);
|
||||||
iosVpnProtocol = new IOSVpnProtocol(proto, m_vpnConfiguration);
|
|
||||||
//}
|
|
||||||
// IOSVpnProtocol *iosVpnProtocol = new IOSVpnProtocol(proto, m_vpnConfiguration);
|
|
||||||
if (!iosVpnProtocol->initialize()) {
|
if (!iosVpnProtocol->initialize()) {
|
||||||
qDebug() << QString("Init failed") ;
|
qDebug() << QString("Init failed") ;
|
||||||
emit VpnProtocol::Error;
|
emit VpnProtocol::Error;
|
||||||
|
iosVpnProtocol->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(&m_checkTimer, &QTimer::timeout, iosVpnProtocol, &IOSVpnProtocol::checkStatus);
|
||||||
m_vpnProtocol.reset(iosVpnProtocol);
|
m_vpnProtocol.reset(iosVpnProtocol);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
createProtocolConnections();
|
createProtocolConnections();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QRemoteObjectNode>
|
#include <QRemoteObjectNode>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "protocols/vpnprotocol.h"
|
#include "protocols/vpnprotocol.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
|
@ -85,10 +86,6 @@ protected slots:
|
||||||
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||||
void onConnectionStateChanged(VpnProtocol::VpnConnectionState state);
|
void onConnectionStateChanged(VpnProtocol::VpnConnectionState state);
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
void checkIOSStatus();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<VpnProtocol> m_vpnProtocol;
|
QSharedPointer<VpnProtocol> m_vpnProtocol;
|
||||||
|
|
||||||
|
@ -99,14 +96,14 @@ private:
|
||||||
QJsonObject m_vpnConfiguration;
|
QJsonObject m_vpnConfiguration;
|
||||||
QJsonObject m_routeMode;
|
QJsonObject m_routeMode;
|
||||||
QString m_remoteAddress;
|
QString m_remoteAddress;
|
||||||
bool m_isIOSConnected; //remove later move to isConnected,
|
|
||||||
|
// Only for iOS for now, check counters
|
||||||
|
QTimer m_checkTimer;
|
||||||
|
|
||||||
#ifdef AMNEZIA_DESKTOP
|
#ifdef AMNEZIA_DESKTOP
|
||||||
IpcClient *m_IpcClient {nullptr};
|
IpcClient *m_IpcClient {nullptr};
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
IOSVpnProtocol * iosVpnProtocol{nullptr};
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
AndroidVpnProtocol* androidVpnProtocol = nullptr;
|
AndroidVpnProtocol* androidVpnProtocol = nullptr;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue