Skip to content

Commit

Permalink
Exclude build folder from Swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Nov 13, 2023
1 parent bb568e8 commit 4369ccb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 38 deletions.
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.
- relayConstraints: relay constraints.
- privateKey: WireGuard private key.
- connectionAttemptCount: number of failed connection attempts so far.

- 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

0 comments on commit 4369ccb

Please sign in to comment.