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 9, 2023
1 parent bb568e8 commit 960d99e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 36 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
28 changes: 16 additions & 12 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

configureLogging()

addressCache = REST.AddressCache(canWriteToCache: true, cacheDirectory: containerURL)
addressCache.loadFromFile()

setUpProxies(containerURL: containerURL)

let relayCache = RelayCache(cacheDirectory: containerURL)
relayCacheTracker = RelayCacheTracker(relayCache: relayCache, application: application, apiProxy: apiProxy)

addressCacheTracker = AddressCacheTracker(
application: application,
apiProxy: apiProxy,
store: addressCache
)
setUpCaches(application: application, containerURL: containerURL, relayCache: relayCache)

tunnelStore = TunnelStore(application: application)

Expand Down Expand Up @@ -122,6 +111,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
return true
}

private func setUpCaches(application: UIApplication, containerURL: URL, relayCache: RelayCache) {
addressCache = REST.AddressCache(canWriteToCache: true, cacheDirectory: containerURL)
addressCache.loadFromFile()

setUpProxies(containerURL: containerURL)

relayCacheTracker = RelayCacheTracker(relayCache: relayCache, application: application, apiProxy: apiProxy)

addressCacheTracker = AddressCacheTracker(
application: application,
apiProxy: apiProxy,
store: addressCache
)
}

private func setUpProxies(containerURL: URL) {
proxyFactory = REST.ProxyFactory.makeProxyFactory(
transportProvider: REST.AnyTransportProvider { [weak self] in
Expand Down
74 changes: 50 additions & 24 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 connectedState(
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 connectedState(
nextRelay: nextRelay,
settings: settings,
keyPolicy: blockedState.keyPolicy,
networkReachability: blockedState.networkReachability,
connectionAttemptCount: 0,
lastKeyRotation: blockedState.lastKeyRotation
)

Expand All @@ -344,6 +330,44 @@ extension PacketTunnelActor {
}
}

/**
Create a connection state.

- 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: selector result that contains the credentials of the next relay that the tunnel should connect to.
*/
private func connectedState(
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.

Expand Down Expand Up @@ -383,3 +407,5 @@ extension PacketTunnelActor {
}

extension PacketTunnelActor: PacketTunnelActorProtocol {}

// swiftlint:disable:this file_length

0 comments on commit 960d99e

Please sign in to comment.