Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIA-1291: Make wireguard the default option #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we apply this update only when the platform is not tvOS?


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

vpnProfileName = "Private Internet Access"
vpnReconnectionDelay = 2000

Expand Down
24 changes: 24 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
}
kp-laura-sempere marked this conversation as resolved.
Show resolved Hide resolved
#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,15 @@ extension Client.Preferences {
useWiFiProtection = true
trustCellularData = false
nmtMigrationSuccess = false

#if os(iOS)
vpnType = PIAWGTunnelProfile.vpnType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other comments: for tvOS we still want IKEv2 to be the default

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also have all references to PIAWGTunnelProfile inside the iOS condition since this class is not available on tvOS otherwise it won't compile on tvOS

#endif

#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
Loading