-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fixes tunnel startup options handling #489
Conversation
@@ -65,7 +65,10 @@ public enum ExtensionMessage: RawRepresentable { | |||
case .isHavingConnectivityIssues: | |||
self = .isHavingConnectivityIssues | |||
case .setSelectedServer: | |||
guard data.count > 1 else { return nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not have been ignored. It should have reset the selected server.
public enum NetworkProtectionOptionValue { | ||
public static let `true` = "true" as NSString | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can send bools as numbers which is the standard.
@@ -184,19 +190,22 @@ open class PacketTunnelProvider: NEPacketTunnelProvider { | |||
} | |||
|
|||
private func setKeyValidity(_ interval: TimeInterval?) { | |||
guard keyValidity != interval, | |||
let interval = interval else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nil
interval wasn't meant to bail out... it's meant to be a request to reset the key validity interval.
switch options.keyValidity { | ||
case .set(let validity): | ||
setKeyValidity(validity) | ||
case .useExisting: | ||
break | ||
case .reset: | ||
setKeyValidity(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have a basic mechanism to know whether we need to set the validity, use the existing one or reset it.
case .set(let selectedServer): | ||
selectedServerStore.selectedServer = selectedServer | ||
case .useExisting: | ||
break | ||
case .reset: | ||
selectedServerStore.selectedServer = .automatic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above but for server selection.
case .set(let authToken): | ||
try tokenStore.store(authToken) | ||
case .useExisting: | ||
break | ||
case .reset: | ||
// This case should in theory not be possible, but it's ideal to have this in place | ||
// in case an error in the controller on the client side allows it. | ||
try tokenStore.deleteToken() | ||
throw TunnelError.startingTunnelWithoutAuthToken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above but for the auth token.
var isOnDemand: Bool { | ||
options?[NetworkProtectionOptionKey.isOnDemand] as? Bool == true | ||
} | ||
var isActivatedFromSystemSettings: Bool { | ||
options?[NetworkProtectionOptionKey.activationAttemptId] == nil && !isOnDemand | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now handled within StartupOptions
.
if error != nil { | ||
self?.connectionStatus = .disconnected | ||
completionHandler(error) | ||
guard let error else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this condition using a guard so things moved around a bit... sorry!
|
||
let internalCompletionHandler = { [weak self] (error: Error?) in | ||
if error != nil { | ||
self?.connectionStatus = .disconnected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tis was moved to line 422. The diff in this file is really awful. Apologies!
@@ -342,32 +369,42 @@ open class PacketTunnelProvider: NEPacketTunnelProvider { | |||
let vendorOptions = provider?.providerConfiguration | |||
|
|||
loadRoutes(from: vendorOptions) | |||
self.isConnectionTesterEnabled = vendorOptions?[NetworkProtectionOptionKey.connectionTesterEnabled] as? Bool ?? true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not have been in vendor options. In fact it was not disabled in iOS due to this.
I've moved it to line 362 so it's part of the startup options instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Nice extraction of the options. Maybe have a look at those linter issues but I trust you to figure out whether to fix or whether they’re invalid.
Task/Issue URL: https://app.asana.com/0/0/1205465612515839/f BSK PR: duckduckgo/BrowserServicesKit#489 iOS PR: duckduckgo/iOS#2003 ## Description Fixes startup options reset, and improves the options loading logic so we can easily unit test it.
Network Protection: Connection Tester Task/Issue URL: https://app.asana.com/0/0/1205465612515839/f BSK PR: duckduckgo/BrowserServicesKit#489 macOS PR: duckduckgo/macos-browser#1581 ## Description Fixes startup options reset, and improves the options loading logic so we can easily unit test it.
Task/Issue URL: https://app.asana.com/0/0/1205466155643247/f
iOS PR: duckduckgo/iOS#2003
macOS PR: duckduckgo/macos-browser#1581
What kind of version bump will this require?: Patch
Description
Fixes tunnel startup options handling, and improves the options loading mechanism to make it unit testable.
Steps to test this PR
Follow the testing steps in the macOS and iOS PRs.
Internal references:
Software Engineering Expectations
Technical Design Template