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