-
Notifications
You must be signed in to change notification settings - Fork 36
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
Improved IPC support #536
Merged
diegoreymendez
merged 12 commits into
main
from
diego/feature/change-netp-vpn-ownership-prototype
Oct 22, 2023
Merged
Improved IPC support #536
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9edda22
Implements tunnel IPC settings management through user defaults
diegoreymendez 7c93a88
Removes some old code and starts the tunnel with the correct tunnel s…
diegoreymendez 8e0084d
Adds support for includeAllNetworks through IPC
diegoreymendez bc0f82c
Adds support for excludeLocalNetworks
diegoreymendez 846b2ec
Adds support for sending test notifications
diegoreymendez a273b53
Adds support for expiring the registration key through IPC
diegoreymendez c5dd356
WIP
diegoreymendez 3eea64f
Merge branch 'main' into diego/feature/change-netp-vpn-ownership-prot…
diegoreymendez b0829a7
swiftlint --fix
diegoreymendez 81afb3a
Fixes the unit tests
diegoreymendez f1e7e1c
Removes some commented code
diegoreymendez 4089fc0
Merge branch 'main' into diego/feature/change-netp-vpn-ownership-prot…
diegoreymendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...es/BrowserServicesKit/SmarterEncryption/Store/HTTPSUpgrade.xcdatamodeld/.xccurrentversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>_XCCurrentVersionName</key> | ||
<string>HTTPSUpgrade 3.xcdatamodel</string> | ||
</dict> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ public enum ExtensionMessage: RawRepresentable { | |
public typealias RawValue = Data | ||
|
||
enum Name: UInt8 { | ||
// This is actually an improved way to send messages. | ||
// Please avoid adding new messages to this enum, and instead | ||
// add them to `ExtensionRequest` | ||
case request = 255 | ||
|
||
case resetAllState = 0 | ||
case getRuntimeConfiguration | ||
case getLastErrorMessage | ||
|
@@ -40,6 +45,11 @@ public enum ExtensionMessage: RawRepresentable { | |
case simulateConnectionInterruption | ||
} | ||
|
||
// This is actually an improved way to send messages. | ||
// Please avoid adding new messages to this enum, and instead | ||
// add them to `ExtensionRequest` | ||
case request(_ request: ExtensionRequest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment has it... |
||
|
||
// important: Preserve this order because Message Name is represented by Int value | ||
case resetAllState | ||
case getRuntimeConfiguration | ||
|
@@ -62,6 +72,12 @@ public enum ExtensionMessage: RawRepresentable { | |
public init?(rawValue data: Data) { | ||
let name = data.first.flatMap(Name.init(rawValue:)) | ||
switch name { | ||
case .request: | ||
guard let request = try? JSONDecoder().decode(ExtensionRequest.self, from: data[1...]) else { | ||
return nil | ||
} | ||
|
||
self = .request(request) | ||
case .resetAllState: | ||
self = .resetAllState | ||
case .getRuntimeConfiguration: | ||
|
@@ -127,6 +143,7 @@ public enum ExtensionMessage: RawRepresentable { | |
// TO BE: Replaced with auto case name generating Macro when Xcode 15 | ||
private var name: Name { | ||
switch self { | ||
case .request: return .request | ||
case .resetAllState: return .resetAllState | ||
case .getRuntimeConfiguration: return .getRuntimeConfiguration | ||
case .getLastErrorMessage: return .getLastErrorMessage | ||
|
@@ -149,6 +166,14 @@ public enum ExtensionMessage: RawRepresentable { | |
public var rawValue: Data { | ||
var encoder: (inout Data) -> Void = { _ in } | ||
switch self { | ||
case .request(let request): | ||
encoder = { | ||
do { | ||
try $0.append(JSONEncoder().encode(request)) | ||
} catch { | ||
assertionFailure("could not encode request: \(error)") | ||
} | ||
} | ||
case .setSelectedServer(.some(let serverName)): | ||
encoder = { | ||
$0.append(ExtensionMessageString(serverName).rawValue) | ||
|
29 changes: 29 additions & 0 deletions
29
Sources/NetworkProtection/ExtensionMessage/ExtensionRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// ExtensionRequest.swift | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum DebugCommand: Codable { | ||
case expireRegistrationKey | ||
case sendTestNotification | ||
} | ||
|
||
public enum ExtensionRequest: Codable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The advantage of using this is two folded:
|
||
case changeTunnelSetting(_ change: TunnelSettings.Change) | ||
case debugCommand(_ command: DebugCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Interesting, any reason why this changed?