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

Exclude build folder from Swiftlint #5412

Merged
merged 1 commit into from
Nov 14, 2023
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
1 change: 1 addition & 0 deletions ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ included: # case-sensitive paths to include during linting. `--path` is ignored
excluded: # case-sensitive paths to ignore during linting. Takes precedence over `included`
- AdditionalAssets
- Assets
- Build
- Configurations
- MullvadVPNScreenshots

Expand Down
23 changes: 13 additions & 10 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
)

tunnelStore = TunnelStore(application: application)

tunnelManager = TunnelManager(
application: application,
tunnelStore: tunnelStore,
relayCacheTracker: relayCacheTracker,
accountsProxy: accountsProxy,
devicesProxy: devicesProxy,
apiProxy: apiProxy,
accessTokenManager: proxyFactory.configuration.accessTokenManager
)
tunnelManager = createTunnelManager(application: application)

let constraintsUpdater = RelayConstraintsUpdater()
relayConstraintsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in
Expand Down Expand Up @@ -122,6 +113,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
return true
}

private func createTunnelManager(application: UIApplication) -> TunnelManager {
return TunnelManager(
application: application,
tunnelStore: tunnelStore,
relayCacheTracker: relayCacheTracker,
accountsProxy: accountsProxy,
devicesProxy: devicesProxy,
apiProxy: apiProxy,
accessTokenManager: proxyFactory.configuration.accessTokenManager
)
}

private func setUpProxies(containerURL: URL) {
proxyFactory = REST.ProxyFactory.makeProxyFactory(
transportProvider: REST.AnyTransportProvider { [weak self] in
Expand Down
82 changes: 54 additions & 28 deletions ios/PacketTunnelCore/Actor/PacketTunnelActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,14 @@ extension PacketTunnelActor {
settings: Settings,
reason: ReconnectReason
) throws -> ConnectionState? {
let relayConstraints = settings.relayConstraints
let privateKey = settings.privateKey

switch state {
case .initial:
return ConnectionState(
selectedRelay: try selectRelay(
nextRelay: nextRelay,
relayConstraints: relayConstraints,
currentRelay: nil,
connectionAttemptCount: 0
),
relayConstraints: relayConstraints,
currentKey: privateKey,
return try makeConnectionStateInner(
nextRelay: nextRelay,
settings: settings,
keyPolicy: .useCurrent,
networkReachability: defaultPathObserver.defaultPath?.networkReachability ?? .undetermined,
connectionAttemptCount: 0
lastKeyRotation: nil
)

case var .connecting(connState), var .reconnecting(connState):
Expand All @@ -312,30 +303,25 @@ extension PacketTunnelActor {
fallthrough

case var .connected(connState):
let relayConstraints = settings.relayConstraints

connState.selectedRelay = try selectRelay(
nextRelay: nextRelay,
relayConstraints: relayConstraints,
currentRelay: connState.selectedRelay,
connectionAttemptCount: connState.connectionAttemptCount
)
connState.relayConstraints = relayConstraints
connState.currentKey = privateKey
connState.currentKey = settings.privateKey

return connState

case let .error(blockedState):
return ConnectionState(
selectedRelay: try selectRelay(
nextRelay: nextRelay,
relayConstraints: relayConstraints,
currentRelay: nil,
connectionAttemptCount: 0
),
relayConstraints: relayConstraints,
currentKey: privateKey,
return try makeConnectionStateInner(
nextRelay: nextRelay,
settings: settings,
keyPolicy: blockedState.keyPolicy,
networkReachability: blockedState.networkReachability,
connectionAttemptCount: 0,
lastKeyRotation: blockedState.lastKeyRotation
)

Expand All @@ -344,14 +330,52 @@ extension PacketTunnelActor {
}
}

/**
Create a connection state when `State` is either `.inital` or `.error`.

- Parameters:
- nextRelay: Next relay to connect to.
- settings: Current settings.
- keyPolicy: Current key that should be used by the tunnel.
- networkReachability: Network connectivity outside of tunnel.
- lastKeyRotation: Last time packet tunnel rotated the key.

- Returns: New connection state, or `nil` if new relay cannot be selected.
*/
private func makeConnectionStateInner(
nextRelay: NextRelay,
settings: Settings,
keyPolicy: KeyPolicy,
networkReachability: NetworkReachability,
lastKeyRotation: Date?
) throws -> ConnectionState? {
let relayConstraints = settings.relayConstraints
let privateKey = settings.privateKey

return ConnectionState(
selectedRelay: try selectRelay(
nextRelay: nextRelay,
relayConstraints: relayConstraints,
currentRelay: nil,
connectionAttemptCount: 0
),
relayConstraints: relayConstraints,
currentKey: privateKey,
keyPolicy: keyPolicy,
networkReachability: networkReachability,
connectionAttemptCount: 0,
lastKeyRotation: lastKeyRotation
)
}

/**
Select next relay to connect to based on `NextRelay` and other input parameters.

- Parameters:
- nextRelay: next relay to connect to.
- relayConstraints: relay constraints.
- currentRelay: currently selected relay.
- connectionAttemptCount: number of failed connection attempts so far.
- nextRelay: next relay to connect to.
- relayConstraints: relay constraints.
- currentRelay: currently selected relay.
- connectionAttemptCount: number of failed connection attempts so far.

- Returns: selector result that contains the credentials of the next relay that the tunnel should connect to.
*/
Expand Down Expand Up @@ -383,3 +407,5 @@ extension PacketTunnelActor {
}

extension PacketTunnelActor: PacketTunnelActorProtocol {}

// swiftlint:disable:this file_length