-
Notifications
You must be signed in to change notification settings - Fork 268
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
fix(apple): sync tunnel configuration after saving #4338
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -123,10 +123,7 @@ public final class TunnelStore: ObservableObject { | |||
func createManager() async throws { | |||
let protocolConfiguration = NETunnelProviderProtocol() | |||
let manager = NETunnelProviderManager() | |||
let providerConfiguration = | |||
protocolConfiguration.providerConfiguration | |||
as? [String: String] |
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 was the a bug.
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.
Was it trying to read something that wasn't there?
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.
I think by default it's an empty dict []
which can be cast to [String: String]
, causing the conditional to evaluate true
.
Terraform Cloud Plan Output
|
Performance Test ResultsTCP
UDP
|
d70aeb0
to
d68d311
Compare
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 TunnelStore class is full of code smells still, but at least it's commented. Baby steps.
@@ -26,12 +26,12 @@ public final class SettingsViewModel: ObservableObject { | |||
public init(tunnelStore: TunnelStore, logger: AppLogger) { | |||
self.tunnelStore = tunnelStore | |||
self.logger = logger | |||
settings = Settings.defaultValue | |||
self.settings = tunnelStore.settings |
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.
Fixes another exposed race condition that we hit more often now because we connect faster and don't switch between states unless we need to.
} | ||
|
||
func loadSettings() { | ||
func setupObservers() { |
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.
Renamed to match the convention elsewhere
func loadSettings() { | ||
model.loadSettings() | ||
func reloadSettings() { | ||
model.settings = model.tunnelStore.settings |
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.
Not sure why this was rebinding settings each time... maybe a memory leak
import Foundation | ||
|
||
#if os(iOS) | ||
import UIKit.UIDevice | ||
#endif | ||
|
||
public class DeviceMetadata { | ||
// If firezone-id hasn't ever been written, the app is considered | ||
// to be launched for the first time. | ||
public static func firstTime() -> Bool { |
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.
Moved to DeviceMetadata since it doesn't really belong in TunnelStore
@@ -20,7 +20,7 @@ public enum KeychainError: Error { | |||
public actor Keychain { | |||
private let label = "Firezone token" | |||
private let description = "Firezone access token used to authenticate the client." | |||
private let service = "dev.firezone.firezone" | |||
private let service = Bundle.main.bundleIdentifier! |
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 updated just so that debug testing and release testing don't clobber each other's Keychain items.
static func fromProviderConfiguration(providerConfiguration: [String: Any]?) -> Settings { | ||
if let providerConfiguration = providerConfiguration as? [String: String] { | ||
return Settings( | ||
authBaseURL: providerConfiguration[TunnelStoreKeys.authBaseURL] | ||
?? Settings.defaultValue.authBaseURL, | ||
apiURL: providerConfiguration[TunnelStoreKeys.apiURL] ?? Settings.defaultValue.apiURL, | ||
apiURL: providerConfiguration[TunnelStoreKeys.apiURL] | ||
?? Settings.defaultValue.apiURL, |
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.
Cleanup
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.
I don't understand most of it and I just skimmed through it
@@ -27,12 +27,13 @@ struct Settings: Equatable { | |||
} | |||
|
|||
// Convert provider configuration (which may have empty fields if it was tampered with) to Settings | |||
static func fromProviderConfiguration(providerConfiguration: [String: String]?) -> Settings { | |||
if let providerConfiguration = providerConfiguration { | |||
static func fromProviderConfiguration(providerConfiguration: [String: Any]?) -> Settings { |
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.
Why did this change to Any?
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 take on the responsibility of casting in here instead of making the caller do it
// loadAllFromPreferences() returns list of tunnel configurations we created. Since our bundle ID | ||
// can change (by us), find the one that's current and ignore the others. | ||
// loadAllFromPreferences() returns list of tunnel configurations created by our bundle ID. | ||
// Since our bundle ID can change (by us), find the one that's current and ignore the others. |
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.
It can't change at runtime, right? This is talking about the ID changing after an update is installed?
The App Store doesn't use the bundle as a package ID? Is such a thing possible?
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.
Nah, this can't change at runtime. It's inexorably linked to other things in the App Store listing, so it wouldn't be easy to change.
One scenario we may want to change it though is if we build a different Network Extension for some reason (different transport, DNS proxy, content filter, etc) and want to include both or update this one's name.
@@ -123,10 +123,7 @@ public final class TunnelStore: ObservableObject { | |||
func createManager() async throws { | |||
let protocolConfiguration = NETunnelProviderProtocol() | |||
let manager = NETunnelProviderManager() | |||
let providerConfiguration = | |||
protocolConfiguration.providerConfiguration | |||
as? [String: String] |
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.
Was it trying to read something that wasn't there?
// Network Extensions don't have a 2-way binding up to the GUI process, | ||
// so we need to periodically ask the tunnel process for them. |
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.
Right, you mentioned that, now I remember.
ff503d2
to
b3a019b
Compare
Fixes #4321
Fixes #4339