Skip to content

Commit

Permalink
PIA-1291: Make wireguard the default option
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-juan-docal committed Feb 7, 2024
1 parent 0e0b7c0 commit 18e340f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Sources/PIALibrary/Client+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ extension Client {
enablesServerPings = false
minPingInterval = 120000

availableVPNProfiles = []

#if os(tvOS)
availableVPNProfiles = [IKEv2Profile()]
#endif

vpnProfileName = "Private Internet Access"
vpnReconnectionDelay = 2000

Expand Down
21 changes: 21 additions & 0 deletions Sources/PIALibrary/Client+Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ extension Client {
allMaps[vpnType] = customConfiguration.serialized()
accessedDatabase.plain.vpnCustomConfigurationMaps = allMaps
}

#if os(iOS)
public func setVpnTypeToWireguard() {
self.vpnType = PIAWGTunnelProfile.vpnType
}
#endif

/// The `String` array of available WiFi networks
public fileprivate(set) var availableNetworks: [String] {
Expand Down Expand Up @@ -399,6 +405,16 @@ extension Client {
accessedDatabase.plain.timeToConnectVPN = newValue
}
}

/// Store a bool that represents whether we already attempted to migrate to wireguard
public var wireguardMigrationPerformed: Bool {
get {
return accessedDatabase.plain.wireguardMigrationPerformed
}
set {
accessedDatabase.plain.wireguardMigrationPerformed = newValue
}
}

/// Store a bool that represents the status of leak protection property
public var leakProtection: Bool {
Expand Down Expand Up @@ -481,7 +497,12 @@ extension Client.Preferences {
useWiFiProtection = true
trustCellularData = false
nmtMigrationSuccess = false
vpnType = PIAWGTunnelProfile.vpnType

#if os(tvOS)
vpnType = IKEv2Profile.vpnType
#endif

vpnDisconnectsOnSleep = false
vpnCustomConfigurations = [:]
availableNetworks = []
Expand Down
2 changes: 2 additions & 0 deletions Sources/PIALibrary/Persistence/PlainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protocol PlainStore: class {
var lastVPNConnectionAttempt: Double { get set }

var timeToConnectVPN: Double { get set }

var wireguardMigrationPerformed: Bool { get set }

var leakProtection: Bool { get set }

Expand Down
14 changes: 14 additions & 0 deletions Sources/PIALibrary/Persistence/UserDefaultsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
static let lastVPNConnectionAttempt = "lastVPNConnectionAttempt"

static let timeToConnectVPN = "timeToConnectVPN"

static let wireguardMigrationPerformed = "WireguardMigrationPerformed"

static let leakProtection = "LeakProtection"

Expand Down Expand Up @@ -441,6 +443,18 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
backend.set(newValue, forKey: Entries.timeToConnectVPN)
}
}

var wireguardMigrationPerformed: Bool {
get {
if backend.object(forKey: Entries.wireguardMigrationPerformed) == nil {
backend.set(false, forKey: Entries.wireguardMigrationPerformed)
}
return backend.bool(forKey: Entries.wireguardMigrationPerformed)
}
set {
backend.set(newValue, forKey: Entries.wireguardMigrationPerformed)
}
}

var leakProtection: Bool {
get {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PIALibrary/VPN/IKEv2Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class IKEv2Profile: NetworkExtensionProfile {
return NEVPNManager.shared()
}

init() {
public init() {
}

// MARK: VPNProfile
Expand Down
1 change: 1 addition & 0 deletions Sources/PIALibrary/VPN/PIATunnelProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class PIATunnelProfile: NetworkExtensionProfile {
callback?(error)
return
}

self.doSave(vpn, withConfiguration: configuration, force: true) { (error) in
if let _ = error {
callback?(error)
Expand Down
1 change: 1 addition & 0 deletions Sources/PIALibrary/VPN/PIAWGTunnelProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public class PIAWGTunnelProfile: NetworkExtensionProfile {
callback?(error)
return
}

self.doSave(vpn, withConfiguration: configuration, force: true) { (error) in
if let _ = error {
callback?(error)
Expand Down

0 comments on commit 18e340f

Please sign in to comment.