Merge branch 'dev' of github.com:amnezia-vpn/amnezia-client into feature/new-gui

This commit is contained in:
vladimir.kuznetsov 2023-09-11 14:03:14 +05:00
commit 6bb85deca6
4 changed files with 25 additions and 29 deletions

View file

@ -72,7 +72,7 @@ private:
NETunnelProviderManager *m_currentTunnel{}; NETunnelProviderManager *m_currentTunnel{};
NSString *m_serverAddress{}; NSString *m_serverAddress{};
bool isOurManager(NETunnelProviderManager* manager); bool isOurManager(NETunnelProviderManager* manager);
void sendVpnExtensionMessage(NSDictionary* message, std::function<void(NSDictionary*)> callback); void sendVpnExtensionMessage(NSDictionary* message, std::function<void(NSDictionary*)> callback = nullptr);
#endif #endif
amnezia::Proto m_proto; amnezia::Proto m_proto;

View file

@ -55,7 +55,6 @@ IosController* s_instance = nullptr;
IosController::IosController() : QObject() IosController::IosController() : QObject()
{ {
qDebug() << "IosController::IosController() init";
s_instance = this; s_instance = this;
m_iosControllerWrapper = [[IosControllerWrapper alloc] initWithCppController:this]; m_iosControllerWrapper = [[IosControllerWrapper alloc] initWithCppController:this];
@ -78,8 +77,6 @@ IosController* IosController::Instance() {
bool IosController::initialize() bool IosController::initialize()
{ {
qDebug() << "IosController::initialize";
__block bool ok = true; __block bool ok = true;
[NETunnelProviderManager loadAllFromPreferencesWithCompletionHandler:^(NSArray<NETunnelProviderManager *> * _Nullable managers, NSError * _Nullable error) { [NETunnelProviderManager loadAllFromPreferencesWithCompletionHandler:^(NSArray<NETunnelProviderManager *> * _Nullable managers, NSError * _Nullable error) {
@try { @try {
@ -116,8 +113,6 @@ bool IosController::initialize()
bool IosController::connectVpn(amnezia::Proto proto, const QJsonObject& configuration) bool IosController::connectVpn(amnezia::Proto proto, const QJsonObject& configuration)
{ {
qDebug() << "IosController::connectVpn called from thread:" << QThread::currentThread();
m_proto = proto; m_proto = proto;
m_rawConfig = configuration; m_rawConfig = configuration;
m_serverAddress = configuration.value(config_key::hostName).toString().toNSString(); m_serverAddress = configuration.value(config_key::hostName).toString().toNSString();
@ -137,7 +132,6 @@ bool IosController::connectVpn(amnezia::Proto proto, const QJsonObject& configur
qDebug() << "IosController::connectVpn" << tunnelName; qDebug() << "IosController::connectVpn" << tunnelName;
// reset m_currentTunnel
m_currentTunnel = nullptr; m_currentTunnel = nullptr;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
@ -261,8 +255,6 @@ void IosController::vpnConfigurationDidChange(void *pNotification)
bool IosController::setupOpenVPN() bool IosController::setupOpenVPN()
{ {
qDebug() << "IosController::setupOpenVPN";
QJsonObject ovpn = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::OpenVpn)].toObject(); QJsonObject ovpn = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::OpenVpn)].toObject();
QString ovpnConfig = ovpn[config_key::config].toString(); QString ovpnConfig = ovpn[config_key::config].toString();
@ -271,7 +263,6 @@ bool IosController::setupOpenVPN()
bool IosController::setupCloak() bool IosController::setupCloak()
{ {
qDebug() << "IosController::setupCloak";
m_serverAddress = @"127.0.0.1"; m_serverAddress = @"127.0.0.1";
QJsonObject ovpn = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::OpenVpn)].toObject(); QJsonObject ovpn = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::OpenVpn)].toObject();
QString ovpnConfig = ovpn[config_key::config].toString(); QString ovpnConfig = ovpn[config_key::config].toString();
@ -309,7 +300,6 @@ bool IosController::setupCloak()
bool IosController::setupWireGuard() bool IosController::setupWireGuard()
{ {
qDebug() << "IosController::setupWireGuard";
QJsonObject config = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::WireGuard)].toObject(); QJsonObject config = m_rawConfig[ProtocolProps::key_proto_config_data(amnezia::Proto::WireGuard)].toObject();
QString wgConfig = config[config_key::config].toString(); QString wgConfig = config[config_key::config].toString();
@ -353,17 +343,13 @@ void IosController::startTunnel()
[m_currentTunnel saveToPreferencesWithCompletionHandler:^(NSError *saveError) { [m_currentTunnel saveToPreferencesWithCompletionHandler:^(NSError *saveError) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
qDebug() << "IosController::saveToPreferencesWithCompletionHandler called from thread:" << QThread::currentThread();
if (saveError) { if (saveError) {
qDebug() << "IosController::startOpenVPN : Connect OpenVPN Tunnel Save Error" << saveError.localizedDescription.UTF8String;
emit connectionStateChanged(Vpn::ConnectionState::Error); emit connectionStateChanged(Vpn::ConnectionState::Error);
return; return;
} }
[m_currentTunnel loadFromPreferencesWithCompletionHandler:^(NSError *loadError) { [m_currentTunnel loadFromPreferencesWithCompletionHandler:^(NSError *loadError) {
qDebug() << "IosController::loadFromPreferencesWithCompletionHandler called from thread:" << QThread::currentThread();
if (loadError) { if (loadError) {
qDebug() << "IosController::startOpenVPN : Connect OpenVPN Tunnel Load Error" << loadError.localizedDescription.UTF8String; qDebug() << "IosController::startOpenVPN : Connect OpenVPN Tunnel Load Error" << loadError.localizedDescription.UTF8String;
emit connectionStateChanged(Vpn::ConnectionState::Error); emit connectionStateChanged(Vpn::ConnectionState::Error);
@ -380,9 +366,7 @@ void IosController::startTunnel()
NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @""; NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @"";
NSDictionary* message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue}; NSDictionary* message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue};
sendVpnExtensionMessage(message, [&](NSDictionary* response){ sendVpnExtensionMessage(message);
qDebug() << "sendVpnExtensionMessage" << response;
});
BOOL started = [m_currentTunnel.connection startVPNTunnelWithOptions:nil andReturnError:&startError]; BOOL started = [m_currentTunnel.connection startVPNTunnelWithOptions:nil andReturnError:&startError];
@ -441,7 +425,7 @@ void IosController::sendVpnExtensionMessage(NSDictionary* message, std::function
void (^completionHandler)(NSData *) = ^(NSData *responseData) { void (^completionHandler)(NSData *) = ^(NSData *responseData) {
if (!responseData) { if (!responseData) {
callback(nil); if (callback) callback(nil);
return; return;
} }
@ -449,13 +433,13 @@ void IosController::sendVpnExtensionMessage(NSDictionary* message, std::function
NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&deserializeError]; NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&deserializeError];
if (response && [response isKindOfClass:[NSDictionary class]]) { if (response && [response isKindOfClass:[NSDictionary class]]) {
callback(response); if (callback) callback(response);
return; return;
} else if (deserializeError) { } else if (deserializeError) {
qDebug() << "Failed to deserialize the VpnExtension response"; qDebug() << "Failed to deserialize the VpnExtension response";
} }
callback(nil); if (callback) callback(nil);
}; };
NETunnelProviderSession *session = (NETunnelProviderSession *)m_currentTunnel.connection; NETunnelProviderSession *session = (NETunnelProviderSession *)m_currentTunnel.connection;

View file

@ -231,6 +231,24 @@ QString Settings::routeModeString(RouteMode mode) const
} }
} }
Settings::RouteMode Settings::routeMode() const
{
// TODO implement for mobiles
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
return RouteMode::VpnAllSites;
#endif
return static_cast<RouteMode>(m_settings.value("Conf/routeMode", 0).toInt());
}
Settings::RouteMode Settings::routeMode() const
{
// TODO implement for mobiles
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
return RouteMode::VpnAllSites;
#endif
return static_cast<RouteMode>(m_settings.value("Conf/routeMode", 0).toInt());
}
bool Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip) bool Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip)
{ {
QVariantMap sites = vpnSites(mode); QVariantMap sites = vpnSites(mode);

View file

@ -109,14 +109,8 @@ public:
QString routeModeString(RouteMode mode) const; QString routeModeString(RouteMode mode) const;
RouteMode routeMode() const RouteMode routeMode() const;
{ void setRouteMode(RouteMode mode) { m_settings.setValue("Conf/routeMode", mode); }
return static_cast<RouteMode>(m_settings.value("Conf/routeMode", 0).toInt());
}
void setRouteMode(RouteMode mode)
{
m_settings.setValue("Conf/routeMode", mode);
}
QVariantMap vpnSites(RouteMode mode) const QVariantMap vpnSites(RouteMode mode) const
{ {