Skip to content

Commit

Permalink
Merge pull request #333 in ADGUARD-IOS/adguard-ios from bug/946_2 to …
Browse files Browse the repository at this point in the history
…master

* commit '503252cb2be9511ecac5c327c602ee94e09bcd50':
  version up
  fix issue with jumping dns server selection
  • Loading branch information
IvanIin committed Jul 10, 2019
2 parents d5128f7 + 503252c commit d355323
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion AdguardExtension/Adguard-Config.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Global product settings
AG_PRODUCT = AdGuard
AG_VERSION = 3.0.1
AG_BUILD = 155
AG_BUILD = 156

// URL scheme for receiving commands in Adguard main app from Safari
ADGUARD_URL_SCHEME = adguard
Expand Down
32 changes: 15 additions & 17 deletions AdguardExtension/AdguardApp/Services/APVPNManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ @implementation APVPNManager{
ACLExecuteBlockDelayed *_delayedSendNotify;

NETunnelProviderManager *_manager;
NETunnelProviderProtocol *_protocolConfiguration;
NSMutableArray *_observers;

BOOL _enabled;
Expand Down Expand Up @@ -572,12 +571,10 @@ - (void)loadConfiguration{
}

_manager = nil;
_protocolConfiguration = nil;
}
else {

_manager = managers[0];
_protocolConfiguration = (NETunnelProviderProtocol *)_manager.protocolConfiguration;
}
}
}
Expand Down Expand Up @@ -615,14 +612,11 @@ - (void)updateConfigurationForRemoteServer:(DnsServerInfo *)remoteServer tunnelM
remoteServer = self.defaultServer;
}

NETunnelProviderProtocol *protocol;
NETunnelProviderProtocol *protocol = (NETunnelProviderProtocol *)_manager.protocolConfiguration;
NETunnelProviderManager *newManager;

if (_protocolConfiguration) {
protocol = _protocolConfiguration;
}
else{

if (!protocol)
{
protocol = [NETunnelProviderProtocol new];
protocol.providerBundleIdentifier = AP_TUNNEL_ID;
}
Expand Down Expand Up @@ -707,7 +701,6 @@ - (void)removeVpnConfiguration {
}

_manager = nil;
_protocolConfiguration = nil;
}
}

Expand All @@ -723,7 +716,8 @@ - (void)setStatuses{

if (_manager) {

NSData *remoteDnsServerData = _protocolConfiguration.providerConfiguration[APVpnManagerParameterRemoteDnsServer];
NETunnelProviderProtocol * protocolConfiguration = (NETunnelProviderProtocol *)_manager.protocolConfiguration;
NSData *remoteDnsServerData = protocolConfiguration.providerConfiguration[APVpnManagerParameterRemoteDnsServer];

// Getting current settings from configuration.
//If settings are incorrect, then we assign default values.
Expand All @@ -734,14 +728,14 @@ - (void)setStatuses{
_resources.activeDnsServer = _activeDnsServer;

[self willChangeValueForKey:@"tunnelMode"];
_tunnelMode = _protocolConfiguration.providerConfiguration[APVpnManagerParameterTunnelMode] ?
[_protocolConfiguration.providerConfiguration[APVpnManagerParameterTunnelMode] unsignedIntValue] : APVpnManagerTunnelModeSplit;
_tunnelMode = protocolConfiguration.providerConfiguration[APVpnManagerParameterTunnelMode] ?
[protocolConfiguration.providerConfiguration[APVpnManagerParameterTunnelMode] unsignedIntValue] : APVpnManagerTunnelModeSplit;

[self didChangeValueForKey:@"tunnelMode"];
//-------------

_restartByReachability = _protocolConfiguration.providerConfiguration[APVpnManagerRestartByReachability] ?
[_protocolConfiguration.providerConfiguration[APVpnManagerRestartByReachability] boolValue] : NO; // NO by default
_restartByReachability = protocolConfiguration.providerConfiguration[APVpnManagerRestartByReachability] ?
[protocolConfiguration.providerConfiguration[APVpnManagerRestartByReachability] boolValue] : NO; // NO by default

NSString *connectionStatusReason = @"Unknown";

Expand Down Expand Up @@ -818,7 +812,9 @@ - (void)attachToNotifications{
if(!error) {
DDLogInfo(@"(APVPNManager) Notify that vpn configuration changed.");

[self setStatuses];
dispatch_sync(workingQueue, ^{
[self setStatuses];
});
} else {
DDLogError(@"(APVPNManager) Error loading vpn configuration: %@, %ld, %@", error.domain, error.code, error.localizedDescription);
_lastError = _standartError;
Expand All @@ -838,7 +834,9 @@ - (void)attachToNotifications{
if(!error) {
DDLogInfo(@"(APVPNManager) Notify that vpn connection status changed.");

[self setStatuses];
dispatch_sync(workingQueue, ^{
[self setStatuses];
});
} else {
DDLogError(@"(APVPNManager) Error loading vpn configuration: %@, %ld, %@", error.domain, error.code, error.localizedDescription);
_lastError = _standartError;
Expand Down

0 comments on commit d355323

Please sign in to comment.