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

Fixes tunnel startup options handling #489

Merged
merged 8 commits into from
Sep 12, 2023

Conversation

diegoreymendez
Copy link
Contributor

@diegoreymendez diegoreymendez commented Sep 3, 2023

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

@@ -65,7 +65,10 @@ public enum ExtensionMessage: RawRepresentable {
case .isHavingConnectivityIssues:
self = .isHavingConnectivityIssues
case .setSelectedServer:
guard data.count > 1 else { return nil }
Copy link
Contributor Author

@diegoreymendez diegoreymendez Sep 3, 2023

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.

Comment on lines -32 to -36
public enum NetworkProtectionOptionValue {
public static let `true` = "true" as NSString
}
Copy link
Contributor Author

@diegoreymendez diegoreymendez Sep 3, 2023

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 {
Copy link
Contributor Author

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.

Comment on lines +353 to +359
switch options.keyValidity {
case .set(let validity):
setKeyValidity(validity)
case .useExisting:
break
case .reset:
setKeyValidity(nil)
Copy link
Contributor Author

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.

Comment on lines +365 to +370
case .set(let selectedServer):
selectedServerStore.selectedServer = selectedServer
case .useExisting:
break
case .reset:
selectedServerStore.selectedServer = .automatic
Copy link
Contributor Author

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.

Comment on lines +376 to +384
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
Copy link
Contributor Author

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.

Comment on lines -394 to -399
var isOnDemand: Bool {
options?[NetworkProtectionOptionKey.isOnDemand] as? Bool == true
}
var isActivatedFromSystemSettings: Bool {
options?[NetworkProtectionOptionKey.activationAttemptId] == nil && !isOnDemand
}
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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!

@diegoreymendez diegoreymendez changed the title Fixes startup options reset Implements a better mechanism for handling statup options. Sep 11, 2023
@diegoreymendez diegoreymendez changed the title Implements a better mechanism for handling statup options. Fixes tunnel startup options handling Sep 11, 2023

let internalCompletionHandler = { [weak self] (error: Error?) in
if error != nil {
self?.connectionStatus = .disconnected
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@diegoreymendez diegoreymendez marked this pull request as ready for review September 11, 2023 14:37
Copy link
Contributor

@graeme graeme left a 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.

@diegoreymendez diegoreymendez self-assigned this Sep 12, 2023
@diegoreymendez diegoreymendez merged commit 6246a82 into main Sep 12, 2023
@diegoreymendez diegoreymendez deleted the diego/fix-startup-options-reset branch September 12, 2023 16:47
diegoreymendez added a commit to duckduckgo/macos-browser that referenced this pull request Sep 12, 2023
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.
diegoreymendez added a commit to duckduckgo/iOS that referenced this pull request Sep 12, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants